Databases
AuraScore 81/100

PostGIS Land Parcel Spatial Indexing Script

Generate an automated SQL migration script for indexing, validating, and partitioning geospatial land parcels.

Use when restructuring cadastral, zoning, or land parcel boundaries in spatial databases. It delivers production-ready DDL and spatial index maintenance routines.

Template

Role: Senior Geospatial Database Engineer specializing in cadastral architectures and spatial indexing.

Context

  • Database engine target: {{target_database_engine}}
  • Primary parcel boundary table: {{parcel_table_name}}
  • Coordinate reference system SRID: {{spatial_reference_system}}
  • Overlay zoning boundary dataset: {{zoning_layer_table}}
  • Migration batch limit: {{staging_batch_size}}
  • Index page storage density parameter: {{index_fill_factor}}

Task

Generate a complete, idempotent spatial migration SQL script that validates geometries, builds performant R-Tree/GiST spatial indexes, and prepares {{parcel_table_name}} for high-throughput topological spatial joins against {{zoning_layer_table}}.

Method

  1. Inspect table schemas and inject safety checks ensuring PostGIS or equivalent spatial extensions are loaded on {{target_database_engine}}.
  2. Write pre-migration schema guards with transactional DDL wrappers.
  3. Implement geometry validation routines to catch and correct invalid polygon rings, self-intersections, and unclosed boundaries conforming to {{spatial_reference_system}}.
  4. Define spatial index creation commands on {{parcel_table_name}} utilizing GiST/SP-GiST with configurable fill factor settings via {{index_fill_factor}}.
  5. Construct batch update statements processing unindexed parcel batches limited by {{staging_batch_size}} to prevent locking live read replicas.
  6. Generate analytical ST_Intersects and ST_Contains sample verification queries linking {{parcel_table_name}} and {{zoning_layer_table}}.
  7. Include comprehensive rollback operations that drop spatial indexes and revert staging columns safely.

Constraints

  • MUST wrap all non-concurrent schema alterations in explicit transactional blocks.
  • MUST NOT leave invalid polygon topologies unlogged or silently dropped during execution.
  • Scripts MUST include execution timing checkpoints and detailed comment headers per section.
  • Geometry column transformations must strictly enforce {{spatial_reference_system}}.

Output format

Executable SQL script file structured in four sequential sections:

  1. Environment Prerequisites and Schema Verifications (max 30 lines)
  2. Geometry Sanitization & Transformation Procedures (max 60 lines)
  3. Spatial Index DDL and Vacuum/Analyze Directives (max 40 lines)
  4. Post-Migration Verification Queries and Rollback DDL (max 50 lines)

Self-review

  • Confirm that no raw SQL statements drop data columns without backup tables.
  • Ensure all spatial function calls match the specified {{spatial_reference_system}}.
  • Verify script idempotency so repeated execution does not produce duplicate index errors.
AuraScore breakdown
81/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering12/12 · Strong

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness3/5 · Adequate

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

developers
developers-databases
real-estate-construction
postgis
cadastral
spatial-indexing