I am using Microsoft SQL Server 2019 and am having some problems with SPATIAL calulations. What I am trying to do is see if a “Location” is contained within a POLYGONAL “GeoBoundary”.
But, no matter what I do I keep getting a wrong answer of OUTSIDE
- I’ve tried using CONTAINS
- I’ve tried using INTERSECTS
- I’ve tried using one of the actual edge-values within the POLYGON
But I always get the same answer of OUTSIDE.
The SITE
Name: Bar Junction
Location: Changuinola, Panama [9.432300, -82.518100]
Latitude: 9.432300
Longitude: -82.518100
POLYGON ((-82.518294 9.4324935, -82.517906 9.4324935, -82.517906 9.4321065, -82.518294 9.4321065, -82.518294 9.4324935))
-----------------
-- USING CONTAINS: Fails
DECLARE @Point GEOGRAPHY = GEOGRAPHY::Point(9.432300, -82.518150, 4326);
DECLARE @Polygon GEOGRAPHY = GEOGRAPHY::STPolyFromText('POLYGON ((-82.518294 9.4324935, -82.517906 9.4324935, -82.517906 9.4321065, -82.518294 9.4321065, -82.518294 9.4324935))', 4326);
IF @Polygon.STContains(@Point) = 1
BEGIN
PRINT 'The point is INSIDE the polygon.'
END
ELSE
BEGIN
PRINT 'The point is OUTSIDE the polygon.'
END