用于与Numpy和SciPy一起使用的快速直接栅格I/O
项目描述
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)
输出
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。
请参阅插件注册表以获取可用插件列表。
安装
支持
关于 Rasterio 的安装和使用问题的主要论坛是 https://rasterio.groups.io/g/main。作者和其他用户将在有专业知识分享和时间解释时回答问题。请花时间精心构思一个问题,并对回复保持耐心。
请勿将这些问题提交到 Rasterio 的问题跟踪器,我们希望将其保留为错误报告和其他可操作问题。
开发和测试
请参阅CONTRIBUTING.rst。
文档
请参阅docs/。
许可协议
请参阅LICENSE.txt。
变更
请参阅CHANGES.txt。
谁在使用 Rasterio?
请参阅这里。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪一个,请了解更多关于 安装包的信息。
源分布
构建的发行版
文件 rasterio-1.4.1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d750362bb792d2311f94803ff309baec48486ecba75c9b905ea9b1f5eb06ef9f |
|
MD5 | 88ec246641b7369009a744bed7a2f727 |
|
BLAKE2b-256 | 5de992a09209093831ef02a42bb58e3ef73d20e49931ea6043d82c29319780d9 |
哈希值 for rasterio-1.4.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 2466adf39009115de23209a4b343fdb0db9a3aef97119d826d09df26b7f3beb9 |
|
MD5 | 6963e10536a53b1bda1de10a2cd1c2d3 |
|
BLAKE2b-256 | 0261c0a9bf081d23a47d17e1eed3031f5c2d11449da8f977760f73c96106ac72 |
哈希值 for rasterio-1.4.1-cp313-cp313-macosx_11_0_arm64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 0c2f21b4fe0f6f8af0a902c4f86fb51d25a058fabf4dada1d453f8dce6be7938 |
|
MD5 | 639c0b3a78df6294fed9bf526e7c7bb2 |
|
BLAKE2b-256 | 13d7a1118060427123cf03ce38eff1b2178e742e82c205fb8a5b6908a8d0b31b |
哈希值 for rasterio-1.4.1-cp313-cp313-macosx_10_15_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c5b626dc0c08dc593e462265ce974266f3e1dd90fa67807bef33704d88c62a28 |
|
MD5 | 2e33fc10808157217f31fbfbabe7747d |
|
BLAKE2b-256 | efbe3ec2b6a45e3ee77a660447d3f83ed22e316452593be5e6730c24ce22a232 |
哈希值 for rasterio-1.4.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5b85f7d912b868ce8dd25e01d5042c8426cc9208a715f093081503ee864e870b |
|
MD5 | 58a9bd518d78acc296e7bb0f9c6a3531 |
|
BLAKE2b-256 | cf9b4b3a407a3083806cf4de0add82553a8b79744a3bda0df758212d10289d23 |
哈希值 for rasterio-1.4.1-cp312-cp312-macosx_11_0_arm64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | af5e0559eb8da3cf0adbc1d26ce86e505ea82814012b7b6711855674ae3f6425 |
|
MD5 | 80c283ab1c6bd5bc1bba53675249f1da |
|
BLAKE2b-256 | 9288c5722be244f426db8024139fc958079b71879a935e469886edc5dbe6130a |
哈希值 for rasterio-1.4.1-cp312-cp312-macosx_10_15_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a0cd7b8eda7d3b0097a42a047d2604c3f1f27b4093e2a4e1e7ad379c9f639f65 |
|
MD5 | 23a800bd2f198a402fb7e6cd835ee7ec |
|
BLAKE2b-256 | 6a98ba5e1f4764ecde8678c6b8653150314964677ad35425b1e0d3ccc8d71a0a |
哈希值 for rasterio-1.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ef99c77d2c52bd95b42ff862c252a74c7528ec3b3cbb665c783e3948ebd811cf |
|
MD5 | fa1834160fcf606c3448e76c21b5cc29 |
|
BLAKE2b-256 | 7a5a9462fc26a16035cc8042ceb1604af55cad00b14cd73ef38e91942e113476 |
哈希值 for rasterio-1.4.1-cp311-cp311-macosx_11_0_arm64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 50fb06c2895cc055f34d813600cb5dc56b170d02c216913fdf80b573d771e972 |
|
MD5 | 9ce589fbd698d51a2b6383957fb773a4 |
|
BLAKE2b-256 | 26dc638c5e075a08f3895fbbbcbaabc4122c1fe73d30cb053c88cbdcd4f561ed |
哈希值 for rasterio-1.4.1-cp311-cp311-macosx_10_15_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5037188f3582cdb21a308d6cacfc6a4f2828cd05d382f8b848c8bb405a0778b4 |
|
MD5 | 8d7242b40669a2a61e9669e60cd6845e |
|
BLAKE2b-256 | 26ea91fa2792084a4bfebd48c0c9b3d7a48777ab047213ca02f7fe6d24188958 |
哈希值 for rasterio-1.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 0f0903fe08724e99b7404c8069474eab08c50b06c3436476f8fa63e381bd0a36 |
|
MD5 | 57a36a5573951b62aafe83e1074349f2 |
|
BLAKE2b-256 | a82d6c68d781c0dd711e1537854b29a5ca68b25cea952175d32dca72edbe7f33 |
哈希值 for rasterio-1.4.1-cp310-cp310-macosx_11_0_arm64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 919c3fada8825b385fa057f9dfdde502b10f65b940ce3299cc932252edb1c57b |
|
MD5 | 2e8dfae30db9bcf8a982a479bbbeaa8a |
|
BLAKE2b-256 | b0c41bb5bf595c29714386fc3d600cddf88c700d4b7527cd97322dbdd93adfaa |
哈希值 for rasterio-1.4.1-cp310-cp310-macosx_10_15_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b30c4f60951e70f25cca03c8c127ff1cb6eb4670c551d8561cb71f8cd5aaad3f |
|
MD5 | ac13b1617c0cc1b5d2a6905fbcb7adb8 |
|
BLAKE2b-256 | 2af28864969ee9707f62eff4fe9806c4df039357002adf21a8e06ee097a77c8c |
哈希值 for rasterio-1.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | e4a89441afa7cbd2f5df4e822b0d9f581971f805fa6884b59911cf238bdfa9b6 |
|
MD5 | 7288ed1c4eeba5d660e96fefd02d4616 |
|
BLAKE2b-256 | 30dc63c5e2a1ce56ffa21a11680bb0870693825e2e7e723f90cca5df1273f56d |
哈希值 for rasterio-1.4.1-cp39-cp39-macosx_11_0_arm64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b53e08a86d9180d87021b0ea0d5d4eacf7c252adfaa85dafcd8f1e3daf89dbf9 |
|
MD5 | 7f86b56222d46a7f4fccaf7fd49a9fc6 |
|
BLAKE2b-256 | c451701300256b943254a15f103154226e0f16c0d076286dcb83fb75160f5743 |
哈希值 for rasterio-1.4.1-cp39-cp39-macosx_10_15_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 03f0d04ed18b4311ec807fe00fff85a9c744cb340e494dbb208ed1dc39dc1cd4 |
|
MD5 | 3972190617ddf95745954f5bd7e08abc |
|
BLAKE2b-256 | 20ef7633241f7955e4abb604565bfa210bd467b2389bf685fc11bbd5264fe93d |