3
votes

i have a list of boundaries (polygons) and a list of ways all represented by latitudes and longitudes. i would like to find out if one way is inside a polygon. i do this in perl but cant find anything useful to calculate. Math::Polygon (::Calc) has interesting functions, but not for lat/lon only for x/y.

So im thinking about making it easier and generating a bounding box of each polygon, so its easier for me to check if one point of a way is inside a bounding box.

Does anyone know how the algorithm looks like to get the bounding box. a pseudo code would be enough so i can code it in perl.

It would be even better to check for being inside a polygon without converting a polygon into a bounding box, but i wasnt able to find anything useful on the net. There are some for simple 2d x/y based coordinate systems, but not for spherical lat/lon.

1

1 Answers

3
votes

First, place the start and end points of each of the polygon's line segments in an array. Then iterate over the array to find MinX, MinY, MaxX and MaxY. Then the point (MinX, MinY) is the lower left corner of your box, and (MaxX, MaxY) is the upper right corner.