Skip to main content

A Python library for regularizing building footprints in geospatial data. This library helps clean up and standardize building polygon geometries by aligning edges to principal directions.

Project description

Building Footprint Regularization

A Python library for regularizing building footprints in geospatial data. This library helps clean up and standardize building polygon geometries by aligning edges to principal directions. Built as an open source alternative to the ArcGIS Regularize Building Footprint (3D Analyst) tool.

Python License

Example Results

Before and after regularization:

Example 1: Before and After Regularization Example 2: Before and After Regularization

Overview

Building footprints extracted from remote sensing imagery often contain noise, irregular edges, and geometric inconsistencies. This library provides tools to regularize these footprints by:

  • Aligning edges to principal directions (orthogonal and optional 45-degree angles)
  • Converting near-rectangular buildings to perfect rectangles
  • Converting near-circular buildings to perfect circles
  • Simplifying complex polygons while maintaining their essential shape
  • Supporting parallel processing for efficient computation with large datasets

Inspired by RS-building-regularization, this library takes a geometric approach to building regularization with improvements for usability and integration with the GeoPandas ecosystem.

Installation

pip install buildingregulariser

Quick Start

import geopandas as gpd
from buildingregulariser import regularize_geodataframe

# Load your building footprints
buildings = gpd.read_file("buildings.gpkg")

# Regularize the building footprints
regularized_buildings = regularize_geodataframe(
    buildings, 
)

# Save the results
regularized_buildings.to_file("regularized_buildings.gpkg")

Features

  • GeoDataFrame Integration: Works seamlessly with GeoPandas GeoDataFrames
  • CRS Handling: Intelligently handles coordinate reference systems
  • Polygon Regularization: Aligns edges to principal directions
  • 45-Degree Support: Optional alignment to 45-degree angles
  • Circle Detection: Identifies and converts near-circular shapes to perfect circles
  • Edge Simplification: Reduces the number of vertices while preserving shape
  • Geometry Cleanup: Fixes invalid geometries and removes artifacts
  • Parallel Processing: Utilizes multiple CPU cores for faster processing of large datasets

Usage Examples

Basic Regularization

from buildingregulariser import regularize_geodataframe
import geopandas as gpd

buildings = gpd.read_file("buildings.gpkg")
regularized = regularize_geodataframe(buildings)

Working with Different Coordinate Systems

regularized = regularize_geodataframe(
    buildings,
    target_crs="EPSG:3857"  # Web Mercator projection
)

Fine-tuning Regularization Parameters

regularized = regularize_geodataframe(
    buildings,
    parallel_threshold=2.0,   # Higher values allow less edge alignment
    simplify=True,
    simplify_tolerance=0.5,   # Controls simplification level
    allow_45_degree=True,     # Enable 45-degree angles
    allow_circles=True,       # Enable circle detection
    circle_threshold=0.9      # IOU threshold for circle detection
)

Parallel Processing for Large Datasets

import multiprocessing

# Use multiple CPU cores for processing
regularized = regularize_geodataframe(
    buildings,
    num_cores=32 # Using 32 cores
)

Parameters

  • geodataframe: Input GeoDataFrame with polygon geometries
  • parallel_threshold: Distance threshold for handling parallel lines (default: 1.0)
  • target_crs: Target CRS for reprojection. If None, uses the input CRS
  • simplify: If True, applies simplification to the geometry (default: True)
  • simplify_tolerance: Tolerance for simplification (default: 0.5)
  • allow_45_degree: If True, allows edges to be oriented at 45-degree angles (default: True)
  • allow_circles: If True, detects and converts near-circular shapes to perfect circles (default: True)
  • circle_threshold: Intersection over Union (IoU) threshold for circle detection (default: 0.9)
  • num_cores: Number of CPU cores to use for parallel processing (default: 1)

Returns

  • A new GeoDataFrame with regularized polygon geometries

How It Works

  1. Edge Analysis: Analyzes each polygon to identify principal directions
  2. Edge Orientation: Aligns edges to be parallel, perpendicular, or at 45 degrees to the main direction
  3. Circle Detection: Optionally identifies shapes that are nearly circular and converts them to perfect circles
  4. Edge Connection: Ensures proper connectivity between oriented edges
  5. Angle Enforcement: Post-processing to ensure target angles are precisely maintained

License

This project is licensed under the MIT License

Acknowledgments

This library was inspired by the RS-building-regularization project, with improvements for integration with the GeoPandas ecosystem and enhanced regularization algorithms.

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

buildingregulariser-0.1.8.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

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

buildingregulariser-0.1.8-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file buildingregulariser-0.1.8.tar.gz.

File metadata

  • Download URL: buildingregulariser-0.1.8.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for buildingregulariser-0.1.8.tar.gz
Algorithm Hash digest
SHA256 9c11b2aa747303e9cd467ecb0e9a22fc287c2cc086761dbfb9947a7fe405dba4
MD5 6c8dbb8f6c93b2800f9607560dfacf8c
BLAKE2b-256 65e30d387e83c8dbd1e29773efbf993d3d1457c357f5ac139bf2d5e6d465c475

See more details on using hashes here.

File details

Details for the file buildingregulariser-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for buildingregulariser-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 323e96899dc072c96a829e9a1861bc294d5d8f983a1db64f40ddd07450af740e
MD5 09e373ca2953039ba792facf0cfa2e04
BLAKE2b-256 d1b849c912b64a471d2c8b41f748c2136118d0cfd9f2b43848c47012d8ecd6c9

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