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 #include <geos/geom/Geometry.h>
00025 #include <geos/geom/GeometryCollection.h>
00026 #include <geos/geom/MultiPoint.h>
00027 #include <geos/geom/MultiLineString.h>
00028 #include <geos/geom/MultiPolygon.h>
00029 #include <geos/export.h>
00030 #include <geos/inline.h>
00031
00032 #include <vector>
00033 #include <memory>
00034 #include <cassert>
00035
00036 namespace geos {
00037 namespace geom {
00038 class CoordinateSequenceFactory;
00039 class Coordinate;
00040 class CoordinateSequence;
00041 class Envelope;
00042 class Geometry;
00043 class GeometryCollection;
00044 class LineString;
00045 class LinearRing;
00046 class MultiLineString;
00047 class MultiPoint;
00048 class MultiPolygon;
00049 class Point;
00050 class Polygon;
00051 class PrecisionModel;
00052 }
00053 }
00054
00055 namespace geos {
00056 namespace geom {
00057
00068 class GEOS_DLL GeometryFactory {
00069 public:
00075 GeometryFactory();
00076
00089 GeometryFactory(const PrecisionModel *pm, int newSRID,
00090 CoordinateSequenceFactory *nCoordinateSequenceFactory);
00091
00098 GeometryFactory(CoordinateSequenceFactory *nCoordinateSequenceFactory);
00099
00108 GeometryFactory(const PrecisionModel *pm);
00109
00119 GeometryFactory(const PrecisionModel* pm, int newSRID);
00120
00126 GeometryFactory(const GeometryFactory &gf);
00127
00134 static const GeometryFactory*
00135 getDefaultInstance();
00136
00138 virtual ~GeometryFactory();
00139
00140
00141
00142 Point* createPointFromInternalCoord(const Coordinate* coord,
00143 const Geometry *exemplar) const;
00144
00146
00149 Geometry* toGeometry(const Envelope* envelope) const;
00150
00154 const PrecisionModel* getPrecisionModel() const;
00155
00157 Point* createPoint() const;
00158
00160 Point* createPoint(const Coordinate& coordinate) const;
00161
00163 Point* createPoint(CoordinateSequence *coordinates) const;
00164
00166 Point* createPoint(const CoordinateSequence &coordinates) const;
00167
00169 GeometryCollection* createGeometryCollection() const;
00170
00172 Geometry* createEmptyGeometry() const;
00173
00175 GeometryCollection* createGeometryCollection(
00176 std::vector<Geometry *> *newGeoms) const;
00177
00179 GeometryCollection* createGeometryCollection(
00180 const std::vector<Geometry *> &newGeoms) const;
00181
00183 MultiLineString* createMultiLineString() const;
00184
00186 MultiLineString* createMultiLineString(
00187 std::vector<Geometry *> *newLines) const;
00188
00190 MultiLineString* createMultiLineString(
00191 const std::vector<Geometry *> &fromLines) const;
00192
00194 MultiPolygon* createMultiPolygon() const;
00195
00197 MultiPolygon* createMultiPolygon(std::vector<Geometry *> *newPolys) const;
00198
00200 MultiPolygon* createMultiPolygon(
00201 const std::vector<Geometry *> &fromPolys) const;
00202
00204 LinearRing* createLinearRing() const;
00205
00207 LinearRing* createLinearRing(CoordinateSequence* newCoords) const;
00208
00209 std::auto_ptr<Geometry> createLinearRing(
00210 std::auto_ptr<CoordinateSequence> newCoords) const;
00211
00213 LinearRing* createLinearRing(
00214 const CoordinateSequence& coordinates) const;
00215
00217 MultiPoint* createMultiPoint() const;
00218
00220 MultiPoint* createMultiPoint(std::vector<Geometry *> *newPoints) const;
00221
00223 MultiPoint* createMultiPoint(
00224 const std::vector<Geometry *> &fromPoints) const;
00225
00229 MultiPoint* createMultiPoint(
00230 const CoordinateSequence &fromCoords) const;
00231
00235 MultiPoint* createMultiPoint(
00236 const std::vector<Coordinate> &fromCoords) const;
00237
00239 Polygon* createPolygon() const;
00240
00242 Polygon* createPolygon(LinearRing *shell,
00243 std::vector<Geometry *> *holes) const;
00244
00246 Polygon* createPolygon(const LinearRing &shell,
00247 const std::vector<Geometry *> &holes) const;
00248
00250 LineString* createLineString() const;
00251
00253 std::auto_ptr<LineString> createLineString(const LineString& ls) const;
00254
00256 LineString* createLineString(CoordinateSequence* coordinates) const;
00257
00258 std::auto_ptr<Geometry> createLineString(
00259 std::auto_ptr<CoordinateSequence> coordinates) const;
00260
00262 LineString* createLineString(
00263 const CoordinateSequence& coordinates) const;
00264
00296 Geometry* buildGeometry(std::vector<Geometry *> *geoms) const;
00297
00299
00306 template <class T>
00307 std::auto_ptr<Geometry> buildGeometry(T from, T toofar) const
00308 {
00309 bool isHeterogeneous = false;
00310 size_t count = 0;
00311 int geomClass = -1;
00312 for (T i=from; i != toofar; ++i)
00313 {
00314 ++count;
00315 const Geometry* g = *i;
00316 if ( geomClass < 0 ) {
00317 geomClass = g->getClassSortIndex();
00318 }
00319 else if ( geomClass != g->getClassSortIndex() ) {
00320 isHeterogeneous = true;
00321 }
00322 }
00323
00324
00325 if ( count == 0 ) {
00326 return std::auto_ptr<Geometry>( createGeometryCollection() );
00327 }
00328
00329
00330 if ( count == 1 ) {
00331 return std::auto_ptr<Geometry>( (*from)->clone() );
00332 }
00333
00334
00335
00336
00337
00338
00339
00340 std::vector<Geometry*> fromGeoms;
00341 for (T i=from; i != toofar; ++i) {
00342 const Geometry* g = *i;
00343 fromGeoms.push_back(const_cast<Geometry*>(g));
00344 }
00345
00346
00347
00348 if ( isHeterogeneous ) {
00349 return std::auto_ptr<Geometry>( createGeometryCollection(fromGeoms) );
00350 }
00351
00352
00353 if ( dynamic_cast<const Polygon*>(*from) ) {
00354 return std::auto_ptr<Geometry>( createMultiPolygon(fromGeoms) );
00355 } else if ( dynamic_cast<const LineString*>(*from) ) {
00356 return std::auto_ptr<Geometry>( createMultiLineString(fromGeoms) );
00357 } else if ( dynamic_cast<const Point*>(*from) ) {
00358 return std::auto_ptr<Geometry>( createMultiPoint(fromGeoms) );
00359 }
00360
00361 assert(0);
00362 return std::auto_ptr<Geometry>();
00363 }
00364
00372 Geometry* buildGeometry(const std::vector<Geometry *> &geoms) const;
00373
00374 int getSRID() const;
00375
00379 const CoordinateSequenceFactory* getCoordinateSequenceFactory() const;
00380
00382 Geometry* createGeometry(const Geometry *g) const;
00383
00385 void destroyGeometry(Geometry *g) const;
00386
00387 private:
00388 const PrecisionModel* precisionModel;
00389 int SRID;
00390 const CoordinateSequenceFactory *coordinateListFactory;
00391 };
00392
00393 }
00394 }
00395
00396 #ifdef GEOS_INLINE
00397 # include "geos/geom/GeometryFactory.inl"
00398 #endif
00399
00400 #endif // ndef GEOS_GEOM_GEOMETRYFACTORY_H
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
00450
00451
00452