GEOS 3.6.2
GeometryFactory.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
7 * Copyright (C) 2006 Refractions Research Inc.
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************
15 *
16 * Last port: geom/GeometryFactory.java r320 (JTS-1.12)
17 *
18 **********************************************************************/
19
20#ifndef GEOS_GEOM_GEOMETRYFACTORY_H
21#define GEOS_GEOM_GEOMETRYFACTORY_H
22
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/export.h>
29#include <geos/inline.h>
30
31#include <vector>
32#include <memory>
33#include <cassert>
34
35namespace geos {
36 namespace geom {
38 class Coordinate;
40 class Envelope;
41 class Geometry;
43 class LineString;
44 class LinearRing;
45 class MultiLineString;
46 class MultiPoint;
47 class MultiPolygon;
48 class Point;
49 class Polygon;
50 class PrecisionModel;
51 }
52}
53
54namespace geos {
55namespace geom { // geos::geom
56
67class GEOS_DLL GeometryFactory {
68public:
69
70 // TODO: typedef std::unique_ptr<GeometryFactory,destroy>
71 class unique_ptr {
72 mutable GeometryFactory *_f;
73 public:
74 // Copying an auto_unique_ptr transfers ownership
75 unique_ptr(const unique_ptr& o): _f(o.release()) {};
76 GeometryFactory* release() const { GeometryFactory *f = _f; _f=0; return f; }
77 void reset(GeometryFactory* f) { if ( _f ) _f->destroy(); _f = f; }
78 // assigning an auto_unique_ptr transfers ownership
79 unique_ptr& operator=(const unique_ptr& o) {
80 reset( o.release() );
81 return *this;
82 }
83 GeometryFactory* get() const { return _f; }
84 GeometryFactory* operator->() const { return _f; }
85 GeometryFactory& operator*() { return *_f; };
86 unique_ptr(): _f(0) {}
87 unique_ptr(GeometryFactory* f): _f(f) {}
88 ~unique_ptr() { reset(0); }
89 };
90
96 static GeometryFactory::unique_ptr create();
97
110 static GeometryFactory::unique_ptr create(const PrecisionModel *pm, int newSRID,
111 CoordinateSequenceFactory *nCoordinateSequenceFactory);
112
119 static GeometryFactory::unique_ptr create(CoordinateSequenceFactory *nCoordinateSequenceFactory);
120
129 static GeometryFactory::unique_ptr create(const PrecisionModel *pm);
130
140 static GeometryFactory::unique_ptr create(const PrecisionModel* pm, int newSRID);
141
147 static GeometryFactory::unique_ptr create(const GeometryFactory &gf);
148
155 static const GeometryFactory*
157
158//Skipped a lot of list to array convertors
159
160 Point* createPointFromInternalCoord(const Coordinate* coord,
161 const Geometry *exemplar) const;
162
164 //
167 Geometry* toGeometry(const Envelope* envelope) const;
168
173
176
178 Point* createPoint(const Coordinate& coordinate) const;
179
182
184 Point* createPoint(const CoordinateSequence &coordinates) const;
185
188
190 Geometry* createEmptyGeometry() const;
191
194 std::vector<Geometry *> *newGeoms) const;
195
198 const std::vector<Geometry *> &newGeoms) const;
199
202
205 std::vector<Geometry *> *newLines) const;
206
209 const std::vector<Geometry *> &fromLines) const;
210
213
215 MultiPolygon* createMultiPolygon(std::vector<Geometry *> *newPolys) const;
216
219 const std::vector<Geometry *> &fromPolys) const;
220
223
226
227 std::auto_ptr<Geometry> createLinearRing(
228 std::auto_ptr<CoordinateSequence> newCoords) const;
229
232 const CoordinateSequence& coordinates) const;
233
236
238 MultiPoint* createMultiPoint(std::vector<Geometry *> *newPoints) const;
239
242 const std::vector<Geometry *> &fromPoints) const;
243
248 const CoordinateSequence &fromCoords) const;
249
254 const std::vector<Coordinate> &fromCoords) const;
255
258
261 std::vector<Geometry *> *holes) const;
262
265 const std::vector<Geometry *> &holes) const;
266
269
271 std::auto_ptr<LineString> createLineString(const LineString& ls) const;
272
275
276 std::auto_ptr<Geometry> createLineString(
277 std::auto_ptr<CoordinateSequence> coordinates) const;
278
281 const CoordinateSequence& coordinates) const;
282
314 Geometry* buildGeometry(std::vector<Geometry *> *geoms) const;
315
317 //
324 template <class T>
325 std::auto_ptr<Geometry> buildGeometry(T from, T toofar) const
326 {
327 bool isHeterogeneous = false;
328 size_t count = 0;
329 int geomClass = -1;
330 for (T i=from; i != toofar; ++i)
331 {
332 ++count;
333 const Geometry* g = *i;
334 if ( geomClass < 0 ) {
335 geomClass = g->getClassSortIndex();
336 }
337 else if ( geomClass != g->getClassSortIndex() ) {
338 isHeterogeneous = true;
339 }
340 }
341
342 // for the empty geometry, return an empty GeometryCollection
343 if ( count == 0 ) {
344 return std::auto_ptr<Geometry>( createGeometryCollection() );
345 }
346
347 // for the single geometry, return a clone
348 if ( count == 1 ) {
349 return std::auto_ptr<Geometry>( (*from)->clone() );
350 }
351
352 // Now we know it is a collection
353
354 // FIXME:
355 // Until we tweak all the createMulti* interfaces
356 // to support taking iterators we'll have to build
357 // a custom vector here.
358 std::vector<Geometry*> fromGeoms;
359 for (T i=from; i != toofar; ++i) {
360 const Geometry* g = *i;
361 fromGeoms.push_back(const_cast<Geometry*>(g));
362 }
363
364
365 // for an heterogeneous ...
366 if ( isHeterogeneous ) {
367 return std::auto_ptr<Geometry>( createGeometryCollection(fromGeoms) );
368 }
369
370 // At this point we know the collection is not hetereogenous.
371 if ( dynamic_cast<const Polygon*>(*from) ) {
372 return std::auto_ptr<Geometry>( createMultiPolygon(fromGeoms) );
373 } else if ( dynamic_cast<const LineString*>(*from) ) {
374 return std::auto_ptr<Geometry>( createMultiLineString(fromGeoms) );
375 } else if ( dynamic_cast<const Point*>(*from) ) {
376 return std::auto_ptr<Geometry>( createMultiPoint(fromGeoms) );
377 }
378 // FIXME: Why not to throw an exception? --mloskot
379 assert(0); // buildGeomtry encountered an unkwnon geometry type
380 return std::auto_ptr<Geometry>(); // nullptr
381 }
382
390 Geometry* buildGeometry(const std::vector<Geometry *> &geoms) const;
391
392 int getSRID() const;
393
398
400 Geometry* createGeometry(const Geometry *g) const;
401
403 void destroyGeometry(Geometry *g) const;
404
406 //
411 void destroy();
412
413protected:
414
421
434 GeometryFactory(const PrecisionModel *pm, int newSRID,
435 CoordinateSequenceFactory *nCoordinateSequenceFactory);
436
443 GeometryFactory(CoordinateSequenceFactory *nCoordinateSequenceFactory);
444
454
464 GeometryFactory(const PrecisionModel* pm, int newSRID);
465
472
475
476private:
477
478 const PrecisionModel* precisionModel;
479 int SRID;
480 const CoordinateSequenceFactory *coordinateListFactory;
481
482 mutable int _refCount;
483 bool _autoDestroy;
484
485friend class Geometry;
486
487 void addRef() const;
488 void dropRef() const;
489
490};
491
492} // namespace geos::geom
493} // namespace geos
494
495#ifdef GEOS_INLINE
496# include "geos/geom/GeometryFactory.inl"
497#endif
498
499#endif // ndef GEOS_GEOM_GEOMETRYFACTORY_H
A factory to create concrete instances of CoordinateSequences.
Definition CoordinateSequenceFactory.h:47
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:59
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:60
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:53
Represents a collection of heterogeneous Geometry objects.
Definition GeometryCollection.h:56
MultiPoint * createMultiPoint(const std::vector< Geometry * > &fromPoints) const
Construct a MultiPoint with a deep-copy of given arguments.
static const GeometryFactory * getDefaultInstance()
Return a pointer to the default GeometryFactory. This is a global shared object instantiated using de...
Polygon * createPolygon(LinearRing *shell, std::vector< Geometry * > *holes) const
Construct a Polygon taking ownership of given arguments.
MultiPoint * createMultiPoint() const
Constructs an EMPTY MultiPoint.
Point * createPoint() const
Creates an EMPTY Point.
GeometryFactory(const PrecisionModel *pm)
Constructs a GeometryFactory that generates Geometries having the given PrecisionModel and the defaul...
Geometry * buildGeometry(std::vector< Geometry * > *geoms) const
GeometryCollection * createGeometryCollection() const
Construct an EMPTY GeometryCollection.
MultiPoint * createMultiPoint(std::vector< Geometry * > *newPoints) const
Construct a MultiPoint taking ownership of given arguments.
std::auto_ptr< Geometry > buildGeometry(T from, T toofar) const
See buildGeometry(std::vector<Geometry *>&) for semantics.
Definition GeometryFactory.h:325
std::auto_ptr< LineString > createLineString(const LineString &ls) const
Copy a LineString.
LineString * createLineString(const CoordinateSequence &coordinates) const
Construct a LineString with a deep-copy of given argument.
static GeometryFactory::unique_ptr create(const GeometryFactory &gf)
Copy constructor.
LineString * createLineString(CoordinateSequence *coordinates) const
Construct a LineString taking ownership of given argument.
Point * createPoint(const CoordinateSequence &coordinates) const
Creates a Point with a deep-copy of the given CoordinateSequence.
const PrecisionModel * getPrecisionModel() const
Returns the PrecisionModel that Geometries created by this factory will be associated with.
LinearRing * createLinearRing(const CoordinateSequence &coordinates) const
Construct a LinearRing with a deep-copy of given arguments.
MultiPoint * createMultiPoint(const std::vector< Coordinate > &fromCoords) const
Construct a MultiPoint containing a Point geometry for each Coordinate in the given vector.
static GeometryFactory::unique_ptr create(CoordinateSequenceFactory *nCoordinateSequenceFactory)
Constructs a GeometryFactory that generates Geometries having the given CoordinateSequence implementa...
static GeometryFactory::unique_ptr create(const PrecisionModel *pm)
Constructs a GeometryFactory that generates Geometries having the given PrecisionModel and the defaul...
GeometryFactory(CoordinateSequenceFactory *nCoordinateSequenceFactory)
Constructs a GeometryFactory that generates Geometries having the given CoordinateSequence implementa...
static GeometryFactory::unique_ptr create(const PrecisionModel *pm, int newSRID)
Constructs a GeometryFactory that generates Geometries having the given PrecisionModel and spatial-re...
LineString * createLineString() const
Construct an EMPTY LineString.
Point * createPoint(const Coordinate &coordinate) const
Creates a Point using the given Coordinate.
void destroyGeometry(Geometry *g) const
Destroy a Geometry, or release it.
Geometry * createEmptyGeometry() const
Construct the EMPTY Geometry.
GeometryCollection * createGeometryCollection(const std::vector< Geometry * > &newGeoms) const
Constructs a GeometryCollection with a deep-copy of args.
MultiPolygon * createMultiPolygon(std::vector< Geometry * > *newPolys) const
Construct a MultiPolygon taking ownership of given arguments.
static GeometryFactory::unique_ptr create(const PrecisionModel *pm, int newSRID, CoordinateSequenceFactory *nCoordinateSequenceFactory)
Constructs a GeometryFactory that generates Geometries having the given PrecisionModel,...
GeometryFactory(const PrecisionModel *pm, int newSRID, CoordinateSequenceFactory *nCoordinateSequenceFactory)
Constructs a GeometryFactory that generates Geometries having the given PrecisionModel,...
Point * createPoint(CoordinateSequence *coordinates) const
Creates a Point taking ownership of the given CoordinateSequence.
GeometryCollection * createGeometryCollection(std::vector< Geometry * > *newGeoms) const
Construct a GeometryCollection taking ownership of given arguments.
MultiPoint * createMultiPoint(const CoordinateSequence &fromCoords) const
Construct a MultiPoint containing a Point geometry for each Coordinate in the given list.
GeometryFactory(const PrecisionModel *pm, int newSRID)
Constructs a GeometryFactory that generates Geometries having the given PrecisionModel and spatial-re...
virtual ~GeometryFactory()
Destructor.
Geometry * buildGeometry(const std::vector< Geometry * > &geoms) const
This function does the same thing of the omonimouse function taking vector pointer instead of referen...
static GeometryFactory::unique_ptr create()
Constructs a GeometryFactory that generates Geometries having a floating PrecisionModel and a spatial...
Geometry * createGeometry(const Geometry *g) const
Returns a clone of given Geometry.
MultiPolygon * createMultiPolygon(const std::vector< Geometry * > &fromPolys) const
Construct a MultiPolygon with a deep-copy of given arguments.
Polygon * createPolygon() const
Construct an EMPTY Polygon.
MultiLineString * createMultiLineString(std::vector< Geometry * > *newLines) const
Construct a MultiLineString taking ownership of given arguments.
LinearRing * createLinearRing() const
Construct an EMPTY LinearRing.
MultiPolygon * createMultiPolygon() const
Construct an EMPTY MultiPolygon.
MultiLineString * createMultiLineString() const
Construct an EMPTY MultiLineString.
const CoordinateSequenceFactory * getCoordinateSequenceFactory() const
Returns the CoordinateSequenceFactory associated with this GeometryFactory.
GeometryFactory(const GeometryFactory &gf)
Copy constructor.
GeometryFactory()
Constructs a GeometryFactory that generates Geometries having a floating PrecisionModel and a spatial...
Polygon * createPolygon(const LinearRing &shell, const std::vector< Geometry * > &holes) const
Construct a Polygon with a deep-copy of given arguments.
void destroy()
Request that the instance is deleted.
MultiLineString * createMultiLineString(const std::vector< Geometry * > &fromLines) const
Construct a MultiLineString with a deep-copy of given arguments.
LinearRing * createLinearRing(CoordinateSequence *newCoords) const
Construct a LinearRing taking ownership of given arguments.
Geometry * toGeometry(const Envelope *envelope) const
Converts an Envelope to a Geometry.
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:167
Definition LineString.h:70
Models an OGC SFS LinearRing.
Definition LinearRing.h:57
Models a collection of (}s.
Definition MultiLineString.h:51
Definition MultiPoint.h:56
Models a collection of Polygons.
Definition MultiPolygon.h:61
Definition Point.h:68
Represents a linear polygon, which may include holes.
Definition Polygon.h:67
Specifies the precision model of the Coordinate in a Geometry.
Definition PrecisionModel.h:87
Contains the Geometry interface hierarchy and supporting classes.
Definition IndexedNestedRingTester.h:26
Basic namespace for all GEOS functionalities.
Definition IndexedNestedRingTester.h:25