Converting pixel position to geographical coordinates (lat, long) for a Sentinel-1 SAR image

我的未来我决定 提交于 2019-12-06 13:27:42

问题


How can i get the geographical coordinates from x,y position in a Sentinel-1 Synthetic Aperture Radar (SAR) satellite image?

For example, I can access a downloaded image info sg as

from snappy import ProductIO
from snappy import PixelPos 
path='path_name'
product = ProductIO.readProduct(path)
sg = product.getSceneGeoCoding()

But how can I get latitude and longitude for a desired point (x, y) in sg using ESA's snap engine within Python?


回答1:


Using the custom function below, we can easily convert any point inside our image sg to its coordinates (latitude,longitude):

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

UPD: Because of various snap version updates, function above may not be working properly. Function below should work most of the times.

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

E.g. for the given sg product, we can get coordinates of pixel (x=12000, y=2000) as

latitude, longitude = LatLon_from_XY(sg, 12000, 2000)


来源:https://stackoverflow.com/questions/51046217/converting-pixel-position-to-geographical-coordinates-lat-long-for-a-sentinel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!