Skip to content

Commit

Permalink
Work with a distance tolerance for locateAlongFeature, report event i…
Browse files Browse the repository at this point in the history
…tems where linear referencing did not succeed
  • Loading branch information
mhugent committed Feb 3, 2012
1 parent f827095 commit 287cf8f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions python/analysis/qgsgeometryanalyzer.sip
Expand Up @@ -54,8 +54,8 @@ class QgsGeometryAnalyzer
@param locationField1 attribute index of location field in event layer
@param locationField2 attribute index of location end field (or -1 for point layer)
*/
bool eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer* eventLayer, int lineField, int eventField, const QString& outputLayer,
const QString& outputFormat, int locationField1, int locationField2 = -1, QgsVectorDataProvider* memoryProvider = 0, QProgressDialog* p = 0 );
bool eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer* eventLayer, int lineField, int eventField, QList<int>& unlocatedFeatureIds /Out/,
const QString& outputLayer, const QString& outputFormat, int locationField1, int locationField2 = -1, QgsVectorDataProvider* memoryProvider = 0, QProgressDialog* p = 0 );

/**Returns multilinestring*/
QgsGeometry* locateBetweenMeasures( double fromMeasure, double toMeasure, QgsGeometry* lineGeom );
Expand Down
29 changes: 22 additions & 7 deletions src/analysis/vector/qgsgeometryanalyzer.cpp
Expand Up @@ -909,7 +909,7 @@ void QgsGeometryAnalyzer::bufferFeature( QgsFeature& f, int nProcessedFeatures,
}
}

bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer* eventLayer, int lineField, int eventField, const QString& outputLayer,
bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer* eventLayer, int lineField, int eventField, QList<int>& unlocatedFeatureIds, const QString& outputLayer,
const QString& outputFormat, int locationField1, int locationField2, QgsVectorDataProvider* memoryProvider, QProgressDialog* p )
{
if ( !lineLayer || !eventLayer || !lineLayer->isValid() || !eventLayer->isValid() )
Expand All @@ -929,12 +929,13 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*

//create output datasource or attributes in memory provider
QgsVectorFileWriter* fileWriter = 0;
QgsFeatureList memoryProviderFeatures;
if ( !memoryProvider )
{
fileWriter = new QgsVectorFileWriter( outputLayer,
eventLayer->dataProvider()->encoding(),
eventLayer->pendingFields(),
locationField2 == -1 ? QGis::WKBMultiPoint25D : QGis::WKBMultiLineString25D,
locationField2 == -1 ? QGis::WKBMultiPoint : QGis::WKBMultiLineString,
&( lineLayer->crs() ),
outputFormat );
}
Expand All @@ -951,6 +952,7 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*

int nEventFeatures = eventLayer->pendingFeatureCount();
int featureCounter = 0;
int nOutputFeatures = 0; //number of output features for the current event feature
if ( p )
{
p->setWindowModality( Qt::WindowModal );
Expand All @@ -961,6 +963,8 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*

while ( eventLayer->nextFeature( fet ) )
{
nOutputFeatures = 0;

//update progress dialog
if ( p )
{
Expand Down Expand Up @@ -998,24 +1002,34 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*

if ( lrsGeom )
{
++nOutputFeatures;
fet.setGeometry( lrsGeom );
if ( memoryProvider )
{
memoryProvider->addFeatures( QgsFeatureList() << fet );
memoryProviderFeatures << fet;
}
else
else if ( fileWriter )
{
fileWriter->addFeature( fet );
}
}
}
if ( nOutputFeatures < 1 )
{
unlocatedFeatureIds.push_back( fet.id() );
}
}

if ( p )
{
p->setValue( nEventFeatures );
}

if ( memoryProvider )
{
memoryProvider->addFeatures( memoryProviderFeatures );
}
delete fileWriter;
return true;
}

Expand Down Expand Up @@ -1295,6 +1309,7 @@ void QgsGeometryAnalyzer::locateAlongSegment( double x1, double y1, double m1, d
bool reversed = false;
pt1Ok = false;
pt2Ok = false;
double tolerance = 0.000001; //work with a small tolerance to catch e.g. locations at endpoints

if ( m1 > m2 )
{
Expand All @@ -1305,15 +1320,15 @@ void QgsGeometryAnalyzer::locateAlongSegment( double x1, double y1, double m1, d
}

//segment does not match
if ( measure < m1 || measure > m2 )
if (( m1 - measure ) > tolerance || ( measure - m2 ) > tolerance )
{
pt1Ok = false;
pt2Ok = false;
return;
}

//match with vertex1
if ( doubleNear( m1, measure ) )
if ( doubleNear( m1, measure, tolerance ) )
{
if ( reversed )
{
Expand All @@ -1328,7 +1343,7 @@ void QgsGeometryAnalyzer::locateAlongSegment( double x1, double y1, double m1, d
}

//match with vertex2
if ( doubleNear( m2, measure ) )
if ( doubleNear( m2, measure, tolerance ) )
{
if ( reversed )
{
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/vector/qgsgeometryanalyzer.h
Expand Up @@ -109,7 +109,7 @@ class ANALYSIS_EXPORT QgsGeometryAnalyzer
@param locationField1 attribute index of location field in event layer
@param locationField2 attribute index of location end field (or -1 for point layer)
*/
bool eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer* eventLayer, int lineField, int eventField, const QString& outputLayer,
bool eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer* eventLayer, int lineField, int eventField, QList<int>& unlocatedFeatureIds, const QString& outputLayer,
const QString& outputFormat, int locationField1, int locationField2 = -1, QgsVectorDataProvider* memoryProvider = 0, QProgressDialog* p = 0 );

/**Returns linear reference geometry as a multiline (or 0 if no match). Currently, the z-coordinates are considered to be the measures (no support for m-values in QGIS)*/
Expand Down

0 comments on commit 287cf8f

Please sign in to comment.