Skip to main content

A sleek, object-oriented interface designed for intuitive raster data manipulation in Python.

Project description

rasterra

PyPI PyPI - Python Version PyPI - License


Documentation: https://collijk.github.io/rasterra

Source Code: https://github.com/collijk/rasterra

PyPI: https://pypi.org/project/rasterra/


An in-memory object-oriented raster manipulation library.

rasterra is a library for manipulating raster data in memory. It is designed to be used in lieu of rasterio to allow for easier manipulation of raster data. It is designed to be used in conjunction with geopandas when vector data is also being used.

Currently, rasterra is in a very early stage of development. It's primary limitation at this point is that it only supports single-band raster data. Multi-band support is planned for the near future.

Installation

pip install rasterra

Usage

File I/O

Reading and writing raster data is done using the load_raster and to_file functions.

import rasterra as rt

# Read in a raster
raster = rt.load_raster("path/to/raster.tif")

# Write a raster to disk
raster.to_file("path/to/output.tif")

A raster can also be read and mosaic'd from multiple files using the load_mf_raster function.

import rasterra as rt

# Read in a multi-file raster
raster = rt.load_mf_raster(["path/to/raster1.tif", "path/to/raster2.tif"])

Raster Manipulation

rasterra provides a number of methods for manipulating raster data. These methods are designed to be used in a method-chaining style, similar to pandas and geopandas.

import rasterra as rt
import geopandas as gpd

# Read in a raster
raster = rt.load_raster("path/to/raster.tif")
shapes = gpd.read_file("path/to/polygons.shp")


new_raster = (
    raster
    .to_crs(shapes.crs)          # Reproject the raster to the same CRS as the polygons
    .clip(shapes)                # Clip the raster to the bounding box of the polygons
    .mask(shapes, fill_value=0)  # Mask the raster to the polygons, filling in areas outside the polygons with 0
    .resample(0.5, 'sum')        # Downsample the raster half the original resolution,
                                 # computing the area-weighted sum of the contributing pixels
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rasterra-0.6.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

rasterra-0.6.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file rasterra-0.6.0.tar.gz.

File metadata

  • Download URL: rasterra-0.6.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.5.0-1025-azure

File hashes

Hashes for rasterra-0.6.0.tar.gz
Algorithm Hash digest
SHA256 d2d229263cf5d06dc7030f42727359fe13ecd02522a47bc55b9299d1c23638d5
MD5 3ab9d1e98b1c12ccf9bafb71590717ce
BLAKE2b-256 928247b74773bf39d481b7d4820ce33bd38aca305c9dded2a6201b639d7e66ef

See more details on using hashes here.

File details

Details for the file rasterra-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: rasterra-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.5.0-1025-azure

File hashes

Hashes for rasterra-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b26d128ee880f2313d6d0e070df821f9275877a77675118be41679e4d81d2de
MD5 85ca246aaa743e7052a07be8e147d5fb
BLAKE2b-256 828394ccb8487d0f28c15ad93877cef10e705bf63c4255450c92dfbc2082284b

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