20 #ifndef GEOS_GEOM_GEOMETRYFACTORY_H
21 #define GEOS_GEOM_GEOMETRYFACTORY_H
23 #include <geos/geom/Geometry.h>
24 #include <geos/geom/GeometryCollection.h>
25 #include <geos/geom/MultiPoint.h>
26 #include <geos/geom/MultiLineString.h>
27 #include <geos/geom/MultiPolygon.h>
28 #include <geos/geom/PrecisionModel.h>
29 #include <geos/export.h>
30 #include <geos/inline.h>
31 #include <geos/util.h>
36 #include <geos/util/IllegalArgumentException.h>
40 class CoordinateSequenceFactory;
42 class CoordinateSequence;
45 class GeometryCollection;
48 class MultiLineString;
68 class GEOS_DLL GeometryFactory {
71 struct GeometryFactoryDeleter {
73 operator()(GeometryFactory* p)
const
81 using Ptr = std::unique_ptr<GeometryFactory, GeometryFactoryDeleter>;
88 static GeometryFactory::Ptr create();
102 static GeometryFactory::Ptr create(
const PrecisionModel* pm,
int newSRID,
103 CoordinateSequenceFactory* nCoordinateSequenceFactory);
111 static GeometryFactory::Ptr create(CoordinateSequenceFactory* nCoordinateSequenceFactory);
121 static GeometryFactory::Ptr create(
const PrecisionModel* pm);
132 static GeometryFactory::Ptr create(
const PrecisionModel* pm,
int newSRID);
139 static GeometryFactory::Ptr create(
const GeometryFactory& gf);
147 static const GeometryFactory*
148 getDefaultInstance();
152 Point* createPointFromInternalCoord(
const Coordinate* coord,
153 const Geometry* exemplar)
const;
159 std::unique_ptr<Geometry> toGeometry(
const Envelope* envelope)
const;
164 const PrecisionModel* getPrecisionModel()
const;
167 std::unique_ptr<Point> createPoint()
const;
170 Point* createPoint(
const Coordinate& coordinate)
const;
173 Point* createPoint(CoordinateSequence* coordinates)
const;
176 Point* createPoint(
const CoordinateSequence& coordinates)
const;
179 std::unique_ptr<GeometryCollection> createGeometryCollection()
const;
182 std::unique_ptr<Geometry> createEmptyGeometry()
const;
185 GeometryCollection* createGeometryCollection(
186 std::vector<Geometry*>* newGeoms)
const;
188 std::unique_ptr<GeometryCollection> createGeometryCollection(
189 std::vector<std::unique_ptr<Geometry>> && newGeoms)
const;
192 GeometryCollection* createGeometryCollection(
193 const std::vector<const Geometry*>& newGeoms)
const;
196 std::unique_ptr<MultiLineString> createMultiLineString()
const;
199 MultiLineString* createMultiLineString(
200 std::vector<Geometry*>* newLines)
const;
203 MultiLineString* createMultiLineString(
204 const std::vector<const Geometry*>& fromLines)
const;
206 std::unique_ptr<MultiLineString> createMultiLineString(
207 std::vector<std::unique_ptr<LineString>> && fromLines)
const;
209 std::unique_ptr<MultiLineString> createMultiLineString(
210 std::vector<std::unique_ptr<Geometry>> && fromLines)
const;
213 std::unique_ptr<MultiPolygon> createMultiPolygon()
const;
216 MultiPolygon* createMultiPolygon(std::vector<Geometry*>* newPolys)
const;
219 MultiPolygon* createMultiPolygon(
220 const std::vector<const Geometry*>& fromPolys)
const;
222 std::unique_ptr<MultiPolygon> createMultiPolygon(
223 std::vector<std::unique_ptr<Polygon>> && fromPolys)
const;
225 std::unique_ptr<MultiPolygon> createMultiPolygon(
226 std::vector<std::unique_ptr<Geometry>> && fromPolys)
const;
229 std::unique_ptr<LinearRing> createLinearRing()
const;
232 LinearRing* createLinearRing(CoordinateSequence* newCoords)
const;
234 std::unique_ptr<LinearRing> createLinearRing(
235 std::unique_ptr<CoordinateSequence> && newCoords)
const;
238 LinearRing* createLinearRing(
239 const CoordinateSequence& coordinates)
const;
242 std::unique_ptr<MultiPoint> createMultiPoint()
const;
245 MultiPoint* createMultiPoint(std::vector<Geometry*>* newPoints)
const;
247 std::unique_ptr<MultiPoint> createMultiPoint(std::vector<std::unique_ptr<Point>> && newPoints)
const;
249 std::unique_ptr<MultiPoint> createMultiPoint(std::vector<std::unique_ptr<Geometry>> && newPoints)
const;
252 MultiPoint* createMultiPoint(
253 const std::vector<const Geometry*>& fromPoints)
const;
258 MultiPoint* createMultiPoint(
259 const CoordinateSequence& fromCoords)
const;
264 MultiPoint* createMultiPoint(
265 const std::vector<Coordinate>& fromCoords)
const;
268 std::unique_ptr<Polygon> createPolygon()
const;
271 Polygon* createPolygon(LinearRing* shell,
272 std::vector<LinearRing*>* holes)
const;
274 std::unique_ptr<Polygon> createPolygon(std::unique_ptr<LinearRing> && shell)
const;
276 std::unique_ptr<Polygon> createPolygon(std::unique_ptr<LinearRing> && shell,
277 std::vector<std::unique_ptr<LinearRing>> && holes)
const;
280 Polygon* createPolygon(
const LinearRing& shell,
281 const std::vector<LinearRing*>& holes)
const;
284 std::unique_ptr<LineString> createLineString()
const;
287 std::unique_ptr<LineString> createLineString(
const LineString& ls)
const;
290 LineString* createLineString(CoordinateSequence* coordinates)
const;
292 std::unique_ptr<LineString> createLineString(
293 std::unique_ptr<CoordinateSequence> && coordinates)
const;
296 LineString* createLineString(
297 const CoordinateSequence& coordinates)
const;
329 Geometry* buildGeometry(std::vector<Geometry*>* geoms)
const;
331 std::unique_ptr<Geometry> buildGeometry(std::vector<std::unique_ptr<Geometry>> && geoms)
const;
342 std::unique_ptr<Geometry>
343 buildGeometry(T from, T toofar)
const
345 bool isHeterogeneous =
false;
348 for(T i = from; i != toofar; ++i) {
352 geomClass = g->getSortIndex();
354 else if(geomClass != g->getSortIndex()) {
355 isHeterogeneous =
true;
361 return std::unique_ptr<Geometry>(createGeometryCollection());
366 return (*from)->clone();
375 std::vector<std::unique_ptr<Geometry>> fromGeoms;
376 for(T i = from; i != toofar; ++i) {
377 fromGeoms.push_back((*i)->clone());
381 if(isHeterogeneous) {
382 return createGeometryCollection(std::move(fromGeoms));
386 switch((*from)->getDimension()) {
387 case Dimension::A:
return createMultiPolygon(std::move(fromGeoms));
388 case Dimension::L:
return createMultiLineString(std::move(fromGeoms));
389 case Dimension::P:
return createMultiPoint(std::move(fromGeoms));
402 Geometry* buildGeometry(
const std::vector<const Geometry*>& geoms)
const;
415 void destroyGeometry(
Geometry* g)
const;
494 mutable int _refCount;
500 void dropRef()
const;
508 # include "geos/geom/GeometryFactory.inl"
511 #endif // ndef GEOS_GEOM_GEOMETRYFACTORY_H