【问题标题】:Python | How do i get the pixel values from an geotiff map by coordinate蟒蛇 |如何通过坐标从 geotiff 地图中获取像素值
【发布时间】:2020-05-24 09:24:00
【问题描述】:

我正在尝试使用 geotiff 地图中的坐标获取像素值 (RGB)。

我在这里下载了一张栅格地图: https://www.naturalearthdata.com/downloads/10m-raster-data/10m-natural-earth-2/

我想获取例如这些坐标的像素值 lat: 41.902782, lon: 12.496366(这里应该是罗马)

我已经尝试过 rasterio 和 gdal 但没有成功。下载附带一个 .tfw 文件,但我无法包含它,所以我想知道我的 Python 脚本中的坐标是否准确。

所以最后我可以得到世界上每一平方米的 rgb 值 但是简单打印一个坐标的 rgb 值将是一个好的开始

每一个答案我都会很高兴:)

【问题讨论】:

  • 我已经尝试了 rasterio 和 gdal,但没有成功。 然后问那些尝试,不是吗?就目前而言,这太宽泛/模糊了。请参阅:How to Asktourhelp center

标签: python geolocation geocoding geo geotiff


【解决方案1】:
import rasterio

def getCoordinatePixel(map,lon,lat):
    # open map
    dataset = rasterio.open(map)
    # get pixel x+y of the coordinate
    py, px = dataset.index(lon, lat)
    # create 1x1px window of the pixel
    window = rasterio.windows.Window(px - 1//2, py - 1//2, 1, 1)
    # read rgb values of the window
    clip = dataset.read(window=window)
    return(clip[0][0][0],clip[1][0][0],clip[2][0][0])

print(getCoordinatePixel("world.tif",0,0))

此代码为您提供地图上坐标的像素 rgb 值

现在我只需要计算每个纬度和经度中的米数:)

【讨论】:

    猜你喜欢
    • 2018-10-15
    • 2018-04-25
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    • 2014-07-16
    相关资源
    最近更新 更多