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.0a7.tar.gz (137.3 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.0a7-py3-none-any.whl (92.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polyforge-0.1.0a7.tar.gz
  • Upload date:
  • Size: 137.3 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.0a7.tar.gz
Algorithm Hash digest
SHA256 6fe63c78362e8700fa19bffd91d2e51574754f2566104b5060f3981a255886d9
MD5 bcf686030d408ad13eacc93d181083e3
BLAKE2b-256 798ba950a505fd068ae319f8b538d9d84f74e4f35eee97252f4c27a9406678ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for polyforge-0.1.0a7.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.0a7-py3-none-any.whl.

File metadata

  • Download URL: polyforge-0.1.0a7-py3-none-any.whl
  • Upload date:
  • Size: 92.4 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.0a7-py3-none-any.whl
Algorithm Hash digest
SHA256 4501f944ab43b5bf7e36e164277137502b3537ed4991db4455da74c6243f7dde
MD5 aecf10e5457e20eabadd0e467270f83d
BLAKE2b-256 1f05d18259466869633d7f5a679a99c301cdf9d4ebf4fa89768e1bd4b76c7294

See more details on using hashes here.

Provenance

The following attestation bundles were made for polyforge-0.1.0a7-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