python - 将 Sentinel-1 SAR 图像的地理坐标(经纬度)转换为像素位置 (x,y)
问题描述
如何从 Sentinel-1 合成孔径雷达 (SAR) 卫星图像中的地理坐标获取 (x, y) 像素位置?
我可以访问下载的图像信息 sg
from snappy import ProductIO
path='path_name'
product = ProductIO.readProduct(path)
sg = product.getSceneGeoCoding()
但是,如何在 Python 中使用 ESA 的 snap 引擎获得所需纬度和经度的 (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
UPD:下面的更新功能应该适用于更多快照版本
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)
推荐阅读
- recursion - 在 Prolog 中检查家谱的后代
- javascript - 单击链接时如何将文本作为参数附加到 url?
- typescript - ES6 typescript 将所有导出的常量导入为数组
- python - Pandas - 如何获取数据帧中多列的行总和
- python - 使用 Python 中的单行 for 循环将数字转换为数字数组
- scala - Scala中用户定义对象的类型
- chart.js - Chart.js v2:如何让工具提示总是出现在折线图上?
- opencv - 如何从还有其他矩形对象的图像中提取手机屏幕?
- php - Dompdf 在实时服务器中不起作用(使用 Laravel)
- java - 我在线程“main”java.util.InputMismatchException 中收到此错误消息异常