bliako has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know a CPAN module for defining and operating on geographical bounding boxes?

Defining a bbox is straight forward: specify 2 opposite corners as (lat,lon) each. However, I need functionality like:

I found some functionality (e.g. centred-at) in Geo::Calc but ideally I would like a single module that does all these before creating my own and risking a lot of pitfalls.

Replies are listed 'Best First'.
Re: Geo bounding box module?
by swl (Prior) on May 07, 2019 at 21:54 UTC

    Math::Polygon looks to do some of what you need, but not all. Maybe something in the Geometry and related namespaces?

      thanks! the tricky bit with geo-calculations is that the earth is neither flat nor perfect sphere. for example, calculating the centre of a bounding box: https://stackoverflow.com/questions/34549767/how-to-calculate-the-center-of-the-bounding-box

        I did not realise you needed geodesic calculations.

        The options below need code, so do not address your original criterion of being pre-packaged, but maybe they will help.

        One option is to use Geo::Proj to project your coordinates into a projected coordinate system, perhaps varying the system by location and extent to minimise distortions. Or hand roll such a system yourself. This should in many cases involve updating an existing system with your own central meridian and perhaps parallel(s) of latitude, and this can be done using the proj string.

        Coordinate systems can be downloaded from http://spatialreference.org/. Which is best depends on the spatial extent of your bounding boxes.

        You might also have some luck with GDAL via Geo::GDAL::FFI. I have not checked if its centroid method handles data in geographic coordinates, but it's not a new problem so I would not be surprised if it does. The issue with this approach is that GDAL is a big beast, so it will take a while to install Alien::gdal and its dependencies if they are not already on your system.

        Edit: I just re-read your initial requirements, and GDAL has operations for all the criteria you listed.

Re: Geo bounding box module?
by QM (Parson) on May 09, 2019 at 10:57 UTC
    I assume your bounding boxes are small enough not to worry about edge cases, like what is "inside" and what is "outside", overlapping the antimeridian, a pole, or zero area?

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

      one more reason why I want something off-the-shelf...