Skip to main content

Geospatial Raster datatype library for Python.

Project description


rastr

PyPI Version uv Ruff usethis

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

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.create import full_raster
from rastr.meta import RasterMeta
from rastr.raster import RasterModel

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

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

# Create full rasters with specified values
cell_size = 1.0
empty_raster = full_raster(
    RasterMeta(
        cell_size=cell_size,
        crs=CRS.from_epsg(2193),
        transform=from_origin(0, 100, cell_size, cell_size),
    ),
    bounds=(0, 0, 100, 100),
    fill_value=0.0,
)

# 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(new_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")

Limitations

Current version limitations:

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

Contributing

See the CONTRIBUTING.md file.

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

rastr-0.4.0.tar.gz (308.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rastr-0.4.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file rastr-0.4.0.tar.gz.

File metadata

  • Download URL: rastr-0.4.0.tar.gz
  • Upload date:
  • Size: 308.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.13

File hashes

Hashes for rastr-0.4.0.tar.gz
Algorithm Hash digest
SHA256 f1792103eeb7558ee4aae180d4db082c53004a698d0571bba1772bda62a83218
MD5 2dbb68dc7774ca501a6c283667deb8f5
BLAKE2b-256 19fd024add755a39a91ae9a2112740770a4dacffb2494ae6fe6719f1fb578086

See more details on using hashes here.

File details

Details for the file rastr-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: rastr-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.13

File hashes

Hashes for rastr-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92051e95a6d010eb92ff3980a352260dcb4e4824a35c94ef32a0f3b9fff07c80
MD5 930ceee71511c075c331c68705bbd7cf
BLAKE2b-256 dd1fda67780448d2e86d62a2cae64623407a553140decb32e7ef433dc3ff1b42

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page