29 #ifdef TERRALIB_GEOS_ENABLED 31 #include "../core/translator/Translator.h" 33 #include "Exception.h" 46 #include <geos/geom/Coordinate.h> 47 #include <geos/geom/CoordinateArraySequence.h> 48 #include <geos/geom/Envelope.h> 49 #include <geos/geom/GeometryCollection.h> 50 #include <geos/geom/LineSegment.h> 51 #include <geos/geom/LineString.h> 52 #include <geos/geom/LinearRing.h> 53 #include <geos/geom/MultiLineString.h> 54 #include <geos/geom/MultiPoint.h> 55 #include <geos/geom/MultiPolygon.h> 56 #include <geos/geom/Point.h> 57 #include <geos/geom/Polygon.h> 66 switch(geom->getGeomTypeId())
72 return write(static_cast<const Point*>(geom));
79 return write(static_cast<const LineString*>(geom));
85 return write(static_cast<const Polygon*>(geom));
91 return write(static_cast<const MultiPolygon*>(geom));
97 return write(static_cast<const MultiPoint*>(geom));
103 return write(static_cast<const MultiLineString*>(geom));
109 return write(static_cast<const MultiSurface*>(geom));
115 return write(static_cast<const GeometryCollection*>(geom));
136 throw Exception(
TE_TR(
"The type of informed geometry can not be converted from TerraLib to GEOS!"));
142 geos::geom::Coordinate c;
143 geos::geom::Point*
p;
145 switch (tePt->getGeomTypeId())
148 assert((tePt !=
nullptr) && (tePt->getGeomTypeId() ==
PointType));
153 p = GEOSGeometryFactory::getGeomFactory()->createPoint(c);
157 p->setSRID(tePt->getSRID());
162 assert((tePt !=
nullptr) && (tePt->getGeomTypeId() ==
PointZType));
168 p = GEOSGeometryFactory::getGeomFactory()->createPoint(c);
172 p->setSRID(tePt->getSRID());
177 assert((tePt !=
nullptr) && (tePt->getGeomTypeId() ==
PointMType));
183 p = GEOSGeometryFactory::getGeomFactory()->createPoint(c);
187 p->setSRID(tePt->getSRID());
192 assert((tePt !=
nullptr) && (tePt->getGeomTypeId() ==
PointZMType));
198 p = GEOSGeometryFactory::getGeomFactory()->createPoint(c);
202 p->setSRID(tePt->getSRID());
212 geos::geom::LineString* ls = GEOSGeometryFactory::getGeomFactory()->createLineString(cl);
214 ls->setSRID(teLine->getSRID());
223 geos::geom::LinearRing* r = GEOSGeometryFactory::getGeomFactory()->createLinearRing(cl);
225 r->setSRID(teRing->getSRID());
232 assert((tePoly !=
nullptr) && (tePoly->getGeomTypeId() ==
PolygonType ||
237 std::size_t n = tePoly->getNumRings();
241 geos::geom::Polygon* poly = GEOSGeometryFactory::getGeomFactory()->createPolygon();
243 poly->setSRID(tePoly->getSRID());
248 std::vector<geos::geom::Geometry*>* holes =
new std::vector<geos::geom::Geometry*>(n - 1);
250 for(std::size_t i = 1; i < n; ++i)
251 (*holes)[i - 1] =
write(static_cast<const LinearRing*>(tePoly->getRingN(i)));
253 geos::geom::LinearRing* outer =
write(static_cast<const LinearRing*>(tePoly->getRingN(0)));
255 geos::geom::Polygon* poly = GEOSGeometryFactory::getGeomFactory()->createPolygon(outer, holes);
257 poly->setSRID(tePoly->getSRID());
264 assert((teMPoly !=
nullptr) && (teMPoly->getGeomTypeId() ==
MultiPolygonType ||
269 std::vector<geos::geom::Geometry*>* geoms =
getGeometries(teMPoly);
271 geos::geom::MultiPolygon* mpoly = GEOSGeometryFactory::getGeomFactory()->createMultiPolygon(geoms);
275 mpoly->setSRID(teMPoly->getSRID());
287 std::vector<geos::geom::Geometry*>* geoms =
getGeometries(teMLine);
291 geos::geom::MultiLineString* mline = GEOSGeometryFactory::getGeomFactory()->createMultiLineString(geoms);
295 mline->setSRID(teMLine->getSRID());
302 assert((teMPt !=
nullptr) && (teMPt->getGeomTypeId() ==
MultiPointType ||
307 std::vector<geos::geom::Geometry*>* geoms =
getGeometries(teMPt);
309 geos::geom::MultiPoint* mpt = GEOSGeometryFactory::getGeomFactory()->createMultiPoint(geoms);
313 mpt->setSRID(teMPt->getSRID());
321 geos::geom::Envelope* env =
new geos::geom::Envelope(teEnv->getLowerLeftX(), teEnv->getUpperRightX(), teEnv->getLowerLeftY(), teEnv->getUpperRightY());
330 geos::geom::LineSegment *ls =
new geos::geom::LineSegment(teLin->getX(0), teLin->getY(0), teLin->getX(1), teLin->getY(1));
347 std::vector<geos::geom::Geometry*>* geoms =
getGeometries(teGeomColl);
349 geos::geom::GeometryCollection* geomColl= GEOSGeometryFactory::getGeomFactory()->createGeometryCollection(geoms);
353 geomColl->setSRID(teGeomColl->getSRID());
360 assert((teLine !=
nullptr) && (teLine->getGeomTypeId() ==
LineStringType ||
365 const std::size_t nPts = teLine->size();
367 std::vector<geos::geom::Coordinate>* geosCoords =
new std::vector<geos::geom::Coordinate>(nPts);
369 Coord2D* teCoords = teLine->getCoordinates();
371 for(std::size_t i = 0; i < nPts; ++i)
373 (*geosCoords)[i].x = teCoords[i].x;
374 (*geosCoords)[i].y = teCoords[i].y;
378 (*geosCoords)[i].z = teLine->getZ(i);
381 geos::geom::CoordinateSequence* cl =
new geos::geom::CoordinateArraySequence(geosCoords);
390 std::size_t size = teGeomColl->getNumGeometries();
392 std::vector<geos::geom::Geometry*>* geoms =
new std::vector<geos::geom::Geometry*>(size);
394 for(std::size_t i = 0; i < size; ++i)
396 geos::geom::Geometry* g =
write(teGeomColl->getGeometryN(i));
406 #endif // TERRALIB_GEOS_ENABLED The global factory used by TerraLib in order to create GEOS geometries.
A Line is LineString with 2 points.
A LinearRing is a LineString that is both closed and simple.
A point with x and y coordinate values.
static std::vector< geos::geom::Geometry * > * getGeometries(const GeometryCollection *teGeomColl)
It creates a vector of GEOS geometry from the input TerraLib geometry collection. ...
static geos::geom::CoordinateSequence * getCoordinateSequence(const LineString *teLine)
It creates a coordinate sequence from the input TerraLib line string (or TerraLib linear ring)...
#define TE_TR(message)
It marks a string in order to get translated.
MultiPoint is a GeometryCollection whose elements are restricted to points.
MultiLineString is a MultiCurve whose elements are LineStrings.
MultiPolygon is a MultiSurface whose elements are Polygons.
static geos::geom::Geometry * write(const Geometry *teGeom)
It reads a TerraLib geometry and make a GEOS geometry.
A class that converts a TerraLib geometry to a GEOS geometry.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
LineString is a curve with linear interpolation between points.
It is a collection of other geometric objects.