跳转到主要内容

用于与Numpy和SciPy一起使用的快速直接栅格I/O

项目描述

Rasterio读取和写入地理空间栅格数据。

https://github.com/rasterio/rasterio/actions/workflows/tests.yaml/badge.svg https://github.com/rasterio/rasterio/actions/workflows/test_gdal_latest.yaml/badge.svg https://github.com/rasterio/rasterio/actions/workflows/test_gdal_tags.yaml/badge.svg https://img.shields.io/pypi/v/rasterio

地理信息系统使用GeoTIFF和其他格式来组织和存储栅格数据集。Rasterio读取和写入这些格式,并提供基于N-D数组的Python API。

Rasterio 1.4与Python >= 3.9、Numpy >= 1.24和GDAL >= 3.5兼容。PyPI上提供了Linux、macOS和Windows的官方二进制包,包括大多数内置格式驱动程序以及HDF5、netCDF和OpenJPEG2000。

阅读文档以获取更多详细信息: https://rasterio.readthedocs.io/.

示例

以下是一些Rasterio提供的基本功能的示例。从图像中读取三个波段并平均,产生类似全色波段的图像。然后将新波段写入新的单波段TIFF。

import numpy as np
import rasterio

# Read raster bands directly to Numpy arrays.
#
with rasterio.open('tests/data/RGB.byte.tif') as src:
    r, g, b = src.read()

# Combine arrays in place. Expecting that the sum will
# temporarily exceed the 8-bit integer range, initialize it as
# a 64-bit float (the numpy default) array. Adding other
# arrays to it in-place converts those arrays "up" and
# preserves the type of the total array.
total = np.zeros(r.shape)

for band in r, g, b:
    total += band

total /= 3

# Write the product as a raster band to a new 8-bit file. For
# the new file's profile, we start with the meta attributes of
# the source file, but then change the band count to 1, set the
# dtype to uint8, and specify LZW compression.
profile = src.profile
profile.update(dtype=rasterio.uint8, count=1, compress='lzw')

with rasterio.open('example-total.tif', 'w', **profile) as dst:
    dst.write(total.astype(rasterio.uint8), 1)

输出

http://farm6.staticflickr.com/5501/11393054644_74f54484d9_z_d.jpg

API概述

Rasterio提供对地理空间栅格文件属性的访问。

with rasterio.open('tests/data/RGB.byte.tif') as src:
    print(src.width, src.height)
    print(src.crs)
    print(src.transform)
    print(src.count)
    print(src.indexes)

# Printed:
# (791, 718)
# {u'units': u'm', u'no_defs': True, u'ellps': u'WGS84', u'proj': u'utm', u'zone': 18}
# Affine(300.0379266750948, 0.0, 101985.0,
#        0.0, -300.041782729805, 2826915.0)
# 3
# [1, 2, 3]

一个Rasterio数据集还提供了一些方法,用于根据地理参考坐标获取读写窗口(类似于扩展数组切片)。

with rasterio.open('tests/data/RGB.byte.tif') as src:
    window = src.window(*src.bounds)
    print(window)
    print(src.read(window=window).shape)

# Printed:
# Window(col_off=0.0, row_off=0.0, width=791.0000000000002, height=718.0)
# (3, 718, 791)

Rasterio CLI

Rasterio的命令行界面,名为“rio”,在cli.rst中有文档。它的“rio insp”命令可以打开任何栅格数据集的引擎盖,以便您可以使用Python进行探索。

$ rio insp tests/data/RGB.byte.tif
Rasterio 0.10 Interactive Inspector (Python 3.4.1)
Type "src.meta", "src.read(1)", or "help(src)" for more information.
>>> src.name
'tests/data/RGB.byte.tif'
>>> src.closed
False
>>> src.shape
(718, 791)
>>> src.crs
{'init': 'epsg:32618'}
>>> b, g, r = src.read()
>>> b
masked_array(data =
 [[-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 ...,
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]
 [-- -- -- ..., -- -- --]],
             mask =
 [[ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 ...,
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]
 [ True  True  True ...,  True  True  True]],
       fill_value = 0)

>>> np.nanmin(b), np.nanmax(b), np.nanmean(b)
(0, 255, 29.94772668847656)

Rio插件

Rio 提供了使用插件创建子命令的功能。有关构建插件的更多信息,请参阅cli.rst

