Fast and direct raster I/O for use with Numpy and SciPy
Project description
Rasterio reads and writes geospatial raster data.
Geographic information systems use GeoTIFF and other formats to organize and store gridded, or raster, datasets. Rasterio reads and writes these formats and provides a Python API based on N-D arrays.
Rasterio 1.4 works with Python >= 3.9, Numpy >= 1.24, and GDAL >= 3.5. Official binary packages for Linux, macOS, and Windows with most built-in format drivers plus HDF5, netCDF, and OpenJPEG2000 are available on PyPI.
Read the documentation for more details: https://rasterio.readthedocs.io/.
Example
Here’s an example of some basic features that Rasterio provides. Three bands are read from an image and averaged to produce something like a panchromatic band. This new band is then written to a new single band 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)
The output:
API Overview
Rasterio gives access to properties of a geospatial raster file.
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]
A rasterio dataset also provides methods for getting read/write windows (like extended array slices) given georeferenced coordinates.
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’s command line interface, named “rio”, is documented at cli.rst. Its rio insp command opens the hood of any raster dataset so you can poke around using 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 Plugins
Rio provides the ability to create subcommands using plugins. See cli.rst for more information on building plugins.
See the plugin registry for a list of available plugins.
Installation
Support
The primary forum for questions about installation and usage of Rasterio is https://rasterio.groups.io/g/main. The authors and other users will answer questions when they have expertise to share and time to explain. Please take the time to craft a clear question and be patient about responses.
Please do not bring these questions to Rasterio’s issue tracker, which we want to reserve for bug reports and other actionable issues.
Development and Testing
See CONTRIBUTING.rst.
Documentation
See docs/.
License
See LICENSE.txt.
Changes
See CHANGES.txt.
Who is Using Rasterio?
See here.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for rasterio-1.4.2-cp313-cp313-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25ec2a35548c1c45ea1dd5341e777e5aeea8f79310bbae6aaed4d5f6a4c53f26 |
|
MD5 | 8f3a39578a494fc33f84879b6dea3dcb |
|
BLAKE2b-256 | 297bddbd284fa466221f38c339b218a66da3512ad7fa736318c727577c7d4371 |
Hashes for rasterio-1.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6f2952e1b4ad01f0dcf97f477050d8122ca781abbb3ef8b5a5751835a222317 |
|
MD5 | 1a411bc13730fad282c86d8b8caca643 |
|
BLAKE2b-256 | 904c6990768de10ae2be50dc70365dfed7c3181501bf0173e6aeed867b061c06 |
Hashes for rasterio-1.4.2-cp313-cp313-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7dbf3d084e1f72f322d378eb2b9e155fbe0ead97f0a1b0065a389e9435a5a3db |
|
MD5 | cb44d5faec23332581f731c311d6eba9 |
|
BLAKE2b-256 | 5aa81a4d5cbeb17310595928801dd2d1500f9d094c97893afc0ed11f9639a008 |
Hashes for rasterio-1.4.2-cp313-cp313-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e405e92ab03f5606a959d4a7d9ae1589e2212f9720c2db55853bfa8c91f6d736 |
|
MD5 | ee39625af1267341dfb0586dc988cd2b |
|
BLAKE2b-256 | 4cb1f12bc309403f2b4f6c0ebb5fdc93f2506358b85864f7b3a1bc66ca8cecf5 |
Hashes for rasterio-1.4.2-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83bf03b39dc7e1d932907d1b05d99a53b7fc184c215a27b938f4697db7295f53 |
|
MD5 | 1db6a5a3437758e176e73193c9dc00ec |
|
BLAKE2b-256 | 97ae388db0a3ad01b273d183fb9204b33d8a2d45c6fbd385f6ff11bc713f5ca4 |
Hashes for rasterio-1.4.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43a21306c8dc265f50d3cb8a13a58d50e055477ace1003bb8a507658a4124c37 |
|
MD5 | 67507f46301001818c5390197d36b664 |
|
BLAKE2b-256 | 2bbb52089954facaf6ec9edbbcc837b9de3ea5cb34a413481507870c0ad86a8a |
Hashes for rasterio-1.4.2-cp312-cp312-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 856c740e621211a19f0efddc2f0a61cc3d37c89c50699ea6cb249da3930d601b |
|
MD5 | a94a26c8794eb18c70c96661b68eb051 |
|
BLAKE2b-256 | 6caf494772e3ba2e9c70321f83ed631d12ff3d5f957a17abf183e039bb793053 |
Hashes for rasterio-1.4.2-cp312-cp312-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84ce104a3017c04bfb809f268faaef4287458916f7af4f25a39b93f420fa8ef4 |
|
MD5 | 5e3b6819a0eebddd14d947464babce20 |
|
BLAKE2b-256 | d5a1cd3b8592322d5e898acab6447819df3d9a5fe1bf9c966d4d8146d0b880c6 |
Hashes for rasterio-1.4.2-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c74d6a2e64fae6c2293bf520fa4048e12598379736953c34ca3dfb058cedfc5 |
|
MD5 | 93f4bad479d5701e8e1f76f9fc345cab |
|
BLAKE2b-256 | 4d389bc2bd4b2df4527debd278011e917cc085007e6cf60c9ec44fea38cb8a7a |
Hashes for rasterio-1.4.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea3f38da794e7a4df409f2c57799a26a777a2560025ad401fe33a0b8efe90a5a |
|
MD5 | 561df9fe925a1770a8d18851b8f3499f |
|
BLAKE2b-256 | 8c5825a6531d8b578493c66a672c0ea47c976c4e702979d4d18cb538789a30a3 |
Hashes for rasterio-1.4.2-cp311-cp311-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9830e0c9d09d2680079b8a31085cc2a2b885b1ed6c4d95d2a91e2813efc22aa |
|
MD5 | 8db28653357f69c1de50407c8cf0fe04 |
|
BLAKE2b-256 | 09b9169a76e257e527d352da021da6602480a829eac03b0ab3045639c3f80fb6 |
Hashes for rasterio-1.4.2-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 019e6fbfea250fea91987a38abc7a02c752b50beadb3178d82a5d47e8e265313 |
|
MD5 | c11896abeb792d1f10c3f94699f7428c |
|
BLAKE2b-256 | 8d1debdadd0b74704e09553753b23510fbd43fb7d9c2de468d5cf4ac223a4087 |
Hashes for rasterio-1.4.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e38f2869f6379dc7f0d46af2e879f14ad194ccf0b634c121b630693fee23cdbe |
|
MD5 | b65b1aab998b6e0a56950f7209b14187 |
|
BLAKE2b-256 | c063a5de023ecb5b1f35f993dcec5727e581e8d124997fa5b7b8154a52bb21db |
Hashes for rasterio-1.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90303c1ec8f9c89b1c3c4036c8595e84b4afa21e3ad6d87b4a46bd81f4bbbd3a |
|
MD5 | 6cfa0b17c07b851c17fe2ffa7ca7d0be |
|
BLAKE2b-256 | cdad2d3a14e5a97ca827a38d4963b86071267a6cd09d45065cd753d7325699b6 |
Hashes for rasterio-1.4.2-cp310-cp310-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fabae0d84ff5455f588d5283d1a007769e63a679ab095e739abefc780332517 |
|
MD5 | 5d796600608f52ac453be2baee07cd1a |
|
BLAKE2b-256 | 3c08862ac9a68ffd6906eac75374dddddb84e697bb1e88306fb21abca6af0a2a |
Hashes for rasterio-1.4.2-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cf84f566c12ab1d3b42466038ef79edb3d37037a421293db93a30d046e13c43 |
|
MD5 | fa60f90c84d93c70f0695510dd7d1897 |
|
BLAKE2b-256 | f80c0cf754292ef021b8a7f1bd32fdb32daad6535e49d14e3ce16cfe82de4485 |
Hashes for rasterio-1.4.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b27965b50466a1d297ea41b4b8fbe19178b05ab3dd78f35fb64ccdc0e502819 |
|
MD5 | 262b023f9446dd8e3f73df8171606c51 |
|
BLAKE2b-256 | ea8144a46c31329e70ddd240dd17f89aeacb1a77a14a30f06862b66c9605c658 |
Hashes for rasterio-1.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | beec16eb4d951f111235d46f66319922bbc5744e7b8e50303725b46819b458b9 |
|
MD5 | 7247a8aef5808375fe0d0274436cb967 |
|
BLAKE2b-256 | d9e94181a031d919e965c09a66437a9c0cf7bad627f1aa59e93abbf03b20c652 |
Hashes for rasterio-1.4.2-cp39-cp39-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11fdfc2a8b610eb2f6e3d47c396455d4d65c290d69b53e0a986cd58feac3af7b |
|
MD5 | ed949d839e816577501223b1dabefccf |
|
BLAKE2b-256 | bac0e00d120ede0ed46a59b3f98ec58ef116bbeebf6c4ed3e71efc4b2d30639b |
Hashes for rasterio-1.4.2-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56811e3fee89a74ccd18f11849f9dbf0c98eb652671b16c90c29bd06b122c4c6 |
|
MD5 | a22d2b41db26e17455237c0e3da49d51 |
|
BLAKE2b-256 | 1f5e4fad2e9561028f4e719dba8f876392183d17e93b9abfb73f6b95c0f311fe |