Table of Contents

Property IndexGeographyCast

Namespace
YndigoBlue.Velocity.Data.PostgreSql
Assembly
YndigoBlue.Velocity.dll

IndexGeographyCast

Gets or sets whether a spatial index built on a geometry column also indexes that column's ::geography cast, alongside its native geometry representation.

public bool IndexGeographyCast { get; set; }

Property Value

bool

Remarks

PostGIS defines geometry → geography as an implicit cast (confirmed via pg_cast), but the reverse is explicit-only. That asymmetry means any spatial function call that needs a geography overload to resolve — most notably every Spatial* function taking a UnitOfMeasure (real-world-unit distance/buffer calculations), and any comparison against a Geography literal — gets that cast inserted by Postgres itself, silently, with no ::geography ever appearing in the SQL text Velocity emits. A plain GIST index built only on the bare geometry column no longer matches the expression the planner actually evaluates once that implicit cast is in play, so the query silently falls back to a full sequential scan instead of using the index — correct results, unexpectedly slow.

Enabled (True): BuildCreateSpatialIndex emits a two-key GIST index — USING GIST (column, (column::geography)) — so Postgres can use the same index object for both the native-geometry functions (ST_Contains, ST_Centroid, ST_GeneratePoints, plain ST_Intersects(geometry, geometry), …) and the implicit-geography ones. GIST, unlike btree, doesn't require a leftmost-prefix match — either key serves its matching predicate independently. Costs roughly double the on-disk size of that index (both representations are stored per row) and adds the same overhead on every insert/update.

Disabled (False — default): BuildCreateSpatialIndex builds the plain, single-key geometry index only — today's existing behavior, and the right choice for a column that genuinely never needs a UnitOfMeasure-based spatial function, or one whose data isn't real-world WGS84 geography at all (a planar/engineering coordinate system, where the ::geography cast — which doesn't validate the source SRID — would silently produce a geodetic index over numbers that were never meant to represent a point on Earth).

Set via the IndexGeographyCast context setting (e.g. Context="IndexGeographyCast=true"), same convention as every other context-setting-backed property on this class.