Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Geo bounding box module?

by bliako (Prior)
on May 07, 2019 at 12:25 UTC ( #1233426=perlquestion: print w/replies, xml ) Need Help??

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:

  • create a bounding box centred at (lat,lon) of so-and-so width and height
  • bbox1 encloses/equals bbox2
  • trim a bbox, expand a bbox
  • find area, find centre
  • convert to different formats, e.g. OpenStreetMap bbox, trivial but convenient
  • ...

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 (Priest) 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...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1233426]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2021-02-25 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?