Skip to content

Commit 287cf8f

Browse files
committed
Work with a distance tolerance for locateAlongFeature, report event items where linear referencing did not succeed
1 parent f827095 commit 287cf8f

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

python/analysis/qgsgeometryanalyzer.sip

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class QgsGeometryAnalyzer
5454
@param locationField1 attribute index of location field in event layer
5555
@param locationField2 attribute index of location end field (or -1 for point layer)
5656
*/
57-
bool eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer* eventLayer, int lineField, int eventField, const QString& outputLayer,
58-
const QString& outputFormat, int locationField1, int locationField2 = -1, QgsVectorDataProvider* memoryProvider = 0, QProgressDialog* p = 0 );
57+
bool eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer* eventLayer, int lineField, int eventField, QList<int>& unlocatedFeatureIds /Out/,
58+
const QString& outputLayer, const QString& outputFormat, int locationField1, int locationField2 = -1, QgsVectorDataProvider* memoryProvider = 0, QProgressDialog* p = 0 );
5959

6060
/**Returns multilinestring*/
6161
QgsGeometry* locateBetweenMeasures( double fromMeasure, double toMeasure, QgsGeometry* lineGeom );

src/analysis/vector/qgsgeometryanalyzer.cpp

+22-7
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ void QgsGeometryAnalyzer::bufferFeature( QgsFeature& f, int nProcessedFeatures,
909909
}
910910
}
911911

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

930930
//create output datasource or attributes in memory provider
931931
QgsVectorFileWriter* fileWriter = 0;
932+
QgsFeatureList memoryProviderFeatures;
932933
if ( !memoryProvider )
933934
{
934935
fileWriter = new QgsVectorFileWriter( outputLayer,
935936
eventLayer->dataProvider()->encoding(),
936937
eventLayer->pendingFields(),
937-
locationField2 == -1 ? QGis::WKBMultiPoint25D : QGis::WKBMultiLineString25D,
938+
locationField2 == -1 ? QGis::WKBMultiPoint : QGis::WKBMultiLineString,
938939
&( lineLayer->crs() ),
939940
outputFormat );
940941
}
@@ -951,6 +952,7 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
951952

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

962964
while ( eventLayer->nextFeature( fet ) )
963965
{
966+
nOutputFeatures = 0;
967+
964968
//update progress dialog
965969
if ( p )
966970
{
@@ -998,24 +1002,34 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
9981002

9991003
if ( lrsGeom )
10001004
{
1005+
++nOutputFeatures;
10011006
fet.setGeometry( lrsGeom );
10021007
if ( memoryProvider )
10031008
{
1004-
memoryProvider->addFeatures( QgsFeatureList() << fet );
1009+
memoryProviderFeatures << fet;
10051010
}
1006-
else
1011+
else if ( fileWriter )
10071012
{
10081013
fileWriter->addFeature( fet );
10091014
}
10101015
}
10111016
}
1017+
if ( nOutputFeatures < 1 )
1018+
{
1019+
unlocatedFeatureIds.push_back( fet.id() );
1020+
}
10121021
}
10131022

10141023
if ( p )
10151024
{
10161025
p->setValue( nEventFeatures );
10171026
}
10181027

1028+
if ( memoryProvider )
1029+
{
1030+
memoryProvider->addFeatures( memoryProviderFeatures );
1031+
}
1032+
delete fileWriter;
10191033
return true;
10201034
}
10211035

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

12991314
if ( m1 > m2 )
13001315
{
@@ -1305,15 +1320,15 @@ void QgsGeometryAnalyzer::locateAlongSegment( double x1, double y1, double m1, d
13051320
}
13061321

13071322
//segment does not match
1308-
if ( measure < m1 || measure > m2 )
1323+
if (( m1 - measure ) > tolerance || ( measure - m2 ) > tolerance )
13091324
{
13101325
pt1Ok = false;
13111326
pt2Ok = false;
13121327
return;
13131328
}
13141329

13151330
//match with vertex1
1316-
if ( doubleNear( m1, measure ) )
1331+
if ( doubleNear( m1, measure, tolerance ) )
13171332
{
13181333
if ( reversed )
13191334
{
@@ -1328,7 +1343,7 @@ void QgsGeometryAnalyzer::locateAlongSegment( double x1, double y1, double m1, d
13281343
}
13291344

13301345
//match with vertex2
1331-
if ( doubleNear( m2, measure ) )
1346+
if ( doubleNear( m2, measure, tolerance ) )
13321347
{
13331348
if ( reversed )
13341349
{

src/analysis/vector/qgsgeometryanalyzer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class ANALYSIS_EXPORT QgsGeometryAnalyzer
109109
@param locationField1 attribute index of location field in event layer
110110
@param locationField2 attribute index of location end field (or -1 for point layer)
111111
*/
112-
bool eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer* eventLayer, int lineField, int eventField, const QString& outputLayer,
112+
bool eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer* eventLayer, int lineField, int eventField, QList<int>& unlocatedFeatureIds, const QString& outputLayer,
113113
const QString& outputFormat, int locationField1, int locationField2 = -1, QgsVectorDataProvider* memoryProvider = 0, QProgressDialog* p = 0 );
114114

115115
/**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)*/

0 commit comments

Comments
 (0)