27 #include "../common/Globals.h" 28 #include "../core/translator/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/geom/Point.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),
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 153 catch(geos::util::GEOSException& e)
158 throw Exception(
TE_TR(
"isEmpty routine is supported by GEOS! Please, enable the GEOS support."));
164 #ifdef TERRALIB_GEOS_ENABLED 169 return g->isSimple();
171 catch(geos::util::GEOSException& e)
176 throw Exception(
TE_TR(
"isSimple routine is supported by GEOS! Please, enable the GEOS support."));
182 #ifdef TERRALIB_GEOS_ENABLED 189 catch(
const geos::util::GEOSException& e)
194 throw Exception(
TE_TR(
"isValid routine is supported by GEOS! Please, enable the GEOS support."));
203 if((
m_gType & 0x0F00) == 0x300)
239 #ifdef TERRALIB_GEOS_ENABLED 244 std::unique_ptr<geos::geom::Geometry>
b(g->getBoundary());
246 return GEOSReader::read(
b.get());
248 catch(geos::util::GEOSException& e)
261 #ifdef TERRALIB_GEOS_ENABLED 266 std::unique_ptr<geos::geom::Point> point(thisGeom->getCentroid());
268 coord2d.
x = point->getX();
269 coord2d.
y = point->getY();
271 catch(geos::util::GEOSException& e)
284 #ifdef TERRALIB_GEOS_ENABLED 285 if(
m_srid != rhs->m_srid )
297 return thisGeom->equalsExact(rhsGeom.get());
299 return thisGeom->equals(rhsGeom.get());
301 catch(geos::util::GEOSException& e)
312 #ifdef TERRALIB_GEOS_ENABLED 313 if(
m_srid != rhs->m_srid )
324 return thisGeom->disjoint(rhsGeom.get());
326 catch(geos::util::GEOSException& e)
337 #ifdef TERRALIB_GEOS_ENABLED 338 if(
m_srid != rhs->m_srid )
349 return thisGeom->intersects(rhsGeom.get());
351 catch(geos::util::GEOSException& e)
363 #ifdef TERRALIB_GEOS_ENABLED 364 if(
m_srid != rhs->m_srid )
375 return thisGeom->touches(rhsGeom.get());
377 catch(geos::util::GEOSException& e)
388 #ifdef TERRALIB_GEOS_ENABLED 389 if(
m_srid != rhs->m_srid )
400 return thisGeom->crosses(rhsGeom.get());
402 catch(geos::util::GEOSException& e)
413 #ifdef TERRALIB_GEOS_ENABLED 414 if(
m_srid != rhs->m_srid )
425 return thisGeom->within(rhsGeom.get());
427 catch(geos::util::GEOSException& e)
438 #ifdef TERRALIB_GEOS_ENABLED 439 if(
m_srid != rhs->m_srid )
450 return thisGeom->contains(rhsGeom.get());
452 catch(geos::util::GEOSException& e)
463 #ifdef TERRALIB_GEOS_ENABLED 464 if(
m_srid != rhs->m_srid )
475 return thisGeom->overlaps(rhsGeom.get());
477 catch(geos::util::GEOSException& e)
488 assert(matrix.size() == 9);
490 #ifdef TERRALIB_GEOS_ENABLED 491 if(
m_srid != rhs->m_srid )
502 return thisGeom->relate(rhsGeom.get(), matrix);
504 catch(geos::util::GEOSException& e)
516 #ifdef TERRALIB_GEOS_ENABLED 517 if(
m_srid != rhs->m_srid )
528 std::unique_ptr<geos::geom::IntersectionMatrix> m(thisGeom->relate(rhsGeom.get()));
530 return m->toString();
532 catch(geos::util::GEOSException& e)
543 #ifdef TERRALIB_GEOS_ENABLED 544 if(
m_srid != rhs->m_srid )
555 return thisGeom->covers(rhsGeom.get());
557 catch(geos::util::GEOSException& e)
568 #ifdef TERRALIB_GEOS_ENABLED 569 if(
m_srid != rhs->m_srid )
580 return thisGeom->coveredBy(rhsGeom.get());
582 catch(geos::util::GEOSException& e)
598 #ifdef TERRALIB_GEOS_ENABLED 599 if(
m_srid != rhs->m_srid )
610 return thisGeom->distance(rhsGeom.get());
612 catch(geos::util::GEOSException& e)
623 #ifdef TERRALIB_GEOS_ENABLED 636 int quadrantSegments,
639 #ifdef TERRALIB_GEOS_ENABLED 644 std::unique_ptr<geos::geom::Geometry> bg(g->buffer(
distance, quadrantSegments, static_cast<int>(endCapStyle)));
648 return GEOSReader::read(bg.get());
650 catch(geos::util::GEOSException& e)
661 #ifdef TERRALIB_GEOS_ENABLED 666 std::unique_ptr<geos::geom::Geometry> hull(g->convexHull());
670 return GEOSReader::read(hull.get());
672 catch(geos::util::GEOSException& e)
683 #ifdef TERRALIB_GEOS_ENABLED 684 if(
m_srid != rhs->m_srid )
695 std::unique_ptr<geos::geom::Geometry> intersectionGeom(thisGeom->intersection(rhsGeom.get()));
697 intersectionGeom->setSRID(
m_srid);
699 return GEOSReader::read(intersectionGeom.get());
701 catch(geos::util::GEOSException& e)
712 #ifdef TERRALIB_GEOS_ENABLED 713 if(
m_srid != rhs->m_srid )
724 std::unique_ptr<geos::geom::Geometry> unionGeom(thisGeom->
Union(rhsGeom.get()));
726 unionGeom->setSRID(
m_srid);
728 return GEOSReader::read(unionGeom.get());
730 catch(geos::util::GEOSException& e)
741 #ifdef TERRALIB_GEOS_ENABLED 742 if(
m_srid != rhs->m_srid )
753 std::unique_ptr<geos::geom::Geometry> differenceGeom(thisGeom->difference(rhsGeom.get()));
755 differenceGeom->setSRID(
m_srid);
757 return GEOSReader::read(differenceGeom.get());
759 catch(geos::util::GEOSException& e)
770 #ifdef TERRALIB_GEOS_ENABLED 771 if(
m_srid != rhs->m_srid )
782 std::unique_ptr<geos::geom::Geometry> symDifferenceGeom(thisGeom->symDifference(rhsGeom.get()));
784 symDifferenceGeom->setSRID(
m_srid);
786 return GEOSReader::read(symDifferenceGeom.get());
788 catch(geos::util::GEOSException& e)
801 #ifdef TERRALIB_GEOS_ENABLED 802 if(
m_srid != rhs->m_srid )
813 return thisGeom->isWithinDistance(rhsGeom.get(),
distance);
815 catch(geos::util::GEOSException& e)
826 std::map<std::string, GeomType>::const_iterator it =
sm_geomTypeMap.find(gtype);
866 return "GeometryCollection";
878 return "MultiLineString";
884 return "MultiPolygon";
890 return "CircularString";
896 return "CompoundCurve";
902 return "CurvePolygon";
908 return "MultiSurface";
911 return "UnknownGeometry";
998 std::map<std::string, GeomType>::const_iterator it;
1002 if (it->second == static_cast<GeomType>(gId))
1006 return "UNKNOWGEOMETRYTYPE";
virtual Geometry * difference(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns a geometric object that represents the point set difference with another geometry...
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
virtual Geometry * symDifference(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns a geometric object that represents the point set symetric difference with another geometry...
bool isCollection() const _NOEXCEPT_OP(true)
It returns true if this geometric object is a collection.
BufferCapStyle
Buffer end cap style.
static void loadGeomTypeId()
It loads the internal MAP of geometry type names to geometry type ids.
virtual double distance(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns the shortest distance between any two points in the two geometry objects.
Base exception class for plugin module.
virtual Geometry * buffer(const double &distance) const _NOEXCEPT_OP(false)
This method calculates the buffer of a geometry.
bool isMeasured() const _NOEXCEPT_OP(true)
It returns true if this geometric object has m coordinate values.
GeomType getGeomTypeId() const _NOEXCEPT_OP(true)
It returns the geometry subclass type identifier.
int m_srid
The Spatial Reference System code associated to the Geometry.
virtual Geometry * intersection(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns a geometric object that represents the point set intersection with another geometry...
virtual bool dWithin(const Geometry *const rhs, const double &distance) const _NOEXCEPT_OP(false)
It returns true if the geometries are within the specified distance.
static const MachineByteOrder sm_machineByteOrder
A flag that indicates the machine byte order (Big Endian or Little Endian).
virtual bool disjoint(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object is spatially disjoint from rhs geometry.
virtual bool relate(const Geometry *const rhs, const std::string &matrix) const _NOEXCEPT_OP(false)
It returns true if this geometry object is spatially related to rhs geometry according to the pattern...
static std::size_t size(const Geometry *geom)
It calculates the number of bytes required to encode the geometry in a WKB format.
An utility struct for representing 2D coordinates.
#define TE_TR(message)
It marks a string in order to get translated.
virtual Geometry * Union(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns a geometric object that represents the point set union with another geometry.
virtual bool intersects(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object spatially intersects rhs geometry.
virtual bool touches(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object spatially touches rhs geometry.
virtual bool isSimple() const _NOEXCEPT_OP(false)
It returns true if this geometric object has no anomalous points, such as self intersection or self t...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
std::size_t getWkbSize() const _NOEXCEPT_OP(true)
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.
A class that serializes a geometry to the WKB format.
virtual bool overlaps(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if this geometry object spatially overlaps rhs geometry.
virtual Geometry * locateBetween(const double &mStart, const double &mEnd) const _NOEXCEPT_OP(false)
It returns a derived geometry collection value according to the range of coordinate values inclusivel...
te::gm::Coord2D getCentroid() const _NOEXCEPT_OP(false)
It will get the centroid of the input geometries.
Utility functions for the Geometry Module.
virtual void computeMBR(bool cascade) const _NOEXCEPT_OP(true)=0
It computes the minimum bounding rectangle for the geometry.
An Envelope defines a 2D rectangular region.
Geometry * getEnvelope() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle (MBR) for the geometry.
#define TE_GEOS_DEFAULT_QUADRANT_SEGMENTS
Determines the number of default segments used to create buffers.
virtual GeomType get2DGeomTypeId() const _NOEXCEPT_OP(true)
It returns the 2D geometry subclass type identifier.
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
virtual bool isValid() const _NOEXCEPT_OP(false)
It tells if the geometry is well formed.
An Envelope defines a 2D rectangular region.
std::string asText() const _NOEXCEPT_OP(true)
It returns an string with the Well-Known Text Representation for the geometry.
int getTypeCode() const
It returns the data type code associated to the data value.
virtual bool within(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object is spatially within rhs geometry.
void write(const Geometry *geom)
It serializes the geometry to a WKT representation.
virtual bool isEmpty() const _NOEXCEPT_OP(false)
It returns true if this geometric object is the empty Geometry.
virtual bool contains(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if this geometry object spatially contains rhs geometry.
virtual const std::string get2DGeometryType() const _NOEXCEPT_OP(true)
It returns the name of 2D geometry subclass.
MachineByteOrder
Endianness.
virtual ~Geometry()
Virtual destructor.
bool is3D() const _NOEXCEPT_OP(true)
It returns true if this geometric object has z coordinate values.
char * asBinary(std::size_t &size) const _NOEXCEPT_OP(false)
It serializes the geometric object to a Well-known Binary Representation (WKB).
static geos::geom::Geometry * write(const Geometry *teGeom)
It reads a TerraLib geometry and make a GEOS geometry.
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.
virtual Geometry & operator=(const Geometry &rhs) _NOEXCEPT_OP(true)
Assignment operator.
Envelope * m_mbr
The geometry minimum bounding rectangle.
A class that converts a TerraLib geometry to a GEOS geometry.
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 Geometry * getBoundary() const _NOEXCEPT_OP(false)
It returns the geometry boundary.
GeomType m_gType
Internal geometry type.
static std::string getGeomTypeString(const int &gId)
It returns the TerraLib geometry type string given a type id.
virtual bool crosses(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object spatially crosses rhs geometry.
static std::map< std::string, GeomType > sm_geomTypeMap
A set of geometry type names (in UPPER CASE).
An exception class for the Geometry module.
A class that serializes a geometry to the WKT format.
int getCoordinateDimension() const _NOEXCEPT_OP(true)
It returns the number of measurements or axes needed to describe a position in a coordinate system...
A class that deserializes a geometry from a valid WKT.
virtual Geometry * convexHull() const _NOEXCEPT_OP(false)
This method calculates the Convex Hull of a geometry.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
virtual bool coveredBy(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if this geometry object is spatially covered by rhs geometry.
virtual bool equals(const Geometry *const rhs, const bool exact=false) const _NOEXCEPT_OP(false)
It returns true if the geometry object is spatially equal to rhs geometry.
Geometry(GeomType t, int srid=0, Envelope *mbr=0) _NOEXCEPT_OP(true)
It initializes the Geometry with the specified spatial reference system id and envelope.
virtual bool covers(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if this geometry object spatially covers the rhs geometry.
void getWkb(char *wkb, te::common::MachineByteOrder byteOrder) const _NOEXCEPT_OP(false)
It serializes the geometry to a WKB representation into the specified buffer.