使用rasterio获取单个点的像素值


14

要使用rasterio在栅格中的某个点上获得单个像素值,请参见此处的示例:https : //github.com/mapbox/rasterio/pull/275

但是,在rasterio(而不是cli)中是否有直接API可用于在栅格中的单个点提取值?

-编辑

with rasterio.drivers():

    # Read raster bands directly to Numpy arrays.
    #
    with rasterio.open('C:\\Users\\rit\\38ERP.tif') as src:
        x = (src.bounds.left + src.bounds.right) / 2.0
        y = (src.bounds.bottom + src.bounds.top) / 2.0

        vals = src.sample((x, y))
        for val in vals:
            print list(val)

Answers:


12

支持rio-sample命令的Python API方法在此处记录:https : //rasterio.readthedocs.io/en/latest/api/rasterio._io.html#rasterio._io.DatasetReaderBase.sample

src.sample() 对x,y元组进行迭代,因此: for val in src.sample([(x, y)]): print(val)


谢谢!我在语法上遇到麻烦。应该是:vals = src.sample((x, y))还是vals = src.sample(x, y)?似乎都无法正常工作
user1186 '16

我上面的问题中添加了代码
user1186 '16

4
src.sample()x, y元组上使用迭代器,这样做for val in src.sample([(x, y)]): print(val)
sgillies '16
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.