http://qs321.pair.com?node_id=11141817


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 https://libgeos.org/specifications/wkb, and WKT at https://libgeos.org/specifications/wkt/.

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 http://www.geopackage.org/spec131/index.html#gpb_format. This should be of use if you decide to write your own parser to extract the first and last coordinates of each linestring.