Skip to content

Commit

Permalink
Added fromMultiPoint method to QgsGeometry
Browse files Browse the repository at this point in the history
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 c39d6a9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/core/qgsgeometry.sip
Expand Up @@ -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*/
Expand Down
34 changes: 34 additions & 0 deletions src/core/qgsgeometry.cpp
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsgeometry.h
Expand Up @@ -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*/
Expand Down

0 comments on commit c39d6a9

Please sign in to comment.