Skip to main content

Fast and direct raster I/O for use with Numpy and SciPy

Project description

Rasterio reads and writes geospatial raster data.

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

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.21+, and GDAL 3.3+. 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:

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

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

See docs/installation.rst

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.

Authors

The rasterio project was begun at Mapbox and was transferred to the rasterio Github organization in October 2021.

See AUTHORS.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

rasterio-1.4a1.tar.gz (428.1 kB view details)

Uploaded Source

Built Distributions

rasterio-1.4a1-cp312-cp312-win_amd64.whl (24.4 MB view details)

Uploaded CPython 3.12 Windows x86-64

rasterio-1.4a1-cp312-cp312-manylinux2014_x86_64.whl (21.7 MB view details)

Uploaded CPython 3.12

rasterio-1.4a1-cp312-cp312-macosx_11_0_arm64.whl (19.7 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

rasterio-1.4a1-cp312-cp312-macosx_10_15_x86_64.whl (24.2 MB view details)

Uploaded CPython 3.12 macOS 10.15+ x86-64

rasterio-1.4a1-cp311-cp311-win_amd64.whl (24.4 MB view details)

Uploaded CPython 3.11 Windows x86-64

rasterio-1.4a1-cp311-cp311-manylinux2014_x86_64.whl (21.7 MB view details)

Uploaded CPython 3.11

rasterio-1.4a1-cp311-cp311-macosx_11_0_arm64.whl (19.8 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

rasterio-1.4a1-cp311-cp311-macosx_10_15_x86_64.whl (24.2 MB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

rasterio-1.4a1-cp310-cp310-win_amd64.whl (24.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

rasterio-1.4a1-cp310-cp310-manylinux2014_x86_64.whl (21.7 MB view details)

Uploaded CPython 3.10

rasterio-1.4a1-cp310-cp310-macosx_11_0_arm64.whl (19.8 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

rasterio-1.4a1-cp310-cp310-macosx_10_15_x86_64.whl (24.2 MB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

rasterio-1.4a1-cp39-cp39-win_amd64.whl (24.4 MB view details)

Uploaded CPython 3.9 Windows x86-64

rasterio-1.4a1-cp39-cp39-manylinux2014_x86_64.whl (21.7 MB view details)

Uploaded CPython 3.9

rasterio-1.4a1-cp39-cp39-macosx_11_0_arm64.whl (19.8 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

rasterio-1.4a1-cp39-cp39-macosx_10_15_x86_64.whl (24.2 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

File details

Details for the file rasterio-1.4a1.tar.gz.

File metadata

  • Download URL: rasterio-1.4a1.tar.gz
  • Upload date:
  • Size: 428.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for rasterio-1.4a1.tar.gz
Algorithm Hash digest
SHA256 1450b1d23becfaf96461e26fc7d63bada91f50febe9fe1ccd583ea0562c643b0
MD5 db58902b52cff9e0b3b63f88e0c19530
BLAKE2b-256 1e8f12b50b33ad368ac122dc497ec90154873cddb3f3aa1ddff2c7e20ac4d01e

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: rasterio-1.4a1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 24.4 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for rasterio-1.4a1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 11e245fd7b4fda315ec8b81e5aac686da4954b4169d01499063c18a7e15167cc
MD5 c932eedf6fcc369190999f7819c7c805
BLAKE2b-256 d6a016278c8f940d0baccc596e070b4105d1dbb01ba509492c1a9cb2bd8f7ac2

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp312-cp312-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rasterio-1.4a1-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 22630932b25937461b7476e774e3bce408236181fc7cb8dc0dd54f535893b7ba
MD5 549e8d7ab9612475520c84664c0b0e26
BLAKE2b-256 ed5c25293a7b866cf2a1ca896a0e2a2c29b18494e11253c5c6b044d017accdaa

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rasterio-1.4a1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 88e2cad25e1c0a9111dba97e787ddec3c2f3cf6716234134b8a7b3ebedd68fd3
MD5 346b749e6fd72a967b3be19132b06d96
BLAKE2b-256 b837c5655efbfa7da9c27444dd9dd8367a6a5727eca93f139d56504e2c2cd601

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp312-cp312-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for rasterio-1.4a1-cp312-cp312-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ab7404aadb53153bba350581f18807877feb0b3d8da77d5429ad5ee550a18f8b
MD5 a7d235d8567cde51681a5c879a27f97e
BLAKE2b-256 e0cbf6a2d2e1ee0a7b8191689612786d5fde52a38ae6f603c1ad09ac7823a301

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: rasterio-1.4a1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 24.4 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for rasterio-1.4a1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0b06afaddd0a4d629c5433f351b6df0504e167adfe4d7859906c5ec9eafadbbe
MD5 f62e9e22c80d01c0578f6554bc69be64
BLAKE2b-256 c602f79353da0c766f67f0988d83757b2d426dbe1bbdf184a13a67125fa51eee

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp311-cp311-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rasterio-1.4a1-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a3f6d41c6cde28e70385077c529e77fe8967aa24766851f32875d67b3db6078b
MD5 c274dd4f88f21713769139c48a5359c5
BLAKE2b-256 d82f3c3215508314c662396f59239d625623868f654450f55b97cadd99a93482

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rasterio-1.4a1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 af82ff6aea97d5b145805ca7932faeba4f5932e3d93ce71b0d93f4b44e9fffea
MD5 a10a5cf1fee1d6cdc70e16316784fc6b
BLAKE2b-256 1a3ffb0c7cba214d0db80b8d030808394a15b87bc84c723598233cfdd5c3ef21

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp311-cp311-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for rasterio-1.4a1-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 abbb765c80e18256f447b05aba729c96289f39d911b3d632a4349c380088e904
MD5 92171b84c868a0361e0061dc1d732d02
BLAKE2b-256 2efc17c06e1fc67ebf9b469d39583a0bc4e3fc7c1c2235f601d898e00c7da32f

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: rasterio-1.4a1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 24.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for rasterio-1.4a1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0530d4b2099fab67f342f5f695c7b996fc0847f18cec3795e4c3a509d2226d4e
MD5 2d452c1cf388b6833847139060dfa88a
BLAKE2b-256 662851b2df636a5ef47047584aad8207ccd66bdd4df253fe48c11d3e89a329b9

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp310-cp310-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rasterio-1.4a1-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a4c9f5d891d97fa58c7001b0bfb1e4c86f60c3b4a44842c63b71efb7fde1972d
MD5 a5e30d81126157e4aa289f811ec55ff2
BLAKE2b-256 e692fe56fea3b7bf1b9eba9ea13394d2b8c969dde5bd066ed3d73c3a05f6bf4f

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rasterio-1.4a1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d794441a5acd68115519c79aa8f5351463e3d095c14b10545f367e5e19306f37
MD5 aa4e950e0fed810db8047fd8cc33754c
BLAKE2b-256 a5b247ed1cd740e0e51669c77645ce5da4ebe583a5eb71ef6b27470cbff8bfec

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for rasterio-1.4a1-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 e45f192c87ef302988ccefd3453e389d8f107c7457f54928d4b55e93831218da
MD5 25fabe56c59f0a0fd2ebd57188bfb9cc
BLAKE2b-256 517636cdae111cd0666181a955cac52a7633ac6edfe505813d8076f1e78e7805

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: rasterio-1.4a1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 24.4 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for rasterio-1.4a1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 606611a6eddb4d0d1c71fb64f81ae0ab98e6b22fc2a6d1e83611ef6d9f0a4fd6
MD5 ae89baf59a47f5966726d712f7dae733
BLAKE2b-256 9d0c12509b494586150ca9a60cf522bcb714c17b9417ed9d24a7c9a27e8eb6fb

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rasterio-1.4a1-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b021b42d378a701b2dcdaa8aef52e30a636980b49aed69dde032086b9855527e
MD5 e8be585733882e39b864ae9e961c544b
BLAKE2b-256 f11e781de724237a537e743b0b124cdfd0ac6998ea0a2781de7a285ec6a10fe1

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rasterio-1.4a1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f5caab025710089ca5f11d25fd4b63a5fedd4cf3708e18bee6071ced08bc776
MD5 fafc87442d6476bc9b2f0bcbf0b2b050
BLAKE2b-256 882621c7f70caa61ee50ebbaedcff42d03f72fbaa9b089f58d906b573e67aae9

See more details on using hashes here.

File details

Details for the file rasterio-1.4a1-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for rasterio-1.4a1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 0fb6b895f6d4bdb12edd6d5abc3d506ba5587db5557cdc7bc895e6b7b5c1f0cb
MD5 5e562e350fa26e5b5e2fea190d1db8a4
BLAKE2b-256 b5b779b9107652d55557ef0ea0dd5e776e72d4947e4ff44369a7ddae68bf684e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page