00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GEOS_GEOM_GEOMETRYFACTORY_H
00022 #define GEOS_GEOM_GEOMETRYFACTORY_H
00023
00024
00025 #include <geos/geom/Geometry.h>
00026 #include <geos/export.h>
00027 #include <geos/inline.h>
00028
00029 #include <vector>
00030 #include <memory>
00031 #include <cassert>
00032
00033 namespace geos {
00034 namespace geom {
00035 class CoordinateSequenceFactory;
00036 class Coordinate;
00037 class CoordinateSequence;
00038 class Envelope;
00039 class Geometry;
00040 class GeometryCollection;
00041 class LineString;
00042 class LinearRing;
00043 class MultiLineString;
00044 class MultiPoint;
00045 class MultiPolygon;
00046 class Point;
00047 class Polygon;
00048 class PrecisionModel;
00049 }
00050 }
00051
00052 namespace geos {
00053 namespace geom {
00054
00065 class GEOS_DLL GeometryFactory {
00066 public:
00072 GeometryFactory();
00073
00086 GeometryFactory(const PrecisionModel *pm, int newSRID,
00087 CoordinateSequenceFactory *nCoordinateSequenceFactory);
00088
00095 GeometryFactory(CoordinateSequenceFactory *nCoordinateSequenceFactory);
00096
00105 GeometryFactory(const PrecisionModel *pm);
00106
00116 GeometryFactory(const PrecisionModel* pm, int newSRID);
00117
00123 GeometryFactory(const GeometryFactory &gf);
00124
00131 static const GeometryFactory*
00132 getDefaultInstance();
00133
00135 virtual ~GeometryFactory();
00136
00137
00138
00139 Point* createPointFromInternalCoord(const Coordinate* coord,
00140 const Geometry *exemplar) const;
00141
00143
00146 Geometry* toGeometry(const Envelope* envelope) const;
00147
00151 const PrecisionModel* getPrecisionModel() const;
00152
00154 Point* createPoint() const;
00155
00157 Point* createPoint(const Coordinate& coordinate) const;
00158
00160 Point* createPoint(CoordinateSequence *coordinates) const;
00161
00163 Point* createPoint(const CoordinateSequence &coordinates) const;
00164
00166 GeometryCollection* createGeometryCollection() const;
00167
00169 Geometry* createEmptyGeometry() const;
00170
00172 GeometryCollection* createGeometryCollection(
00173 std::vector<Geometry *> *newGeoms) const;
00174
00176 GeometryCollection* createGeometryCollection(
00177 const std::vector<Geometry *> &newGeoms) const;
00178
00180 MultiLineString* createMultiLineString() const;
00181
00183 MultiLineString* createMultiLineString(
00184 std::vector<Geometry *> *newLines) const;
00185
00187 MultiLineString* createMultiLineString(
00188 const std::vector<Geometry *> &fromLines) const;
00189
00191 MultiPolygon* createMultiPolygon() const;
00192
00194 MultiPolygon* createMultiPolygon(std::vector<Geometry *> *newPolys) const;
00195
00197 MultiPolygon* createMultiPolygon(
00198 const std::vector<Geometry *> &fromPolys) const;
00199
00201 LinearRing* createLinearRing() const;
00202
00204 LinearRing* createLinearRing(CoordinateSequence* newCoords) const;
00205
00206 std::auto_ptr<Geometry> createLinearRing(
00207 std::auto_ptr<CoordinateSequence> newCoords) const;
00208
00210 LinearRing* createLinearRing(
00211 const CoordinateSequence& coordinates) const;
00212
00214 MultiPoint* createMultiPoint() const;
00215
00217 MultiPoint* createMultiPoint(std::vector<Geometry *> *newPoints) const;
00218
00220 MultiPoint* createMultiPoint(
00221 const std::vector<Geometry *> &fromPoints) const;
00222
00226 MultiPoint* createMultiPoint(
00227 const CoordinateSequence &fromCoords) const;
00228
00232 MultiPoint* createMultiPoint(
00233 const std::vector<Coordinate> &fromCoords) const;
00234
00236 Polygon* createPolygon() const;
00237
00239 Polygon* createPolygon(LinearRing *shell,
00240 std::vector<Geometry *> *holes) const;
00241
00243 Polygon* createPolygon(const LinearRing &shell,
00244 const std::vector<Geometry *> &holes) const;
00245
00247 LineString* createLineString() const;
00248
00250 std::auto_ptr<LineString> createLineString(const LineString& ls) const;
00251
00253 LineString* createLineString(CoordinateSequence* coordinates) const;
00254
00255 std::auto_ptr<Geometry> createLineString(
00256 std::auto_ptr<CoordinateSequence> coordinates) const;
00257
00259 LineString* createLineString(
00260 const CoordinateSequence& coordinates) const;
00261
00293 Geometry* buildGeometry(std::vector<Geometry *> *geoms) const;
00294
00296
00303 template <class T>
00304 std::auto_ptr<Geometry> buildGeometry(T from, T toofar) const
00305 {
00306 bool isHeterogeneous = false;
00307 size_t count = 0;
00308 int geomClass = -1;
00309 for (T i=from; i != toofar; ++i)
00310 {
00311 ++count;
00312 const Geometry* g = *i;
00313 if ( geomClass < 0 ) {
00314 geomClass = g->getClassSortIndex();
00315 }
00316 else if ( geomClass != g->getClassSortIndex() ) {
00317 isHeterogeneous = true;
00318 }
00319 }
00320
00321
00322 if ( count == 0 ) {
00323 return std::auto_ptr<Geometry>( createGeometryCollection() );
00324 }
00325
00326
00327 if ( count == 1 ) {
00328 return std::auto_ptr<Geometry>( (*from)->clone() );
00329 }
00330
00331
00332
00333
00334
00335
00336
00337 std::vector<Geometry*> fromGeoms;
00338 for (T i=from; i != toofar; ++i) {
00339 const Geometry* g = *i;
00340 fromGeoms.push_back(const_cast<Geometry*>(g));
00341 }
00342
00343
00344
00345 if ( isHeterogeneous ) {
00346 return std::auto_ptr<Geometry>( createGeometryCollection(fromGeoms) );
00347 }
00348
00349
00350 if ( dynamic_cast<const Polygon*>(*from) ) {
00351 return std::auto_ptr<Geometry>( createMultiPolygon(fromGeoms) );
00352 } else if ( dynamic_cast<const LineString*>(*from) ) {
00353 return std::auto_ptr<Geometry>( createMultiLineString(fromGeoms) );
00354 } else if ( dynamic_cast<const Point*>(*from) ) {
00355 return std::auto_ptr<Geometry>( createMultiPoint(fromGeoms) );
00356 }
00357
00358 assert(0);
00359 return std::auto_ptr<Geometry>();
00360 }
00361
00369 Geometry* buildGeometry(const std::vector<Geometry *> &geoms) const;
00370
00371 int getSRID() const;
00372
00376 const CoordinateSequenceFactory* getCoordinateSequenceFactory() const;
00377
00379 Geometry* createGeometry(const Geometry *g) const;
00380
00382 void destroyGeometry(Geometry *g) const;
00383
00384 private:
00385 const PrecisionModel* precisionModel;
00386 int SRID;
00387 const CoordinateSequenceFactory *coordinateListFactory;
00388 };
00389
00390 }
00391 }
00392
00393 #ifdef GEOS_INLINE
00394 # include "geos/geom/GeometryFactory.inl"
00395 #endif
00396
00397 #endif // ndef GEOS_GEOM_GEOMETRYFACTORY_H
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449