Table of Contents
TerraLib → Geometry → Serialization
Well-Known Binary (WKB)
TerraLib has support for encoding/decoding geometries to/from a binary data in the well-known binary format (WKB). The following classes provides this hability:
- WKBWriter: a class that serializes a geometry to the WKB format.
- WKBReader: a class that deserializes a geometry from a valid WKB.
- WKBSize: a class that computes the number of bytes necessary to encode a geometry in WKB.
The code snippet shows how to convert from a Point to a Wkb and then getting back to Point:
te::gm::Point pt(1.5, 1.8); // compute the buffer size needed to encode the point geometry std::size_t wkbSize = te::gm::WKBSize::size(pt); // allocate a buffer to encode the geometry to a wkb char* wkb = new char[wkbSize]; // encode the point geometry to a wkb in little-endian te::gm::WKBWriter::write(&pt, wkb, te::common::NDR); // create/decode a geometry from the wkb te::gm::Geometry* g = te::gm::WKBReader::read(wkb); // check if the reader has done its job bool result = g->equals(&pt, true); std::cout << result; delete g; delete [] wkb;
Well-Known Text Representation for Geometry (WKT)
As hiligthed in the OGC SFS spec, the WKT is case insensitive and upper-case should be used to the geometry names.