jgoodale
asked on
Test whether or not a coord exisits in polygon defined by geocodes
I have a list of geocodes that define a polygon on a map and I want to find if a particular geocode lands within the values. The polygon shape in this case is like a 7 but changes in nearly all cases. We are using SQL 2008 and I can define the table any way needed to take a single geocode and return true or false.
-117.218499,33.099865,0
-117.216804,33.09991,0
-117.216182,33.099919,0
-117.215549,33.099811,0
-117.21498,33.099658,0
-117.215602,33.098624,0
-117.21557,33.097519,0
-117.215291,33.096692,0
-117.215055,33.095532,0
-117.215173,33.095317,0
-117.215184,33.095146,0
-117.21616,33.095038,0
-117.21689,33.097267,0
-117.216825,33.098786,0
-117.219089,33.098858,0
-117.218553,33.099847,0
-117.218499,33.099865,0
-117.218499,33.099865,0
-117.216804,33.09991,0
-117.216182,33.099919,0
-117.215549,33.099811,0
-117.21498,33.099658,0
-117.215602,33.098624,0
-117.21557,33.097519,0
-117.215291,33.096692,0
-117.215055,33.095532,0
-117.215173,33.095317,0
-117.215184,33.095146,0
-117.21616,33.095038,0
-117.21689,33.097267,0
-117.216825,33.098786,0
-117.219089,33.098858,0
-117.218553,33.099847,0
-117.218499,33.099865,0
ASKER
Can you clarify you answer more? I'm not sure what a 2d coord system like utm is..
Thanks!
Thanks!
You cannot use this function if you coord are in a form of degrees
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Solved
public bool isPointInside( Ponto ponto )
{
int i, j;
bool res = false;
for ( i = 0, j = Count - 1; i < Count; j = i++ ) {
if ( (((polygono[i].Y <= ponto.Y) && (ponto.Y < polygono[j].Y)) ||
((polygono[j].Y <= ponto.Y) && (ponto.Y < polygono[i].Y))) &&
(ponto.X < (polygono[j].X - polygono[i].X) * (ponto.Y - polygono[i].Y) / (polygono[j].Y - polygono[i].Y) + polygono[i].X) )
res = !res;
}
return res;
}