in reply to Re: Geo Package files
in thread Geo Package files
Thanks soonix - that has got me much further :)
But - I am not understanding how to map the GeoPackage spec to Perl's unpack. I've read perlpacktut although I cannot say I understand much of it. So I've made a start based on your information and after a lot of pondering I think I understand why C is the second and third parts of the template
I don't understand why we start with n
The spec says "byte2 magic = ox4750" - so it's 2 bytes or 16 bits. Why is it n and not v or even s?
Spec 2 says it is an "8-bit unsigned integer" so C fits the bill.
I'm guessing we know 3 is unsigned from looking at the bits laid out in the spec - is that about right?
Now I get completely lost...
There is an int32 between 3 and 4 so that's N or V - but how can we tell? I've tried unpacking with those templates options and get 879493120 and 27700 respectively. I cannot tell from those values which is right.
Next we have 4 double[] envelope
As spec 3 returns 00000101 (5), the envelope consists of 6 values 2: envelope is [minx, maxx, miny, maxy, minz, maxz], 48 bytes so I am using d6 in the template. The returned values don't seem to make sense!
Next is spec 5, the GeoPackageBinaryHeader - I'm took an educated guess this is a but the result didn't seem right so I've used N as it seems to be another flag byte.
Finally we have the geometry which I expect to be text of unknown length. So I tried a100 and A100 but they take me back to the gobbledegook and I cannot work out which one I might need to use.
This is what I have tried...
use DBD::SQLite; use Data::Dumper; use strict; use warnings; my $dbh = DBI->connect("dbi:SQLite:uri=file:osopenusrn_202203.gpkg?mod +e=rwc"); my $tab = $dbh->prepare("SELECT * FROM openUSRN"); $tab->execute; my $n = $tab->fetchrow_hashref; my $geo = $n->{'geometry'}; my @test = unpack "nCCVd6C100", $geo; foreach my $t(@test) { print "$t\n"; }
Am I heading in the right direction here or am I going down a blind alley with my reasoning behind the mapping from the specs to the unpack template?
Is there a simpler way to understand this mapping and work out the correct template?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Geo Package files
by soonix (Chancellor) on Mar 04, 2022 at 20:39 UTC | |
by Marshall (Canon) on Mar 04, 2022 at 22:46 UTC | |
|
Re^3: Geo Package files
by Marshall (Canon) on Mar 04, 2022 at 19:52 UTC | |
by Bod (Parson) on Mar 05, 2022 at 00:58 UTC | |
by Marshall (Canon) on Mar 05, 2022 at 04:19 UTC | |
by Bod (Parson) on Mar 05, 2022 at 14:17 UTC | |
by soonix (Chancellor) on Mar 05, 2022 at 18:07 UTC | |
| |
by Marshall (Canon) on Mar 07, 2022 at 23:50 UTC | |
| |
by hv (Prior) on Mar 05, 2022 at 14:21 UTC | |
by Bod (Parson) on Mar 12, 2022 at 19:16 UTC | |
by Marshall (Canon) on Mar 12, 2022 at 20:12 UTC |