TransWikia.com

STContains on SQL Server vs ST_Contains on PostGIS

Geographic Information Systems Asked by Jeffery Candiloro on April 27, 2021

I am trying to run a basic point in polygon query against a table of polygons. In PostGIS this works:

SELECT *
FROM schema.table
WHERE ST_Contains(
  table.geom,
  ST_PointFromText('POINT(XXX.XXXXXXX YY.YYYYYY)',4283)
);

As I understand it, this is the equivalent in SQL Server:

SELECT *
FROM schema.table
WHERE column.STContains(
  geography::STPointFromText('POINT(XXX.XXXXXXX YY.YYYYYY)',4283)
) = 1;

Both tables are generated from exactly the same shapefile. For PostGIS I use shp2pgsql and for SQL Server I use ogr2ogr to convert the data. In SQL Server I need to run a query to MakeValid the 8 errors in the source data (confirmed in QGIS).

When I run the above query in PostGIS I am returned a single, correct polygon. When I run the other query in SQL Server I am returned a set of polygons, none of which is correct.

Can someone assist me in getting the query correct for SQL Server?

One Answer

Sort of figured it out. Looks like it is a problem in geography vs geometry. If I import the polygons as geometries then it works properly.

Answered by Jeffery Candiloro on April 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP