栅格:访问地理空间栅格数据

地理信息系统使用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。