Skip to content

Commit

Permalink
QgsGeometry::asCollection works also for single-part geometries
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10034 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jan 27, 2009
1 parent 1eb426e commit a2fd1a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion python/core/qgsgeometry.sip
Expand Up @@ -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

9 changes: 5 additions & 4 deletions src/core/qgsgeometry.cpp
Expand Up @@ -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 );
Expand Down

0 comments on commit a2fd1a5

Please sign in to comment.