GEOS
3.3.2
|
00001 /********************************************************************** 00002 * $Id: GeometryFactory.h 3471 2011-09-20 14:34:57Z strk $ 00003 * 00004 * GEOS - Geometry Engine Open Source 00005 * http://geos.refractions.net 00006 * 00007 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net> 00008 * Copyright (C) 2006 Refractions Research Inc. 00009 * 00010 * This is free software; you can redistribute and/or modify it under 00011 * the terms of the GNU Lesser General Public Licence as published 00012 * by the Free Software Foundation. 00013 * See the COPYING file for more information. 00014 * 00015 ********************************************************************** 00016 * 00017 * Last port: geom/GeometryFactory.java r320 (JTS-1.12) 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 { // geos::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 //Skipped a lot of list to array convertors 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 // for the empty geometry, return an empty GeometryCollection 00325 if ( count == 0 ) { 00326 return std::auto_ptr<Geometry>( createGeometryCollection() ); 00327 } 00328 00329 // for the single geometry, return a clone 00330 if ( count == 1 ) { 00331 return std::auto_ptr<Geometry>( (*from)->clone() ); 00332 } 00333 00334 // Now we know it is a collection 00335 00336 // FIXME: 00337 // Until we tweak all the createMulti* interfaces 00338 // to support taking iterators we'll have to build 00339 // a custom vector here. 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 // for an heterogeneous ... 00348 if ( isHeterogeneous ) { 00349 return std::auto_ptr<Geometry>( createGeometryCollection(fromGeoms) ); 00350 } 00351 00352 // At this point we know the collection is not hetereogenous. 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 // FIXME: Why not to throw an exception? --mloskot 00361 assert(0); // buildGeomtry encountered an unkwnon geometry type 00362 return std::auto_ptr<Geometry>(); // nullptr 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 } // namespace geos::geom 00394 } // namespace geos 00395 00396 #ifdef GEOS_INLINE 00397 # include "geos/geom/GeometryFactory.inl" 00398 #endif 00399 00400 #endif // ndef GEOS_GEOM_GEOMETRYFACTORY_H 00401 00402 /********************************************************************** 00403 * $Log$ 00404 * Revision 1.11 2006/07/08 00:33:55 strk 00405 * * configure.in: incremented CAPI minor version, to avoid falling behind any future version from the 2.2. branch. 00406 * * source/geom/Geometry.cpp, source/geom/GeometryFactory.cpp, 00407 * source/geomgraph/EdgeRing.cpp, 00408 * source/headers/geos/geom/Geometry.h, 00409 * source/headers/geos/geom/GeometryFactory.h, 00410 * source/headers/geos/geom/GeometryFactory.inl, 00411 * source/headers/geos/geomgraph/EdgeRing.h: 00412 * updated doxygen comments (sync with JTS head). 00413 * * source/headers/geos/platform.h.in: include <inttypes.h> 00414 * rather then <stdint.h> 00415 * 00416 * Revision 1.10 2006/06/19 21:17:24 strk 00417 * port info and doxygen dox. 00418 * 00419 * Revision 1.9 2006/04/28 11:56:52 strk 00420 * * source/geom/GeometryFactory.cpp, source/headers/geos/geom/GeometryFactory.h: added LineString copy constructor. 00421 * * source/geom/Polygon.cpp: fixed getBoundary method to always return a geometry composed by LineStrings (not LinearRings) 00422 * 00423 * Revision 1.8 2006/04/12 11:39:34 strk 00424 * Removed Geometry.h and CoordinateSequence.h includes. 00425 * The former created a circular dependency. 00426 * 00427 * Revision 1.7 2006/04/11 11:16:25 strk 00428 * Added LineString and LinearRing constructors by auto_ptr 00429 * 00430 * Revision 1.6 2006/04/10 13:09:49 strk 00431 * Added GeometryFactory::defaultInstance() 00432 * Made Geometry::INTERNAL_GEOMETRY_FACTORY an alias for it 00433 * removed last deletion from Unload::Release class 00434 * 00435 * Revision 1.5 2006/03/31 17:51:26 strk 00436 * A few assertion checking, comments cleanup, use of initialization lists 00437 * in constructors, handled NULL parameters. 00438 * 00439 * Revision 1.4 2006/03/28 16:33:14 strk 00440 * Added note about args responsibility in GeometryFactory constructor 00441 * 00442 * Revision 1.3 2006/03/24 09:52:41 strk 00443 * USE_INLINE => GEOS_INLINE 00444 * 00445 * Revision 1.2 2006/03/20 17:27:03 strk 00446 * Bug #72 - Missing <vector> header 00447 * 00448 * Revision 1.1 2006/03/09 16:46:49 strk 00449 * geos::geom namespace definition, first pass at headers split 00450 * 00451 **********************************************************************/ 00452