Geometry Validity Topology Checks

Architecture

Spatial ETL and ELT pipelines require a dedicated validation topology that operates as a stateless, horizontally scalable gate between raw ingestion zones and curated data products. The architecture isolates geometry validation and topology verification into a compute-optimized layer that leverages distributed spatial indexing—typically R-tree or Quadtree structures—to eliminate full-table scans during predicate evaluation. Raw vector payloads land in a transient staging bucket where coordinate reference system (CRS) validation occurs first. This early-stage normalization guarantees that all downstream topology predicates execute against a consistent spatial datum, preventing silent projection drift.

Once CRS alignment is confirmed, a validation microservice or distributed Spark/Flink cluster applies OGC Simple Features compliance checks, ring orientation normalization, and self-intersection detection. This design explicitly decouples heavy geometric operations from transactional OLTP/OLAP workloads, enabling enterprise scaling and predictive maintenance by routing validation telemetry to a centralized observability plane. The topology natively supports automated row count and attribute sync verification by emitting structured validation metadata alongside spatial payloads, allowing downstream consumers to correlate structural integrity with business-critical attributes before materialization.

flowchart TD
  RAW["Raw vector payload"] --> CRS["CRS normalization"]
  CRS --> V{"ST_IsValid?"}
  V -- "yes" --> CUR["Curated store"]
  V -- "no" --> RP["ST_MakeValid repair"]
  RP --> V2{"Repaired valid?"}
  V2 -- "yes" --> CUR
  V2 -- "no" --> Q["Quarantine · DLQ for review"]

Metric

Geometry validity and topology monitoring rely on a tightly defined set of quantitative signals that measure spatial integrity at both the record and dataset levels. The primary metric tracks the invalid geometry ratio, calculated as:

invalid_geometry_ratio = COUNT(ST_IsValid(geom) = FALSE) / COUNT(*)

This ratio is computed per ingestion window and normalized against partition boundaries. Topology violation density measures rule-specific failures such as polygon overlaps, sliver gaps, dangling nodes, and non-planar intersections, aggregated per spatial partition or administrative boundary. CRS validation introduces a secondary metric that quantifies distortion-induced topology degradation when features undergo projection transformations, typically tracked via maximum coordinate delta (ΔX, ΔY) before and after transformation.

These signals feed directly into broader Spatial Data Freshness & Quality Metrics by establishing a baseline for acceptable geometric drift. Temporal baseline alignment for time-series GIS extends these metrics by tracking how topology violations evolve across ingestion windows, enabling teams to distinguish between transient ETL artifacts and systemic source degradation. Metric collection occurs at the partition level, with rolling averages (7d/30d) and standard deviations computed to establish dynamic thresholds that adapt to seasonal spatial data volume fluctuations.

Detection

Detection logic operates through a configurable rule engine that evaluates spatial predicates against severity thresholds and routes alerts based on ownership, operational impact, and SLA boundaries. The engine ingests telemetry from the validation layer and applies the following tiered routing matrix:

Severity Invalid Geometry Ratio Topology Violation Density Action
P3 (Info) < 0.1% < 5 per 10k features Log to observability dashboard, no page
P2 (Warning) 0.1% – 2.0% 5 – 50 per 10k features Route to data engineering queue, trigger automated quarantine
P1 (Critical) > 2.0% > 50 per 10k features Halt downstream materialization, page SRE/GIS Ops, trigger rollback

A P2 alert triggers when the invalid geometry ratio exceeds 0.1% but remains below 2%, indicating localized corruption that can be quarantined without disrupting the broader pipeline. The detection layer integrates directly with Tracking Spatial Data Freshness SLAs by correlating topology failures with ingestion latency, ensuring that delayed or malformed payloads do not silently breach contractual freshness windows.

Sample Alertmanager Routing Configuration:

route:
  receiver: 'default-pager'
  group_by: ['pipeline_id', 'severity', 'partition_key']
  routes:
    - match_re:
        severity: 'P2|P1'
      receiver: 'spatial-validation-team'
      continue: false
      group_wait: 5m
      repeat_interval: 30m
