phayes / geoPHP

Advanced geometry operations in PHP
https://geophp.net
Other
861 stars 261 forks source link

bbox of polygons that cross the international date line #5

Open semiaddict opened 12 years ago

semiaddict commented 12 years ago

Hi,

Thank you very much for this library. I've added a few functionalities such as Yahoo geocoding and reverse geocoding (they have greater request limits than google's) which I will submit as a pull request as soon as my project's rush period is over.

However, I'm getting strange results when using the getBBox function on a multipolygon representing countries that cross the international date line such as Russia and New Zealand.

For Russia, for example, I'm getting a very thin line that follows the international date line. I'm guessing this is an issue with the calculation of the min and max values.

Any idea how to fix this ?

Thank you.

phayes commented 12 years ago

Hmm, this is a super-tricky issue as it only appears for certain projections that "wrap" their coordinates, and geoPHP doesn't really do anything with SRIDs at the moment.

in the getBBOX method we could likely do some fancy-footwork to detect weather the shape crosses such a boundary and do something intelligent. I don't have time to look into this at the moment, but if you find a solution I would encourage a pull request.

phayes commented 12 years ago

Just thinking some more.. I think this is how we do it..

Before doing the actual bbox calulation, we run through all the points to find the global minimum value of each of the X and Y axis. If any of these are less than zero, we mark the amount they are less than zero as a "x-transpose" or "y-transpose" amount.

Next, for calculating or min and max values, we add this transpose amount to our calculations, thereby insuring that the resulting bounding-box only has positive values. Finally, right before passing the bounding-box back, we un-transpose the bounding-box back to normal.

The only tricky piece is that this might result in longitudes like "-190", which your application will have to be able to deal with.

semiaddict commented 12 years ago

Thank you phayes for the super fast reply. I'll try out this solution and let you know.

Note: the application uses Google Earth, which I'm guessing should be able to deal with longitudes like "-190".

phayes commented 12 years ago

Any success on this?

semiaddict commented 12 years ago

No, I didn't manage to get this working, and due to limited time and budget, I ended up going with manual bboxes that didn't overlap the international date line.