GEOS  3.7.2
GeometryFactory.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
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 
35 namespace geos {
36  namespace geom {
37  class CoordinateSequenceFactory;
38  class Coordinate;
39  class CoordinateSequence;
40  class Envelope;
41  class Geometry;
42  class GeometryCollection;
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 
54 namespace geos {
55 namespace geom { // geos::geom
56 
67 class GEOS_DLL GeometryFactory {
68 private:
69 
70  struct GeometryFactoryDeleter
71  {
72  void operator()(GeometryFactory* p) const
73  {
74  p->destroy();
75  }
76  };
77 
78 public:
79 
80  using Ptr = std::unique_ptr<GeometryFactory, GeometryFactoryDeleter>;
81 
87  static GeometryFactory::Ptr create();
88 
101  static GeometryFactory::Ptr create(const PrecisionModel *pm, int newSRID,
102  CoordinateSequenceFactory *nCoordinateSequenceFactory);
103 
110  static GeometryFactory::Ptr create(CoordinateSequenceFactory *nCoordinateSequenceFactory);
111 
120  static GeometryFactory::Ptr create(const PrecisionModel *pm);
121 
131  static GeometryFactory::Ptr create(const PrecisionModel* pm, int newSRID);
132 
138  static GeometryFactory::Ptr create(const GeometryFactory &gf);
139 
146  static const GeometryFactory*
148 
149 //Skipped a lot of list to array convertors
150 
151  Point* createPointFromInternalCoord(const Coordinate* coord,
152  const Geometry *exemplar) const;
153 
155  //
158  Geometry* toGeometry(const Envelope* envelope) const;
159 
164 
166  Point* createPoint() const;
167 
169  Point* createPoint(const Coordinate& coordinate) const;
170 
172  Point* createPoint(CoordinateSequence *coordinates) const;
173 
175  Point* createPoint(const CoordinateSequence &coordinates) const;
176 
179 
182 
185  std::vector<Geometry *> *newGeoms) const;
186 
189  const std::vector<Geometry *> &newGeoms) const;
190 
193 
196  std::vector<Geometry *> *newLines) const;
197 
200  const std::vector<Geometry *> &fromLines) const;
201 
204 
206  MultiPolygon* createMultiPolygon(std::vector<Geometry *> *newPolys) const;
207 
210  const std::vector<Geometry *> &fromPolys) const;
211 
214 
217 
218  std::unique_ptr<Geometry> createLinearRing(
219  std::unique_ptr<CoordinateSequence> newCoords) const;
220 
223  const CoordinateSequence& coordinates) const;
224 
227 
229  MultiPoint* createMultiPoint(std::vector<Geometry *> *newPoints) const;
230 
233  const std::vector<Geometry *> &fromPoints) const;
234 
239  const CoordinateSequence &fromCoords) const;
240 
245  const std::vector<Coordinate> &fromCoords) const;
246 
249 
252  std::vector<Geometry *> *holes) const;
253 
256  const std::vector<Geometry *> &holes) const;
257 
260 
262  std::unique_ptr<LineString> createLineString(const LineString& ls) const;
263 
266 
267  std::unique_ptr<Geometry> createLineString(
268  std::unique_ptr<CoordinateSequence> coordinates) const;
269 
272  const CoordinateSequence& coordinates) const;
273 
305  Geometry* buildGeometry(std::vector<Geometry *> *geoms) const;
306 
308  //
315  template <class T>
316  std::unique_ptr<Geometry> buildGeometry(T from, T toofar) const
317  {
318  bool isHeterogeneous = false;
319  size_t count = 0;
320  int geomClass = -1;
321  for (T i=from; i != toofar; ++i)
322  {
323  ++count;
324  const Geometry* g = *i;
325  if ( geomClass < 0 ) {
326  geomClass = g->getClassSortIndex();
327  }
328  else if ( geomClass != g->getClassSortIndex() ) {
329  isHeterogeneous = true;
330  }
331  }
332 
333  // for the empty geometry, return an empty GeometryCollection
334  if ( count == 0 ) {
335  return std::unique_ptr<Geometry>( createGeometryCollection() );
336  }
337 
338  // for the single geometry, return a clone
339  if ( count == 1 ) {
340  return std::unique_ptr<Geometry>( (*from)->clone() );
341  }
342 
343  // Now we know it is a collection
344 
345  // FIXME:
346  // Until we tweak all the createMulti* interfaces
347  // to support taking iterators we'll have to build
348  // a custom vector here.
349  std::vector<Geometry*> fromGeoms;
350  for (T i=from; i != toofar; ++i) {
351  const Geometry* g = *i;
352  fromGeoms.push_back(const_cast<Geometry*>(g));
353  }
354 
355 
356  // for an heterogeneous ...
357  if ( isHeterogeneous ) {
358  return std::unique_ptr<Geometry>( createGeometryCollection(fromGeoms) );
359  }
360 
361  // At this point we know the collection is not hetereogenous.
362  if ( dynamic_cast<const Polygon*>(*from) ) {
363  return std::unique_ptr<Geometry>( createMultiPolygon(fromGeoms) );
364  } else if ( dynamic_cast<const LineString*>(*from) ) {
365  return std::unique_ptr<Geometry>( createMultiLineString(fromGeoms) );
366  } else if ( dynamic_cast<const Point*>(*from) ) {
367  return std::unique_ptr<Geometry>( createMultiPoint(fromGeoms) );
368  }
369  // FIXME: Why not to throw an exception? --mloskot
370  assert(0); // buildGeomtry encountered an unkwnon geometry type
371  return std::unique_ptr<Geometry>(); // nullptr
372  }
373 
381  Geometry* buildGeometry(const std::vector<Geometry *> &geoms) const;
382 
383  int getSRID() const;
384 
389 
391  Geometry* createGeometry(const Geometry *g) const;
392 
394  void destroyGeometry(Geometry *g) const;
395 
397  //
402  void destroy();
403 
404 protected:
405 
412 
425  GeometryFactory(const PrecisionModel *pm, int newSRID,
426  CoordinateSequenceFactory *nCoordinateSequenceFactory);
427 
434  GeometryFactory(CoordinateSequenceFactory *nCoordinateSequenceFactory);
435 
445 
455  GeometryFactory(const PrecisionModel* pm, int newSRID);
456 
463 
465  virtual ~GeometryFactory();
466 
467 private:
468 
469  const PrecisionModel* precisionModel;
470  int SRID;
471  const CoordinateSequenceFactory *coordinateListFactory;
472 
473  mutable int _refCount;
474  bool _autoDestroy;
475 
476 friend class Geometry;
477 
478  void addRef() const;
479  void dropRef() const;
480 
481 };
482 
483 } // namespace geos::geom
484 } // namespace geos
485 
486 #ifdef GEOS_INLINE
487 # include "geos/geom/GeometryFactory.inl"
488 #endif
489 
490 #endif // ndef GEOS_GEOM_GEOMETRYFACTORY_H
geos::geom::GeometryFactory::GeometryFactory
GeometryFactory(const PrecisionModel *pm, int newSRID, CoordinateSequenceFactory *nCoordinateSequenceFactory)
Constructs a GeometryFactory that generates Geometries having the given PrecisionModel,...
geos::geom::GeometryFactory::createMultiPolygon
MultiPolygon * createMultiPolygon() const
Construct an EMPTY MultiPolygon.
geos::geom::GeometryFactory::createLinearRing
LinearRing * createLinearRing(CoordinateSequence *newCoords) const
Construct a LinearRing taking ownership of given arguments.
geos::geom::GeometryFactory::createGeometryCollection
GeometryCollection * createGeometryCollection() const
Construct an EMPTY GeometryCollection.
geos::geom::GeometryFactory::buildGeometry
Geometry * buildGeometry(std::vector< Geometry * > *geoms) const
geos::geom::MultiPoint
Definition: MultiPoint.h:56
geos::geom::GeometryFactory::createGeometry
Geometry * createGeometry(const Geometry *g) const
Returns a clone of given Geometry.
geos::geom::PrecisionModel
Specifies the precision model of the Coordinate in a Geometry.
Definition: PrecisionModel.h:87
geos::geom::GeometryFactory::createGeometryCollection
GeometryCollection * createGeometryCollection(std::vector< Geometry * > *newGeoms) const
Construct a GeometryCollection taking ownership of given arguments.
geos::geom::GeometryFactory::create
static GeometryFactory::Ptr create(const PrecisionModel *pm)
Constructs a GeometryFactory that generates Geometries having the given PrecisionModel and the defaul...
geos::geom::LinearRing
Models an OGC SFS LinearRing.
Definition: LinearRing.h:57
geos
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
geos::geom::GeometryFactory::createLineString
std::unique_ptr< LineString > createLineString(const LineString &ls) const
Copy a LineString.
geos::geom::GeometryFactory::createMultiPolygon
MultiPolygon * createMultiPolygon(std::vector< Geometry * > *newPolys) const
Construct a MultiPolygon taking ownership of given arguments.
geos::geom::GeometryFactory::createMultiPoint
MultiPoint * createMultiPoint(const CoordinateSequence &fromCoords) const
Construct a MultiPoint containing a Point geometry for each Coordinate in the given list.
geos::geom::GeometryFactory::createMultiPoint
MultiPoint * createMultiPoint() const
Constructs an EMPTY MultiPoint.
geos::geom::GeometryFactory::create
static GeometryFactory::Ptr create(const PrecisionModel *pm, int newSRID)
Constructs a GeometryFactory that generates Geometries having the given PrecisionModel and spatial-re...
geos::geom::GeometryFactory::create
static GeometryFactory::Ptr create(const PrecisionModel *pm, int newSRID, CoordinateSequenceFactory *nCoordinateSequenceFactory)
Constructs a GeometryFactory that generates Geometries having the given PrecisionModel,...
geos::geom::GeometryFactory::create
static GeometryFactory::Ptr create(const GeometryFactory &gf)
Copy constructor.
geos::geom::GeometryFactory::createPolygon
Polygon * createPolygon() const
Construct an EMPTY Polygon.
geos::geom::GeometryFactory::createPolygon
Polygon * createPolygon(const LinearRing &shell, const std::vector< Geometry * > &holes) const
Construct a Polygon with a deep-copy of given arguments.
geos::geom::CoordinateSequenceFactory
A factory to create concrete instances of CoordinateSequences.
Definition: CoordinateSequenceFactory.h:47
geos::geom::MultiLineString
Models a collection of (}s.
Definition: MultiLineString.h:51
geos::geom::GeometryFactory::createPoint
Point * createPoint(const CoordinateSequence &coordinates) const
Creates a Point with a deep-copy of the given CoordinateSequence.
geos::geom::GeometryFactory::createLineString
LineString * createLineString() const
Construct an EMPTY LineString.
geos::geom::GeometryFactory::GeometryFactory
GeometryFactory(const PrecisionModel *pm)
Constructs a GeometryFactory that generates Geometries having the given PrecisionModel and the defaul...
geos::geom::Polygon
Represents a linear polygon, which may include holes.
Definition: Polygon.h:67
geos::geom::GeometryFactory::createMultiPoint
MultiPoint * createMultiPoint(std::vector< Geometry * > *newPoints) const
Construct a MultiPoint taking ownership of given arguments.
geos::geom::GeometryFactory::createMultiPoint
MultiPoint * createMultiPoint(const std::vector< Coordinate > &fromCoords) const
Construct a MultiPoint containing a Point geometry for each Coordinate in the given vector.
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
geos::geom::GeometryFactory::~GeometryFactory
virtual ~GeometryFactory()
Destructor.
geos::geom::GeometryFactory::GeometryFactory
GeometryFactory(const PrecisionModel *pm, int newSRID)
Constructs a GeometryFactory that generates Geometries having the given PrecisionModel and spatial-re...
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:177
geos::geom::GeometryFactory::createMultiLineString
MultiLineString * createMultiLineString(std::vector< Geometry * > *newLines) const
Construct a MultiLineString taking ownership of given arguments.
geos::geom::GeometryCollection
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:56
geos::geom::GeometryFactory::createLineString
LineString * createLineString(const CoordinateSequence &coordinates) const
Construct a LineString with a deep-copy of given argument.
geos::geom::GeometryFactory::createMultiLineString
MultiLineString * createMultiLineString(const std::vector< Geometry * > &fromLines) const
Construct a MultiLineString with a deep-copy of given arguments.
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:59
geos::geom::GeometryFactory::createGeometryCollection
GeometryCollection * createGeometryCollection(const std::vector< Geometry * > &newGeoms) const
Constructs a GeometryCollection with a deep-copy of args.
geos::geom::GeometryFactory::create
static GeometryFactory::Ptr create(CoordinateSequenceFactory *nCoordinateSequenceFactory)
Constructs a GeometryFactory that generates Geometries having the given CoordinateSequence implementa...
geos::geom::GeometryFactory::createPoint
Point * createPoint(CoordinateSequence *coordinates) const
Creates a Point taking ownership of the given CoordinateSequence.
geos::geom::GeometryFactory::destroy
void destroy()
Request that the instance is deleted.
geos::geom::GeometryFactory::createLineString
LineString * createLineString(CoordinateSequence *coordinates) const
Construct a LineString taking ownership of given argument.
geos::geom::GeometryFactory::createLinearRing
LinearRing * createLinearRing() const
Construct an EMPTY LinearRing.
geos::geom::GeometryFactory::createPoint
Point * createPoint(const Coordinate &coordinate) const
Creates a Point using the given Coordinate.
geos::geom::GeometryFactory::createLinearRing
LinearRing * createLinearRing(const CoordinateSequence &coordinates) const
Construct a LinearRing with a deep-copy of given arguments.
geos::geom::GeometryFactory::createMultiLineString
MultiLineString * createMultiLineString() const
Construct an EMPTY MultiLineString.
geos::geom::GeometryFactory::GeometryFactory
GeometryFactory()
Constructs a GeometryFactory that generates Geometries having a floating PrecisionModel and a spatial...
geos::geom::GeometryFactory::destroyGeometry
void destroyGeometry(Geometry *g) const
Destroy a Geometry, or release it.
geos::geom::Envelope
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
geos::geom::GeometryFactory::createPolygon
Polygon * createPolygon(LinearRing *shell, std::vector< Geometry * > *holes) const
Construct a Polygon taking ownership of given arguments.
geos::geom::GeometryFactory::createPoint
Point * createPoint() const
Creates an EMPTY Point.
geos::geom::GeometryFactory::buildGeometry
std::unique_ptr< Geometry > buildGeometry(T from, T toofar) const
See buildGeometry(std::vector<Geometry *>&) for semantics.
Definition: GeometryFactory.h:316
geos::geom::GeometryFactory
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:67
geos::geom::GeometryFactory::GeometryFactory
GeometryFactory(const GeometryFactory &gf)
Copy constructor.
geos::geom::GeometryFactory::buildGeometry
Geometry * buildGeometry(const std::vector< Geometry * > &geoms) const
This function does the same thing of the omonimouse function taking vector pointer instead of referen...
geos::geom::MultiPolygon
Models a collection of Polygons.
Definition: MultiPolygon.h:61
geos::geom::GeometryFactory::getDefaultInstance
static const GeometryFactory * getDefaultInstance()
Return a pointer to the default GeometryFactory. This is a global shared object instantiated using de...
geos::geom::GeometryFactory::getCoordinateSequenceFactory
const CoordinateSequenceFactory * getCoordinateSequenceFactory() const
Returns the CoordinateSequenceFactory associated with this GeometryFactory.
geos::geom::GeometryFactory::getPrecisionModel
const PrecisionModel * getPrecisionModel() const
Returns the PrecisionModel that Geometries created by this factory will be associated with.
geos::geom::GeometryFactory::createEmptyGeometry
Geometry * createEmptyGeometry() const
Construct the EMPTY Geometry.
geos::geom::LineString
Definition: LineString.h:70
geos::geom::Point
Definition: Point.h:68
geos::geom::GeometryFactory::toGeometry
Geometry * toGeometry(const Envelope *envelope) const
Converts an Envelope to a Geometry.
geos::geom::GeometryFactory::createMultiPolygon
MultiPolygon * createMultiPolygon(const std::vector< Geometry * > &fromPolys) const
Construct a MultiPolygon with a deep-copy of given arguments.
geos::geom::GeometryFactory::GeometryFactory
GeometryFactory(CoordinateSequenceFactory *nCoordinateSequenceFactory)
Constructs a GeometryFactory that generates Geometries having the given CoordinateSequence implementa...
geos::geom::GeometryFactory::create
static GeometryFactory::Ptr create()
Constructs a GeometryFactory that generates Geometries having a floating PrecisionModel and a spatial...
geos::geom::GeometryFactory::createMultiPoint
MultiPoint * createMultiPoint(const std::vector< Geometry * > &fromPoints) const
Construct a MultiPoint with a deep-copy of given arguments.