请参阅插件注册表以获取可用插件列表。

安装

请参阅docs/installation.rst

支持

关于 Rasterio 的安装和使用问题的主要论坛是 https://rasterio.groups.io/g/main。作者和其他用户将在有专业知识分享和时间解释时回答问题。请花时间精心构思一个问题,并对回复保持耐心。

请勿将这些问题提交到 Rasterio 的问题跟踪器,我们希望将其保留为错误报告和其他可操作问题。

开发和测试

请参阅CONTRIBUTING.rst

文档

请参阅docs/

许可协议

请参阅LICENSE.txt

作者

rasterio 项目始于 Mapbox,并于 2021 年 10 月转移到 rasterio Github 组织。

请参阅AUTHORS.txt

变更

请参阅CHANGES.txt

谁在使用 Rasterio?

请参阅这里

项目详情


发布历史 发布通知 | RSS 源

下载文件

下载适用于您平台的文件。如果您不确定选择哪一个,请了解更多关于 安装包的信息

源分布

rasterio-1.4.1.tar.gz (440.9 kB 查看哈希值)

上传时间 源代码

构建的发行版

rasterio-1.4.1-cp313-cp313-win_amd64.whl (25.3 MB 查看哈希值)

上传时间 CPython 3.13 Windows x86-64

rasterio-1.4.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.2 MB 查看哈希值)

上传时间 CPython 3.13 manylinux: glibc 2.17+ x86-64

rasterio-1.4.1-cp313-cp313-macosx_11_0_arm64.whl (18.9 MB 查看哈希值)

上传时间 CPython 3.13 macOS 11.0+ ARM64

rasterio-1.4.1-cp313-cp313-macosx_10_15_x86_64.whl (21.5 MB 查看哈希值)

上传时间 CPython 3.13 macOS 10.15+ x86-64

rasterio-1.4.1-cp312-cp312-win_amd64.whl (25.3 MB 查看哈希值)

上传时间 CPython 3.12 Windows x86-64

rasterio-1.4.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.2 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ x86-64

rasterio-1.4.1-cp312-cp312-macosx_11_0_arm64.whl (18.9 MB 查看哈希值)

上传时间 CPython 3.12 macOS 11.0+ ARM64

rasterio-1.4.1-cp312-cp312-macosx_10_15_x86_64.whl (21.5 MB 查看哈希值)

上传时间 CPython 3.12 macOS 10.15+ x86-64

rasterio-1.4.1-cp311-cp311-win_amd64.whl (25.3 MB 查看哈希值)

上传时间 CPython 3.11 Windows x86-64

rasterio-1.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.2 MB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ x86-64

rasterio-1.4.1-cp311-cp311-macosx_11_0_arm64.whl (18.9 MB 查看哈希值)

上传于 CPython 3.11 macOS 11.0+ ARM64

rasterio-1.4.1-cp311-cp311-macosx_10_15_x86_64.whl (21.5 MB 查看哈希值)

上传于 CPython 3.11 macOS 10.15+ x86-64

rasterio-1.4.1-cp310-cp310-win_amd64.whl (25.3 MB 查看哈希值)

上传于 CPython 3.10 Windows x86-64

rasterio-1.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.2 MB 查看哈希值)

上传于 CPython 3.10 manylinux: glibc 2.17+ x86-64

rasterio-1.4.1-cp310-cp310-macosx_11_0_arm64.whl (18.9 MB 查看哈希值)

上传于 CPython 3.10 macOS 11.0+ ARM64

rasterio-1.4.1-cp310-cp310-macosx_10_15_x86_64.whl (21.5 MB 查看哈希值)

上传于 CPython 3.10 macOS 10.15+ x86-64

rasterio-1.4.1-cp39-cp39-win_amd64.whl (25.3 MB 查看哈希值)

上传于 CPython 3.9 Windows x86-64

rasterio-1.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.2 MB 查看哈希值)

上传于 CPython 3.9 manylinux: glibc 2.17+ x86-64

rasterio-1.4.1-cp39-cp39-macosx_11_0_arm64.whl (18.9 MB 查看哈希值)

上传于 CPython 3.9 macOS 11.0+ ARM64

rasterio-1.4.1-cp39-cp39-macosx_10_15_x86_64.whl (21.5 MB 查看哈希值)

上传于 CPython 3.9 macOS 10.15+ x86-64

由以下支持