27 #include "../common/Globals.h"
28 #include "../common/Translator.h"
29 #include "../datatype/Enums.h"
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];
146 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
151 throw Exception(
TR_GEOM(
"isEmpty routine is supported by GEOS! Please, enable the GEOS support."));
158 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
160 return g->isSimple();
163 throw Exception(
TR_GEOM(
"isSimple routine is supported by GEOS! Please, enable the GEOS support."));
170 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
175 throw Exception(
TR_GEOM(
"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)
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());
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());
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());
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());
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());
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());
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());
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());
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);
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);
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();
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());
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());
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());
417 return buffer(distance, quadrantSegments,
CapRoundType);
421 int quadrantSegments,
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());
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());
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());
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());
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());
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);
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())
int GetCoordDimension(GeomType t)
It returns the number of measurements or axes needed to describe a position in a coordinate system...
virtual bool dWithin(const Geometry *const rhs, const double &distance) const
It returns true if the geometries are within the specified distance.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
virtual Geometry * getBoundary() const
It returns the geometry boundary.
std::size_t getWkbSize() const
It returns the size required by a WKB representation for this geometric object.
void write(const Geometry *geom)
It serializes the geometry to a WKT representation.
void getWkb(char *wkb, te::common::MachineByteOrder byteOrder) const
It serializes the geometry to a WKB representation into the specified buffer.
GeomType m_gType
Internal geometry type.
static std::size_t size(const Geometry *geom)
It calculates the number of bytes required to encode the geometry in a WKB format.
virtual Geometry * convexHull() const
This method calculates the Convex Hull of a geometry.
virtual bool isSimple() const
It returns true if this geometric object has no anomalous points, such as self intersection or self t...
virtual bool intersects(const Geometry *const rhs) const
It returns true if the geometry object spatially intersects rhs geometry.
A class that serializes a geometry to the WKB format.
int getTypeCode() const
It returns the data type code associated to the data value.
An exception class for the Geometry module.
virtual double distance(const Geometry *const rhs) const
It returns the shortest distance between any two points in the two geometry objects.
#define TR_GEOM(message)
It marks a string in order to get translated. This is a special mark used in the Vector Geometry modu...
A class that converts a TerraLib geometry to a GEOS geometry.
virtual bool within(const Geometry *const rhs) const
It returns true if the geometry object is spatially within rhs geometry.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
static bool isGeomType(const std::string &stype)
It tells if the given string is a geometry data type.
Geometry(GeomType t, int srid=-1, Envelope *mbr=0)
It initializes the Geometry with the specified spatial reference system id and envelope.
virtual Geometry * buffer(const double &distance) const
This method calculates the buffer of a geometry.
Utility functions for the Geometry Module.
virtual bool isValid() const
It tells if the geometry is well formed.
virtual bool isEmpty() const
It returns true if this geometric object is the empty Geometry.
int getCoordinateDimension() const
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.
static const MachineByteOrder sm_machineByteOrder
A flag that indicates the machine byte order (Big Endian or Little Endian).
virtual bool contains(const Geometry *const rhs) const
It returns true if this geometry object spatially contains rhs geometry.
MachineByteOrder
Endianness.
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...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
virtual Geometry * symDifference(const Geometry *const rhs) const
It returns a geometric object that represents the point set symetric difference with another geometry...
virtual Geometry * intersection(const Geometry *const rhs) const
It returns a geometric object that represents the point set intersection with another geometry...
bool is3D() const
It returns true if this geometric object has z coordinate values.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
static std::map< std::string, GeomType > sm_geomTypeMap
A set of geometry type names (in UPPER CASE).
virtual Geometry * Union(const Geometry *const rhs) const
It returns a geometric object that represents the point set union with another geometry.
virtual bool crosses(const Geometry *const rhs) const
It returns true if the geometry object spatially crosses rhs geometry.
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
bool isMeasured() const
It returns true if this geometric object has m coordinate values.
virtual bool overlaps(const Geometry *const rhs) const
It returns true if this geometry object spatially overlaps rhs geometry.
char * asBinary(std::size_t &size) const
It serializes the geometric object to a Well-known Binary Representation (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 bool touches(const Geometry *const rhs) const
It returns true if the geometry object spatially touches rhs geometry.
virtual Geometry & operator=(const Geometry &rhs)
Assignment operator.
BufferCapStyle
Buffer end cap style.
A class that serializes a geometry to the WKT format.
virtual bool covers(const Geometry *const rhs) const
It returns true if this geometry object spatially covers the rhs geometry.
A class that computes the number of bytes necessary to encode a geometry in WKB.
virtual Geometry * difference(const Geometry *const rhs) const
It returns a geometric object that represents the point set difference with another geometry...
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
An Envelope defines a 2D rectangular region.
Envelope * m_mbr
The geometry minimum bounding rectangle.
A class that converts a GEOS geometry to a TerraLib geometry.
Geometry * getEnvelope() const
It returns the minimum bounding rectangle (MBR) for the geometry.
std::string asText() const
It returns an string with the Well-Known Text Representation for the geometry.
An Envelope defines a 2D rectangular region.
static void loadGeomTypeId()
It loads the internal MAP of geometry type names to geometry type ids.
virtual ~Geometry()
Virtual destructor.
virtual bool coveredBy(const Geometry *const rhs) const
It returns true if this geometry object is spatially covered by rhs geometry.
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...
virtual bool disjoint(const Geometry *const rhs) const
It returns true if the geometry object is spatially disjoint from rhs geometry.
A class that deserializes a geometry from a valid WKT.
#define TE_GEOS_DEFAULT_QUADRANT_SEGMENTS
Determines the number of default segments used to create buffers.