File Coverage

/usr/local/lib/perl5/site_perl/5.26.1/x86_64-linux/CPP/geos.x/i/geos/geom/GeometryFactory.h
Criterion Covered Total %
statement 0 3 0.0
branch n/a
condition n/a
subroutine n/a
pod n/a
total 0 3 0.0


line stmt bran cond sub pod time code
1             /**********************************************************************
2             *
3             * GEOS - Geometry Engine Open Source
4             * http://geos.osgeo.org
5             *
6             * Copyright (C) 2011 Sandro Santilli
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
24             #include
25             #include
26             #include
27             #include
28             #include
29             #include
30              
31             #include
32             #include
33             #include
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              
57             /**
58             * \brief
59             * Supplies a set of utility methods for building Geometry objects
60             * from CoordinateSequence or other Geometry objects.
61             *
62             * Note that the factory constructor methods do not change the input
63             * coordinates in any way.
64             * In particular, they are not rounded to the supplied PrecisionModel.
65             * It is assumed that input Coordinates meet the given precision.
66             */
67             class GEOS_DLL GeometryFactory {
68             private:
69              
70             struct GeometryFactoryDeleter
71             {
72 0           void operator()(GeometryFactory* p) const
73             {
74 0           p->destroy();
75 0           }
76             };
77              
78             public:
79              
80             using Ptr = std::unique_ptr;
81              
82             /**
83             * \brief
84             * Constructs a GeometryFactory that generates Geometries having a
85             * floating PrecisionModel and a spatial-reference ID of 0.
86             */
87             static GeometryFactory::Ptr create();
88              
89             /**
90             * \brief
91             * Constructs a GeometryFactory that generates Geometries having
92             * the given PrecisionModel, spatial-reference ID, and
93             * CoordinateSequence implementation.
94             *
95             * NOTES:
96             * (1) the given PrecisionModel is COPIED
97             * (2) the CoordinateSequenceFactory is NOT COPIED
98             * and must be available for the whole lifetime
99             * of the GeometryFactory
100             */
101             static GeometryFactory::Ptr create(const PrecisionModel *pm, int newSRID,
102             CoordinateSequenceFactory *nCoordinateSequenceFactory);
103              
104             /**
105             * \brief
106             * Constructs a GeometryFactory that generates Geometries having the
107             * given CoordinateSequence implementation, a double-precision floating
108             * PrecisionModel and a spatial-reference ID of 0.
109             */
110             static GeometryFactory::Ptr create(CoordinateSequenceFactory *nCoordinateSequenceFactory);
111              
112             /**
113             * \brief
114             * Constructs a GeometryFactory that generates Geometries having
115             * the given PrecisionModel and the default CoordinateSequence
116             * implementation.
117             *
118             * @param pm the PrecisionModel to use
119             */
120             static GeometryFactory::Ptr create(const PrecisionModel *pm);
121              
122             /**
123             * \brief
124             * Constructs a GeometryFactory that generates Geometries having
125             * the given {@link PrecisionModel} and spatial-reference ID,
126             * and the default CoordinateSequence implementation.
127             *
128             * @param pm the PrecisionModel to use, will be copied internally
129             * @param newSRID the SRID to use
130             */
131             static GeometryFactory::Ptr create(const PrecisionModel* pm, int newSRID);
132              
133             /**
134             * \brief Copy constructor
135             *
136             * @param gf the GeometryFactory to clone from
137             */
138             static GeometryFactory::Ptr create(const GeometryFactory &gf);
139              
140             /**
141             * \brief
142             * Return a pointer to the default GeometryFactory.
143             * This is a global shared object instantiated
144             * using default constructor.
145             */
146             static const GeometryFactory*
147             getDefaultInstance();
148              
149             //Skipped a lot of list to array convertors
150              
151             Point* createPointFromInternalCoord(const Coordinate* coord,
152             const Geometry *exemplar) const;
153              
154             /// Converts an Envelope to a Geometry.
155             //
156             /// Returned Geometry can be a Point, a Polygon or an EMPTY geom.
157             ///
158             Geometry* toGeometry(const Envelope* envelope) const;
159              
160             /// \brief
161             /// Returns the PrecisionModel that Geometries created by this
162             /// factory will be associated with.
163             const PrecisionModel* getPrecisionModel() const;
164              
165             /// Creates an EMPTY Point
166             Point* createPoint() const;
167              
168             /// Creates a Point using the given Coordinate
169             Point* createPoint(const Coordinate& coordinate) const;
170              
171             /// Creates a Point taking ownership of the given CoordinateSequence
172             Point* createPoint(CoordinateSequence *coordinates) const;
173              
174             /// Creates a Point with a deep-copy of the given CoordinateSequence.
175             Point* createPoint(const CoordinateSequence &coordinates) const;
176              
177             /// Construct an EMPTY GeometryCollection
178             GeometryCollection* createGeometryCollection() const;
179              
180             /// Construct the EMPTY Geometry
181             Geometry* createEmptyGeometry() const;
182              
183             /// Construct a GeometryCollection taking ownership of given arguments
184             GeometryCollection* createGeometryCollection(
185             std::vector *newGeoms) const;
186              
187             /// Constructs a GeometryCollection with a deep-copy of args
188             GeometryCollection* createGeometryCollection(
189             const std::vector &newGeoms) const;
190              
191             /// Construct an EMPTY MultiLineString
192             MultiLineString* createMultiLineString() const;
193              
194             /// Construct a MultiLineString taking ownership of given arguments
195             MultiLineString* createMultiLineString(
196             std::vector *newLines) const;
197              
198             /// Construct a MultiLineString with a deep-copy of given arguments
199             MultiLineString* createMultiLineString(
200             const std::vector &fromLines) const;
201              
202             /// Construct an EMPTY MultiPolygon
203             MultiPolygon* createMultiPolygon() const;
204              
205             /// Construct a MultiPolygon taking ownership of given arguments
206             MultiPolygon* createMultiPolygon(std::vector *newPolys) const;
207              
208             /// Construct a MultiPolygon with a deep-copy of given arguments
209             MultiPolygon* createMultiPolygon(
210             const std::vector &fromPolys) const;
211              
212             /// Construct an EMPTY LinearRing
213             LinearRing* createLinearRing() const;
214              
215             /// Construct a LinearRing taking ownership of given arguments
216             LinearRing* createLinearRing(CoordinateSequence* newCoords) const;
217              
218             std::unique_ptr createLinearRing(
219             std::unique_ptr newCoords) const;
220              
221             /// Construct a LinearRing with a deep-copy of given arguments
222             LinearRing* createLinearRing(
223             const CoordinateSequence& coordinates) const;
224              
225             /// Constructs an EMPTY MultiPoint.
226             MultiPoint* createMultiPoint() const;
227              
228             /// Construct a MultiPoint taking ownership of given arguments
229             MultiPoint* createMultiPoint(std::vector *newPoints) const;
230              
231             /// Construct a MultiPoint with a deep-copy of given arguments
232             MultiPoint* createMultiPoint(
233             const std::vector &fromPoints) const;
234              
235             /// \brief
236             /// Construct a MultiPoint containing a Point geometry
237             /// for each Coordinate in the given list.
238             MultiPoint* createMultiPoint(
239             const CoordinateSequence &fromCoords) const;
240              
241             /// \brief
242             /// Construct a MultiPoint containing a Point geometry
243             /// for each Coordinate in the given vector.
244             MultiPoint* createMultiPoint(
245             const std::vector &fromCoords) const;
246              
247             /// Construct an EMPTY Polygon
248             Polygon* createPolygon() const;
249              
250             /// Construct a Polygon taking ownership of given arguments
251             Polygon* createPolygon(LinearRing *shell,
252             std::vector *holes) const;
253              
254             /// Construct a Polygon with a deep-copy of given arguments
255             Polygon* createPolygon(const LinearRing &shell,
256             const std::vector &holes) const;
257              
258             /// Construct an EMPTY LineString
259             LineString* createLineString() const;
260              
261             /// Copy a LineString
262             std::unique_ptr createLineString(const LineString& ls) const;
263              
264             /// Construct a LineString taking ownership of given argument
265             LineString* createLineString(CoordinateSequence* coordinates) const;
266              
267             std::unique_ptr createLineString(
268             std::unique_ptr coordinates) const;
269              
270             /// Construct a LineString with a deep-copy of given argument
271             LineString* createLineString(
272             const CoordinateSequence& coordinates) const;
273              
274             /**
275             * Build an appropriate Geometry, MultiGeometry, or
276             * GeometryCollection to contain the Geometrys in
277             * it.
278             *
279             * For example:
280             *
281             * - If geomList contains a single Polygon,
282             * the Polygon is returned.
283             * - If geomList contains several Polygons, a
284             * MultiPolygon is returned.
285             * - If geomList contains some Polygons and
286             * some LineStrings, a GeometryCollection is
287             * returned.
288             * - If geomList is empty, an empty
289             * GeometryCollection is returned
290             * .
291             *
292             * Note that this method does not "flatten" Geometries in the input,
293             * and hence if any MultiGeometries are contained in the input a
294             * GeometryCollection containing them will be returned.
295             *
296             * @param newGeoms the Geometrys to combine
297             *
298             * @return
299             * A Geometry of the "smallest", "most type-specific"
300             * class that can contain the elements of geomList.
301             *
302             * NOTE: the returned Geometry will take ownership of the
303             * given vector AND its elements
304             */
305             Geometry* buildGeometry(std::vector *geoms) const;
306              
307             /// See buildGeometry(std::vector&) for semantics
308             //
309             /// Will clone the geometries accessible trough the iterator.
310             ///
311             /// @tparam T an iterator yelding something which casts to const Geometry*
312             /// @param from start iterator
313             /// @param toofar end iterator
314             ///
315             template
316             std::unique_ptr 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( createGeometryCollection() );
336             }
337              
338             // for the single geometry, return a clone
339             if ( count == 1 ) {
340             return std::unique_ptr( (*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 fromGeoms;
350             for (T i=from; i != toofar; ++i) {
351             const Geometry* g = *i;
352             fromGeoms.push_back(const_cast(g));
353             }
354              
355              
356             // for an heterogeneous ...
357             if ( isHeterogeneous ) {
358             return std::unique_ptr( createGeometryCollection(fromGeoms) );
359             }
360              
361             // At this point we know the collection is not hetereogenous.
362             if ( dynamic_cast(*from) ) {
363             return std::unique_ptr( createMultiPolygon(fromGeoms) );
364             } else if ( dynamic_cast(*from) ) {
365             return std::unique_ptr( createMultiLineString(fromGeoms) );
366             } else if ( dynamic_cast(*from) ) {
367             return std::unique_ptr( 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(); // nullptr
372             }
373              
374             /** \brief
375             * This function does the same thing of the omonimouse function
376             * taking vector pointer instead of reference.
377             *
378             * The difference is that this version will copy needed data
379             * leaving ownership to the caller.
380             */
381             Geometry* buildGeometry(const std::vector &geoms) const;
382              
383             int getSRID() const;
384              
385             /// \brief
386             /// Returns the CoordinateSequenceFactory associated
387             /// with this GeometryFactory
388             const CoordinateSequenceFactory* getCoordinateSequenceFactory() const;
389              
390             /// Returns a clone of given Geometry.
391             Geometry* createGeometry(const Geometry *g) const;
392              
393             /// Destroy a Geometry, or release it
394             void destroyGeometry(Geometry *g) const;
395              
396             /// Request that the instance is deleted.
397             //
398             /// It will really be deleted only after last child Geometry is
399             /// deleted. Do not use the instance anymore after calling this function
400             /// (unless you're a live child!).
401             ///
402             void destroy();
403              
404             protected:
405              
406             /**
407             * \brief
408             * Constructs a GeometryFactory that generates Geometries having a
409             * floating PrecisionModel and a spatial-reference ID of 0.
410             */
411             GeometryFactory();
412              
413             /**
414             * \brief
415             * Constructs a GeometryFactory that generates Geometries having
416             * the given PrecisionModel, spatial-reference ID, and
417             * CoordinateSequence implementation.
418             *
419             * NOTES:
420             * (1) the given PrecisionModel is COPIED
421             * (2) the CoordinateSequenceFactory is NOT COPIED
422             * and must be available for the whole lifetime
423             * of the GeometryFactory
424             */
425             GeometryFactory(const PrecisionModel *pm, int newSRID,
426             CoordinateSequenceFactory *nCoordinateSequenceFactory);
427              
428             /**
429             * \brief
430             * Constructs a GeometryFactory that generates Geometries having the
431             * given CoordinateSequence implementation, a double-precision floating
432             * PrecisionModel and a spatial-reference ID of 0.
433             */
434             GeometryFactory(CoordinateSequenceFactory *nCoordinateSequenceFactory);
435              
436             /**
437             * \brief
438             * Constructs a GeometryFactory that generates Geometries having
439             * the given PrecisionModel and the default CoordinateSequence
440             * implementation.
441             *
442             * @param pm the PrecisionModel to use
443             */
444             GeometryFactory(const PrecisionModel *pm);
445              
446             /**
447             * \brief
448             * Constructs a GeometryFactory that generates Geometries having
449             * the given {@link PrecisionModel} and spatial-reference ID,
450             * and the default CoordinateSequence implementation.
451             *
452             * @param pm the PrecisionModel to use, will be copied internally
453             * @param newSRID the SRID to use
454             */
455             GeometryFactory(const PrecisionModel* pm, int newSRID);
456              
457             /**
458             * \brief Copy constructor
459             *
460             * @param gf the GeometryFactory to clone from
461             */
462             GeometryFactory(const GeometryFactory &gf);
463              
464             /// Destructor
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