>>
>> You don't repeat addr:city or addr:country and on every node/building in
>> Belgium either, we know where it is by using the coordinates.  It's the
>> same for postal codes once you have the boundary borders, it's piece of
>> cake in any programming language to figure out if a point is inside or
>> outside a polygon.
> 
> I agree.
> 
> For the website ici.brussels how do you load the POI ?
> 
> If you do it in you php script you can load all the POI, then all the
> postcodes then use a library like https://github.com/phayes/geoPHP to
> compute the postal code of the POI.

you don't even need a (huge) library to do this. Turns out my math
classes were useful after all.

I would just download the boundaries relations ways, represent them in
PHP as a polygon, verify if these polygons are ok (needs to be closed,
very important) , then check which one of the polygons are closest (so
you don't have to analyse them all) and run it through something like this:

//  int    polySides  =  how many corners the polygon has
//  float  polyX[]    =  horizontal coordinates of corners
//  float  polyY[]    =  vertical coordinates of corners
//  float  x, y       =  point to be tested

/* The function will return YES if the point x,y is inside the polygon,
or NO if it is not.  If the point is exactly on the edge of the polygon,
then the function may return YES or NO.

Note that division by zero is avoided because the division is protected
by the "if" clause which surrounds it.
*/

function pointInPolygon($polySides, $polyX, $polyY, $x, $y) {
        $j=$polySides-1 ;
        $oddNodes=false;

        for ($i=0; $i<$polySides; $i++) {
                if (($polyY[$i]<$y && $polyY[$j]>=$y) OR ($polyY[$j]<$y
&& $polyY[$i]>=$y)) {
                if
($polyX[$i]+($y-$polyY[$i])/($polyY[$j]-$polyY[$i])*($polyX[$j]-$polyX[$i])<$x)
{
                $oddNodes=!$oddNodes;
                        }
                }
                $j=$i;
        }

  return $oddNodes;
}

Glenn


_______________________________________________
Talk-be mailing list
Talk-be@openstreetmap.org
https://lists.openstreetmap.org/listinfo/talk-be

Reply via email to