Skip to content

Commit b480d17

Browse files
committedJun 4, 2014
Event layer function: catch various error cases for line offsets
1 parent e6b337e commit b480d17

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed
 

‎src/analysis/vector/qgsgeometryanalyzer.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,10 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
986986
if ( locationField2 != -1 )
987987
{
988988
measure2 = fet.attribute( locationField2 ).toDouble();
989+
if ( qgsDoubleNear(( measure2 - measure1 ), 0.0 ) )
990+
{
991+
continue;
992+
}
989993
}
990994

991995
QList<QgsFeature> featureIdList = lineLayerIdMap.values( fet.attribute( eventField ).toString() );
@@ -1052,7 +1056,11 @@ void QgsGeometryAnalyzer::addEventLayerFeature( QgsFeature& feature, QgsGeometry
10521056
{
10531057
double offsetVal = feature.attribute( offsetField ).toDouble();
10541058
offsetVal *= offsetScale;
1055-
createOffsetGeometry( *geomIt, lineGeom, offsetVal );
1059+
if ( !createOffsetGeometry( *geomIt, lineGeom, offsetVal ) )
1060+
{
1061+
delete *geomIt;
1062+
continue;
1063+
}
10561064
}
10571065

10581066
feature.setGeometry( *geomIt );
@@ -1072,11 +1080,11 @@ void QgsGeometryAnalyzer::addEventLayerFeature( QgsFeature& feature, QgsGeometry
10721080
}
10731081
}
10741082

1075-
void QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry* lineGeom, double offset )
1083+
bool QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry* lineGeom, double offset )
10761084
{
10771085
if ( !geom || !lineGeom )
10781086
{
1079-
return;
1087+
return false;
10801088
}
10811089

10821090
QList<QgsGeometry*> inputGeomList;
@@ -1099,7 +1107,17 @@ void QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry*
10991107
//geos 3.3 needed for line offsets
11001108
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
11011109
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
1102-
outputGeomList.push_back( GEOSOffsetCurve(( *inputGeomIt )->asGeos(), -offset, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ ) );
1110+
GEOSGeometry* offsetGeom = GEOSOffsetCurve(( *inputGeomIt )->asGeos(), -offset, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );
1111+
if ( !offsetGeom || !GEOSisValid( offsetGeom ) )
1112+
{
1113+
return false;
1114+
}
1115+
if ( !GEOSisValid( offsetGeom ) || GEOSGeomTypeId( offsetGeom ) != GEOS_LINESTRING || GEOSGeomGetNumPoints( offsetGeom ) < 1 )
1116+
{
1117+
GEOSGeom_destroy( offsetGeom );
1118+
return false;
1119+
}
1120+
outputGeomList.push_back( offsetGeom );
11031121
#else
11041122
outputGeomList.push_back( GEOSGeom_clone(( *inputGeomIt )->asGeos() ) );
11051123
#endif
@@ -1143,6 +1161,7 @@ void QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry*
11431161
geom->fromGeos( collection );
11441162
delete[] geomArray;
11451163
}
1164+
return true;
11461165
}
11471166

11481167
QgsPoint QgsGeometryAnalyzer::createPointOffset( double x, double y, double dist, QgsGeometry* lineGeom ) const

‎src/analysis/vector/qgsgeometryanalyzer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class ANALYSIS_EXPORT QgsGeometryAnalyzer
150150
@param geom the geometry to modify
151151
@param lineGeom the line geometry to which the feature is referenced
152152
@param offset the offset value in layer unit. Negative values mean offset towards left, positive values offset to the right side*/
153-
void createOffsetGeometry( QgsGeometry* geom, QgsGeometry* lineGeom, double offset );
153+
bool createOffsetGeometry( QgsGeometry* geom, QgsGeometry* lineGeom, double offset );
154154
QgsPoint createPointOffset( double x, double y, double dist, QgsGeometry* lineGeom ) const;
155155
const unsigned char* locateBetweenWkbString( const unsigned char* ptr, QgsMultiPolyline& result, double fromMeasure, double toMeasure );
156156
const unsigned char* locateAlongWkbString( const unsigned char* ptr, QgsMultiPoint& result, double measure );

0 commit comments

Comments
 (0)
Please sign in to comment.