27 #include "../common/Globals.h"
28 #include "../common/Translator.h"
29 #include "../datatype/Enums.h"
47 #ifdef TERRALIB_GEOS_ENABLED
49 #include <geos/geom/Geometry.h>
50 #include <geos/geom/IntersectionMatrix.h>
51 #include <geos/operation/buffer/OffsetCurveBuilder.h>
52 #include <geos/operation/union/CascadedPolygonUnion.h>
53 #include <geos/util/GEOSException.h>
66 : m_gType(rhs.m_gType),
87 m_mbr = rhs.m_mbr ?
new Envelope(*rhs.m_mbr) : 0;
113 std::stringstream stream(std::ios_base::in | std::ios_base::out);
115 stream.precision(18);
126 char* wkb =
new char[size];
145 #ifdef TERRALIB_GEOS_ENABLED
146 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
151 throw Exception(
TE_TR(
"isEmpty routine is supported by GEOS! Please, enable the GEOS support."));
157 #ifdef TERRALIB_GEOS_ENABLED
158 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
160 return g->isSimple();
163 throw Exception(
TE_TR(
"isSimple routine is supported by GEOS! Please, enable the GEOS support."));
169 #ifdef TERRALIB_GEOS_ENABLED
170 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
175 throw Exception(
TE_TR(
"isValid routine is supported by GEOS! Please, enable the GEOS support."));
181 if((m_gType & 0xF00) == 0xB00)
184 if((m_gType & 0x0F00) == 0x300)
192 if((m_gType & 0xF00) == 0xB00)
195 if((m_gType & 0xF00) == 0x700)
203 #ifdef TERRALIB_GEOS_ENABLED
204 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
205 std::auto_ptr<geos::geom::Geometry> b(g->getBoundary());
206 return GEOSReader::read(b.get());
215 #ifdef TERRALIB_GEOS_ENABLED
216 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
218 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
221 return thisGeom->equalsExact(rhsGeom.get());
223 return thisGeom->equals(rhsGeom.get());
231 #ifdef TERRALIB_GEOS_ENABLED
232 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
234 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
236 return thisGeom->disjoint(rhsGeom.get());
245 #ifdef TERRALIB_GEOS_ENABLED
246 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
248 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
250 return thisGeom->intersects(rhsGeom.get());
259 #ifdef TERRALIB_GEOS_ENABLED
260 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
262 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
264 return thisGeom->touches(rhsGeom.get());
273 #ifdef TERRALIB_GEOS_ENABLED
274 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
276 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
278 return thisGeom->crosses(rhsGeom.get());
287 #ifdef TERRALIB_GEOS_ENABLED
288 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
290 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
292 return thisGeom->within(rhsGeom.get());
301 #ifdef TERRALIB_GEOS_ENABLED
302 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
304 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
306 return thisGeom->contains(rhsGeom.get());
315 #ifdef TERRALIB_GEOS_ENABLED
316 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
318 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
320 return thisGeom->overlaps(rhsGeom.get());
329 assert(matrix.size() == 9);
331 #ifdef TERRALIB_GEOS_ENABLED
332 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
334 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
336 return thisGeom->relate(rhsGeom.get(), matrix);
345 #ifdef TERRALIB_GEOS_ENABLED
346 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
348 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
350 std::auto_ptr<geos::geom::IntersectionMatrix> m(thisGeom->relate(rhsGeom.get()));
352 return m->toString();
361 #ifdef TERRALIB_GEOS_ENABLED
362 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
364 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
366 return thisGeom->covers(rhsGeom.get());
375 #ifdef TERRALIB_GEOS_ENABLED
376 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
378 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
380 return thisGeom->coveredBy(rhsGeom.get());
394 #ifdef TERRALIB_GEOS_ENABLED
395 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
397 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
399 return thisGeom->distance(rhsGeom.get());
408 #ifdef TERRALIB_GEOS_ENABLED
417 return buffer(distance, quadrantSegments,
CapRoundType);
421 int quadrantSegments,
424 #ifdef TERRALIB_GEOS_ENABLED
425 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
427 std::auto_ptr<geos::geom::Geometry> bg(g->buffer(distance, quadrantSegments, static_cast<int>(endCapStyle)));
431 return GEOSReader::read(bg.get());
441 #ifdef TERRALIB_GEOS_ENABLED
442 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
444 std::auto_ptr<geos::geom::Geometry> hull(g->convexHull());
446 hull->setSRID(m_srid);
448 return GEOSReader::read(hull.get());
457 #ifdef TERRALIB_GEOS_ENABLED
458 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
460 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
462 std::auto_ptr<geos::geom::Geometry> intersectionGeom(thisGeom->intersection(rhsGeom.get()));
464 intersectionGeom->setSRID(m_srid);
466 return GEOSReader::read(intersectionGeom.get());
475 #ifdef TERRALIB_GEOS_ENABLED
477 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
479 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
481 std::auto_ptr<geos::geom::Geometry> unionGeom(thisGeom-> Union(rhsGeom.get()));
483 unionGeom->setSRID(m_srid);
485 return GEOSReader::read(unionGeom.get());
494 #ifdef TERRALIB_GEOS_ENABLED
495 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
497 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
499 std::auto_ptr<geos::geom::Geometry> differenceGeom(thisGeom->difference(rhsGeom.get()));
501 differenceGeom->setSRID(m_srid);
503 return GEOSReader::read(differenceGeom.get());
512 #ifdef TERRALIB_GEOS_ENABLED
513 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
515 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
517 std::auto_ptr<geos::geom::Geometry> symDifferenceGeom(thisGeom->symDifference(rhsGeom.get()));
519 symDifferenceGeom->setSRID(m_srid);
521 return GEOSReader::read(symDifferenceGeom.get());
529 assert(distance >= 0.0);
531 #ifdef TERRALIB_GEOS_ENABLED
532 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
534 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
536 return thisGeom->isWithinDistance(rhsGeom.get(), distance);
545 std::map<std::string, GeomType>::const_iterator it = sm_geomTypeMap.find(gtype);
547 if(it != sm_geomTypeMap.end())
560 if(!sm_geomTypeMap.empty())
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
virtual Geometry * buffer(const double &distance) const
This method calculates the buffer of a geometry.
virtual Geometry & operator=(const Geometry &rhs)
Assignment operator.
int getCoordinateDimension() const
It returns the number of measurements or axes needed to describe a position in a coordinate system...
BufferCapStyle
Buffer end cap style.
static void loadGeomTypeId()
It loads the internal MAP of geometry type names to geometry type ids.
virtual bool covers(const Geometry *const rhs) const
It returns true if this geometry object spatially covers the rhs geometry.
virtual bool intersects(const Geometry *const rhs) const
It returns true if the geometry object spatially intersects rhs geometry.
void getWkb(char *wkb, te::common::MachineByteOrder byteOrder) const
It serializes the geometry to a WKB representation into the specified buffer.
bool isMeasured() const
It returns true if this geometric object has m coordinate values.
static const MachineByteOrder sm_machineByteOrder
A flag that indicates the machine byte order (Big Endian or Little Endian).
static std::size_t size(const Geometry *geom)
It calculates the number of bytes required to encode the geometry in a WKB format.
virtual bool contains(const Geometry *const rhs) const
It returns true if this geometry object spatially contains rhs geometry.
#define TE_TR(message)
It marks a string in order to get translated.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
virtual Geometry * locateBetween(const double &mStart, const double &mEnd) const
It returns a derived geometry collection value according to the range of coordinate values inclusivel...
std::size_t getWkbSize() const
It returns the size required by a WKB representation for this geometric object.
int GetCoordDimension(GeomType t)
It returns the number of measurements or axes needed to describe a position in a coordinate system...
void write(const Geometry *geom)
It serializes the geometry to a WKB representation into the specified buffer.
virtual Geometry * getBoundary() const
It returns the geometry boundary.
virtual bool relate(const Geometry *const rhs, const std::string &matrix) const
It returns true if this geometry object is spatially related to rhs geometry according to the pattern...
A class that serializes a geometry to the WKB format.
virtual bool crosses(const Geometry *const rhs) const
It returns true if the geometry object spatially crosses rhs geometry.
An Envelope defines a 2D rectangular region.
#define TE_GEOS_DEFAULT_QUADRANT_SEGMENTS
Determines the number of default segments used to create buffers.
An Envelope defines a 2D rectangular region.
int getTypeCode() const
It returns the data type code associated to the data value.
virtual bool disjoint(const Geometry *const rhs) const
It returns true if the geometry object is spatially disjoint from rhs geometry.
void write(const Geometry *geom)
It serializes the geometry to a WKT representation.
Geometry * getEnvelope() const
It returns the minimum bounding rectangle (MBR) for the geometry.
char * asBinary(std::size_t &size) const
It serializes the geometric object to a Well-known Binary Representation (WKB).
bool is3D() const
It returns true if this geometric object has z coordinate values.
virtual bool isValid() const
It tells if the geometry is well formed.
Utility functions for the Geometry Module.
MachineByteOrder
Endianness.
virtual ~Geometry()
Virtual destructor.
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
A class that converts a GEOS geometry to a TerraLib geometry.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Envelope * m_mbr
The geometry minimum bounding rectangle.
virtual bool overlaps(const Geometry *const rhs) const
It returns true if this geometry object spatially overlaps rhs geometry.
A class that converts a TerraLib geometry to a GEOS geometry.
virtual bool isEmpty() const
It returns true if this geometric object is the empty Geometry.
An exception class for the Geometry module.
virtual bool touches(const Geometry *const rhs) const
It returns true if the geometry object spatially touches rhs geometry.
Geometry(GeomType t, int srid=-1, Envelope *mbr=0)
It initializes the Geometry with the specified spatial reference system id and envelope.
virtual bool dWithin(const Geometry *const rhs, const double &distance) const
It returns true if the geometries are within the specified distance.
static bool isGeomType(const std::string &stype)
It tells if the given string is a geometry data type.
A class that computes the number of bytes necessary to encode a geometry in WKB.
virtual bool equals(const Geometry *const rhs, const bool exact=false) const
It returns true if the geometry object is spatially equal to rhs geometry.
virtual Geometry * convexHull() const
This method calculates the Convex Hull of a geometry.
virtual bool coveredBy(const Geometry *const rhs) const
It returns true if this geometry object is spatially covered by rhs geometry.
GeomType m_gType
Internal geometry type.
virtual Geometry * intersection(const Geometry *const rhs) const
It returns a geometric object that represents the point set intersection with another geometry...
virtual Geometry * Union(const Geometry *const rhs) const
It returns a geometric object that represents the point set union with another geometry.
static std::map< std::string, GeomType > sm_geomTypeMap
A set of geometry type names (in UPPER CASE).
virtual Geometry * symDifference(const Geometry *const rhs) const
It returns a geometric object that represents the point set symetric difference with another geometry...
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
virtual double distance(const Geometry *const rhs) const
It returns the shortest distance between any two points in the two geometry objects.
virtual bool isSimple() const
It returns true if this geometric object has no anomalous points, such as self intersection or self t...
A class that serializes a geometry to the WKT format.
A class that deserializes a geometry from a valid WKT.
std::string asText() const
It returns an string with the Well-Known Text Representation for the geometry.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
virtual Geometry * difference(const Geometry *const rhs) const
It returns a geometric object that represents the point set difference with another geometry...
virtual bool within(const Geometry *const rhs) const
It returns true if the geometry object is spatially within rhs geometry.