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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12

rasterio-1.4a2-cp312-cp312-macosx_11_0_arm64.whl (19.8 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

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

Uploaded CPython 3.12 macOS 10.15+ x86-64

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11

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

Uploaded CPython 3.11 macOS 11.0+ ARM64

rasterio-1.4a2-cp311-cp311-macosx_10_15_x86_64.whl (24.3 MB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10

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

Uploaded CPython 3.10 macOS 11.0+ ARM64

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

Uploaded CPython 3.10 macOS 10.15+ x86-64

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

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9

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

Uploaded CPython 3.9 macOS 11.0+ ARM64

rasterio-1.4a2-cp39-cp39-macosx_10_15_x86_64.whl (24.3 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

File details

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

File metadata

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

File hashes

Hashes for rasterio-1.4a2.tar.gz
Algorithm Hash digest
SHA256 6d912be413fbc1e474440a7b558daa7c92e09a310feccbb2d27191fb47620639
MD5 03c98ea38cf5950ca59ddf907378ab72
BLAKE2b-256 cc87e43c087872cf9511625ba3f913c0b7a852a84cc48d0f97def324045717a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8be4ec51f31e242d5e8d6073f6c1865d95ce30b1741b5a94a9625f79622f8715
MD5 c64fbeef0865a0eeb414d47a94a8fb8e
BLAKE2b-256 73d5e0bee27f8cddd855d6ccd97e1c8918266dc9c0a9e4dd7e6a19761234487c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e334dba283bf549b57d03441beb745ad6a51b043f12155a1799f8a2ed5062ac4
MD5 10fd81368d908a7e4306a52196370c9a
BLAKE2b-256 e0d003b57ecd6ecd75a622e0e8c93af24d294557751fe3eac28e083f8988752e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b1871733b50524dba69b6c2d20dafd23cd48e053c704fb681bab902f5700c359
MD5 afdba093c50dbe7b688d423099868c14
BLAKE2b-256 e9b1a3f12b05ff9cd0f8bc3bfdd41ea1426ba99ef1f6e30aab9869188980f2f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp312-cp312-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 031eaa1e84fcfedc659bf0608baab4513f130d150d393bd147d3d0e7f15eea98
MD5 17766b52878a50f0d4bd190581061ee6
BLAKE2b-256 e840a8395c3652264d93c6ea04caa8b82c380bff6faea095acd8649c4385b551

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6d840c38b025315488da2c9f2cdbdeaffe245c954b4ce9c4519c044e9041eadc
MD5 fbeea274ef2d485473c6c50c18e1a550
BLAKE2b-256 3c4e7f110b73bc12e2262fefa37286e71778026cdfa7b29a834cbd3a32fc8668

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4a195e62f878a8716bb1b6bed05796fe460451f15930a291e642f892771ce4eb
MD5 c7819eaec2329a6c1dea2a9c3d7a34f0
BLAKE2b-256 25941930ffffed5191125180305e8d8e42fb376559bb1874c8f6d8c47477b3ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ef1cf7963a600cf6cb5fcdddf0bb4c458ed1265620937cb2915d3c38e4e1dc0a
MD5 5b81ca260e100fd0fb51402dff0bcb2d
BLAKE2b-256 8ebfec34c2e81a49cef01b5204edb3067b1cbdc91c0c413c8b31e6c522ccd33b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 acb157c0f7ef658814dc6d8a130bd1e90f88f9d6230b8b14fa4c87e98ad1a7f5
MD5 299bc259c0aea73f2c8102aefbe05811
BLAKE2b-256 2f81ebf92394ab4fdbcd015074b12db66355a696f0623d65b1207276c839211a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 73fc06c422257e963362e803de8f9b6e6c0d6ee012c4751de49a1fddeb036bef
MD5 2231cbfdfd993191edafed78cf342629
BLAKE2b-256 129301baa690dce9be1499d7b85f7b7eb4f23cc9e702081179b8b5a5440be21d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d3684a8576784d58044c751955b005a51bec0b0d8102bd0bf73647772b503dd7
MD5 2c3d064108c5995387106ed6319c7eef
BLAKE2b-256 ad15c1702b523cb28c3b190765529a799bab9d7c8619aaba9803a149ac0958a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c36f0192883c757c710b4b40a49444e818d568962f48dffbed1ce1c2c1145d3
MD5 23dd8daae74b1fc9044d676b99d4ee66
BLAKE2b-256 9c5fe08dd1ec42a3eb3b86ec4d6210baab0dd2d71b30ce2891ef88d7e2a6bfdc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 1c2834ff6cad596551bbd8c6754f5ad0d001e4104acdd152ce66f67c23d44afd
MD5 cd7790b76b6642d79d973039803a8109
BLAKE2b-256 03d15e6cf9cb761f0f249bc3baf498f7ed8326d9ab503748d92f62c5d8261426

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rasterio-1.4a2-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/5.0.0 CPython/3.11.6

File hashes

Hashes for rasterio-1.4a2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a4a3f8fa81ad335f0fa163e23331748005fd80ded7b4482bd5d9d9f8611b4db9
MD5 3f892ce9bc0f319f3a8f9e26280bfcc5
BLAKE2b-256 d4995b3dfdde396d3e90eb6ebaf424aa9673840c1a6f128ef980bf869f7d6a13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3c565beec882285f1a5203af99b687d4b5b645611211542ee461bbb18cee8754
MD5 2ff99343b6d401952476ce05365bc741
BLAKE2b-256 d857a3bbb7b1e3aa8037575887c9ef0e0f472fad196e5fa2c23dfa9413f32807

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7362bd2dc8bc7b93cc2b0e8dc3b694fd6fcb28739276f777ced9889494eb20d4
MD5 6dd8b42612a98a19add1463cebb785e9
BLAKE2b-256 185c8e5c5813c301e5acc3efc93f936351262b9d883b4f52f1464c712360aafb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rasterio-1.4a2-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 bc569873f048c8aea686379645849914715b8fbc0b75ab45a2c77e597f0d48f9
MD5 54377b57da9af37038efafca0790ead3
BLAKE2b-256 95b8b5816b2fb390f384c98ac8f8212f84413b9e59afe1ed24977b75083f5b47

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