使用下面的自定义函数,我们可以轻松地转换图像中的任何点
sg
坐标(纬度、经度):
def LatLon_from_XY(ProductSceneGeoCoding, x, y):
#From x,y position in satellite image (SAR), get the Latitude and Longitude
geopos = ProductSceneGeoCoding.getGeoPos(PixelPos(x, y), None)
latitude = geopos.getLat()
longitude = geopos.getLon()
return latitude, longitude
升级版:
由于各种快照版本更新,上面的函数可能无法正常工作。下面的函数在大多数情况下都应该有效。
def LatLon_from_XY(product, x, y):
geoPosType = jpy.get_type('org.esa.snap.core.datamodel.GeoPos')
geocoding = product.getSceneGeoCoding()
geo_pos = geocoding.getGeoPos(snappy.PixelPos(x, y), geoPosType())
if str(geo_pos.lat)=='nan':
raise ValueError('x, y pixel coordinates not in this product')
else:
return geo_pos.lat, geo_pos.lon
例如,对于给定的
SG公司
积,我们可以得到像素的坐标(x=12000,y=2000)
latitude, longitude = LatLon_from_XY(sg, 12000, 2000)