代码之家  ›  专栏  ›  技术社区  ›  Ioannis Nasios

将sentinel-1sar图像的地理坐标(长,纬度)转换为像素位置(x,y)

  •  1
  • Ioannis Nasios  · 技术社区  · 8 年前

    如何从sentinel-1合成孔径雷达(sar)卫星图像中的地理坐标获取(x,y)像素位置?

    我可以访问下载的图像信息sg as

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

    但是,如何在python中使用esa的snap引擎获得所需经纬度的(x,y)像素位置呢?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Ioannis Nasios    7 年前

    使用下面的自定义函数,我们可以轻松地将图像中的任意位置(纬度、经度)转换为它的(x、y)位置, 如果经纬度在我们产品的范围内 是的。

    from snappy import GeoPos
    def XY_from_LatLon(ProductSceneGeoCoding, latitude, longitude):
        #From Latitude, Longitude satellite image (SAR), get the x, y position in image
        pixelPos = ProductSceneGeoCoding.getPixelPos(GeoPos(latitude, longitude), None)
        x = pixelPos.getX()
        y = pixelPos.getY()
        if str(x)=='nan':
            raise ValueError('Latitude or Longitude out of this product')
        else:
            return x, y
    

    升级版: 下面更新的函数应该可以用于更多快照版本

    import jpy
    import snappy
    def XY_from_LatLon(ProductSceneGeoCoding, latitude, longitude):
        geoPosType = jpy.get_type('org.esa.snap.core.datamodel.PixelPos')
        geocoding = ProductSceneGeoCoding.getSceneGeoCoding()
        pixel_pos = geocoding.getPixelPos(snappy.GeoPos(latitude, longitude), geoPosType())
        if str(pixel_pos.x)=='nan':
            raise ValueError('Latitude or Longitude out of this product')
        else:
            return int(np.round(pixel_pos.x)), int(np.round(pixel_pos.y))
    

    例如,对于下面给出的产品(如中所示 scihub 这是希腊南部的一个产品),我们可以得到雅典坐标(纬度=37.9838,经度=23.7275)图像中的(x,y)位置

    产品名称:s1a_iw_grdh_1sdv_20170821t162310_20170821t162335_018024_01e414_c88b

    path='path to S1A_IW_GRDH_1SDV_20170821T162310_20170821T162335_018024_01E414_C88B.SAFE'
    product = ProductIO.readProduct(path)
    sg = product.getSceneGeoCoding()
    x, y = XY_from_LatLon(sg, 37.9838, 23.7275)
    x, y
    # (13705.242822312131, 14957.933651457932)