Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Geo Package files

by swl (Vicar)
on Mar 04, 2022 at 00:30 UTC ( #11141817=note: print w/replies, xml ) Need Help??

in reply to Geo Package files

You can use Geo::GDAL::FFI to read the contents of a geopackage (untested example code below). The geometry field is stored as Well Known Binary (WKB), or perhaps a variant of it. This can be converted to Well Known Text (WKT) to be human readable.

A definition of WKB is given in the libgeos docs at, and WKT at

The GDAL stack can be a beast to install if the aliens have to compile everything from source (GDAL, Proj, GEOS, libtiff, libsqlite3, optionally also spatialite, freexl and curl). If you are on a unix type machine then install the gdal-dev package using your system package manager, then the GDAL aliens will run system installs.

Example code:

# adapted from the Geo::GDAL::FFI docs, untested my $layer_name = 'some_layer'; my $db = Open('test.gpkg'); my $layer = $dataset->GetLayer($layer_name); $layer->ResetReading; while (my $feature = $layer->GetNextFeature) { my $value = $feature->GetField('name'); my $geom = $feature->GetGeomField; say $value, ' ', $geom->AsText; }

Update: More details of the geopackage geometry format are at This should be of use if you decide to write your own parser to extract the first and last coordinates of each linestring.

Replies are listed 'Best First'.
Re^2: Geo Package files
by Bod (Priest) on Mar 04, 2022 at 00:57 UTC

    Alas I am on Windows and the way to install GDAL seems to be via Anaconda.

    If I can suss out the correct template for unpack then I shall do it that way. But if that proves impossible, or at least too tricky for me, then I'll come back to GDAL.

    The WKB link is certainly helpful, thanks.

      You could have a look at the GIS Internals stable releases. They provide precompiled binaries for windows with a broad range of dependencies (including almost all those I listed in my previous post). If the GIS Internals paths can be found by the various gdal-stack aliens then they will run system installs.

      Edit: Be sure to also get the download flagged as "compiled libraries and headers"

      Another edit: I just tested with the GIS Internals files and the alienfile probe for geos does not work (the probe currently uses geos-config, which is not included).

      Rather than try and get things to work on the inferior OS you might find it worth the effort (to say nothing of being less headaches) to install a docker host and see if you can't get a dedicated environment running a decent real OS instead. With that available then you could install the more off-the-shelf tool chain into it more easily (theoretically . . .). Instead of trying to jump through all these hoops getting this (as you say elsewhere in the thread) occasional procedure running "native" you can just spin up a container to process the results and dump the output out as you need it into a shared volume that you then work with from your "normal" platform.

      Edit: Looks like there's an osgeo/gdal available which you probably could build upon.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        As I've reached the point I've got to, my gut feeling is that it is worth continuing. Perhaps not for this project, but certainly for what I am learning in the process of doing this. Previously, the only use I've made of unpack is to split up an authentication string.

        I think knowing more about pack and unpack would be beneficial to me. Thanks to soonix and Marshall my understanding of these two functions in improving. That alone makes continuing worthwhile.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11141817]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2023-02-08 07:31 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (40 votes). Check out past polls.