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.4b1.tar.gz (439.9 kB view details)

Uploaded Source

Built Distributions

rasterio-1.4b1-cp312-cp312-win_amd64.whl (24.5 MB view details)

Uploaded CPython 3.12 Windows x86-64

rasterio-1.4b1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.0 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

rasterio-1.4b1-cp312-cp312-macosx_11_0_arm64.whl (18.6 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

rasterio-1.4b1-cp312-cp312-macosx_10_15_x86_64.whl (21.2 MB view details)

Uploaded CPython 3.12 macOS 10.15+ x86-64

rasterio-1.4b1-cp311-cp311-win_amd64.whl (24.6 MB view details)

Uploaded CPython 3.11 Windows x86-64

rasterio-1.4b1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (21.9 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

rasterio-1.4b1-cp311-cp311-macosx_11_0_arm64.whl (18.6 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

rasterio-1.4b1-cp311-cp311-macosx_10_15_x86_64.whl (21.2 MB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

rasterio-1.4b1-cp310-cp310-win_amd64.whl (24.6 MB view details)

Uploaded CPython 3.10 Windows x86-64

rasterio-1.4b1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (21.9 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

rasterio-1.4b1-cp310-cp310-macosx_11_0_arm64.whl (18.6 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

rasterio-1.4b1-cp310-cp310-macosx_10_15_x86_64.whl (21.2 MB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

rasterio-1.4b1-cp39-cp39-win_amd64.whl (24.6 MB view details)

Uploaded CPython 3.9 Windows x86-64

rasterio-1.4b1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (21.9 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

rasterio-1.4b1-cp39-cp39-macosx_11_0_arm64.whl (18.6 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

rasterio-1.4b1-cp39-cp39-macosx_10_15_x86_64.whl (21.2 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: rasterio-1.4b1.tar.gz
  • Upload date:
  • Size: 439.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for rasterio-1.4b1.tar.gz
Algorithm Hash digest
SHA256 a7c2f490aa8fc6245eb2ffb2c8b16c817be6857855378ce7856515c305e10b2d
MD5 c2ab2405bb6738cf4c6cefa1e96e9f7d
BLAKE2b-256 70e1d55051c0498940957b30dec43624ede1afdacb8857038ec7a1b3d961aaa1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rasterio-1.4b1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 24.5 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for rasterio-1.4b1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c585652c426c8d608b737c1ad2bbb9f38424d3d7497f7d45b9e504c051578e51
MD5 2bfa860cd5f2cdb10d01edf4d0a38ce1
BLAKE2b-256 7cc7e7a61b1f7701a0990fbc6c9319d75b2f5ae40e3fabb1ae0ec3f5c19b1f24

See more details on using hashes here.

File details

Details for the file rasterio-1.4b1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rasterio-1.4b1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 21e4491ff7dc00f952ed8aaec589ae288d0e8bc301453b544e50405fa62bd552
MD5 059fc26656df33eddebaa0e16dd77775
BLAKE2b-256 08f00afe71bd5055a614d37dca92d27d6927df12f2a8b3728a7b4c8427f7a9fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4b1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 360f335bf29eb1a9f2b6a8d3cdc3f6b881e699d7a5d308bb165fae605079e422
MD5 98924939147d92c12cc76d672e729671
BLAKE2b-256 f7b9b771a23a77d0ee1b36823d0c6b89ae87012769988cdcb6c76e2c6e226ec7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4b1-cp312-cp312-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 3f21b1606a0150af778d1344d592c02c205361f5a4530cc9f73a00573aeb6188
MD5 1f3e54c10dcf2daef9b83eca4ba8fd79
BLAKE2b-256 ef8854d86b00aa2084d88a826ef2eb925dde06123469bdc3413489ba5a577dd2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rasterio-1.4b1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 24.6 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for rasterio-1.4b1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3a68004e2e410ada18039f6a8eacf653a77ce87a5c870b802f9707640b1ec693
MD5 063e2910576298f0b851fd151b5b0565
BLAKE2b-256 66e2250b6a9bf34f8ac25bae4a794dc39da5ed8986d391614a244023bd4cb847

See more details on using hashes here.

File details

Details for the file rasterio-1.4b1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rasterio-1.4b1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e66731683a727c3a111ecb292f5a74408ba84db2134af57dac5151be2958b68f
MD5 2e1b322d614607d29debf3a7882b9374
BLAKE2b-256 df9425cee672bdbdfd11b5687b406f350e0fd5b0f60a16f1a7b3bd28c59eae82

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4b1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 29f8bfc7a260e6f1f05a3be759e9b8dc4ad3596c6dfc48cf07e4bef0fbe21c57
MD5 ad24d64fc41b43903e7154ed7c04c229
BLAKE2b-256 f1f33dd47ee7406b0a8f0a2a8463975c20d132efc7b0f8ef0c6ff5accb645f0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4b1-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 0a144a7170e18d5cc9f0ef3e811e941edf1105a6ac30d7855b5365ef27cf3a9a
MD5 ee48962087125eda8f5dfdddcd5ce990
BLAKE2b-256 f7635c45c752fe33e1ad96a57e7b368cb865596ef2820085a4846e241c019055

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rasterio-1.4b1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 24.6 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for rasterio-1.4b1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d8905efe5c031ddb941c570b01fa6b43e6f376dd5574b36ef5c37f14ff38d5d1
MD5 2dc32c47c815b0aae63be21fb5115fa3
BLAKE2b-256 77b4a989858019c1ac2b305e559f2524934b4cf5e5bd73660e1d25b61a823e3c

See more details on using hashes here.

File details

Details for the file rasterio-1.4b1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rasterio-1.4b1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dcc134a18f07a751d7fba30f268750cf0d1e5a18ed95f783c13d791fa736c2d3
MD5 d0394567cd6711700d59858fa91dcdec
BLAKE2b-256 4334c5e1b22a01c64e4684daffb8e50b0d1c0d13704fcb3ea84a3fa9c07dc29e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4b1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ba32b8f213bf8571d9e75bfc82c06cf3f17112138bb98a62c2e0669174d0a5d4
MD5 e7ff3869427f33782ecfd5d8a80aad51
BLAKE2b-256 449c4190865068f4fafd0ba6e5194abf89495c3b30382af33b6ab5afff10b081

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4b1-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 da92e55103348dbec3a43fecbdba2bfa269277ab404384a6eae5ed8f897c73cb
MD5 e84b608b30bd16b659284814222f29ee
BLAKE2b-256 3ea129cf2c78c96c4caa52efcf0f6385c981726bc31d6ff232f05cec9622a6fa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rasterio-1.4b1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 24.6 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for rasterio-1.4b1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 02fd9262f366792e5353c376598ac3cf88c45c7177de824e83a9952d902f07db
MD5 e20f788395c01b640097fd981a205cc1
BLAKE2b-256 1544a5e44b292d58830e389d1be591868f560189743ff34307e620f643a7e832

See more details on using hashes here.

File details

Details for the file rasterio-1.4b1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rasterio-1.4b1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 27f1b21c28427b904b4f731a2f812f60444e683b70a9744316e0158229a3fdcb
MD5 6a8319c0cfe3225fe25bfb864e6b7e9c
BLAKE2b-256 900f039df6b3f26fdc51bb6e554ea2a5eaf7f60d9ce44c13884785fb7417a9d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4b1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 784c1fa3068d13ad90d346bb8692f822c2f89eb631e42a1676153d75620f6803
MD5 b050da3e8edd848e16f606dba9f29802
BLAKE2b-256 f727d98748e67e710be7b59957e8347226f62503f79758e78db57cc685d08c7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4b1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 56ebdbb672cf9d3f0ac310495cc2f5201dccb48677da093917b7e2b3d445431e
MD5 c2d0382e101935adcb7f0d4edfd7f641
BLAKE2b-256 2d9b2205dae6ba1200b0f3d118659ecf41c25d2dc6b1b9191df8dad7bdeac923

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