python - 将 Sentinel-1 SAR 图像的地理坐标(经度、纬度)转换为像素位置(x、y)

标签 python geolocation sentinel1 snap-python sentinel2

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

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

from snappy import ProductIO

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

但是如何使用 Python 中的 ESA 捕捉引擎获得所需纬度和经度的 (x, y) 像素位置?

最佳答案

使用下面的自定义函数,我们可以轻松地将任何(纬度、经度)转换为其在图像中的 (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

更新: 下面更新的功能应该适用于更多 snap 版本

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 中看到的,它是希腊南部的产品),我们可以获得雅典坐标图像中的 (x, y) 位置(纬度=37.9838,经度=23.7275):

产品名称: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)

关于python - 将 Sentinel-1 SAR 图像的地理坐标(经度、纬度)转换为像素位置(x、y),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51194477/

相关文章:

python - Django Rest Framework - 如何限制使用 Geolocation 返回的结果?

android - Geolocation Ionic 3 总是返回 "{}"

python - 将 Sentinel-1 SAR 图像的像素位置转换为地理坐标(纬度、经度)

python - 如何通过域 django 传输 session 变量?

python - sigmoid激活函数可以用来解决Keras中的回归问题吗?

python - TLS v 1.1 MAC 计算

python - linux 文件中每行下面的总和行

node.js - 如何将 EPSG 坐标转换为纬度/经度?