You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.5+ works with Python >= 3.12, Numpy >= 2, and GDAL >= 3.8. Official
binary packages for Linux, macOS, and Windows with most built-in format drivers
plus HDF5, netCDF, and OpenJPEG2000 are available on PyPI.
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.
importnumpyasnpimportrasterio# Read raster bands directly to Numpy arrays.#withrasterio.open('tests/data/RGB.byte.tif') assrc:
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)
forbandinr, g, b:
total+=bandtotal/=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.profileprofile.update(dtype=rasterio.uint8, count=1, compress='lzw')
withrasterio.open('example-total.tif', 'w', **profile) asdst:
dst.write(total.astype(rasterio.uint8), 1)
The output:
API Overview
Rasterio gives access to properties of a geospatial raster file.
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.
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.