The Well-Known Binary (WKB) representation for geometric values is defined by the OpenGIS specification. It is also defined in the ISO SQL/MM Part 3: Spatial standard.
WKB is used to exchange geometry data as binary streams
represented by BLOB values containing
geometric WKB information.
WKB uses one-byte unsigned integers, four-byte unsigned integers, and eight-byte double-precision numbers (IEEE 754 format). A byte is eight bits.
For example, a WKB value that corresponds to POINT(1
1) consists of this sequence of 21 bytes (each
represented here by two hex digits):
0101000000000000000000F03F000000000000F03F
The sequence may be broken down into these components:
Byte order : 01 WKB type : 01000000 X : 000000000000F03F Y : 000000000000F03F
Component representation is as follows:
The byte order may be either 0 or 1 to indicate little-endian or big-endian storage. The little-endian and big-endian byte orders are also known as Network Data Representation (NDR) and External Data Representation (XDR), respectively.
The WKB type is a code that indicates the geometry type.
Values from 1 through 7 indicate Point,
LineString, Polygon,
MultiPoint,
MultiLineString,
MultiPolygon, and
GeometryCollection.
A Point value has X and Y coordinates,
each represented as a double-precision value.
WKB values for more complex geometry values are represented by more complex data structures, as detailed in the OpenGIS specification.

User Comments
To parse a WKB point in PHP, use the unpack function. It's similar to Perl's except that each format string has a label, and is separated from the next by a slash. The result is an associative array using those labels:
<?php// $wkb is the value retrieved from MySQL using AsBinary(g)
$geometry = unpack(corder/Ltype/dlatitude/dlongitude, $wkb);
if ($geometry['type'] == 1) {
$latitude = $geometry['latitude'];
$longitude = $geometry['longitude'];
}
?>
Add your own comment.