柵格:訪問地理空間柵格數據?

地理信息系統使用geotiff和其他格式來組織和存儲柵格柵格數據集,如衛星圖像和地形模型。Rasterio讀取和寫入這些格式,并提供基于numpy n維數組和geojson的python API。

下面是一個示例程序,它提取柵格有效數據足跡的geojson形狀。

import rasterio
import rasterio.features
import rasterio.warp

with rasterio.open('example.tif') as dataset:

    # Read the dataset's valid data mask as a ndarray.
    mask = dataset.dataset_mask()

    # Extract feature shapes and values from the array.
    for geom, val in rasterio.features.shapes(
            mask, transform=dataset.transform):

        # Transform shapes from the dataset's own coordinate
        # reference system to CRS84 (EPSG:4326).
        geom = rasterio.warp.transform_geom(
            dataset.crs, 'EPSG:4326', geom, precision=6)

        # Print GeoJSON shapes to stdout.
        print(geom)

程序輸出:

{'type': 'Polygon', 'coordinates': [[(-77.730817, 25.282335), ...]]}

Rasterio支持2.7和3.3或更高版本的python。