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

Re^9: Geo Package files

by pryrt (Abbot)
on Mar 11, 2022 at 20:16 UTC ( [id://11142006]=note: print w/replies, xml ) Need Help??


in reply to Re^8: Geo Package files
in thread Geo Package files

Rather than hardcoding assumptions or conclusions about what the machine is now, why not future-proof it? All you have to do is add the < to the unpack string to force the d (double) to be little-endian, no matter what architecture you happen to be running on. So my $minx = unpack ("d<", substr($geo,8,8)); will force it to be little-endian interpretation. (Or better, since your code already has access to that bit in the fourth byte, use logic based on that bit to determine whether your envelope's unpacks use "d<" or "d>" , so that you can handle input files that made either choice for the envelope:
my $unpack_string = ($flag&0x1 == 0x1) ? "d<" : "d>"; ... my $minx = unpack($unpack_string, substr($geo,8,8));

But given that your CPU is little endian, that is what your unpack from Re^4: Geo Package files already showed a value of: 637590.385 is the correct value based on the 8 bytes 50 b8 1e c5 2c 75 23 41 : that is little-endian-double for 637590.385 . The problem is that you don't believe that number is correct. But since you have not apparently tried sanity-checking your interpretation with another tool, like swl suggested in Re^9: Geo Package files, you don't know if your belief is founded in reality or not. Maybe the "min" and "max" in the bounding box might not match the "min" and "max" of the values of the coordinates as stored; the portion of the spec I read wasn't clear on what the min and max were interpreted as. Or maybe the data set you were given just mis-used "min" vs "max". A sanity check in another tool is really going to help you out.

But based on the spec you have shared, and the 16 bytes you have shared, I am confident that 637590.385 is the valid interpretation of those bytes.

(I had wanted to say most of this last week, but I kept only thinking about it when I was in a crunched-for-time or on-my-phone-browser-so-read-only situation.... and then with the week-long pause, I forgot to come back.)

Replies are listed 'Best First'.
Re^10: Geo Package files
by Bod (Parson) on Mar 11, 2022 at 20:34 UTC
    Rather than hardcoding assumptions or conclusions about what the machine is now, why not future-proof it?

    Yes - that is certainly the plan.

    It seems to me that if I need this functionality, someone else will as well. Or, at the very least, would benefit from a head-start in developing code for the next part of dealing with a GeoPackage. So some of the code will probably form a module for CPAN.

    since you have not apparently tried sanity-checking your interpretation with another tool

    I haven't yet as I have been away on training much of this week and haven't had the opportunity! I also feel that an external tool won't be very helpful for checking te envelope data. It will be the next step once I've decoded some fo the actual geometry data.

      I'm not sure why an external tool won't be helpful.

      In QGIS, for example, it is pretty straightforward to calculate the feature envelopes. There is also a coordinate panel at the bottom of the window that shows the map coordinates as you move the mouse. This can be used to check the coordinates of features you are interested in without having to calculate their specific geometries.

      If you are comfortable using R then the sf library has tools to access features (geometries), and the st_bbox function will give you the feature envelope.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-26 00:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found