Skip to content

Commit c39d6a9

Browse files
author
mhugent
committedJan 25, 2008
Added fromMultiPoint method to QgsGeometry
git-svn-id: http://svn.osgeo.org/qgis/trunk@8041 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 671a782 commit c39d6a9

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed
 

‎python/core/qgsgeometry.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class QgsGeometry
3939

4040
/** construct geometry from a point */
4141
static QgsGeometry* fromPoint(const QgsPoint& point) /Factory/;
42+
/** construct geometry from a multipoint */
43+
static QgsGeometry* fromMultiPoint(const QgsMultiPoint& multipoint) /Factory/;
4244
/** construct geometry from a polyline */
4345
static QgsGeometry* fromPolyline(const QgsPolyline& polyline) /Factory/;
4446
/** construct geometry from a multipolyline*/

‎src/core/qgsgeometry.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,40 @@ QgsGeometry* QgsGeometry::fromPoint(const QgsPoint& point)
125125
return g;
126126
}
127127

128+
QgsGeometry* QgsGeometry::fromMultiPoint(const QgsMultiPoint& multipoint)
129+
{
130+
std::vector<GEOS_GEOM::Geometry*>* pointVector = new std::vector<GEOS_GEOM::Geometry*>(multipoint.size());
131+
GEOS_GEOM::Coordinate currentCoord;
132+
133+
for(int i = 0; i < multipoint.size(); ++i)
134+
{
135+
currentCoord.x = multipoint.at(i).x();
136+
currentCoord.y = multipoint.at(i).y();
137+
try
138+
{
139+
(*pointVector)[i] = geosGeometryFactory->createPoint(currentCoord);
140+
}
141+
catch(GEOS_UTIL::GEOSException* e)
142+
{
143+
delete e; delete pointVector; return 0;
144+
}
145+
}
146+
147+
GEOS_GEOM::Geometry* geom = 0;
148+
try
149+
{
150+
geom = geosGeometryFactory->createMultiPoint(pointVector);
151+
}
152+
catch(GEOS_UTIL::GEOSException* e)
153+
{
154+
delete e; return 0;
155+
}
156+
157+
QgsGeometry* g = new QgsGeometry;
158+
g->setGeos(geom);
159+
return g;
160+
}
161+
128162
QgsGeometry* QgsGeometry::fromPolyline(const QgsPolyline& polyline)
129163
{
130164
const GEOS_GEOM::CoordinateSequenceFactory* seqFactory = GEOS_GEOM::COORD_SEQ_FACTORY::instance();

‎src/core/qgsgeometry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class CORE_EXPORT QgsGeometry {
112112

113113
/** construct geometry from a point */
114114
static QgsGeometry* fromPoint(const QgsPoint& point);
115+
/** construct geometry from a multipoint */
116+
static QgsGeometry* fromMultiPoint(const QgsMultiPoint& multipoint);
115117
/** construct geometry from a polyline */
116118
static QgsGeometry* fromPolyline(const QgsPolyline& polyline);
117119
/** construct geometry from a multipolyline*/

0 commit comments

Comments
 (0)
Please sign in to comment.