Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

GeometryFactory.h

00001 /**********************************************************************
00002  * $Id: GeometryFactory.h 3210 2011-02-13 19:51:59Z mloskot $
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/CoordinateSequence.h>
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 { // geos::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 //Skipped a lot of list to array convertors
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     // for the empty geometry, return an empty GeometryCollection
00322     if ( count == 0 ) {
00323       return std::auto_ptr<Geometry>( createGeometryCollection() );
00324     }
00325 
00326     // for the single geometry, return a clone
00327     if ( count == 1 ) {
00328       return std::auto_ptr<Geometry>( (*from)->clone() );
00329     }
00330 
00331     // Now we know it is a collection
00332 
00333     // FIXME:
00334     // Until we tweak all the createMulti* interfaces
00335     // to support taking iterators we'll have to build
00336     // a custom vector here.
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     // for an heterogeneous ...
00345     if ( isHeterogeneous ) {
00346       return std::auto_ptr<Geometry>( createGeometryCollection(fromGeoms) );
00347     }
00348 
00349     // At this point we know the collection is not hetereogenous.
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     // FIXME: Why not to throw an exception? --mloskot
00358     assert(0); // buildGeomtry encountered an unkwnon geometry type
00359     return std::auto_ptr<Geometry>(); // nullptr
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 } // namespace geos::geom
00391 } // namespace geos
00392 
00393 #ifdef GEOS_INLINE
00394 # include "geos/geom/GeometryFactory.inl"
00395 #endif
00396 
00397 #endif // ndef GEOS_GEOM_GEOMETRYFACTORY_H
00398 
00399 /**********************************************************************
00400  * $Log$
00401  * Revision 1.11  2006/07/08 00:33:55  strk
00402  *         * configure.in: incremented CAPI minor version, to avoid                        falling behind any future version from the 2.2. branch.
00403  *         * source/geom/Geometry.cpp, source/geom/GeometryFactory.cpp,
00404  *         source/geomgraph/EdgeRing.cpp,
00405  *         source/headers/geos/geom/Geometry.h,
00406  *         source/headers/geos/geom/GeometryFactory.h,
00407  *         source/headers/geos/geom/GeometryFactory.inl,
00408  *         source/headers/geos/geomgraph/EdgeRing.h:
00409  *         updated doxygen comments (sync with JTS head).
00410  *         * source/headers/geos/platform.h.in: include <inttypes.h>
00411  *         rather then <stdint.h>
00412  *
00413  * Revision 1.10  2006/06/19 21:17:24  strk
00414  * port info and doxygen dox.
00415  *
00416  * Revision 1.9  2006/04/28 11:56:52  strk
00417  * * source/geom/GeometryFactory.cpp, source/headers/geos/geom/GeometryFactory.h: added LineString copy constructor.
00418  * * source/geom/Polygon.cpp: fixed getBoundary method to always return a geometry composed by LineStrings (not LinearRings)
00419  *
00420  * Revision 1.8  2006/04/12 11:39:34  strk
00421  * Removed Geometry.h and CoordinateSequence.h includes.
00422  * The former created a circular dependency.
00423  *
00424  * Revision 1.7  2006/04/11 11:16:25  strk
00425  * Added LineString and LinearRing constructors by auto_ptr
00426  *
00427  * Revision 1.6  2006/04/10 13:09:49  strk
00428  * Added GeometryFactory::defaultInstance()
00429  * Made Geometry::INTERNAL_GEOMETRY_FACTORY an alias for it
00430  * removed last deletion from Unload::Release class
00431  *
00432  * Revision 1.5  2006/03/31 17:51:26  strk
00433  * A few assertion checking, comments cleanup, use of initialization lists
00434  * in constructors, handled NULL parameters.
00435  *
00436  * Revision 1.4  2006/03/28 16:33:14  strk
00437  * Added note about args responsibility in GeometryFactory constructor
00438  *
00439  * Revision 1.3  2006/03/24 09:52:41  strk
00440  * USE_INLINE => GEOS_INLINE
00441  *
00442  * Revision 1.2  2006/03/20 17:27:03  strk
00443  * Bug #72 - Missing <vector> header
00444  *
00445  * Revision 1.1  2006/03/09 16:46:49  strk
00446  * geos::geom namespace definition, first pass at headers split
00447  *
00448  **********************************************************************/
00449 

Generated on Sun Aug 21 23:21:01 2011 for GEOS by  doxygen 1.3.9.1