[geos-commits] r3191 - in trunk: include/geos/geom src src/geom
tests/unit/geom
svn_geos at osgeo.org
svn_geos at osgeo.org
Thu Feb 10 06:09:55 EST 2011
Author: strk
Date: 2011-02-10 03:09:55 -0800 (Thu, 10 Feb 2011)
New Revision: 3191
Removed:
trunk/include/geos/geom/Geometry.inl
Modified:
trunk/include/geos/geom/Geometry.h
trunk/include/geos/geom/GeometryFactory.h
trunk/include/geos/geom/Makefile.am
trunk/src/geom/Geometry.cpp
trunk/src/inlines.cpp
trunk/tests/unit/geom/GeometryFactoryTest.cpp
Log:
Introduce a templated version of GeometryFactory::buildGeometry, and test it.
Modified: trunk/include/geos/geom/Geometry.h
===================================================================
--- trunk/include/geos/geom/Geometry.h 2011-02-10 11:09:41 UTC (rev 3190)
+++ trunk/include/geos/geom/Geometry.h 2011-02-10 11:09:55 UTC (rev 3191)
@@ -866,10 +866,6 @@
#pragma warning(pop)
#endif
-#ifdef GEOS_INLINE
-# include <geos/geom/Geometry.inl>
-#endif
-
#endif // ndef GEOS_GEOM_GEOMETRY_H
/**********************************************************************
Deleted: trunk/include/geos/geom/Geometry.inl
===================================================================
--- trunk/include/geos/geom/Geometry.inl 2011-02-10 11:09:41 UTC (rev 3190)
+++ trunk/include/geos/geom/Geometry.inl 2011-02-10 11:09:55 UTC (rev 3191)
@@ -1,41 +0,0 @@
-/**********************************************************************
- * $Id$
- *
- * GEOS - Geometry Engine Open Source
- * http://geos.refractions.net
- *
- * Copyright (C) 2009 Sandro Santilli <strk at keybit.net>
- * Copyright (C) 2005-2006 Refractions Research Inc.
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of the GNU Lesser General Public Licence as published
- * by the Free Software Foundation.
- * See the COPYING file for more information.
- *
- **********************************************************************
- *
- * Last port: geom/Geometry.java rev. 1.112
- *
- **********************************************************************/
-
-#ifndef GEOS_GEOM_GEOMETRY_INL
-#define GEOS_GEOM_GEOMETRY_INL
-
-#include <geos/geom/Geometry.h>
-#include <geos/geom/GeometryFactory.h>
-
-namespace geos {
-namespace geom { // geos::geom
-
-INLINE const PrecisionModel*
-Geometry::getPrecisionModel() const
-{
- return factory->getPrecisionModel();
-}
-
-} // namespace geos::geom
-} // namespace geos
-
-#endif // GEOS_GEOM_GEOMETRY_INL
-
-
Modified: trunk/include/geos/geom/GeometryFactory.h
===================================================================
--- trunk/include/geos/geom/GeometryFactory.h 2011-02-10 11:09:41 UTC (rev 3190)
+++ trunk/include/geos/geom/GeometryFactory.h 2011-02-10 11:09:55 UTC (rev 3191)
@@ -22,12 +22,13 @@
#define GEOS_GEOM_GEOMETRYFACTORY_H
//#include <geos/geom/CoordinateSequence.h>
-//#include <geos/geom/Geometry.h>
+#include <geos/geom/Geometry.h>
#include <geos/export.h>
#include <geos/inline.h>
#include <vector>
#include <memory>
+#include <cassert>
namespace geos {
namespace geom {
@@ -291,6 +292,72 @@
*/
Geometry* buildGeometry(std::vector<Geometry *> *geoms) const;
+ /// See buildGeometry(std::vector<Geometry *>&) for semantics
+ //
+ /// Will clone the geometries accessible trough the iterator.
+ ///
+ /// @tparam T an iterator yelding something which casts to const Geometry*
+ /// @param from start iterator
+ /// @param toofar end iterator
+ ///
+ template <class T>
+ std::auto_ptr<Geometry> buildGeometry(T from, T toofar) const
+ {
+ bool isHeterogeneous = false;
+ size_t count = 0;
+ int geomClass = -1;
+ for (T i=from; i != toofar; ++i)
+ {
+ ++count;
+ const Geometry* g = *i;
+ if ( geomClass < 0 ) {
+ geomClass = g->getClassSortIndex();
+ }
+ else if ( geomClass != g->getClassSortIndex() ) {
+ isHeterogeneous = true;
+ }
+ }
+
+ // for the empty geometry, return an empty GeometryCollection
+ if ( count == 0 ) {
+ return std::auto_ptr<Geometry>( createGeometryCollection() );
+ }
+
+ // for the single geometry, return a clone
+ if ( count == 1 ) {
+ return std::auto_ptr<Geometry>( (*from)->clone() );
+ }
+
+ // Now we know it is a collection
+
+ // FIXME:
+ // Until we tweak all the createMulti* interfaces
+ // to support taking iterators we'll have to build
+ // a custom vector here.
+ std::vector<Geometry*> fromGeoms;
+ for (T i=from; i != toofar; ++i) {
+ const Geometry* g = *i;
+ fromGeoms.push_back(const_cast<Geometry*>(g));
+ }
+
+
+ // for an heterogeneous ...
+ if ( isHeterogeneous ) {
+ return std::auto_ptr<Geometry>( createGeometryCollection(fromGeoms) );
+ }
+
+ // At this point we know the collection is not hetereogenous.
+ if ( dynamic_cast<const Polygon*>(*from) ) {
+ return std::auto_ptr<Geometry>( createMultiPolygon(fromGeoms) );
+ } else if ( dynamic_cast<const LineString*>(*from) ) {
+ return std::auto_ptr<Geometry>( createMultiLineString(fromGeoms) );
+ } else if ( dynamic_cast<const Point*>(*from) ) {
+ return std::auto_ptr<Geometry>( createMultiPoint(fromGeoms) );
+ }
+ assert(0); // buildGeomtry encountered an unkwnon geometry type
+
+ }
+
/** \brief
* This function does the same thing of the omonimouse function
* taking vector pointer instead of reference.
Modified: trunk/include/geos/geom/Makefile.am
===================================================================
--- trunk/include/geos/geom/Makefile.am 2011-02-10 11:09:41 UTC (rev 3190)
+++ trunk/include/geos/geom/Makefile.am 2011-02-10 11:09:55 UTC (rev 3191)
@@ -32,7 +32,6 @@
GeometryFactory.inl \
GeometryFilter.h \
Geometry.h \
- Geometry.inl \
GeometryList.h \
IntersectionMatrix.h \
LinearRing.h \
Modified: trunk/src/geom/Geometry.cpp
===================================================================
--- trunk/src/geom/Geometry.cpp 2011-02-10 11:09:41 UTC (rev 3190)
+++ trunk/src/geom/Geometry.cpp 2011-02-10 11:09:55 UTC (rev 3191)
@@ -63,10 +63,6 @@
#define SHORTCIRCUIT_PREDICATES 1
-#ifndef GEOS_INLINE
-# include <geos/geom/Geometry.inl>
-#endif
-
using namespace std;
using namespace geos::algorithm;
using namespace geos::operation::valid;
@@ -825,6 +821,13 @@
return op.isSimple();
}
+/* public */
+const PrecisionModel*
+Geometry::getPrecisionModel() const
+{
+ return factory->getPrecisionModel();
+}
+
} // namespace geos::geom
} // namespace geos
Modified: trunk/src/inlines.cpp
===================================================================
--- trunk/src/inlines.cpp 2011-02-10 11:09:41 UTC (rev 3190)
+++ trunk/src/inlines.cpp 2011-02-10 11:09:55 UTC (rev 3191)
@@ -51,7 +51,6 @@
#include <geos/geom/GeometryCollection.inl>
#include <geos/geom/LineSegment.inl>
#include <geos/geom/PrecisionModel.inl>
-#include <geos/geom/Geometry.inl>
#include <geos/geom/Envelope.inl>
#include <geos/geom/Coordinate.inl>
#include <geos/geom/GeometryFactory.inl>
Modified: trunk/tests/unit/geom/GeometryFactoryTest.cpp
===================================================================
--- trunk/tests/unit/geom/GeometryFactoryTest.cpp 2011-02-10 11:09:41 UTC (rev 3190)
+++ trunk/tests/unit/geom/GeometryFactoryTest.cpp 2011-02-10 11:09:55 UTC (rev 3191)
@@ -1237,4 +1237,48 @@
//inform("Test not implemented!");
}
+ // Test of
+ // buildGeometry(from, to, takeOwnership) const
+ template<>
+ template<>
+ void object::test<36>()
+ {
+ typedef std::auto_ptr<geos::geom::Geometry> GeometryAutoPtr;
+ typedef std::vector<PointPtr> PointVect;
+
+ const std::size_t size = 3;
+ geos::geom::Coordinate coord(x_, y_, z_);
+
+ PointVect vec;
+
+ PointPtr geo = 0;
+ geo = factory_.createPoint(coord);
+ vec.push_back(geo);
+
+ coord.x *= 2;
+ coord.y *= 2;
+ coord.z *= 2;
+ geo = factory_.createPoint(coord);
+ vec.push_back(geo);
+
+ coord.x *= 3;
+ coord.y *= 3;
+ coord.z *= 3;
+ geo = factory_.createPoint(coord);
+ vec.push_back(geo);
+
+ // Factory creates copy of the vec collection
+ GeometryAutoPtr go = factory_.buildGeometry(vec.begin(), vec.end());
+ ensure( go.get() );
+ ensure_equals( go->getGeometryTypeId(), geos::geom::GEOS_MULTIPOINT );
+ ensure_equals( go->getNumGeometries(), size );
+
+ // FREE MEMORY
+ PointVect::const_iterator it;
+ for (it = vec.begin(); it != vec.end(); ++it)
+ {
+ delete (*it);
+ }
+ }
+
} // namespace tut
More information about the geos-commits
mailing list