Skip to content
Permalink
Browse files
Added fromMultiPoint method to QgsGeometry
git-svn-id: http://svn.osgeo.org/qgis/trunk@8041 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 25, 2008
1 parent 671a782 commit c39d6a90ce730fb707fde834fabcc56fd91a3a1e
Showing with 38 additions and 0 deletions.
  1. +2 −0 python/core/qgsgeometry.sip
  2. +34 −0 src/core/qgsgeometry.cpp
  3. +2 −0 src/core/qgsgeometry.h
@@ -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*/
@@ -125,6 +125,40 @@ QgsGeometry* QgsGeometry::fromPoint(const QgsPoint& point)
return g;
}

QgsGeometry* QgsGeometry::fromMultiPoint(const QgsMultiPoint& multipoint)
{
std::vector<GEOS_GEOM::Geometry*>* pointVector = new std::vector<GEOS_GEOM::Geometry*>(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();
@@ -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*/

0 comments on commit c39d6a9

Please sign in to comment.