in reply to Geo Package files
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Geo Package files
by Bod (Parson) on Mar 03, 2022 at 23:36 UTC | |
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 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... Next we have 4 double[] envelope 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...
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? | [reply] [d/l] [select] |
by soonix (Chancellor) on Mar 04, 2022 at 20:39 UTC | |
Looking further at the flag byte, I see the the next three bits tell you how many doubles (probably f format, from Perl 5.10 upwards you can distinguish between big-endian "f>" and little-endian "f<") are in the double[] envelope array at the end of the GeoPackageBinaryHeader. Sorry I'm not really into this, so I can't dive very deep into it. Depending on what information comes up in the discussion, it might trigger me to go looking deeper, but don't bet on it :-) | [reply] [d/l] |
by Marshall (Canon) on Mar 04, 2022 at 22:46 UTC | |
| [reply] |
by Marshall (Canon) on Mar 04, 2022 at 19:52 UTC | |
You should wind up with something like: 47 50 XX YY... 0x47 means "G" and 0x50 means "P". The next byte looks like a version number - probably doesn't mean much to you. The very next flag byte means a lot (emphasis added) and we need to know what that is in order to understand what "double[] envelope;" means. My code for dealing with binary headers like this usually has a substr() to select an range of bytes then it applies the appropriate unpack template upon that subset of bytes. I suspect that some relatively straightforward, special purpose code will be able to decode your specific blobs. Decoding this binary geo format in a general sense appears to be a "non-trivial" task. Your code will probably wind up depending upon the flag byte being a particular value - your code being specific to decoding segments with that particular set of flags. The code to decode the bulk of the BLOB depends critically upon knowing what the flag byte is. Lets see the first 16 bytes of this $geo blob in hex dump format... Also don't forget the ord() function. print "Got G!\n" if ( ord(substr($geo,0,1)) == 0x47 ); I think will work. I have no idea of how many BLOB's you need to decode or what the performance implications are. I would try to get something functionally working and then worry about performance tweaks later. It could very well be that such tweaks are not necessary. | [reply] [d/l] [select] |
by Bod (Parson) on Mar 05, 2022 at 00:58 UTC | |
Thank you Marshall Form print join ' ', unpack '(H2)*', $geo; I have much more sensible output to work with. Here are the first 16 hex 'characters' As per the spec, the first two are 0x4750. The version number is 0 which means version 1 which is what I would expect. Next comes 05 - or as I said previously, this is 00000101 The bits correspond to RRXYEEEB - where EEE defines the envelope. So that is 010 = 2 which gives the envelope as being 2: envelope is [minx, maxx, miny, maxy, minz, maxz], 48 bytes. Also from this, B = 1 tells us that it's Little Endian. The SRSID I worked out late last evening using 'V' to unpack it. It is 27700 which is the SRSID for OSGB 1936. That passes the sanity check as the data I am decoding comes from the Ordnance Survey. This is where I got lost... The last two seem reasonable as I am not expecting height data although I would not be surprised if it were included. However, the first and third give a location inland from the east coast (near Norwich if you know your UK geography) and not off the west coast as I would expect for a minimum bounding coordinate. If I ue '(f<)6' I get even less sensible results:
I have no idea of how many BLOB's you need to decode or what the performance implications are. I would try to get something functionally working and then worry about performance tweaks later. It could very well be that such tweaks are not necessary There are 1.4 million BLOBs that need decoding! However, the decode process will be done once every few months (the dataset is updated monthly but doesn't change massively). The decoding process is not time critical. If it needs to run overnight then so be it. | [reply] [d/l] [select] |
by Marshall (Canon) on Mar 05, 2022 at 04:19 UTC | |
by Bod (Parson) on Mar 05, 2022 at 14:17 UTC | |
| |
by hv (Prior) on Mar 05, 2022 at 14:21 UTC | |
A useful technique for dumping binary data is to use the "v" flag in sprintf. Eg: See the section on "vector flag" in sprintf. | [reply] [d/l] |
by Bod (Parson) on Mar 12, 2022 at 19:16 UTC | |
You should wind up with something like: 47 50 XX YY... 0x47 means "G" and 0x50 means "P" Just as a general question... Is it just there so that any processor of the file can fail quickly if it is passed a file that doesn't start with these two bytes or is there more to it than that? | [reply] |
by Marshall (Canon) on Mar 12, 2022 at 20:12 UTC | |