receivers:
  - name: 'spatial-validation-team'
    webhook_configs:
      - url: 'https://hooks.internal/spatial-validation'
        send_resolved: true

Implementation & Pipeline Integration

Deploying geometry validity checks requires embedding validation predicates directly into the transformation DAG while emitting structured telemetry to the observability stack. Below is a production-ready PySpark implementation that performs geometry validation via PostGIS-compatible SQL and a Python UDF stub for illustration:

from pyspark.sql import SparkSession
from pyspark.sql.functions import col, when, count, lit
from pyspark.sql.types import BooleanType, StructType, StructField, StringType

spark = SparkSession.builder.appName("geometry-validation").getOrCreate()

# In a production Sedona or GeoMesa deployment, replace with native spatial UDFs.
# Here we illustrate the DataFrame logic structure:
raw_spatial_df = spark.table("staging.raw_features")

validation_df = (raw_spatial_df
    # is_valid would be set by a real spatial UDF such as ST_IsValid
    .withColumn("is_valid", col("geom").isNotNull())
    .withColumn("violation_type",
        when(~col("is_valid"), lit("INVALID_GEOMETRY"))
        .when(col("geom_area") < 1e-6, lit("SLIVER_GEOMETRY"))
        .otherwise(lit("NONE")))
    .withColumn("crs_code", col("metadata.crs"))
)

# Emit partition-level metrics to OpenTelemetry/Prometheus
metrics_df = validation_df.groupBy("partition_key", "crs_code").agg(
    count("*").alias("total_records"),
    count(when(~col("is_valid"), True)).alias("invalid_records"),
    count(when(col("violation_type") == "SLIVER_GEOMETRY", True)).alias("sliver_count")
)
metrics_df.write.format("delta").mode("append").save("/mnt/metrics/geometry_validation")

The validation output must be cross-referenced with Spatial Coverage & Extent Monitoring to ensure that topology failures do not artificially shrink or expand dataset bounding boxes. For hybrid vector-raster pipelines, topology checks should be paired with Calculating spatial coverage gaps in raster datasets to maintain end-to-end spatial consistency across modalities.

Troubleshooting & Remediation Workflows

When detection thresholds are breached, follow this structured remediation path to isolate root causes and restore pipeline integrity:

  1. CRS Mismatch & Projection Drift

    • Symptom: High topology violation density immediately after ingestion, but geometries appear visually correct.
    • Diagnosis: Run SELECT ST_SRID(geom) FROM staging LIMIT 10; and compare against the declared EPSG code.
    • Fix: Enforce explicit transformation: ST_Transform(ST_SetSRID(geom, source_epsg), target_epsg). Validate using PostGIS ST_IsValid post-transformation.
  2. Ring Orientation & Self-Intersection

    • Symptom: Invalid geometry ratio spikes for polygon datasets; downstream rendering engines fail.
    • Diagnosis: Check winding order consistency. Exterior rings must be counter-clockwise (OGC standard), interior rings clockwise.
    • Fix: Apply normalization: ST_MakeValid(ST_ForcePolygonCCW(geom)). Re-run validation and verify ratio drops below 0.1%.
  3. Floating-Point Precision & Sliver Polygons

    • Symptom: High count of SLIVER_GEOMETRY violations; topology checks fail due to micro-gaps.
    • Diagnosis: Inspect coordinate precision. Values exceeding 15 decimal places often introduce GEOS topology errors.
    • Fix: Snap coordinates to a grid tolerance: ST_SnapToGrid(geom, 1e-5). Combine with ST_Buffer(geom, 0) to collapse micro-edges before revalidation.
  4. Pipeline Backpressure & Quarantine Routing

    • Symptom: P2/P1 alerts trigger, but invalid records continue to downstream materialization.
    • Diagnosis: Check validation DAG checkpointing and quarantine routing logic.
    • Fix: Implement a dead-letter queue (DLQ) for invalid geometries. Route valid payloads to curated zones, persist invalid records to s3://dlq/spatial-invalid/{date}/ with attached validation telemetry for manual review or automated reprocessing.

All remediation steps should be logged to the centralized observability plane, ensuring that topology health trends remain visible across enterprise scaling initiatives and predictive maintenance cycles.