<< All versions

Skill v1.0.0

currentAutomated scan100/100
kendrick-oppong/geoskills/computational-geometry-operations
──Details
PublishedOctober 26, 2026 at 01:47 AM
Content Hashsha256:5a5396b395286891...
Git SHAfe4762133b94
──Files
Files (1 file, 5.5 KB)
SKILL.md5.5 KBactive
SKILL.md · 70 lines · 5.5 KB

version: "1.0.0" name: computational-geometry-operations description: Use when implementing or debugging core geometry algorithms directly — line simplification (Douglas-Peucker/Visvalingam-Whyatt), polygon boolean operations (union/intersection/difference), buffering, convex/concave hulls, and geometry clipping. Covers the algorithmic layer underneath GIS libraries.


Computational Geometry Operations

When to use this skill

  • Implementing or tuning simplification for display-at-zoom-level use cases
  • Boolean operations (union, intersection, difference) producing unexpected results
  • Buffer operations creating self-intersecting or malformed output
  • "Why did clipping this polygon to a bbox produce a broken shape"

Core algorithms and when to use which

Line/polygon simplification:

AlgorithmBehaviorUse when
Douglas-Peucker (RDP)Removes points based on perpendicular distance from a chord; fast, widely implemented (ST_Simplify, Shapely .simplify(), mapshaper)General-purpose simplification for display at a given zoom/tolerance
Visvalingam-WhyattRemoves points based on the triangular area they contribute; generally produces visually smoother results than RDP at aggressive simplification levelsWhen RDP output looks "spiky" or loses characteristic shape at high simplification ratios
Topology-preserving simplification (ST_SimplifyPreserveTopology, mapshaper -simplify)Avoids creating self-intersections or breaking shared-boundary topology between adjacent polygonsSimplifying adjacent/shared-boundary features (administrative boundaries, parcels) where naive per-feature simplification would create gaps/overlaps between neighbors

Boolean operations (union/intersection/difference): implemented via the OGC Simple Features model (JTS/GEOS under the hood — the engine behind Shapely, PostGIS, and most JS geometry libraries via WASM ports). Correctness depends heavily on valid input geometry (see geodata-qaqc) — boolean ops on invalid geometry are a leading cause of GEOS/JTS "TopologyException" errors.

Buffering: expands/contracts a geometry by a distance. Must be done in a metric CRS (never degrees — see crs-and-reprojection). Buffering concave polygons or lines with sharp angles can produce self-intersecting output at certain join/cap style settings; adjust join style (round/mitre/bevel) and mitre limit rather than accepting malformed output.

Convex vs concave (alpha shape) hulls: convex hull is fast and always valid but overestimates area for non-convex point clusters; concave/alpha-shape hulls better represent the actual point distribution's shape but require tuning an alpha parameter and are more expensive to compute.

Checklist

  • [ ] Is input geometry validated (ST_IsValid/.is_valid) before running boolean operations — invalid input is the most common cause of GEOS "TopologyException"/similar errors
  • [ ] Are buffer/simplification/area operations performed in a metric (projected) CRS, not raw degrees?
  • [ ] Is topology-preserving simplification used (not naive per-feature simplification) when simplifying a set of features that share boundaries?
  • [ ] Is the simplification tolerance tied to the actual display zoom level / pixel size, rather than a single global tolerance applied at all zooms?
  • [ ] For buffering, is join/cap/mitre style considered when the output looks malformed at sharp angles, rather than just increasing segment count blindly?
  • [ ] Is a convex hull being used where a concave/alpha-shape hull would better represent a genuinely non-convex point distribution (and vice versa — don't over-engineer with alpha shapes when a convex hull is sufficient)?
  • [ ] Are results spot-checked for degenerate output (zero-area polygons, collapsed lines) after simplification/buffering at aggressive tolerances?

Common pitfalls

  • Boolean operations on invalid input geometry: produces GEOS/JTS exceptions or silently wrong results — always validate/repair first (geodata-qaqc).
  • Simplifying adjacent polygons independently: creates gaps or slivers between features that used to share an exact boundary — use topology-preserving simplification for anything with shared edges.
  • A single global simplification tolerance for all zoom levels: either over-simplifies at high zoom (visible faceting) or under-simplifies at low zoom (performance cost, visual clutter) — tie tolerance to zoom/pixel size.
  • Buffering in degrees: produces wildly inconsistent real-world buffer distances depending on latitude — always reproject to a metric CRS first.
  • Ignoring buffer join style on sharp concave angles: default round joins can produce unexpectedly bulging or self-intersecting output on complex line geometry — mitre/bevel styles with an appropriate limit often behave better.

Reference snippets

sql
-- Topology-preserving simplification for shared-boundary features
SELECT ST_SimplifyPreserveTopology(geom, 10) FROM parcels; -- tolerance in geom's CRS units
-- Buffer with explicit join style
SELECT ST_Buffer(geom, 50, 'join=mitre mitre_limit=2.0') FROM roads;
python
from shapely.validation import make_valid
geom = make_valid(possibly_invalid_geom) # repair before boolean ops
result = geom_a.intersection(geom_b)

Related skills

  • geodata-qaqc — validating geometry before running these operations
  • crs-and-reprojection — the metric-CRS requirement for buffering/area math
  • vector-tile-pipeline — where zoom-dependent simplification is applied at scale
All versions