Reputation: 31
How come this geometry point does not intersect with the polygon? I know for a fact that the point exists in the given polygon. Any reason why it returns 0?
DECLARE @point geometry
DECLARE @poly geometry
SET @point = geometry::STGeomFromText('POINT (-79.393967 43.640056)', 4326)
DECLARE @minY varchar(20) = N'-79.37776573850101'
DECLARE @maxY varchar(20) = N'-79.41055306149906'
DECLARE @minX varchar(20) = N'43.63590433545648'
DECLARE @maxX varchar(20) = N'43.64460037532088'
DECLARE @boundingRect varchar(250)
SET @boundingRect = 'POLYGON((' + @minX + ' ' + @minY + ', ' +
@maxX + ' ' + @minY + ', ' +
@maxX + ' ' + @maxY + ', ' +
@minX + ' ' + @maxY + ', ' +
@minX + ' ' + @minY + '))'
SET @poly = geometry::STGeomFromText(@boundingRect, 4326)
SELECT @point.STIntersects(@poly)
Upvotes: 0
Views: 944
Reputation: 6726
The point should be declared as:
SET @point = geometry::STGeomFromText('POINT (43.640056 -79.393967)', 4326)
Then the Intersect shows the result you're expecting: 1
Upvotes: 0
Reputation: 260
Just a thought: When does a point intersect with a polygon? If it lies INSIDE the polygon? No. Only if it lies directly on one of the edges of the polygon, right?
Try this: Intersect a point with the polygon, which is lying directly on one of the edges of the polygon. If it returns else then 0 you have your answer.
Upvotes: 0
Reputation: 2130
I'm not familiar with this SQL notation, so I may be way off base, but I see that your X values seem to be associated with latitude 43N, and Y with longitude 79W. However, your POINT entries might be reversed?
Upvotes: 2