From c39d6a90ce730fb707fde834fabcc56fd91a3a1e Mon Sep 17 00:00:00 2001 From: mhugent Date: Fri, 25 Jan 2008 07:03:59 +0000 Subject: [PATCH] Added fromMultiPoint method to QgsGeometry git-svn-id: http://svn.osgeo.org/qgis/trunk@8041 c8812cc2-4d05-0410-92ff-de0c093fc19c --- python/core/qgsgeometry.sip | 2 ++ src/core/qgsgeometry.cpp | 34 ++++++++++++++++++++++++++++++++++ src/core/qgsgeometry.h | 2 ++ 3 files changed, 38 insertions(+) diff --git a/python/core/qgsgeometry.sip b/python/core/qgsgeometry.sip index ac024943501..290b55d10c4 100644 --- a/python/core/qgsgeometry.sip +++ b/python/core/qgsgeometry.sip @@ -39,6 +39,8 @@ class QgsGeometry /** construct geometry from a point */ static QgsGeometry* fromPoint(const QgsPoint& point) /Factory/; + /** construct geometry from a multipoint */ + static QgsGeometry* fromMultiPoint(const QgsMultiPoint& multipoint) /Factory/; /** construct geometry from a polyline */ static QgsGeometry* fromPolyline(const QgsPolyline& polyline) /Factory/; /** construct geometry from a multipolyline*/ diff --git a/src/core/qgsgeometry.cpp b/src/core/qgsgeometry.cpp index 409a8b5404d..048b557aa90 100644 --- a/src/core/qgsgeometry.cpp +++ b/src/core/qgsgeometry.cpp @@ -125,6 +125,40 @@ QgsGeometry* QgsGeometry::fromPoint(const QgsPoint& point) return g; } +QgsGeometry* QgsGeometry::fromMultiPoint(const QgsMultiPoint& multipoint) +{ + std::vector* pointVector = new std::vector(multipoint.size()); + GEOS_GEOM::Coordinate currentCoord; + + for(int i = 0; i < multipoint.size(); ++i) + { + currentCoord.x = multipoint.at(i).x(); + currentCoord.y = multipoint.at(i).y(); + try + { + (*pointVector)[i] = geosGeometryFactory->createPoint(currentCoord); + } + catch(GEOS_UTIL::GEOSException* e) + { + delete e; delete pointVector; return 0; + } + } + + GEOS_GEOM::Geometry* geom = 0; + try + { + geom = geosGeometryFactory->createMultiPoint(pointVector); + } + catch(GEOS_UTIL::GEOSException* e) + { + delete e; return 0; + } + + QgsGeometry* g = new QgsGeometry; + g->setGeos(geom); + return g; +} + QgsGeometry* QgsGeometry::fromPolyline(const QgsPolyline& polyline) { const GEOS_GEOM::CoordinateSequenceFactory* seqFactory = GEOS_GEOM::COORD_SEQ_FACTORY::instance(); diff --git a/src/core/qgsgeometry.h b/src/core/qgsgeometry.h index 9520de9e61c..e94a3ddde63 100644 --- a/src/core/qgsgeometry.h +++ b/src/core/qgsgeometry.h @@ -112,6 +112,8 @@ class CORE_EXPORT QgsGeometry { /** construct geometry from a point */ static QgsGeometry* fromPoint(const QgsPoint& point); + /** construct geometry from a multipoint */ + static QgsGeometry* fromMultiPoint(const QgsMultiPoint& multipoint); /** construct geometry from a polyline */ static QgsGeometry* fromPolyline(const QgsPolyline& polyline); /** construct geometry from a multipolyline*/