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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

rasterio-1.4a3-cp312-cp312-manylinux2014_x86_64.whl (21.8 MB view details)

Uploaded CPython 3.12

rasterio-1.4a3-cp312-cp312-macosx_11_0_arm64.whl (18.4 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

rasterio-1.4a3-cp312-cp312-macosx_10_15_x86_64.whl (20.9 MB view details)

Uploaded CPython 3.12 macOS 10.15+ x86-64

rasterio-1.4a3-cp311-cp311-win_amd64.whl (24.5 MB view details)

Uploaded CPython 3.11 Windows x86-64

rasterio-1.4a3-cp311-cp311-manylinux2014_x86_64.whl (21.8 MB view details)

Uploaded CPython 3.11

rasterio-1.4a3-cp311-cp311-macosx_11_0_arm64.whl (18.4 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

rasterio-1.4a3-cp311-cp311-macosx_10_15_x86_64.whl (20.9 MB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

rasterio-1.4a3-cp310-cp310-win_amd64.whl (24.5 MB view details)

Uploaded CPython 3.10 Windows x86-64

rasterio-1.4a3-cp310-cp310-manylinux2014_x86_64.whl (21.8 MB view details)

Uploaded CPython 3.10

rasterio-1.4a3-cp310-cp310-macosx_11_0_arm64.whl (18.4 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

rasterio-1.4a3-cp310-cp310-macosx_10_15_x86_64.whl (20.9 MB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

rasterio-1.4a3-cp39-cp39-win_amd64.whl (24.5 MB view details)

Uploaded CPython 3.9 Windows x86-64

rasterio-1.4a3-cp39-cp39-manylinux2014_x86_64.whl (21.8 MB view details)

Uploaded CPython 3.9

rasterio-1.4a3-cp39-cp39-macosx_11_0_arm64.whl (18.4 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

rasterio-1.4a3-cp39-cp39-macosx_10_15_x86_64.whl (20.9 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

File details

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

File metadata

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

File hashes

Hashes for rasterio-1.4a3.tar.gz
Algorithm Hash digest
SHA256 e2273b1ed418d2feb7596ef6d86ffe594012a0f7677596048a240dea1d296428
MD5 e2cec15745c69b152748c6fd6195b851
BLAKE2b-256 02e300d83823700c933c9ace781e613d0d0b858ff919d05ef51a340fe008ae6a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rasterio-1.4a3-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.4a3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fe5b8693a420efe497ce4db80ce14f4ff28e1d0f235df1c03c1a2ff12bd33add
MD5 ffaf4e1179996213bb2930c4f4f8106e
BLAKE2b-256 2f13641019fe4d3c67e5e271bc6606f0e4cf51f2e57ca87c7b46dff26eb9143b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a3-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eb001263b71700beba158a28c13fc690e06de27532570051cd582b9f81105ef4
MD5 5bdfa5755e7c2ef7b484c30ffdc09fba
BLAKE2b-256 4438d166001c523f847003cac5595bcc0401b5315c9e2f20c8bbe026fb0ea89d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 763db223fc6a55a3a7f43f8b891c57ef6f1ee8690463b9860f34239e22c1a38e
MD5 7e19f4918f00bbbbf6a34f82eb0511e2
BLAKE2b-256 5c1e1c265f3b1e2c1718431a5b7c55aa2f6828004eb56aefd6ee64b904c23251

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a3-cp312-cp312-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 4b52109d5d4078a793da84ba569ff85d730d50dca93a16be88fbfd45dbc31c13
MD5 660fb0e57beb2f0471fa87c7e634d543
BLAKE2b-256 70865430c2d3e89cfdea6c29f579e50e93e8bc1ec5319312d120a88f620f23f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rasterio-1.4a3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 24.5 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.4a3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ae9148130f9fc1f8cdca111790912a90f03ad7fd6021f406476c2ccfcfc79d01
MD5 98e0e15e0d8163e09a1f6cc2e0a320be
BLAKE2b-256 7ab7963040d4c30bba838b58438b1f12f3b0a8f56835f6db1d08a8f6c715ebc0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a3-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bfaf17b1b3d6307c8a7ca291a3a103b7099bd590a9febb23694a9dfc5c0ac2d6
MD5 b5664027f957354ca7c04251a1de2a42
BLAKE2b-256 2e7945d6b6e8e9f01f4676dfd437bc44ae664fbfc3d6262acdfb14328a214e1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 54f69cbef50bc189eaae6207fc8a3df3d21e1b46c087fc5c235f427e17abc075
MD5 702d308204b8f6a276f2efd7beacd0f3
BLAKE2b-256 06ed235eb6e68789ef63318f37e1a4f050d314a55efc42786ad8ac521b3012ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a3-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 d1a657562a02139bad22b7936c8682d2ea6978d3af4aaea237057a4a3b1e9bdf
MD5 201533a62323f549151378868e9effca
BLAKE2b-256 f043ae657d88bc658b4c42bab3e29194ba4d0d67da971896f518d7856fa4af58

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rasterio-1.4a3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 24.5 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.4a3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 22d7a36026d31b5d53f12f8212c18e4d40c1d1e97057004a6f017cab8bde31ce
MD5 217b7245180459e05cc3e794c7360ba2
BLAKE2b-256 d68356586ba38992fcfbb276e54d4d63e184572d30057c53b45e2d30b8c4ff81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a3-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 785be8c389d43f1c6822885a2a040967d11dd3cc08b84c94ba304533a8ffc8b1
MD5 ce5ea7ba37b39addfb485dbe381742dc
BLAKE2b-256 1fefa9499b6509a653832c3f0835b9638aa346e40e6d84179d810e79c5234fac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8ae45d3f54d7a04ef53ce195c7921931d8b982ac0bfc8118c1a8594cc4f5589b
MD5 7103e53ddec6bdc6d9bab52778207ee4
BLAKE2b-256 e86394a6ca9b15e1d430c8d5eb872cb3aba16a4407be630cfac52b33a33227f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a3-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 dafe5ae9b5d1593527273dbd904a590da0671a5d516ac882f11d54af5a6d4a62
MD5 f9d5e88b90fa4fd17a082a9ab322f09d
BLAKE2b-256 05fca38a5012329d6637f93a903c636a9286fecbb16b57243a03da68dd4db2ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rasterio-1.4a3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 24.5 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.4a3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 943251690775fc019ab3c4af5346b6a499f888c886ea4cf54e42e7a751195bee
MD5 aaf58b5d533c21e1e35e282b60827af3
BLAKE2b-256 87ebeb7461776449ca4e6defcc7e0828c05ad2a59bcc39b987b09379e7225e39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a3-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6f8f01869b3365dfbfd69ed7598fe198b0c17ded32fe00743ba5a91b8196463f
MD5 baac28d8ffe708a51f0ed52d2fd07ca6
BLAKE2b-256 62231bc42cffe2ec3c37ea01a1574482a455c9264986543b16d835ab7eaf71e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a54aa62437618e102cbf5cfe3f8e4dc5249e7ceef32377074cd0b98636ace3d8
MD5 15c292a9b98a025727d025bbab0b2228
BLAKE2b-256 90e2f603a8f00a67c6b5e20e67b79b31939b62b88e8721e4458b9eacfd144c7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a3-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 e7c3f368aacb1d55e2d1aa220ca66cfbcef696cc47e518d18c25137428b7997b
MD5 4e34176fc8d70be8c062e60dfbdb6146
BLAKE2b-256 df130d94735273cf40e068d9d57d0913b1576d47d78c58d73997154939202b07

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