Skip to main content


rastr

PyPI Version PyPI Supported Versions PyPI License

A lightweight geospatial raster datatype library for Python focused on simplicity.

For more details, read the documentation: https://rastr.readthedocs.io/en/stable/.

Overview

rastr provides an intuitive interface for creating, reading, manipulating, and exporting geospatial raster data in Python.

Features

  • 🧮 Complete raster arithmetic: Full support for mathematical operations (+, -, *, /) between rasters and scalars.
  • 📊 Flexible visualization: Built-in plotting with matplotlib and interactive mapping with folium.
  • 🗺️ Geospatial analysis tools: Contour generation, Gaussian blurring, and spatial sampling.
  • 🛠️ Data manipulation: Fill NaN values, extrapolate missing data, and resample to different resolutions.
  • 🔗 Seamless integration: Works with GeoPandas, rasterio, and the broader Python geospatial ecosystem.
  • ↔️ Vector-to-raster workflows: Convert GeoDataFrame polygons, points, and lines to raster format.

Installation

# With uv
uv add rastr

# With pip
pip install rastr

Quick Start

from pyproj.crs.crs import CRS
from rasterio.transform import from_origin
from rastr import Raster, RasterMeta
from rastr.create import full_raster


# Create an example raster
raster = Raster.example()

# Write to and read from a file
raster.to_file("raster.tif")
raster = Raster.read_file("raster.tif")

# Basic arithmetic operations
doubled = raster * 2
summed = raster + 10
combined = raster + doubled

# Visualize the data
ax = raster.plot(cbar_label="Values")

# Interactive web mapping (requires folium)
m = raster.explore(opacity=0.8, colormap="plasma")

# Sample values at specific coordinates
xy_points = [(100.0, 200.0), (150.0, 250.0)]
values = raster.sample(xy_points)

# Generate contour lines
contours = raster.contour(levels=[0.1, 0.5, 0.9], smoothing=True)

# Apply spatial operations
blurred = raster.blur(sigma=2.0)  # Gaussian blur
filled = raster.extrapolate(method="nearest")  # Fill NaN values via nearest-neighbours
resampled = raster.resample(cell_size=0.5)  # Change resolution

# Export to file
raster.to_file("output.tif")

# Convert to GeoDataFrame for vector analysis
gdf = raster.as_geodataframe(name="elevation")

Quick Reference

from rastr import Raster

Data access

I/O

Geometric Operations

NaN Management and value replacements

Image Processing

Visualization

Cell-wise Operations

Limitations

Current version limitations:

  • Only Single-band rasters are supported.
  • In-memory processing only (streaming support planned).
  • Only float dtypes (integer support planned).

Similar Projects

  • rasters is a project with similar goals of providing a dedicated raster datatype in Python with higher-level interfaces for GIS operations. Unlike rastr, it has support for multi-band rasters, and has some more advanced functionality for Earth Science applications. Both projects are relatively new and under active development.
  • rasterio is a core dependency of rastr and provides low-level raster I/O and processing capabilities.
  • rioxarray extends xarray for raster data with geospatial support via rasterio.

Contributing

Commits since latest release

See the CONTRIBUTING.md file.

Metadata

Release files for rastr 0.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rastr 0.14.0
File Size Uploaded
rastr-0.14.0.tar.gz 407.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rastr 0.14.0
File Interpreter ABI Platform
rastr-0.14.0-py3-none-any.whl Python 3 none any Details

Total release size: 453.5 kB

Release files / rastr-0.14.0.tar.gz

Download URL rastr-0.14.0.tar.gz
Size 407.4 kB
Tags Source
SHA-256 checksum
How to use checksums
26bba57fe58461a72ac742ee6bea212bf1a9d9738409b425cee677a32b5201b3
BLAKE2b-256 checksum
How to use checksums
69769a1ec859491897a71e6bfadfd43a60a32bfaac6f3a3c7d4067757d2035a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.7.13

Release files / rastr-0.14.0-py3-none-any.whl

Download URL rastr-0.14.0-py3-none-any.whl
Size 46.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f8492f5349c19bc342e1df0061a67884614b74bb7abd35e0d8731bfaba07b0c
BLAKE2b-256 checksum
How to use checksums
da25dd0a38aadbd5671cba445efe9550274997b93173c1a06292991237e902e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.7.13

Release history Release notifications | RSS feed

This release

0.14.0 This release

2 release files

0.12.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page