Search for a geography point in a rectangular (polygonal)

I have an interesting / annoying problem with finding lats and long ground marks inside a rectangular border. I believe that my two points are inside my rectangular border. but since you can test yourself, the result of the first choice is false instead of true!

DECLARE @boundingRect varchar(1000)
DECLARE @maxLat VARCHAR(20)
DECLARE @minLong VARCHAR(20)
DECLARE @minLat VARCHAR(20)
DECLARE @maxLong VARCHAR(20)


set @maxLat ='-36.06631759541187'
set @minLong ='125.23310677812492'
set @minLat ='-44.43329881450396'
set @maxLong='167.04707162187492'


SET @boundingRect = 'POLYGON((' +   @minLong + ' '  + @minLat + ', ' +
                                        @maxLong + ' ' + @minLat + ', ' + 
                                        @maxLong + ' ' + @maxLat + ', ' + 
                                        @minLong + ' ' + @maxLat + ', ' + 
                                        @minLong + ' ' + @minLat + '))'

DECLARE @Bounds AS Geography =GEOGRAPHY::STPolyFromText(@boundingRect,4326)

DECLARE @point1 AS GEOGRAPHY = GEOGRAPHY::Point(-37.81502, 144.94601, 4326)
DECLARE @point2 AS GEOGRAPHY = GEOGRAPHY::Point(-38.81502, 144.94601, 4326)


SELECT @Bounds.STIntersects(@point1)
SELECT @Bounds.STIntersects(@point2) 

enter image description here , (lat, long), Google Maps. , . , , , . - ( , ) - (. , ) Google , . , , , .

+2
2

, :

enter image description here

, :

enter image description here

+3

@point1 , :

DECLARE @boundingRect varchar(1000)
DECLARE @maxLat VARCHAR(20)
DECLARE @minLong VARCHAR(20)
DECLARE @minLat VARCHAR(20)
DECLARE @maxLong VARCHAR(20)


set @maxLat ='-36.06631759541187'
set @minLong ='125.23310677812492'
set @minLat ='-44.43329881450396'
set @maxLong='167.04707162187492'


SET @boundingRect = 'POLYGON((' +   @minLong + ' '  + @minLat + ', ' +
                                        @maxLong + ' ' + @minLat + ', ' + 
                                        @maxLong + ' ' + @maxLat + ', ' + 
                                        @minLong + ' ' + @maxLat + ', ' + 
                                        @minLong + ' ' + @minLat + '))'

DECLARE @Bounds AS Geography =GEOGRAPHY::STPolyFromText(@boundingRect,4326);

DECLARE @point1 AS GEOGRAPHY = GEOGRAPHY::Point(-37.81502, 144.94601, 4326);
DECLARE @point2 AS GEOGRAPHY = GEOGRAPHY::Point(-38.81502, 144.94601, 4326);


SELECT @Bounds.STIntersects(@point1);
SELECT @Bounds.STIntersects(@point2); 


SELECT @point1, 'Point 1'
UNION ALL
SELECT @Point2, 'Point 2'
UNION ALL
SELECT @BoundingRect, 'Rect'
+7

All Articles