Skip to content

Commit

Permalink
Fix for bug #1424, split feature segfault
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9712 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 27, 2008
1 parent 630ddb7 commit f5c8c4e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/core/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4864,7 +4864,7 @@ int QgsGeometry::splitPolygonGeometry( GEOSGeometry* splitLine, QList<QgsGeometr
//ratio intersect geometry / geometry. This should be close to 1
//if the polygon belongs to the input geometry

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

bool splitDone = true;
int nGeometriesThis = GEOSGetNumGeometries( mGeos ); //original number of geometries
int nGeometriesThis = getNumberOfGeometries( mGeos ); //original number of geometries
if ( testedGeometries.size() == nGeometriesThis )
{
splitDone = false;
Expand Down Expand Up @@ -5003,6 +5003,23 @@ GEOSGeometry *QgsGeometry::nodeGeometries( const GEOSGeometry *splitLine, GEOSGe
return unionGeometry;
}

int QgsGeometry::getNumberOfGeometries(GEOSGeometry* g) const
{
if(!g)
{
return 0;
}
int geometryType = GEOSGeomTypeId(g);
if(geometryType == GEOS_POINT || geometryType == GEOS_LINESTRING || geometryType == GEOS_LINEARRING
|| geometryType == GEOS_POLYGON)
{
return 1;
}

//calling GEOSGetNumGeometries is save for multi types and collections also in geos2
return GEOSGetNumGeometries(g);
}

int QgsGeometry::mergeGeometriesMultiTypeSplit( QVector<GEOSGeometry*>& splitResult )
{
if ( !mGeos || mDirtyGeos )
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ class CORE_EXPORT QgsGeometry
@return the noded multiline geometry or 0 in case of error. The calling function takes ownership of the node geometry*/
GEOSGeometry* nodeGeometries( const GEOSGeometry *splitLine, GEOSGeometry *poly ) const;

/**Returns number of single geometry in a geos geometry. Is save for geos 2 and 3*/
int getNumberOfGeometries(GEOSGeometry* g) const;

int mergeGeometriesMultiTypeSplit( QVector<GEOSGeometry*>& splitResult );

/** return point from wkb */
Expand Down

0 comments on commit f5c8c4e

Please sign in to comment.