27 #include "../common/ByteSwapUtils.h"
28 #include "../common/Globals.h"
29 #include "../common/Translator.h"
30 #include "../dataaccess/Exception.h"
31 #include "../geometry/Envelope.h"
32 #include "../geometry/GeometryCollection.h"
33 #include "../geometry/LinearRing.h"
34 #include "../geometry/LineString.h"
35 #include "../geometry/MultiLineString.h"
36 #include "../geometry/MultiPoint.h"
37 #include "../geometry/MultiPolygon.h"
38 #include "../geometry/PointM.h"
39 #include "../geometry/PointZ.h"
40 #include "../geometry/PointZM.h"
41 #include "../geometry/Polygon.h"
50 #ifdef TE_ENABLE_SPATIALITE
52 #include <spatialite/gaiageo.h>
61 char* aux = (
char*)ewkb;
63 memcpy(ewkb, &nPts, 4);
72 memcpy(ewkb, coords, 16 * nPts);
77 for(
unsigned int i = 0; i < nPts; ++i)
79 memcpy(ewkb, &(coords[i]), 16);
80 memcpy(ewkb + 16, &(l.
getZ()[i]), 8);
86 for(
unsigned int i = 0; i < nPts; ++i)
88 memcpy(ewkb, &(coords[i]), 16);
89 memcpy(ewkb + 16, &(l.
getM()[i]), 8);
95 for(
unsigned int i = 0; i < nPts; ++i)
97 memcpy(ewkb, &(coords[i]), 16);
98 memcpy(ewkb + 16, &(l.
getZ()[i]), 8);
99 memcpy(ewkb + 24, &(l.
getM()[i]), 8);
105 throw te::da::Exception(TR_COMMON(
"Invalid geometry type to encode to a SpatiaLIte EWKB!"));
122 std::size_t nStep = nPts * dim;
124 for(std::size_t i = 0; i < nStep; ++i)
139 m_byteOrder(byteOrder)
143 te::sqlite::EWKBWriter::~EWKBWriter()
149 m_ewkb[0] = GAIA_MARK_START;
151 m_ewkb[1] = GAIA_LITTLE_ENDIAN;
166 *((
int*)(m_ewkb + 2)) = srid;
168 *((
double*)(m_ewkb + 6)) = mbr.m_llx;
169 *((
double*)(m_ewkb + 14)) = mbr.m_lly;
170 *((
double*)(m_ewkb + 22)) = mbr.m_urx;
171 *((
double*)(m_ewkb + 30)) = mbr.m_ury;
173 m_ewkb[38] = GAIA_MARK_MBR;
179 m_ewkb[0] = GAIA_MARK_END;
184 EWKBWriter w(ewkb, byteOrder);
192 m_byteOrder = byteOrder;
197 unsigned int gType =
static_cast<unsigned int>(visited.
getGeomTypeId());
198 unsigned int nGeoms =
static_cast<unsigned int>(visited.
getNumGeometries());
199 unsigned int nGeomsAux = nGeoms;
207 memcpy(m_ewkb, &gType, 4);
208 memcpy(m_ewkb + 4, &nGeomsAux, 4);
212 for(
unsigned int i = 0; i < nGeoms; ++i)
214 m_ewkb[0] = GAIA_MARK_ENTITY;
224 m_ewkb =
Write2WKB(visited, static_cast<unsigned int>(visited.
size()), m_ewkb, m_byteOrder);
229 unsigned int gType =
static_cast<unsigned int>(visited.
getGeomTypeId());
230 unsigned int nPts =
static_cast<unsigned int>(visited.
size());
235 memcpy(m_ewkb, &gType, 4);
237 m_ewkb =
Write2WKB(visited, nPts, m_ewkb + 4, m_byteOrder);
255 void te::sqlite::EWKBWriter::visit(
const te::gm::Point& visited)
257 unsigned int gType =
static_cast<unsigned int>(visited.
getGeomTypeId());
259 double x = visited.
getX();
260 double y = visited.
getY();
269 memcpy(m_ewkb, &gType, 4);
270 memcpy(m_ewkb + 4, &x, 8);
271 memcpy(m_ewkb + 12, &y, 8);
278 unsigned int gType =
static_cast<unsigned int>(visited.
getGeomTypeId());
280 double x = visited.
getX();
281 double y = visited.
getY();
282 double m = visited.
getM();
292 memcpy(m_ewkb, &gType, 4);
293 memcpy(m_ewkb + 4, &x, 8);
294 memcpy(m_ewkb + 12, &y, 8);
295 memcpy(m_ewkb + 20, &m, 8);
302 unsigned int gType =
static_cast<unsigned int>(visited.
getGeomTypeId());
304 double x = visited.
getX();
305 double y = visited.
getY();
306 double z = visited.
getZ();
316 memcpy(m_ewkb, &gType, 4);
317 memcpy(m_ewkb + 4, &x, 8);
318 memcpy(m_ewkb + 12, &y, 8);
319 memcpy(m_ewkb + 20, &z, 8);
326 unsigned int gType =
static_cast<unsigned int>(visited.
getGeomTypeId());
328 double x = visited.
getX();
329 double y = visited.
getY();
330 double z = visited.
getZ();
331 double m = visited.
getM();
342 memcpy(m_ewkb, &gType, 4);
343 memcpy(m_ewkb + 4, &x, 8);
344 memcpy(m_ewkb + 12, &y, 8);
345 memcpy(m_ewkb + 20, &z, 8);
346 memcpy(m_ewkb + 28, &m, 8);
353 unsigned int nRings =
static_cast<unsigned int>(visited.
getNumRings());
354 unsigned int gType =
static_cast<unsigned int>(visited.
getGeomTypeId());
362 memcpy(m_ewkb, &gType, 4);
363 memcpy(m_ewkb + 4, &nRings, 4);
367 for(
unsigned int i = 0; i < nRings; ++i)
371 #endif // TE_ENABLE_SPATIALITE
std::size_t getNumRings() const
It returns the number of rings in this CurvePolygon.
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
int getSRID() const
It returns the Spatial Reference System ID associated to this geometric object.
MultiPolygon is a MultiSurface whose elements are Polygons.
Coord2D * getCoordinates() const
It returns a pointer to the internal array of coordinates.
void Swap8Bytes(char *v)
It swaps an array of eight bytes in local.
char * Write2WKB(const LineString &l, unsigned int nPts, char *wkb, te::common::MachineByteOrder byteOrder)
It encodes the line to WKB.
static const MachineByteOrder sm_machineByteOrder
A flag that indicates the machine byte order (Big Endian or Little Endian).
An utility struct for representing 2D coordinates.
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.
const double & getY() const
It returns the Point y-coordinate value.
A point with x and y coordinate values.
An Envelope defines a 2D rectangular region.
void Swap4Bytes(T &v)
It swaps four bytes in local.
const double & getZ() const
It returns the Point z-coordinate value.
const double & getM() const
It returns the Point z-coordinate value.
MachineByteOrder
Endianness.
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
A class that serializes a geometry to the SpatiaLite EWKB format.
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
MultiLineString is a MultiCurve whose elements are LineStrings.
const double & getZ() const
It returns the Point z-coordinate value.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
const double & getM() const
It returns the Point z-coordinate value.
const double & getZ(std::size_t i) const
It returns the n-th z coordinate value.
const double & getM(std::size_t i) const
It returns the n-th m measure value.
It is a collection of other geometric objects.
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
const double & getX() const
It returns the Point x-coordinate value.
void SwapBytes(T &v)
It swaps the bytes in local.
Curve * getRingN(std::size_t i) const
It returns the n-th ring for this curve polygon as a curve.
std::size_t size() const
It returns the number of points (vertexes) in the geometry.