Navigation Menu

Skip to content

Commit

Permalink
implemented QgsGeometry::asGeometryCollection()
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@10026 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jan 26, 2009
1 parent 071f3cc commit 55d52f7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/core/qgsgeometry.sip
Expand Up @@ -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

36 changes: 36 additions & 0 deletions src/core/qgsgeometry.cpp
Expand Up @@ -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;
}
4 changes: 4 additions & 0 deletions src/core/qgsgeometry.h
Expand Up @@ -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

Expand Down

0 comments on commit 55d52f7

Please sign in to comment.