获取像素质心的纬度/经度

时间:2018-06-28 14:51:46

标签: python geocoding latitude-longitude centroid

下面我在Python中有一个代码。 它给出像素最左角的经度和纬度。 我需要质心的经/纬度值。 请给我提意见。我是Python的初学者。 有没有出路?

from osgeo import gdal
# Open raster file

ds = gdal.Open('C:\\Users\\ADMIN\\Desktop\\datanew\\ndvi_alig_landsat_clipped.img')
# GDAL affine transform parameters, According to gdal documentation xoff/yoff 
#are image left corner, a/e are pixel wight/height and b/d is rotation and is 
#zero if image is north up. 
xoff, a, b, yoff, d, e = ds.GetGeoTransform() 
def pixel2coord(x, y):
"""Returns global coordinates from pixel x, y coords"""   
xp = a * x + b * y + xoff
yp = d * x + e * y + yoff
return(xp, yp)
# get columns and rows of your image from gdalinfo
rows = 15381+1
colms = 15081+1

if __name__ == "__main__":
for row in  range(0,rows):
    for col in  range(0,colms): 
        print pixel2coord(col,row)'

0 个答案:

没有答案