QgsGeometry::asCollection works also for single-part geometries

git-svn-id: http://svn.osgeo.org/qgis/trunk@10034 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
wonder 2009-01-27 12:44:59 +00:00
parent 59f2eb3879
commit 3ac50201b5
2 changed files with 7 additions and 5 deletions

View File

@ -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

View File

@ -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 );