Skip to main content

Geometry Validity and Topology

Geometry validity asks whether a representation satisfies rules for its type. Topology asks how interiors, boundaries, and exteriors relate. A closed-looking polygon can still be invalid, and a numerically tiny gap can change touches, intersects, or an overlay.

Prerequisites​

Complete geospatial file formats. Keep an immutable source geometry and provenance record available before attempting repairs.

Learning goals​

  • Check emptiness, geometry type, validity, and a validity reason.
  • Distinguish coordinate closure from a topologically valid polygon.
  • Explain boundary-sensitive predicates such as contains, covers, within, and touches.
  • Treat make_valid as a documented transformation whose output type and meaning require review.

Diagnose before transforming​

A polygon shell must follow validity rules: rings close, boundaries do not improperly cross, and holes and shells form a coherent surface. The fixture's bow-tie ring returns to its starting coordinate but crosses itself. Closure alone is insufficient.

Run validation before spatial joins, overlay, area, or dissolve. Store at least feature ID, original validity, reason, action, output type, and reviewer or rule version. Do not replace the source geometry in place. Repair may split one polygon into a MultiPolygon, return lower-dimensional parts in a GeometryCollection, or alter boundaries. Those are semantic changes, not cosmetic formatting.

Buffering by zero has historically been used as an ad hoc repair, but it does not express intent or guarantee the desired output. Use a documented validity operation, inspect the result, and decide whether it still represents the source entity. Some records should be rejected or sent back to the authoritative producer instead.

Worked example​

import json
from pathlib import Path

import shapely
from shapely.geometry import shape

path = Path("tests/fixtures/geospatial-data-science/invalid-areas.geojson")
document = json.loads(path.read_text(encoding="utf-8"))
geometries = {
feature["properties"]["area_id"]: shape(feature["geometry"])
for feature in document["features"]
}
validity = {name: geometry.is_valid for name, geometry in sorted(geometries.items())}
source = geometries["bow-tie"]
reason = shapely.is_valid_reason(source).split("[")[0]
candidate = shapely.make_valid(source)
parts = len(candidate.geoms) if hasattr(candidate, "geoms") else 1
print(f"validity={validity}")
print(f"bow_tie_reason={reason} repair={candidate.geom_type} parts={parts}")
print(f"source_replaced={source is candidate}")

Expected output:

validity={'bow-tie': False, 'valid-courtyard': True}
bow_tie_reason=Self-intersection repair=MultiPolygon parts=2
source_replaced=False

The candidate is valid, but the two output parts still need a domain decision: did the source intend two areas, one area with a different vertex order, or something else? The verifier checks only the transparent computational outcome.

Predicates and boundaries​

Simple-feature predicates are not synonyms. A polygon generally does not contain a point that lies only on its boundary, while it can cover that point. Two neighboring polygons can touch because their boundaries meet without their interiors overlapping. intersects is broader: any shared interior or boundary point qualifies.

Precision and near-coincident coordinates complicate these decisions. Snapping or applying a precision grid can remove tiny gaps but can also collapse narrow features or create new contacts. Record the tolerance in CRS units and relate it to source accuracy; never choose it merely to obtain a desired count.

Limitations and common mistakes​

  • is_valid=True does not prove the geometry is located correctly or matches reality.
  • Validity rules focus mainly on polygonal topology; logical network connectivity needs separate checks.
  • Ring orientation is not the same as validity and can be format-specific.
  • Repair can change feature count, geometry type, area, and downstream join cardinality.
  • Floating-point equality and topological equality answer different questions.

Practice​

Draft a repair ledger for the bow-tie feature with source ID, reason, proposed operation, output type, part count, area change, decision owner, and disposition. State what evidence would justify accepting the repair.

Next steps​

Next, use GeoPandas and Shapely while keeping CRS, missingness, and geometry semantics explicit.

Primary sources​

Checked 2026-10-18: OGC, Simple Feature Access 1.2.1; Shapely 2.2, predicates and make_valid; GeoPandas, GeoSeries.make_valid.