27 #include "../common/ByteSwapUtils.h" 28 #include "../common/Globals.h" 29 #include "../core/utils/HexUtils.h" 30 #include "../core/translator/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;
138 return getGeometry(ewkb, &aux);
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);
207 return getGeometryCollection(ewkb, endptr);
235 assert(ewkb && endptr);
238 unsigned int gType = 0;
245 memcpy(&byteOrder, ewkb, 1);
246 memcpy(&gType, ewkb + 1, 4);
255 memcpy(&srid, ewkb, 4);
262 memcpy(&y, ewkb + 8, 8);
283 memcpy(&m, ewkb + 8, 8);
334 assert(ewkb && endptr);
337 unsigned int gType = 0;
339 memcpy(&byteOrder, ewkb, 1);
340 memcpy(&gType, ewkb + 1, 4);
347 te::gm::LineString* l = GetCoordSequence<te::gm::LineString>(ewkb, endptr, gType, byteOrder);
354 assert(ewkb && endptr);
356 te::gm::LinearRing* r = GetCoordSequence<te::gm::LinearRing>(ewkb, endptr, t, wkbByteOrder);
364 assert(ewkb && endptr);
367 unsigned int gType = 0;
369 unsigned int nRings = 0;
371 memcpy(&byteOrder, ewkb, 1);
372 memcpy(&gType, ewkb + 1, 4);
379 memcpy(&srid, ewkb + 5, 4);
380 memcpy(&nRings, ewkb + 9, 4);
385 memcpy(&nRings, ewkb + 5, 4);
433 for(
unsigned int i = 0; i < nRings; ++i)
445 assert(ewkb && endptr);
448 unsigned int gType = 0;
450 unsigned int nGeoms = 0;
452 memcpy(&byteOrder, ewkb, 1);
453 memcpy(&gType, ewkb + 1, 4);
460 memcpy(&srid, ewkb + 5, 4);
461 memcpy(&nGeoms, ewkb + 9, 4);
466 memcpy(&nGeoms, ewkb + 5, 4);
520 for(
unsigned int i = 0; i < nGeoms; ++i)
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.
static te::gm::Geometry * getGeometry(const char *ewkb, const char **endptr)
char * Hex2Binary(const char *hex)
It converts each pair of hex characters from a NULL-terminated string of hex characters into a binary...
static te::gm::Polygon * getPolygon(const char *ewkb, const char **endptr)
Utility functions for PostgreSQL.
static const MachineByteOrder sm_machineByteOrder
A flag that indicates the machine byte order (Big Endian or Little Endian).
#define TE_EWKB_SRID_FLAG
te::gm::GeometryCollection * gc
A LinearRing is a LineString that is both closed and simple.
An exception class for the PostGIS driver.
MultiPoint is a GeometryCollection whose elements are restricted to points.
LineString is a curve with linear interpolation between points.
A point with x and y coordinate values.
void setM(const double &m)
It sets the Point m-coordinate value.
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.
void setX(const double &x)
It sets the Point x-coordinate value.
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)
virtual void setSRID(int srid) _NOEXCEPT_OP(true)=0
It sets the Spatial Reference System ID of the geometry and all its parts if it is a GeometryCollecti...
void setSRID(int srid)
It sets the Spatial Reference System ID of the linestring.
An utility class for reading a PostGIS EWKB.
void setY(const double &y)
It sets the Point y-coordinate value.
It is a collection of other geometric objects.
void SwapBytes(T &v)
It swaps the bytes in local.
void setZ(const double &z)
It sets the Point z-coordinate value.