Skip to content
Permalink
Browse files

implemented QgsGeometry::asGeometryCollection()

git-svn-id: http://svn.osgeo.org/qgis/trunk@10026 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jan 26, 2009
1 parent 071f3cc commit 55d52f76ff0b5582688ced3e002951780023cb1f
Showing with 44 additions and 0 deletions.
  1. +4 −0 python/core/qgsgeometry.sip
  2. +36 −0 src/core/qgsgeometry.cpp
  3. +4 −0 src/core/qgsgeometry.h
@@ -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

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

0 comments on commit 55d52f7

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