Skip to content
Permalink
Browse files

QgsGeometry::asCollection works also for single-part geometries

git-svn-id: http://svn.osgeo.org/qgis/trunk@10034 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jan 27, 2009
1 parent 59f2eb3 commit 3ac50201b50cc159c1f3a982abde0a77bde0628c
Showing with 7 additions and 5 deletions.
  1. +2 −1 python/core/qgsgeometry.sip
  2. +5 −4 src/core/qgsgeometry.cpp
@@ -278,7 +278,8 @@ not disjoint with existing polygons of the feature*/

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

}; // class QgsGeometry

@@ -5457,20 +5457,21 @@ QList<QgsGeometry*> QgsGeometry::asGeometryCollection()
int type = GEOSGeomTypeId( mGeos );
QgsDebugMsg("geom type: "+QString::number(type));

QList<QgsGeometry*> geomCollection;

if ( type != GEOS_MULTIPOINT &&
type != GEOS_MULTILINESTRING &&
type != GEOS_MULTIPOLYGON &&
type != GEOS_GEOMETRYCOLLECTION )
{
// we have a single-part geometry
return QList<QgsGeometry*>();
// we have a single-part geometry - put there a copy of this one
geomCollection.append( new QgsGeometry(*this) );
return geomCollection;
}

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

QList<QgsGeometry*> geomCollection;

for ( int i = 0; i < count; ++i )
{
const GEOSGeometry * geometry = GEOSGetGeometryN( mGeos, i );

0 comments on commit 3ac5020

Please sign in to comment.
You can’t perform that action at this time.