Skip to content

Commit

Permalink
[network analysis] use QgsFeatureSource instead of QgsVectorLayer in
Browse files Browse the repository at this point in the history
QgsVectorLayerDirector
  • Loading branch information
alexbruy committed Jul 16, 2017
1 parent 23a4d60 commit 126a274
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
9 changes: 6 additions & 3 deletions doc/api_break.dox
Expand Up @@ -361,8 +361,6 @@ Data Providers {#qgis_api_break_3_0_DataProviders}
- mAttrPalIndexName: overwrite palAttributeIndexNames()




Qgis {#qgis_api_break_3_0_Qgis}
----

Expand Down Expand Up @@ -1116,7 +1114,7 @@ version instead.
- QgsExpression::Node::referencedColumns() returns QSet<QString> instead of QStringList
- `QgsExpression::Node` was renamed to `QgsExpressionNode`
- `QgsExpression::Function` was renamed to `QgsExpressionFunction`
- variableHelpText() no longer returns a formatted HTML string. It now just returns the plain text help string. Use formatVariableHelp()
- variableHelpText() no longer returns a formatted HTML string. It now just returns the plain text help string. Use formatVariableHelp()
to obtain the formatted version.


Expand Down Expand Up @@ -2512,6 +2510,11 @@ QgsRendererAbstractMetadata {#qgis_api_break_3_0_QgsRendererAbstractMetadata}

- createRenderer() now expects a reference to QgsReadWriteContext as the second argument

QgsVectorLayerDirector {#qgis_api_break_3_0_QgsVectorLayerDirector}
----------------------

- QgsVectorLayerDirector() constructor now expects a reference to QgsFeatureSource as the first argument


Processing {#qgis_api_break_3_0_Processing}
----------
Expand Down
4 changes: 2 additions & 2 deletions python/analysis/network/qgsvectorlayerdirector.sip
Expand Up @@ -29,7 +29,7 @@ class QgsVectorLayerDirector : QgsGraphDirector
DirectionBoth,
};

QgsVectorLayerDirector( QgsVectorLayer *myLayer,
QgsVectorLayerDirector( QgsFeatureSource *source,
int directionFieldId,
const QString &directDirectionValue,
const QString &reverseDirectionValue,
Expand All @@ -38,7 +38,7 @@ class QgsVectorLayerDirector : QgsGraphDirector
);
%Docstring
Default constructor
\param myLayer source vector layer
\param source feature source representing network
\param directionFieldId field containing direction value
\param directDirectionValue value for direct one-way road
\param reverseDirectionValue value for reversed one-way road
Expand Down
33 changes: 14 additions & 19 deletions src/analysis/network/qgsvectorlayerdirector.cpp
Expand Up @@ -22,12 +22,12 @@
#include "qgsgraphbuilderinterface.h"

#include "qgsfeatureiterator.h"
#include <qgsvectorlayer.h>
#include <qgsvectordataprovider.h>
#include <qgspoint.h>
#include <qgsgeometry.h>
#include <qgsdistancearea.h>
#include <qgswkbtypes.h>
#include "qgsfeaturesource.h"
#include "qgsvectordataprovider.h"
#include "qgspoint.h"
#include "qgsgeometry.h"
#include "qgsdistancearea.h"
#include 'qgswkbtypes.h"
#include <QString>
#include <QtAlgorithms>
Expand Down Expand Up @@ -102,15 +102,15 @@ bool TiePointInfoCompare( const TiePointInfo &a, const TiePointInfo &b )
return a.mFirstPoint.x() == b.mFirstPoint.x() ? a.mFirstPoint.y() < b.mFirstPoint.y() : a.mFirstPoint.x() < b.mFirstPoint.x();
}
QgsVectorLayerDirector::QgsVectorLayerDirector( QgsVectorLayer *myLayer,
QgsVectorLayerDirector::QgsVectorLayerDirector( QgsFeatureSource *source,
int directionFieldId,
const QString &directDirectionValue,
const QString &reverseDirectionValue,
const QString &bothDirectionValue,
const Direction defaultDirection
)
{
mVectorLayer = myLayer;
mSource = source;
mDirectionFieldId = directionFieldId;
mDirectDirectionValue = directDirectionValue;
mReverseDirectionValue = reverseDirectionValue;
Expand All @@ -126,23 +126,18 @@ QString QgsVectorLayerDirector::name() const
void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPointXY > &additionalPoints,
QVector< QgsPointXY > &snappedPoints ) const
{
QgsVectorLayer *vl = mVectorLayer;

if ( !vl )
return;

int featureCount = ( int ) vl->featureCount() * 2;
int featureCount = ( int ) mSource->featureCount() * 2;
int step = 0;
QgsCoordinateTransform ct;
ct.setSourceCrs( vl->crs() );
ct.setSourceCrs( mSource->sourceCrs() );
if ( builder->coordinateTransformationEnabled() )
{
ct.setDestinationCrs( builder->destinationCrs() );
}
else
{
ct.setDestinationCrs( vl->crs() );
ct.setDestinationCrs( mSource->sourceCrs() );
}
snappedPoints = QVector< QgsPointXY >( additionalPoints.size(), QgsPointXY( 0.0, 0.0 ) );
Expand All @@ -156,7 +151,7 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
//Graph's points;
QVector< QgsPointXY > points;
QgsFeatureIterator fit = vl->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( QgsAttributeList() ) );
QgsFeatureIterator fit = mSource->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( QgsAttributeList() ) );
// begin: tie points to the graph
QgsAttributeList la;
Expand Down Expand Up @@ -276,7 +271,7 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
} // end fill attribute list 'la'
// begin graph construction
fit = vl->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( la ) );
fit = mSource->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( la ) );
while ( fit.nextFeature( feature ) )
{
Direction directionType = mDefaultDirection;
Expand Down Expand Up @@ -388,5 +383,5 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
} // for (it = pl.begin(); it != pl.end(); ++it)
}
emit buildProgress( ++step, featureCount );
} // while( vl->nextFeature(feature) )
} // while( mSource->nextFeature(feature) )
} // makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPointXY >& additionalPoints, QVector< QgsPointXY >& tiedPoint )
8 changes: 4 additions & 4 deletions src/analysis/network/qgsvectorlayerdirector.h
Expand Up @@ -22,7 +22,7 @@
#include "qgis_analysis.h"

