Okay, so I think I'm close here, but I'm hitting a limitation in my understanding of binary data.
I'm parsing some MySQL data inserted as geometry types, using PHP's unpack()
as my parser, and everything was going swimmingly until I started trying to unpack complex geometry types (e.g. MULTIPOINT
).
For a POINT
data type, I've had good success using an unpack pattern that simply disregards the first chunk and then gives me an associative array of type
, order
, lat
and lon
:
$coords = unpack('x/x/x/x/corder/Ltype/dlat/dlon', $point);
// >>> [
// 'order' => 1,
// 'type' => 1,
// 'lat' => (expected value),
// 'lon' => (expected value)
// ];
Naturally, applying the exact same pattern to MULTIPOINT
geometries doesn't work the same. It gets the order
and the type
becomes 4, but the values of lat
and lon
are not at all what I'd expect. So, curious to see what the whole thing looked like, I changed the pattern to just spew it all out as "double (machine dependent size and representation)" types:
$coords = unpack('x/x/x/x/corder/Ltype/d*', $multipoint);
// >>> mayhem
What that unpacks actually includes five additional array items, instead of the 4 I'd expect for a multipoint with two points (2x2), and the values are totally wack. For instance, a value I'd expect to be somewhere in the 40-something-point-whatever range seems to read something like -1.0977282851114052e-218
.
What is the proper way to unpack a MULTIPOINT
? My instinct says I'm slicing the bytes where I shouldn't or casting them to an inappropriate type, but I'm not sure what those should be.