[QGIS Commit] r10026 - in trunk/qgis: python/core src/core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Jan 26 17:04:12 EST 2009
Author: wonder
Date: 2009-01-26 17:04:12 -0500 (Mon, 26 Jan 2009)
New Revision: 10026
Modified:
trunk/qgis/python/core/qgsgeometry.sip
trunk/qgis/src/core/qgsgeometry.cpp
trunk/qgis/src/core/qgsgeometry.h
Log:
implemented QgsGeometry::asGeometryCollection()
Modified: trunk/qgis/python/core/qgsgeometry.sip
===================================================================
--- trunk/qgis/python/core/qgsgeometry.sip 2009-01-26 22:00:19 UTC (rev 10025)
+++ trunk/qgis/python/core/qgsgeometry.sip 2009-01-26 22:04:12 UTC (rev 10026)
@@ -276,5 +276,9 @@
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
Modified: trunk/qgis/src/core/qgsgeometry.cpp
===================================================================
--- trunk/qgis/src/core/qgsgeometry.cpp 2009-01-26 22:00:19 UTC (rev 10025)
+++ trunk/qgis/src/core/qgsgeometry.cpp 2009-01-26 22:04:12 UTC (rev 10026)
@@ -5443,3 +5443,39 @@
}
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;
+}
Modified: trunk/qgis/src/core/qgsgeometry.h
===================================================================
--- trunk/qgis/src/core/qgsgeometry.h 2009-01-26 22:00:19 UTC (rev 10025)
+++ trunk/qgis/src/core/qgsgeometry.h 2009-01-26 22:04:12 UTC (rev 10026)
@@ -318,6 +318,10 @@
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
More information about the QGIS-commit
mailing list