[Fdo-trac] [fdo-trac] #1023: SQLServerSpatial: Spatial queries against geography columns are winding-order sensitive
FDO
trac_fdo at osgeo.org
Sun Oct 25 18:17:58 PDT 2026
#1023: SQLServerSpatial: Spatial queries against geography columns are winding-
order sensitive
-------------------------------+----------------------
Reporter: jng | Owner: jng
Type: defect | Status: closed
Priority: major | Milestone: 4.2.0
Component: SQLServer Spatial | Version:
Severity: 3 | Resolution: fixed
Keywords: | External ID:
-------------------------------+----------------------
Changes (by jng):
* resolution: => fixed
* status: assigned => closed
Comment:
In [changeset:"8425" 8425]:
{{{#!CommitTicketReference repository="" revision="8425"
SQLServerSpatial: reorient geography literals to the class's polygon
vertex order rule
SQL Server's geography type does not treat a polygon's rings as a
container with an
inside: it reads the ring direction as which side of the ring is the
interior, so a loop
wound the other way round describes everything except the area it
encloses. The provider
passed the caller's literal through unchanged, so a box selection against
a geographic
feature class selected the whole table, and an insert or update stored the
complement of
the polygon it was given. In MapGuide this surfaces as DB_LOG_BUFFER_FULL
on the
persisted selection, because selecting the whole table makes the selection
blob larger
than the session repository's log buffer.
Every stage below the caller was already correct - BuildPolygon writes
rings in arrival
order with ring 0 as the exterior ring - so the winding the client sent is
the winding
SQL Server saw. The capability was already advertised, and already plumbed
as far as the
class definition: FdoSmPhSqsDbObject::GetPolygonVertexOrderStrictness()
reports a geography
column as strict, and FdoSmLpClassBase::Capabilities carries that up to
it. What was
missing is the consumer - FdoSpatialUtility::FixPolygonVertexOrder()
applies a rule, but
nothing on the path that binds a filter literal or a stored value called
it.
FdoRdbmsSchemaUtil::FixGeometryVertexOrder() now reads the rule and the
strictness the
class advertises for the property and reorients a literal through
FdoSpatialUtility::FixPolygonVertexOrder() when - and only when - the rule
is declared
strict. Strictness is the guard rather than the rule itself: among the
GenericRdbms
providers only a SQL Server geography column declares it, so planar
geometry columns and
the MySQL, PostGIS and ODBC literals pass through unchanged, and a
deliberately large
geography polygon is still expressible through a provider that does not
declare
strictness. It is applied on both sides:
- FdoRdbmsSqlServerFilterProcessor and FdoRdbmsSqlServerSqlBuilder
reorient the filter
literal;
- the four bind sites that write geometry - FdoRdbmsSimpleInsertCommand,
FdoRdbmsSimpleUpdateCommand, and the insert and update PVC handlers -
reorient stored
values.
The reoriented values are owned by FdoRdbmsGeometryValueOwner for as long
as the command
or filter processor that binds them lives, so a command that reuses its
bound parameters
keeps the fixed literal instead of reverting to the original on rebind.
Tests:
* SqlServerFdoSelectTest::TestSpatialGeogWinding selects the same box
wound both ways
against a geography column and requires the same two features. It fails
without the
change (cwNames->GetCount() == ccwNames->GetCount()) and passes with it.
The suite had
no coverage for this because TestSpatialGeog associates its geometry
property named Geog
with the projected spatial context projSC, so that fixture never created
a geography
column at all.
Verified on ubuntu22 amd64 against the dbs/docker-compose.yml mssql_cs
fixture
(Latin1_General_CS_AS), Debug (ASan/LSan) and Release, through
run_fdo_tests.sh
--with-sqlserver-init:
* FdoSelectTest: Run: 26, Failure total: 2 before the change and 1 after,
the failure the
change clears being TestSpatialGeogWinding.
* UnitTestSQLServerSpatial, whole suite, Debug: OK (290) in 22m 39s on a
freshly recreated
mssql_cs. 3 direct leak records remain, all of them allocating in test
code
(TestSpatialGeog's CreateLinearRing,
TestExplicitPropertyListGeometryTypes'
FdoIdentifier::Create, and a dropped FdoSchemaException from the
negative DropDatastore
path); none has a frame in this change.
* UnitTestMySql OK (249), UnitTestPostGis OK (140) and UnitTest (SHP) OK
(138) are
unchanged, and are the suites that compile the same RDBMS bind code.
Fixes #1023
}}}
--
Ticket URL: <https://trac.osgeo.org/fdo/ticket/1023#comment:1>
FDO <http://fdo.osgeo.org/>
Feature Data Objects
More information about the fdo-trac
mailing list