Reputation: 3251
I have the coordinates that represents bounding rectangle on the earth:
Upper Left Corner Latitude
Upper Left Corner Longitude
Lower Right Corner Latitude
Lower Right Corner Longitude
I need to write the function that determines whether the given point with lat long coordinates hit the bounding rectangle.
Is there any way to do it ? I didn't find functions in sql server to do it. All functions work with lines and polygons, but I have only bounds, not the complete polygon or line.
Upvotes: 1
Views: 3644
Reputation: 51494
You need to create a polygon of your four points, and call STWithin
against your geometry point, or STIntersects
against a geography
ie: http://msdn.microsoft.com/en-us/library/ff929207.aspx
declare @area geography, @point geography
select @area = geography :: STGeomFromText('polygon((10 10, 20 10, 20 20, 10 20, 10 10))', 4326)
select @point = geography :: STGeomFromText('point(15 15)', 4326)
select @area.STIntersects(@point)
select @point = geography :: STGeomFromText('point(5 5)', 4326)
select @area.STIntersects(@point)
Upvotes: 1