27 #include "terralib_config.h"
28 #include "../common/Globals.h"
29 #include "../common/Translator.h"
30 #include "../datatype/Enums.h"
48 #ifdef TERRALIB_GEOS_ENABLED
50 #include <geos/geom/Geometry.h>
51 #include <geos/geom/IntersectionMatrix.h>
52 #include <geos/operation/buffer/OffsetCurveBuilder.h>
53 #include <geos/operation/union/CascadedPolygonUnion.h>
54 #include <geos/util/GEOSException.h>
67 : m_gType(rhs.m_gType),
88 m_mbr = rhs.m_mbr ?
new Envelope(*rhs.m_mbr) : 0;
114 std::stringstream stream(std::ios_base::in | std::ios_base::out);
116 stream.precision(18);
127 char* wkb =
new char[size];
146 #ifdef TERRALIB_GEOS_ENABLED
147 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
152 throw Exception(
TE_TR(
"isEmpty routine is supported by GEOS! Please, enable the GEOS support."));
158 #ifdef TERRALIB_GEOS_ENABLED
159 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
161 return g->isSimple();
164 throw Exception(
TE_TR(
"isSimple routine is supported by GEOS! Please, enable the GEOS support."));
170 #ifdef TERRALIB_GEOS_ENABLED
171 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
176 throw Exception(
TE_TR(
"isValid routine is supported by GEOS! Please, enable the GEOS support."));
182 if((m_gType & 0xF00) == 0xB00)
185 if((m_gType & 0x0F00) == 0x300)
193 if((m_gType & 0xF00) == 0xB00)
196 if((m_gType & 0xF00) == 0x700)
204 #ifdef TERRALIB_GEOS_ENABLED
205 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
206 std::auto_ptr<geos::geom::Geometry> b(g->getBoundary());
207 return GEOSReader::read(b.get());
216 #ifdef TERRALIB_GEOS_ENABLED
217 if( m_srid != rhs->m_srid )
222 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
224 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
227 return thisGeom->equalsExact(rhsGeom.get());
229 return thisGeom->equals(rhsGeom.get());
237 #ifdef TERRALIB_GEOS_ENABLED
238 if( m_srid != rhs->m_srid )
243 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
245 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
247 return thisGeom->disjoint(rhsGeom.get());
256 #ifdef TERRALIB_GEOS_ENABLED
257 if( m_srid != rhs->m_srid )
262 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
264 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
266 return thisGeom->intersects(rhsGeom.get());
275 #ifdef TERRALIB_GEOS_ENABLED
276 if( m_srid != rhs->m_srid )
281 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
283 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
285 return thisGeom->touches(rhsGeom.get());
294 #ifdef TERRALIB_GEOS_ENABLED
295 if( m_srid != rhs->m_srid )
300 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
302 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
304 return thisGeom->crosses(rhsGeom.get());
313 #ifdef TERRALIB_GEOS_ENABLED
314 if( m_srid != rhs->m_srid )
319 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
321 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
323 return thisGeom->within(rhsGeom.get());
332 #ifdef TERRALIB_GEOS_ENABLED
333 if( m_srid != rhs->m_srid )
338 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
340 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
342 return thisGeom->contains(rhsGeom.get());
351 #ifdef TERRALIB_GEOS_ENABLED
352 if( m_srid != rhs->m_srid )
357 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
359 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
361 return thisGeom->overlaps(rhsGeom.get());
370 assert(matrix.size() == 9);
372 #ifdef TERRALIB_GEOS_ENABLED
373 if( m_srid != rhs->m_srid )
378 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
380 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
382 return thisGeom->relate(rhsGeom.get(), matrix);
391 #ifdef TERRALIB_GEOS_ENABLED
392 if( m_srid != rhs->m_srid )
397 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
399 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
401 std::auto_ptr<geos::geom::IntersectionMatrix> m(thisGeom->relate(rhsGeom.get()));
403 return m->toString();
412 #ifdef TERRALIB_GEOS_ENABLED
413 if( m_srid != rhs->m_srid )
418 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
420 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
422 return thisGeom->covers(rhsGeom.get());
431 #ifdef TERRALIB_GEOS_ENABLED
432 if( m_srid != rhs->m_srid )
437 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
439 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
441 return thisGeom->coveredBy(rhsGeom.get());
455 #ifdef TERRALIB_GEOS_ENABLED
456 if( m_srid != rhs->m_srid )
461 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
463 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
465 return thisGeom->distance(rhsGeom.get());
474 #ifdef TERRALIB_GEOS_ENABLED
483 return buffer(distance, quadrantSegments,
CapRoundType);
487 int quadrantSegments,
490 #ifdef TERRALIB_GEOS_ENABLED
491 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
493 std::auto_ptr<geos::geom::Geometry> bg(g->buffer(distance, quadrantSegments, static_cast<int>(endCapStyle)));
497 return GEOSReader::read(bg.get());
507 #ifdef TERRALIB_GEOS_ENABLED
508 std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(
this));
510 std::auto_ptr<geos::geom::Geometry> hull(g->convexHull());
512 hull->setSRID(m_srid);
514 return GEOSReader::read(hull.get());
523 #ifdef TERRALIB_GEOS_ENABLED
524 if( m_srid != rhs->m_srid )
529 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
531 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
533 std::auto_ptr<geos::geom::Geometry> intersectionGeom(thisGeom->intersection(rhsGeom.get()));
535 intersectionGeom->setSRID(m_srid);
537 return GEOSReader::read(intersectionGeom.get());
546 #ifdef TERRALIB_GEOS_ENABLED
547 if( m_srid != rhs->m_srid )
552 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
554 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
556 std::auto_ptr<geos::geom::Geometry> unionGeom(thisGeom-> Union(rhsGeom.get()));
558 unionGeom->setSRID(m_srid);
560 return GEOSReader::read(unionGeom.get());
569 #ifdef TERRALIB_GEOS_ENABLED
570 if( m_srid != rhs->m_srid )
575 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
577 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
579 std::auto_ptr<geos::geom::Geometry> differenceGeom(thisGeom->difference(rhsGeom.get()));
581 differenceGeom->setSRID(m_srid);
583 return GEOSReader::read(differenceGeom.get());
592 #ifdef TERRALIB_GEOS_ENABLED
593 if( m_srid != rhs->m_srid )
598 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
600 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
602 std::auto_ptr<geos::geom::Geometry> symDifferenceGeom(thisGeom->symDifference(rhsGeom.get()));
604 symDifferenceGeom->setSRID(m_srid);
606 return GEOSReader::read(symDifferenceGeom.get());
614 assert(distance >= 0.0);
616 #ifdef TERRALIB_GEOS_ENABLED
617 if( m_srid != rhs->m_srid )
622 std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(
this));
624 std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
626 return thisGeom->isWithinDistance(rhsGeom.get(), distance);
635 std::map<std::string, GeomType>::const_iterator it = sm_geomTypeMap.find(gtype);
637 if(it != sm_geomTypeMap.end())
650 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.