class QgsGraphBuilderInterface;
class QgsVectorLayer;
class QgsFeatureSource;

/**
* \ingroup analysis
Expand Down Expand Up @@ -51,15 +51,15 @@ class ANALYSIS_EXPORT QgsVectorLayerDirector : public QgsGraphDirector

/**
* Default constructor
* \param myLayer source vector layer
* \param source feature source representing network
* \param directionFieldId field containing direction value
* \param directDirectionValue value for direct one-way road
* \param reverseDirectionValue value for reversed one-way road
* \param bothDirectionValue value for two-way (bidirectional) road
* \param defaultDirection default direction. Will be used if corresponding
* attribute value is not set or does not equal to the given values
*/
QgsVectorLayerDirector( QgsVectorLayer *myLayer,
QgsVectorLayerDirector( QgsFeatureSource *source,
int directionFieldId,
const QString &directDirectionValue,
const QString &reverseDirectionValue,
Expand All @@ -79,7 +79,7 @@ class ANALYSIS_EXPORT QgsVectorLayerDirector : public QgsGraphDirector
QString name() const override;

private:
QgsVectorLayer *mVectorLayer = nullptr;
QgsFeatureSource *mSource = nullptr;
int mDirectionFieldId;
QString mDirectDirectionValue;
QString mReverseDirectionValue;
Expand Down

0 comments on commit 126a274

Please sign in to comment.