Skip to content

Instantly share code, notes, and snippets.

@fxcosta
Created February 18, 2020 20:54
Show Gist options
  • Save fxcosta/718078d48371ab57ce8e9e6eb7349f75 to your computer and use it in GitHub Desktop.
Save fxcosta/718078d48371ab57ce8e9e6eb7349f75 to your computer and use it in GitHub Desktop.
SQL Server query to check if a polygon contains a specific point (coordinates)
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('POLYGON ((-4583852.3559951019 -1744384.5747652152, -4511274.7500624815 -1744384.5747652152, -4511274.7500624815 -1637044.6921474137, -4583852.3559951019 -1637044.6921474137, -4583852.3559951019 -1744384.5747652152))', 4326);
SET @h = geometry::STGeomFromText('POINT (-4546586.20608064 -1672720.54193957)', 4326);
SELECT @g.STContains(@h);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment