GEOS: GeometryFactory.h Source File

GEOS 3.5.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

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
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 public:
74 GeometryFactory();
75
88 GeometryFactory(const PrecisionModel *pm, int newSRID,
89 CoordinateSequenceFactory *nCoordinateSequenceFactory);
90
97 GeometryFactory(CoordinateSequenceFactory *nCoordinateSequenceFactory);
98
107 GeometryFactory(const PrecisionModel *pm);
108
118 GeometryFactory(const PrecisionModel* pm, int newSRID);
119
125 GeometryFactory(const GeometryFactory &gf);
126
133 static const GeometryFactory*
134 getDefaultInstance();
135
137 virtual ~GeometryFactory();
138
139 //Skipped a lot of list to array convertors
140
141 Point* createPointFromInternalCoord(const Coordinate* coord,
142 const Geometry *exemplar) const;
143
145 //
148 Geometry* toGeometry(const Envelope* envelope) const;
149
153 const PrecisionModel* getPrecisionModel() const;
154
156 Point* createPoint() const;
157
159 Point* createPoint(const Coordinate& coordinate) const;
160
162 Point* createPoint(CoordinateSequence *coordinates) const;
163
165 Point* createPoint(const CoordinateSequence &coordinates) const;
166
168 GeometryCollection* createGeometryCollection() const;
169
171 Geometry* createEmptyGeometry() const;
172
174 GeometryCollection* createGeometryCollection(
175 std::vector<Geometry *> *newGeoms) const;
176
178 GeometryCollection* createGeometryCollection(
179 const std::vector<Geometry *> &newGeoms) const;
180
182 MultiLineString* createMultiLineString() const;
183
185 MultiLineString* createMultiLineString(
186 std::vector<Geometry *> *newLines) const;
187
189 MultiLineString* createMultiLineString(
190 const std::vector<Geometry *> &fromLines) const;
191
193 MultiPolygon* createMultiPolygon() const;
194
196 MultiPolygon* createMultiPolygon(std::vector<Geometry *> *newPolys) const;
197
199 MultiPolygon* createMultiPolygon(
200 const std::vector<Geometry *> &fromPolys) const;
201
203 LinearRing* createLinearRing() const;
204
206 LinearRing* createLinearRing(CoordinateSequence* newCoords) const;
207
208 std::auto_ptr<Geometry> createLinearRing(
209 std::auto_ptr<CoordinateSequence> newCoords) const;
210
212 LinearRing* createLinearRing(
213 const CoordinateSequence& coordinates) const;
214
216 MultiPoint* createMultiPoint() const;
217
219 MultiPoint* createMultiPoint(std::vector<Geometry *> *newPoints) const;
220
222 MultiPoint* createMultiPoint(
223 const std::vector<Geometry *> &fromPoints) const;
224
228 MultiPoint* createMultiPoint(
229 const CoordinateSequence &fromCoords) const;
230
234 MultiPoint* createMultiPoint(
235 const std::vector<Coordinate> &fromCoords) const;
236
238 Polygon* createPolygon() const;
239
241 Polygon* createPolygon(LinearRing *shell,
242 std::vector<Geometry *> *holes) const;
243
245 Polygon* createPolygon(const LinearRing &shell,
246 const std::vector<Geometry *> &holes) const;
247
249 LineString* createLineString() const;
250
252 std::auto_ptr<LineString> createLineString(const LineString& ls) const;
253
255 LineString* createLineString(CoordinateSequence* coordinates) const;
256
257 std::auto_ptr<Geometry> createLineString(
258 std::auto_ptr<CoordinateSequence> coordinates) const;
259
261 LineString* createLineString(
262 const CoordinateSequence& coordinates) const;
263
295 Geometry* buildGeometry(std::vector<Geometry *> *geoms) const;
296
298 //
305 template <class T>
306 std::auto_ptr<Geometry> buildGeometry(T from, T toofar) const
307 {
308 bool isHeterogeneous = false;
309 size_t count = 0;
310 int geomClass = -1;
311 for (T i=from; i != toofar; ++i)
312 {
313 ++count;
314 const Geometry* g = *i;
315 if ( geomClass < 0 ) {
316 geomClass = g->getClassSortIndex();
317 }
318 else if ( geomClass != g->getClassSortIndex() ) {
319 isHeterogeneous = true;
320 }
321 }
322
323 // for the empty geometry, return an empty GeometryCollection
324 if ( count == 0 ) {
325 return std::auto_ptr<Geometry>( createGeometryCollection() );
326 }
327
328 // for the single geometry, return a clone
329 if ( count == 1 ) {
330 return std::auto_ptr<Geometry>( (*from)->clone() );
331 }
332
333 // Now we know it is a collection
334
335 // FIXME:
336 // Until we tweak all the createMulti* interfaces
337 // to support taking iterators we'll have to build
338 // a custom vector here.
339 std::vector<Geometry*> fromGeoms;
340 for (T i=from; i != toofar; ++i) {
341 const Geometry* g = *i;
342 fromGeoms.push_back(const_cast<Geometry*>(g));
343 }
344
345
346 // for an heterogeneous ...
347 if ( isHeterogeneous ) {
348 return std::auto_ptr<Geometry>( createGeometryCollection(fromGeoms) );
349 }
350
351 // At this point we know the collection is not hetereogenous.
352 if ( dynamic_cast<const Polygon*>(*from) ) {
353 return std::auto_ptr<Geometry>( createMultiPolygon(fromGeoms) );
354 } else if ( dynamic_cast<const LineString*>(*from) ) {
355 return std::auto_ptr<Geometry>( createMultiLineString(fromGeoms) );
356 } else if ( dynamic_cast<const Point*>(*from) ) {
357 return std::auto_ptr<Geometry>( createMultiPoint(fromGeoms) );
358 }
359 // FIXME: Why not to throw an exception? --mloskot
360 assert(0); // buildGeomtry encountered an unkwnon geometry type
361 return std::auto_ptr<Geometry>(); // nullptr
362 }
363
371 Geometry* buildGeometry(const std::vector<Geometry *> &geoms) const;
372
373 int getSRID() const;
374
378 const CoordinateSequenceFactory* getCoordinateSequenceFactory() const;
379
381 Geometry* createGeometry(const Geometry *g) const;
382
384 void destroyGeometry(Geometry *g) const;
385
386 private:
387 const PrecisionModel* precisionModel;
388 int SRID;
389 const CoordinateSequenceFactory *coordinateListFactory;
390 };
391
392 } // namespace geos::geom
393 } // namespace geos
394
395 #ifdef GEOS_INLINE
396 # include "geos/geom/GeometryFactory.inl"
397 #endif
398
399 #endif // ndef GEOS_GEOM_GEOMETRYFACTORY_H
geos::geom::Envelope
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:53
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
geos::geom::MultiPolygon
Models a collection of Polygons.
Definition: MultiPolygon.h:60
geos::geom::PrecisionModel
Specifies the precision model of the Coordinate in a Geometry.
Definition: PrecisionModel.h:87
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:167
geos::geom::LineString
Definition: LineString.h:70
geos::geom::Polygon
Represents a linear polygon, which may include holes.
Definition: Polygon.h:66
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::buildGeometry
std::auto_ptr< Geometry > buildGeometry(T from, T toofar) const
See buildGeometry(std::vector<Geometry *>&) for semantics.
Definition: GeometryFactory.h:306
geos::geom::GeometryCollection
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:56
geos
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
geos::geom::MultiPoint
Definition: MultiPoint.h:55
geos::geom::LinearRing
Models an OGC SFS LinearRing.
Definition: LinearRing.h:57
geos::geom::CoordinateSequenceFactory
A factory to create concrete instances of CoordinateSequences.
Definition: CoordinateSequenceFactory.h:47
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:59
geos::geom::Point
Definition: Point.h:67
geos::geom::MultiLineString
Models a collection of (}s.
Definition: MultiLineString.h:51