From 34bd12402362e8af1ba3b1cae09f6be9fb7c2c52 Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Sat, 12 Mar 2016 22:32:29 +0100 Subject: [PATCH] [Geometry checker] Make polyLineSize survive empty geometries --- .../geometry_checker/utils/qgsgeomutils.h | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/plugins/geometry_checker/utils/qgsgeomutils.h b/src/plugins/geometry_checker/utils/qgsgeomutils.h index 0046ad91c2c2..57583a4ac134 100644 --- a/src/plugins/geometry_checker/utils/qgsgeomutils.h +++ b/src/plugins/geometry_checker/utils/qgsgeomutils.h @@ -39,13 +39,22 @@ namespace QgsGeomUtils */ inline int polyLineSize( const QgsAbstractGeometryV2* geom, int iPart, int iRing, bool* isClosed = nullptr ) { - int nVerts = geom->vertexCount( iPart, iRing ); - QgsPointV2 front = geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) ); - QgsPointV2 back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) ); - bool closed = back == front; - if ( isClosed ) - *isClosed = closed; - return closed ? nVerts - 1 : nVerts; + if ( !geom->isEmpty() ) + { + int nVerts = geom->vertexCount( iPart, iRing ); + QgsPointV2 front = geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) ); + QgsPointV2 back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) ); + bool closed = back == front; + if ( isClosed ) + *isClosed = closed; + return closed ? nVerts - 1 : nVerts; + } + else + { + if ( isClosed ) + *isClosed = true; + return 0; + } } double sharedEdgeLength( const QgsAbstractGeometryV2* geom1, const QgsAbstractGeometryV2* geom2, double tol );