Skip to content

Commit f5c8c4e

Browse files

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
 

‎src/core/qgsgeometry.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4864,7 +4864,7 @@ int QgsGeometry::splitPolygonGeometry( GEOSGeometry* splitLine, QList<QgsGeometr
48644864
//ratio intersect geometry / geometry. This should be close to 1
48654865
//if the polygon belongs to the input geometry
48664866

4867-
for ( int i = 0; i < GEOSGetNumGeometries( polygons ); i++ )
4867+
for ( int i = 0; i < getNumberOfGeometries( polygons ); i++ )
48684868
{
48694869
const GEOSGeometry *polygon = GEOSGetGeometryN( polygons, i );
48704870
intersectGeometry = GEOSIntersection( mGeos, polygon );
@@ -4883,7 +4883,7 @@ int QgsGeometry::splitPolygonGeometry( GEOSGeometry* splitLine, QList<QgsGeometr
48834883
}
48844884

48854885
bool splitDone = true;
4886-
int nGeometriesThis = GEOSGetNumGeometries( mGeos ); //original number of geometries
4886+
int nGeometriesThis = getNumberOfGeometries( mGeos ); //original number of geometries
48874887
if ( testedGeometries.size() == nGeometriesThis )
48884888
{
48894889
splitDone = false;
@@ -5003,6 +5003,23 @@ GEOSGeometry *QgsGeometry::nodeGeometries( const GEOSGeometry *splitLine, GEOSGe
50035003
return unionGeometry;
50045004
}
50055005

5006+
int QgsGeometry::getNumberOfGeometries(GEOSGeometry* g) const
5007+
{
5008+
if(!g)
5009+
{
5010+
return 0;
5011+
}
5012+
int geometryType = GEOSGeomTypeId(g);
5013+
if(geometryType == GEOS_POINT || geometryType == GEOS_LINESTRING || geometryType == GEOS_LINEARRING
5014+
|| geometryType == GEOS_POLYGON)
5015+
{
5016+
return 1;
5017+
}
5018+
5019+
//calling GEOSGetNumGeometries is save for multi types and collections also in geos2
5020+
return GEOSGetNumGeometries(g);
5021+
}
5022+
50065023
int QgsGeometry::mergeGeometriesMultiTypeSplit( QVector<GEOSGeometry*>& splitResult )
50075024
{
50085025
if ( !mGeos || mDirtyGeos )

‎src/core/qgsgeometry.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ class CORE_EXPORT QgsGeometry
417417
@return the noded multiline geometry or 0 in case of error. The calling function takes ownership of the node geometry*/
418418
GEOSGeometry* nodeGeometries( const GEOSGeometry *splitLine, GEOSGeometry *poly ) const;
419419

420+
/**Returns number of single geometry in a geos geometry. Is save for geos 2 and 3*/
421+
int getNumberOfGeometries(GEOSGeometry* g) const;
422+
420423
int mergeGeometriesMultiTypeSplit( QVector<GEOSGeometry*>& splitResult );
421424

422425
/** return point from wkb */

0 commit comments

Comments
 (0)
Please sign in to comment.