27 #include "../common/ByteSwapUtils.h"
28 #include "../common/Globals.h"
29 #include "../common/HexUtils.h"
30 #include "../common/Translator.h"
31 #include "../geometry.h"
44 template<
class T>
inline T*
GetCoordSequence(
const char* ewkb,
const char** endptr,
unsigned int gType,
char byteOrder)
46 assert(ewkb && endptr);
48 unsigned int nPts = 0;
53 memcpy(&srid, ewkb, 4);
54 memcpy(&nPts, ewkb + 4, 4);
59 memcpy(&nPts, ewkb, 4);
76 memcpy(cs->getCoordinates(), ewkb, 16 * nPts);
81 for(
unsigned int i = 0; i < nPts; ++i)
83 memcpy(&(cs->getCoordinates()[i]), ewkb, 16);
84 memcpy(&(cs->getZ()[i]), ewkb + 16, 8);
90 for(
unsigned int i = 0; i < nPts; ++i)
92 memcpy(&(cs->getCoordinates()[i]), ewkb, 16);
93 memcpy(&(cs->getM()[i]), ewkb + 16, 8);
99 for(
unsigned int i = 0; i < nPts; ++i)
101 memcpy(&(cs->getCoordinates()[i]), ewkb, 16);
102 memcpy(&(cs->getZ()[i]), ewkb + 16, 8);
103 memcpy(&(cs->getM()[i]), ewkb + 24, 8);
111 for(
unsigned int i = 0; i < nPts; ++i)
118 for(
unsigned int i = 0; i < nPts; ++i)
122 for(
unsigned int i = 0; i < nPts; ++i)
136 const char* aux = ewkb;
154 assert(ewkb && endptr);
157 unsigned int gType = 0;
159 memcpy(&byteOrder, ewkb, 1);
160 memcpy(&gType, ewkb + 1, 4);
173 return getPoint(ewkb, endptr);
179 return getLineString(ewkb, endptr);
185 return getPolygon(ewkb, endptr);
203 return getGeometryCollection(ewkb, endptr);
231 assert(ewkb && endptr);
234 unsigned int gType = 0;
241 memcpy(&byteOrder, ewkb, 1);
242 memcpy(&gType, ewkb + 1, 4);
251 memcpy(&srid, ewkb, 4);
258 memcpy(&y, ewkb + 8, 8);
279 memcpy(&m, ewkb + 8, 8);
314 assert(ewkb && endptr);
317 unsigned int gType = 0;
319 memcpy(&byteOrder, ewkb, 1);
320 memcpy(&gType, ewkb + 1, 4);
327 te::gm::LineString* l = GetCoordSequence<te::gm::LineString>(ewkb, endptr, gType, byteOrder);
334 assert(ewkb && endptr);
336 te::gm::LinearRing* r = GetCoordSequence<te::gm::LinearRing>(ewkb, endptr, t, wkbByteOrder);
344 assert(ewkb && endptr);
347 unsigned int gType = 0;
349 unsigned int nRings = 0;
351 memcpy(&byteOrder, ewkb, 1);
352 memcpy(&gType, ewkb + 1, 4);
359 memcpy(&srid, ewkb + 5, 4);
360 memcpy(&nRings, ewkb + 9, 4);
365 memcpy(&nRings, ewkb + 5, 4);
413 for(
unsigned int i = 0; i < nRings; ++i)
425 assert(ewkb && endptr);
428 unsigned int gType = 0;
430 unsigned int nGeoms = 0;
432 memcpy(&byteOrder, ewkb, 1);
433 memcpy(&gType, ewkb + 1, 4);
440 memcpy(&srid, ewkb + 5, 4);
441 memcpy(&nGeoms, ewkb + 9, 4);
446 memcpy(&nGeoms, ewkb + 5, 4);
500 for(
unsigned int i = 0; i < nGeoms; ++i)
An utility class for reading a PostGIS EWKB.
static te::gm::LineString * getLineString(const char *ewkb, const char **endptr)
MultiPolygon is a MultiSurface whose elements are Polygons.
static te::gm::Geometry * readHex(const char *hewkb)
It returns a valid geometry from a given hex-encoded EWKB.
static te::gm::Geometry * read(const char *ewkb)
It returns a valid geometry from a given EWKB.
std::vector< Curve * > & getRings()
It returns the polygon rings.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
#define TE_EWKB_SRID_FLAG
static te::gm::Geometry * getGeometry(const char *ewkb, const char **endptr)
static te::gm::Polygon * getPolygon(const char *ewkb, const char **endptr)
static const MachineByteOrder sm_machineByteOrder
A flag that indicates the machine byte order (Big Endian or Little Endian).
A point with a z-coordinate value and an associated measurement.
A point with an associated measure.
A LinearRing is a LineString that is both closed and simple.
MultiPoint is a GeometryCollection whose elements are restricted to points.
A point with z-coordinate value.
LineString is a curve with linear interpolation between points.
A point with x and y coordinate values.
Utility functions for PostgreSQL.
static te::gm::LinearRing * getLinearRing(const char *ewkb, te::gm::GeomType t, int srid, char wkbByteOrder, const char **endptr)
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
static te::gm::GeometryCollection * getGeometryCollection(const char *ewkb, const char **endptr)
static te::gm::Point * getPoint(const char *ewkb, const char **endptr)
MultiLineString is a MultiCurve whose elements are LineStrings.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
An exception class for the PostGIS driver.
void Convert2OGCWKBType(unsigned int &gType)
It converts the PostGIS geometry type to a pure OGC WKB code.
const std::vector< Geometry * > & getGeometries() const
It returns a reference to the internal list of geometries.
T * GetCoordSequence(const char *ewkb, const char **endptr, unsigned int gType, char byteOrder)
char * Hex2Binary(const char *hex)
It converts each pair of hex characters from a NULL-terminated string of hex characters into a binary...
void setSRID(int srid)
It sets the Spatial Reference System ID of the linestring.
It is a collection of other geometric objects.
virtual void setSRID(int srid)=0
It sets the Spatial Reference System ID of the geometry and all its parts if it is a GeometryCollecti...
void SwapBytes(T &v)
It swaps the bytes in local.