Skip to content

Commit 3ac5020

Browse files
author
wonder
committedJan 27, 2009
QgsGeometry::asCollection works also for single-part geometries
git-svn-id: http://svn.osgeo.org/qgis/trunk@10034 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 59f2eb3 commit 3ac5020

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed
 

‎python/core/qgsgeometry.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ not disjoint with existing polygons of the feature*/
278278

279279
/** return contents of the geometry as a list of geometries
280280
@note added in version 1.1 */
281-
QList<QgsGeometry*> asGeometryCollection();
281+
// TODO: destruction of created geometries??
282+
QList<QgsGeometry*> asGeometryCollection() /Factory/;
282283

283284
}; // class QgsGeometry
284285

‎src/core/qgsgeometry.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5457,20 +5457,21 @@ QList<QgsGeometry*> QgsGeometry::asGeometryCollection()
54575457
int type = GEOSGeomTypeId( mGeos );
54585458
QgsDebugMsg("geom type: "+QString::number(type));
54595459

5460+
QList<QgsGeometry*> geomCollection;
5461+
54605462
if ( type != GEOS_MULTIPOINT &&
54615463
type != GEOS_MULTILINESTRING &&
54625464
type != GEOS_MULTIPOLYGON &&
54635465
type != GEOS_GEOMETRYCOLLECTION )
54645466
{
5465-
// we have a single-part geometry
5466-
return QList<QgsGeometry*>();
5467+
// we have a single-part geometry - put there a copy of this one
5468+
geomCollection.append( new QgsGeometry(*this) );
5469+
return geomCollection;
54675470
}
54685471

54695472
int count = GEOSGetNumGeometries( mGeos );
54705473
QgsDebugMsg("geom count: "+QString::number(count));
54715474

5472-
QList<QgsGeometry*> geomCollection;
5473-
54745475
for ( int i = 0; i < count; ++i )
54755476
{
54765477
const GEOSGeometry * geometry = GEOSGetGeometryN( mGeos, i );

0 commit comments

Comments
 (0)
Please sign in to comment.