Skip to main content

polygon processing and manipulation library built on Shapely - simplification, repair, merging, overlap resolution, and clearance fixing

Project description

Polyforge

Polyforge is a focused toolkit for cleaning, simplifying, repairing, and merging planar geometries built on top of Shapely. It exposes a small set of high-level functions that combine fast NumPy-based vertex processing with STRtree-powered spatial indexing, so you can run the same code on a handful of polygons or on thousands of building footprints.

Installation

pip install polyforge

Python 3.10+ with Shapely ≥ 2.1 is required.

What You Get

Area Highlights
Simplify & Clean simplify_rdp, simplify_vw, collapse_short_edges, remove_small_holes, remove_narrow_holes
Clearance Fixing fix_clearance auto-detects issues (holes too close, spikes, passages) and routes to ops helpers. Individual functions (fix_hole_too_close, fix_narrow_passage, …) now accept either enums or plain strings (e.g. strategy="split").
Overlap & Merge split_overlap for pairs, remove_overlaps for batches, merge_close_polygons with ops-based strategies ("simple_buffer", "selective_buffer", "vertex_movement", "boundary_extension", "convex_bridges").
Repair & QA repair_geometry, analyze_geometry, plus the pipeline-driven robust_fix_geometry / robust_fix_batch that iterate validity → clearance → merge → cleanup steps.
Core Types Strategy enums (MergeStrategy, RepairStrategy, OverlapStrategy, …) remain available, but everything also accepts literal strings; GeometryConstraints + shared ops utilities live in polyforge.ops.*.

Quick Examples

Simplify & Clean

from shapely.geometry import Polygon
from polyforge import simplify_vwp, remove_small_holes

poly = Polygon([(0, 0), (5, 0.1), (10, 0), (10, 10), (0, 10)])
poly = simplify_vwp(poly, threshold=0.2)
poly = remove_small_holes(poly, min_area=1.0)

Fix Narrow Passages Automatically

from polyforge import fix_clearance

improved, info = fix_clearance(complex_poly, min_clearance=1.5, return_diagnosis=True)
print(info.issue, info.fixed)

Merge Buildings into Blocks

from polyforge import merge_close_polygons

merged = merge_close_polygons(
    buildings,
    margin=2.0,
    merge_strategy="boundary_extension",
    insert_vertices=True,
)

Remove Overlaps at Scale

from polyforge import remove_overlaps
clean = remove_overlaps(parcel_list, overlap_strategy='split')

Constrain Repairs

from polyforge import robust_fix_geometry
from polyforge.core import GeometryConstraints

constraints = GeometryConstraints(min_clearance=1.0, min_area_ratio=0.9)
fixed, warn = robust_fix_geometry(polygon, constraints)

Design Notes

  • Ops-first architecture – low-level helpers live in polyforge/ops/… (simplify, cleanup, clearance, merge). Public modules are thin wrappers that call these ops so behaviour stays consistent across the library.
  • Literal-friendly configuration – strategy parameters accept enums or plain strings ("selective_buffer", "smooth", etc.), making it easy to drive Polyforge from config files or CLI flags.
  • Pipeline-driven repairrobust_fix_geometry now runs a simple step list (validity → clearance → merge → cleanup) via polyforge.pipeline.run_steps, replacing the old transactional stage system.
  • process_geometry() everywhere – every simplification/cleanup call is just a NumPy function applied to each vertex array, so Z values are preserved automatically.
  • STRtree first – overlap removal, merges, and vertex insertion all walk spatial indexes, keeping runtime roughly O(n log n) even for thousands of polygons.

Project Layout (high level)

polyforge/
  ops/
    simplify_ops.py        # coordinate-level simplify helpers
    cleanup_ops.py         # hole removal, sliver cleanup
    clearance/             # clearance fix primitives
    merge/ + merge_*       # merge strategies & utilities
  simplify.py              # thin wrappers over ops.simplify
  clearance/               # fix_clearance + public wrappers
  overlap.py               # overlap engine + batch helpers
  merge/                   # merge orchestrator (calls ops)
  repair/                  # classic repair + pipeline-based robust fixes
  core/                    # enums, constraints, geometry/spatial utils
  pipeline.py              # FixConfig + run_steps helper

Advanced: Using the ops layer directly

Most users should stick to the high-level API (polyforge.simplify, polyforge.clearance, polyforge.merge, polyforge.repair). If you need to compose Polyforge primitives yourself (custom pipelines, batch transforms, etc.), import the ops helpers:

from shapely.geometry import Polygon
from polyforge.process import process_geometry
from polyforge.ops.simplify_ops import snap_short_edges
from polyforge.ops.clearance import fix_hole_too_close
from polyforge.ops.merge import merge_selective_buffer

poly = Polygon([(0, 0), (1, 0.01), (2, 0), (2, 2), (0, 2)])

# Run a raw NumPy transform via process_geometry
collapsed = process_geometry(poly, snap_short_edges, min_length=0.1, snap_mode="midpoint")

# Call clearance helpers directly (accept enums or strings)
fixed = fix_hole_too_close(collapsed, min_clearance=1.0, strategy="shrink")

# Use merge strategies without going through merge_close_polygons
merged = merge_selective_buffer([fixed, fixed.translate(1.5, 0)], margin=0.5, preserve_holes=True)

These ops modules expose the same functions the public API uses internally, so they're ideal for custom workflows or experimentation.

Running Tests

python -m pytest -q

The suite asserts all expected warnings, so any output indicates a regression.

That’s it—import what you need from polyforge and combine the high-level functions to build your own geometry pipelines.

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

polyforge-0.1.0a3.tar.gz (130.5 kB view details)

Uploaded Source

Built Distribution

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

polyforge-0.1.0a3-py3-none-any.whl (99.0 kB view details)

Uploaded Python 3

File details

Details for the file polyforge-0.1.0a3.tar.gz.

File metadata

  • Download URL: polyforge-0.1.0a3.tar.gz
  • Upload date:
  • Size: 130.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polyforge-0.1.0a3.tar.gz
Algorithm Hash digest
SHA256 dace2d2cb24f1a4a93e2b5161393646bb0b9b11eb6fd79b7a54265c581345d40
MD5 92c98af76d6ef1ff8d99b5d54461b47c
BLAKE2b-256 0fe636bbe798f133010b88e44bdb40e9ea8f1f7c333513b6eb3b9a78333038bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for polyforge-0.1.0a3.tar.gz:

Publisher: publish.yml on dwastberg/polyforge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polyforge-0.1.0a3-py3-none-any.whl.

File metadata

  • Download URL: polyforge-0.1.0a3-py3-none-any.whl
  • Upload date:
  • Size: 99.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polyforge-0.1.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 9cb3cfbdcac4fb00f158abfbb653b712ab594d67c26e5c2556524e210a2e073b
MD5 03183bfe4327c17ac66c45cfee550b34
BLAKE2b-256 f044043076beb5793aed9aac1400e2e4488dfb06c1804a89b0ca64e9b4feb5b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for polyforge-0.1.0a3-py3-none-any.whl:

Publisher: publish.yml on dwastberg/polyforge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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