29 #ifdef TERRALIB_GEOS_ENABLED 31 #include "../core/translator/Translator.h" 32 #include "Exception.h" 43 #include <geos/geom/Coordinate.h> 44 #include <geos/geom/CoordinateArraySequence.h> 45 #include <geos/geom/GeometryCollection.h> 46 #include <geos/geom/LineString.h> 47 #include <geos/geom/LinearRing.h> 48 #include <geos/geom/MultiLineString.h> 49 #include <geos/geom/MultiPoint.h> 50 #include <geos/geom/MultiPolygon.h> 51 #include <geos/geom/Point.h> 52 #include <geos/geom/Polygon.h> 53 #include <geos/geom/Dimension.h> 62 switch(geom->getGeometryTypeId())
64 case geos::geom::GEOS_POINT:
65 return read(dynamic_cast<const geos::geom::Point*>(geom));
67 case geos::geom::GEOS_LINESTRING:
68 return read(dynamic_cast<const geos::geom::LineString*>(geom));
70 case geos::geom::GEOS_LINEARRING:
71 return read(dynamic_cast<const geos::geom::LinearRing*>(geom));
73 case geos::geom::GEOS_POLYGON:
74 return read(dynamic_cast<const geos::geom::Polygon*>(geom));
76 case geos::geom::GEOS_MULTIPOLYGON:
77 return read(dynamic_cast<const geos::geom::MultiPolygon*>(geom));
79 case geos::geom::GEOS_MULTIPOINT:
80 return read(dynamic_cast<const geos::geom::MultiPoint*>(geom));
82 case geos::geom::GEOS_MULTILINESTRING:
83 return read(dynamic_cast<const geos::geom::MultiLineString*>(geom));
85 case geos::geom::GEOS_GEOMETRYCOLLECTION:
86 return read(dynamic_cast<const geos::geom::GeometryCollection*>(geom));
89 throw Exception(
TE_TR(
"The type of informed geometry can not be converted from GEOS to TerraLib!"));
93 te::gm::Point* te::gm::GEOSReader::read(
const geos::geom::Point* geosPt)
95 assert((geosPt !=
nullptr) && (geosPt->getGeometryTypeId() == geos::geom::GEOS_POINT));
99 switch (geosPt->getCoordinateDimension())
103 pt =
new Point(geosPt->getSRID(), gtype);
104 pt->setX(geosPt->getX());
105 pt->setY(geosPt->getY());
106 pt->setZ(geosPt->getCoordinate()->z);
110 pt =
new Point(geosPt->getSRID(), gtype);
111 pt->setX(geosPt->getX());
112 pt->setY(geosPt->getY());
113 pt->setZ(geosPt->getCoordinate()->z);
114 pt->setM(geosPt->getCoordinate()->z);
118 pt =
new Point(geosPt->getX(), geosPt->getY(), geosPt->getSRID());
126 assert((geosLine !=
nullptr) && (geosLine->getGeometryTypeId() == geos::geom::GEOS_LINESTRING));
128 const geos::geom::CoordinateSequence* cs = geosLine->getCoordinatesRO();
130 std::size_t size = cs->getSize();
132 LineString* l =
new LineString(size,
LineStringType, geosLine->getSRID(),
nullptr);
134 for(std::size_t i = 0; i < size; ++i)
136 l->setX(i, cs->getX(i));
137 l->setY(i, cs->getY(i));
145 assert((geosRing !=
nullptr) && (geosRing->getGeometryTypeId() == geos::geom::GEOS_LINEARRING));
147 const geos::geom::CoordinateSequence* cs = geosRing->getCoordinatesRO();
149 std::size_t size = cs->getSize();
152 switch (cs->getDimension())
164 LinearRing* r =
new LinearRing(size, gtype, geosRing->getSRID(),
nullptr);
166 for(std::size_t i = 0; i < size; ++i)
168 r->setX(i, cs->getX(i));
169 r->setY(i, cs->getY(i));
170 if ((gtype & 0xF00) == 0x300)
171 r->setZ(i, cs->getOrdinate(i, 2));
172 if ((gtype & 0xF00) == 0x700)
173 r->setM(i, cs->getOrdinate(i, 3));
180 te::gm::Polygon* te::gm::GEOSReader::read(
const geos::geom::Polygon* geosPoly)
182 assert((geosPoly !=
nullptr) && (geosPoly->getGeometryTypeId() == geos::geom::GEOS_POLYGON));
184 if(geosPoly->isEmpty())
185 return new Polygon(0,
PolygonType, geosPoly->getSRID());
187 int coordDimension = geosPoly->getCoordinateDimension();
191 if (coordDimension == 3)
193 else if(coordDimension == 4)
198 std::size_t holesSize = geosPoly->getNumInteriorRing();
200 Polygon* poly =
new Polygon(holesSize + 1, gtype, geosPoly->getSRID(),
nullptr);
202 LinearRing* r = read(static_cast<const geos::geom::LinearRing*>(geosPoly->getExteriorRing()));
204 poly->setRingN(0, r);
206 for(std::size_t i = 0; i < holesSize; ++i)
208 LinearRing* r = read(static_cast<const geos::geom::LinearRing*>(geosPoly->getInteriorRingN(i)));
210 poly->setRingN(i + 1, r);
218 assert((geosMPoly !=
nullptr) && (geosMPoly->getGeometryTypeId() == geos::geom::GEOS_MULTIPOLYGON));
220 const std::size_t size = geosMPoly->getNumGeometries();
222 MultiPolygon* mpoly =
new MultiPolygon(size,
MultiPolygonType, geosMPoly->getSRID(),
nullptr);
224 for(std::size_t i = 0; i < size; ++i)
225 mpoly->setGeometryN(i, read(geosMPoly->getGeometryN(i)));
232 assert((geosMLine !=
nullptr) && (geosMLine->getGeometryTypeId() == geos::geom::GEOS_MULTILINESTRING));
234 const std::size_t size = geosMLine->getNumGeometries();
236 MultiLineString* mline =
new MultiLineString(size,
MultiLineStringType, geosMLine->getSRID(),
nullptr);
238 for(std::size_t i = 0; i < size; ++i)
239 mline->setGeometryN(i, read(geosMLine->getGeometryN(i)));
246 assert((geosMPt !=
nullptr) && (geosMPt->getGeometryTypeId() == geos::geom::GEOS_MULTIPOINT));
248 const std::size_t size = geosMPt->getNumGeometries();
250 MultiPoint* mpt =
new MultiPoint(size,
MultiPointType, geosMPt->getSRID(),
nullptr);
252 for(std::size_t i = 0; i < size; ++i)
253 mpt->setGeometryN(i, read(geosMPt->getGeometryN(i)));
260 assert((geosGeomColl !=
nullptr) && (geosGeomColl->getGeometryTypeId() == geos::geom::GEOS_GEOMETRYCOLLECTION));
262 const std::size_t size = geosGeomColl->getNumGeometries();
264 GeometryCollection* geomColl =
new GeometryCollection(size,
GeometryCollectionType, geosGeomColl->getSRID(),
nullptr);
266 for(std::size_t i = 0; i < size; ++i)
267 geomColl->setGeometryN(i, read(geosGeomColl->getGeometryN(i)));
272 #endif // TERRALIB_GEOS_ENABLED MultiPolygon is a MultiSurface whose elements are Polygons.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
A LinearRing is a LineString that is both closed and simple.
A point with x and y coordinate values.
#define TE_TR(message)
It marks a string in order to get translated.
MultiPoint is a GeometryCollection whose elements are restricted to points.
A LinearRing is a LineString that is both closed and simple.
MultiPoint is a GeometryCollection whose elements are restricted to points.
LineString is a curve with linear interpolation between points.
A point with x and y coordinate values.
MultiLineString is a MultiCurve whose elements are LineStrings.
MultiPolygon is a MultiSurface whose elements are Polygons.
A class that converts a GEOS geometry to a TerraLib geometry.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
MultiLineString is a MultiCurve whose elements are LineStrings.
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.
It is a collection of other geometric objects.