Skip to content

Commit 13d407e

Browse files
committedMar 14, 2016
Merge pull request #2905 from manisandro/checker_crash
[Geometry checker] Make polyLineSize survive empty geometries
2 parents d6fca7e + 34bd124 commit 13d407e

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed
 

‎src/plugins/geometry_checker/utils/qgsgeomutils.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,22 @@ namespace QgsGeomUtils
3939
*/
4040
inline int polyLineSize( const QgsAbstractGeometryV2* geom, int iPart, int iRing, bool* isClosed = nullptr )
4141
{
42-
int nVerts = geom->vertexCount( iPart, iRing );
43-
QgsPointV2 front = geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) );
44-
QgsPointV2 back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) );
45-
bool closed = back == front;
46-
if ( isClosed )
47-
*isClosed = closed;
48-
return closed ? nVerts - 1 : nVerts;
42+
if ( !geom->isEmpty() )
43+
{
44+
int nVerts = geom->vertexCount( iPart, iRing );
45+
QgsPointV2 front = geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) );
46+
QgsPointV2 back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) );
47+
bool closed = back == front;
48+
if ( isClosed )
49+
*isClosed = closed;
50+
return closed ? nVerts - 1 : nVerts;
51+
}
52+
else
53+
{
54+
if ( isClosed )
55+
*isClosed = true;
56+
return 0;
57+
}
4958
}
5059

5160
double sharedEdgeLength( const QgsAbstractGeometryV2* geom1, const QgsAbstractGeometryV2* geom2, double tol );

0 commit comments

Comments
 (0)