Skip to content

Commit

Permalink
Event layer function: catch various error cases for line offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jun 4, 2014
1 parent e6b337e commit b480d17
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
27 changes: 23 additions & 4 deletions src/analysis/vector/qgsgeometryanalyzer.cpp
Expand Up @@ -986,6 +986,10 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
if ( locationField2 != -1 )
{
measure2 = fet.attribute( locationField2 ).toDouble();
if ( qgsDoubleNear(( measure2 - measure1 ), 0.0 ) )
{
continue;
}
}

QList<QgsFeature> featureIdList = lineLayerIdMap.values( fet.attribute( eventField ).toString() );
Expand Down Expand Up @@ -1052,7 +1056,11 @@ void QgsGeometryAnalyzer::addEventLayerFeature( QgsFeature& feature, QgsGeometry
{
double offsetVal = feature.attribute( offsetField ).toDouble();
offsetVal *= offsetScale;
createOffsetGeometry( *geomIt, lineGeom, offsetVal );
if ( !createOffsetGeometry( *geomIt, lineGeom, offsetVal ) )
{
delete *geomIt;
continue;
}
}

feature.setGeometry( *geomIt );
Expand All @@ -1072,11 +1080,11 @@ void QgsGeometryAnalyzer::addEventLayerFeature( QgsFeature& feature, QgsGeometry
}
}

void QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry* lineGeom, double offset )
bool QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry* lineGeom, double offset )
{
if ( !geom || !lineGeom )
{
return;
return false;
}

QList<QgsGeometry*> inputGeomList;
Expand All @@ -1099,7 +1107,17 @@ void QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry*
//geos 3.3 needed for line offsets
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
outputGeomList.push_back( GEOSOffsetCurve(( *inputGeomIt )->asGeos(), -offset, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ ) );
GEOSGeometry* offsetGeom = GEOSOffsetCurve(( *inputGeomIt )->asGeos(), -offset, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );
if ( !offsetGeom || !GEOSisValid( offsetGeom ) )
{
return false;
}
if ( !GEOSisValid( offsetGeom ) || GEOSGeomTypeId( offsetGeom ) != GEOS_LINESTRING || GEOSGeomGetNumPoints( offsetGeom ) < 1 )
{
GEOSGeom_destroy( offsetGeom );
return false;
}
outputGeomList.push_back( offsetGeom );
#else
outputGeomList.push_back( GEOSGeom_clone(( *inputGeomIt )->asGeos() ) );
#endif
Expand Down Expand Up @@ -1143,6 +1161,7 @@ void QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry*
geom->fromGeos( collection );
delete[] geomArray;
}
return true;
}

QgsPoint QgsGeometryAnalyzer::createPointOffset( double x, double y, double dist, QgsGeometry* lineGeom ) const
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/vector/qgsgeometryanalyzer.h
Expand Up @@ -150,7 +150,7 @@ class ANALYSIS_EXPORT QgsGeometryAnalyzer
@param geom the geometry to modify
@param lineGeom the line geometry to which the feature is referenced
@param offset the offset value in layer unit. Negative values mean offset towards left, positive values offset to the right side*/
void createOffsetGeometry( QgsGeometry* geom, QgsGeometry* lineGeom, double offset );
bool createOffsetGeometry( QgsGeometry* geom, QgsGeometry* lineGeom, double offset );
QgsPoint createPointOffset( double x, double y, double dist, QgsGeometry* lineGeom ) const;
const unsigned char* locateBetweenWkbString( const unsigned char* ptr, QgsMultiPolyline& result, double fromMeasure, double toMeasure );
const unsigned char* locateAlongWkbString( const unsigned char* ptr, QgsMultiPoint& result, double measure );
Expand Down

0 comments on commit b480d17

Please sign in to comment.