implemented QgsGeometry::asGeometryCollection()

git-svn-id: http://svn.osgeo.org/qgis/trunk@10026 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
wonder 2009-01-26 22:04:12 +00:00
parent 071f3cc5cd
commit 55d52f76ff
3 changed files with 44 additions and 0 deletions

View File

@ -276,5 +276,9 @@ not disjoint with existing polygons of the feature*/
if wkbType is WKBPolygon, otherwise an empty list */
QgsMultiPolygon asMultiPolygon();
/** return contents of the geometry as a list of geometries
@note added in version 1.1 */
QList<QgsGeometry*> asGeometryCollection();
}; // class QgsGeometry

View File

@ -5443,3 +5443,39 @@ QgsGeometry* QgsGeometry::symDifference( QgsGeometry* geometry )
}
CATCH_GEOS( 0 )
}
QList<QgsGeometry*> QgsGeometry::asGeometryCollection()
{
if ( mGeos == NULL )
{
exportWkbToGeos();
if ( mGeos == NULL )
return QList<QgsGeometry*>();
}
int type = GEOSGeomTypeId( mGeos );
QgsDebugMsg("geom type: "+QString::number(type));
if ( type != GEOS_MULTIPOINT &&
type != GEOS_MULTILINESTRING &&
type != GEOS_MULTIPOLYGON &&
type != GEOS_GEOMETRYCOLLECTION )
{
// we have a single-part geometry
return QList<QgsGeometry*>();
}
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 );
geomCollection.append( fromGeosGeom( GEOSGeom_clone(geometry) ) );
}
return geomCollection;
}

View File

@ -318,6 +318,10 @@ class CORE_EXPORT QgsGeometry
if wkbType is WKBPolygon, otherwise an empty list */
QgsMultiPolygon asMultiPolygon();
/** return contents of the geometry as a list of geometries
@note added in version 1.1 */
QList<QgsGeometry*> asGeometryCollection();
private:
// Private variables