[Mapserver-users] OT: Point in Poly
daniel.berstein at dmapas.com
daniel.berstein at dmapas.com
Fri Mar 7 13:12:30 PST 2003
Hope this helps:
/******************************************************/
/* Deterima si un punto esta dentro de un poligono 2D */
/* Retorna: 1=adentro, 0=afuera */
/* Parametros: */
/* poly: puntos del poligono, [0]=x, [1]=y */
/* npoints: numero de puntos en poligono */
/* x (horizontal) de punto de prueba */
/* y (vertical) de punto de prueba */
/******************************************************/
int inpoly(unsigned int poly[][2],
int npoints,
unsigned int xt,
unsigned int yt)
{
unsigned int xnew,ynew;
unsigned int xold,yold;
unsigned int x1,y1;
unsigned int x2,y2;
int i;
int inside=0;
if (npoints < 3) {
return(0);
}
xold=poly[npoints-1][0];
yold=poly[npoints-1][1];
for (i=0 ; i < npoints ; i++) {
xnew=poly[i][0];
ynew=poly[i][1];
if (xnew > xold) {
x1=xold;
x2=xnew;
y1=yold;
y2=ynew;
} else {
x1=xnew;
x2=xold;
y1=ynew;
y2=yold;
}
if ((xnew < xt) == (xt <= xold) /* edge "open" at one end */
&& ((long)yt-(long)y1)*(long)(x2-x1)
< ((long)y2-(long)y1)*(long)(xt-x1)) {
inside=!inside;
}
xold=xnew;
yold=ynew;
}
return(inside);
}
Regards,
Daniel Berstein Z.
Jefe de Proyectos, dmapas.com
Eduardo Hyatt 583, Providencia, Santiago CHILE
*(56) (2) 222 22 60
-----Mensaje original-----
De: Lowther, David W [SMTP:dlowther at ou.edu]
Enviado el: Viernes, 07 de Marzo de 2003 17:30
Para: Mapserver-Users (mapserver-users at lists.gis.umn.edu)
Asunto: [Mapserver-users] OT: Point in Poly
Hi List,
I am looking for point in poly code. Specifically, I would like to pass
a point, and a poly to a routine and return whether the point is inside
or outside the polygon and how far from the polygon the point is. If its
in, then how far inside, if its out, then how far outside.
Can anyone point me in the right direction to locate the pieces of this?
Thanks,
David Lowther
Software Engineer
GEO Information Systems
University of Oklahoma
dlowther at ou.edu
(405) 325-3131
<http://www.geo.ou.edu> http://www.geo.ou.edu
<<Archivo: ATT00015.htm>>
More information about the MapServer-users
mailing list