File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff 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*/
Original file line number Diff line number Diff 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+
128162QgsGeometry* QgsGeometry::fromPolyline (const QgsPolyline& polyline)
129163{
130164 const GEOS_GEOM::CoordinateSequenceFactory* seqFactory = GEOS_GEOM::COORD_SEQ_FACTORY::instance ();
Original file line number Diff line number Diff 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*/
You can’t perform that action at this time.
0 commit comments