[英]calculate latitude and longitude from a geotiff image
How can I calculate mean latitude and mean longitude of each block from a geotiff
image separating it into regular blocks (say, 50 by 50 pixels). 如何从将其分成规则块(例如50 x 50像素)的
geotiff
图像中计算每个块的平均纬度和平均经度。
The input data is just the imagery,for example as downloaded from: http://eoimages.gsfc.nasa.gov/images/imagerecords/57000/57752/land_shallow_topo_2048.tif 输入数据仅是图像,例如从以下位置下载的图像: http : //eoimages.gsfc.nasa.gov/images/imagerecords/57000/57752/land_shallow_topo_2048.tif
This can be opened into python using gdal as folows: 可以使用gdal将其打开到python中:
import gdal
geotiff = gdal.Open ('land_shallow_topo_2048.tif')
colum_numbers,row_numbers,band_numbers=geotiff.RasterXSize,
geotiff.RasterYSize,geotiff.RasterCount
print (colum_numbers,row_numbers,band_numbers)
2048 1024 3
Take a look at this question: Obtain Latitude and Longitude from a GeoTIFF File 看一下这个问题: 从GeoTIFF文件中获取经度和纬度
Since your image is already in lat-lon coordinates, the following values should be in lat-lon: 由于您的图像已经在纬度坐标中,因此以下值应在纬度中:
gt = geotiff.GetGeoTransform()
minx = gt[0]
miny = gt[3] + width*gt[4] + height*gt[5]
maxx = gt[0] + width*gt[1] + height*gt[2]
maxy = gt[3]
Now the size of a pixel is: 现在一个像素的大小是:
latPxSz = (maxy - miny) / row_numbers
lonPxSz = (maxx - minx) / column_numbers
The center of a 50x50 box that is i
box rows and j
box columns away from the corner is: 一个50x50的框的中心是
i
框行, j
框列距角是:
boxCenterLat = (i + 0.5) * 50 * latPxSz + miny
boxCenterLon = (j + 0.5) * 50 * lonPxSz + minx
If you are using some other coordinate system, you can achieve a similar result by doing the transformation from the other, similar, question. 如果您正在使用其他坐标系,则可以通过从另一个类似的问题进行转换来获得相似的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.