Skip to main content

A tool for generating aligned bounding boxes and pixelated geometries from AOI (Area of Interest) files

Project description

SH Batch Grid Builder

A Python tool for generating aligned bounding boxes and pixelated geometries from Area of Interest (AOI) files. This tool is particularly useful for creating grid-aligned geometries that can be used for batch processing workflows.

Features

  • Aligned Bounding Boxes: Generate grid-aligned bounding boxes that snap to a specified grid resolution
  • Pixelated Geometries: Convert geometries to pixelated (rasterized) representations
  • Automatic Splitting: Automatically splits large geometries that exceed pixel limits
  • Multiple CRS Support: Works with any EPSG code, automatically handling CRS-specific grid origins

Installation

From PyPI (when published)

pip install sh-batch-grid-builder

From Source

git clone <repository-url>
cd SH-Batch-Grid-Builder
pip install .

Development Installation

git clone <repository-url>
cd SH-Batch-Grid-Builder
pip install -e ".[dev]"

Usage

Command Line Interface

The tool provides a command-line interface via the sh-grid-builder command:

sh-grid-builder <input_aoi> --resolution <resolution> --epsg <epsg_code> --output-type <type> -o <output_file>

Arguments

  • input_aoi: Path to input AOI file (GeoJSON, GPKG, or other formats supported by GeoPandas)
  • --resolution: Grid resolution in coordinate units (e.g., 10 for 10 meters)
  • --epsg: EPSG code for the output CRS (e.g., 3035 for ETRS89 / LAEA Europe)
  • --output-type: Type of output to generate:
    • bounding-box: Generate aligned bounding boxes
    • pixelated: Generate pixelated geometry
  • -o, --output: Path to output file (GPKG format required)

Examples

Generate aligned bounding boxes:

sh-grid-builder data/aoi.geojson --resolution 10 --epsg 3035 --output-type bounding-box -o output_bbox.gpkg

Generate pixelated geometry:

sh-grid-builder data/aoi.geojson --resolution 10 --epsg 3035 --output-type pixelated -o output_pixelated.gpkg

Python API

You can also use the package programmatically:

from sh_batch_grid_builder import GeoData

# Initialize with AOI file, EPSG code, and resolution
geo_data = GeoData("path/to/aoi.geojson", epsg_code=3035, resolution=10.0)

# Generate aligned bounding boxes
aligned_bboxes = geo_data.create_aligned_bounding_box(max_pixels=3500)

# Generate pixelated geometry
pixelated_geom = geo_data.create_pixelated_geometry_split(max_pixels=3500)

# Save results
aligned_bboxes.to_file("output_bbox.gpkg", driver="GPKG")
pixelated_geom.to_file("output_pixelated.gpkg", driver="GPKG")

How It Works

Aligned Bounding Boxes

The tool creates bounding boxes that are aligned to a grid based on:

  1. The specified resolution
  2. The CRS origin (false easting/northing) for projected coordinate systems
  3. Automatic splitting when dimensions exceed 3500 pixels (fixed limit)

Pixelated Geometries

The pixelated geometry generation uses a raster-based approach:

  1. Converts the input geometry to a raster mask
  2. Polygonizes the raster back to vector format
  3. Automatically splits large geometries to avoid memory issues

This approach is much faster than vector-based methods for large grids.

Requirements

  • Python >= 3.8
  • geopandas >= 0.12.0
  • pyproj >= 3.4.0
  • shapely >= 2.0.0
  • rasterio >= 1.3.0
  • numpy >= 1.21.0

Development

Running Tests

pytest

Building the Package

python -m build

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

sh_batch_grid_builder-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

sh_batch_grid_builder-0.1.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file sh_batch_grid_builder-0.1.0.tar.gz.

File metadata

  • Download URL: sh_batch_grid_builder-0.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for sh_batch_grid_builder-0.1.0.tar.gz
Algorithm Hash digest
SHA256 945142ebed0bfc7564cee659c2830a613e32dca0e8b942d31db9948daa1f67c6
MD5 ad132b02e822fca4edb39186f43ee3aa
BLAKE2b-256 1f2de6e25735875677d63dee633e9d6c74dd556b798787953e456d3ea3fbcfd1

See more details on using hashes here.

File details

Details for the file sh_batch_grid_builder-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sh_batch_grid_builder-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5f22cebc6107daf40fdbed77006045d7992b21ea589857b107a86d9ccee11bd
MD5 f5f5cebbf7dcf5943d2fed83129d1901
BLAKE2b-256 fe9ffb5acc3f31c65bebbfff06e7963680c5921ce032d4dbc1ef2a7ca302bb4a

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