I’m trying to find all data items that have long/lats that are contained by a polygon made up of an array of long lats could be many points. I know you can do this kind of stuff with the new geospacial datatypes in SQL 2008 but i’m using SQL 2005 and C#. Would this be best done on at the DB end or in C#.
Thanks.
I have some code written for SQL2000 to do this. It uses the ‘angle’ method for determining if a point lies within a polygon.
First, the GetAngle user defined function:
Returns Float
As
Begin
End
Next I assume there is a table variable of Latitude/Longitude pairs and a sequence number (indicating the order in which the LAT/LONG pairs define the polygon). It’s important that the first point in this table is the same as the last point in the table.
Also, I have several variables for Min and Max Latitude & Longitude. This effectively creates a bounding box so that I can quickly eliminate points NOT within a rectangular region bounding the polygon.