Skip to content
Permalink
Browse files

Merge pull request #4872 from alexbruy/network-api

[API] small improvements for network analysis API
  • Loading branch information
alexbruy committed Jul 17, 2017
2 parents 246685b + 09bb55a commit 6c0cb2f5c02645e8dc591f96e4acc1691987bd36
@@ -361,8 +361,6 @@ Data Providers {#qgis_api_break_3_0_DataProviders}
- mAttrPalIndexName: overwrite palAttributeIndexNames()




Qgis {#qgis_api_break_3_0_Qgis}
----

@@ -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.


@@ -2512,6 +2510,18 @@ QgsRendererAbstractMetadata {#qgis_api_break_3_0_QgsRendererAbstractMetadata}

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

QgsGraphDirector {#qgis_api_break_3_0_QgsGraphDirector}
----------------

- makeGraph() now uses QgsFeedback for progress reporting and cancelation
- buildProgress() signal was removed
- buildMessage() signal was removed

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

- QgsVectorLayerDirector() constructor now expects a reference to QgsFeatureSource as the first argument
- makeGraph() now uses QgsFeedback for progress reporting and cancelation

Processing {#qgis_api_break_3_0_Processing}
----------
@@ -31,29 +31,21 @@ class QgsGraphDirector : QObject
else
sipType = NULL;
%End
signals:
void buildProgress( int, int ) const;
%Docstring
Emitted to report graph building progress
%End
void buildMessage( const QString & ) const;
%Docstring
Emitted to report information about graph building
%End

public:

virtual ~QgsGraphDirector();

virtual void makeGraph( QgsGraphBuilderInterface *builder,
const QVector< QgsPointXY > &additionalPoints,
QVector< QgsPointXY > &snappedPoints /Out/ ) const;
QVector< QgsPointXY > &snappedPoints /Out/,
QgsFeedback *feedback = 0 ) const;
%Docstring
Make a graph using QgsGraphBuilder

\param builder the graph builder
\param additionalPoints list of points that should be snapped to the graph
\param snappedPoints list of snapped points
\param feedback feedback object for reporting progress
.. note::

if snappedPoints[i] == QgsPointXY(0.0,0.0) then snapping failed.
@@ -29,7 +29,7 @@ class QgsVectorLayerDirector : QgsGraphDirector
DirectionBoth,
};

QgsVectorLayerDirector( QgsVectorLayer *myLayer,
QgsVectorLayerDirector( QgsFeatureSource *source,
int directionFieldId,
const QString &directDirectionValue,
const QString &reverseDirectionValue,
@@ -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
@@ -51,7 +51,8 @@ class QgsVectorLayerDirector : QgsGraphDirector

virtual void makeGraph( QgsGraphBuilderInterface *builder,
const QVector< QgsPointXY > &additionalPoints,
QVector< QgsPointXY> &snappedPoints /Out/ ) const;
QVector< QgsPointXY> &snappedPoints /Out/,
QgsFeedback *feedback = 0 ) const;
%Docstring
MANDATORY DIRECTOR PROPERTY DECLARATION
%End
@@ -20,8 +20,9 @@
#include <QVector>
#include <QList>

#include <qgis.h>
#include <qgspoint.h>
#include "qgis.h"
#include "qgspoint.h"
#include "qgsfeedback.h"
#include "qgsnetworkstrategy.h"
#include "qgis_analysis.h"

@@ -53,12 +54,6 @@ class ANALYSIS_EXPORT QgsGraphDirector : public QObject

Q_OBJECT

signals:
//! Emitted to report graph building progress
void buildProgress( int, int ) const;
//! Emitted to report information about graph building
void buildMessage( const QString & ) const;

public:

virtual ~QgsGraphDirector() { }
@@ -69,15 +64,18 @@ class ANALYSIS_EXPORT QgsGraphDirector : public QObject
* \param builder the graph builder
* \param additionalPoints list of points that should be snapped to the graph
* \param snappedPoints list of snapped points
* \param feedback feedback object for reporting progress
* \note if snappedPoints[i] == QgsPointXY(0.0,0.0) then snapping failed.
*/
virtual void makeGraph( QgsGraphBuilderInterface *builder,
const QVector< QgsPointXY > &additionalPoints,
QVector< QgsPointXY > &snappedPoints SIP_OUT ) const
QVector< QgsPointXY > &snappedPoints SIP_OUT,
QgsFeedback *feedback = nullptr ) const
{
Q_UNUSED( builder );
Q_UNUSED( additionalPoints );
Q_UNUSED( snappedPoints );
Q_UNUSED( feedback );
}

//! Add optimization strategy
@@ -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>
@@ -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;
@@ -124,25 +124,20 @@ QString QgsVectorLayerDirector::name() const
}

void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPointXY > &additionalPoints,
QVector< QgsPointXY > &snappedPoints ) const
QVector< QgsPointXY > &snappedPoints, QgsFeedback *feedback ) 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 ) );
@@ -156,13 +151,18 @@ 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;
QgsFeature feature;
while ( fit.nextFeature( feature ) )
{
if ( feedback && feedback->isCanceled() )
{
return;
}

QgsMultiPolyline mpl;
if ( QgsWkbTypes::flatType( feature.geometry().geometry()->wkbType() ) == QgsWkbTypes::MultiLineString )
mpl = feature.geometry().asMultiPolyline();
@@ -212,7 +212,11 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
isFirstPoint = false;
}
}
emit buildProgress( ++step, featureCount );
if ( feedback )
{
feedback->setProgress( 100.0 * static_cast< double >( ++step ) / featureCount );
}

}
// end: tie points to graph

@@ -276,9 +280,14 @@ 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 ) )
{
if ( feedback && feedback->isCanceled() )
{
return;
}

Direction directionType = mDefaultDirection;

// What direction have feature?
@@ -387,6 +396,10 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
isFirstPoint = false;
} // for (it = pl.begin(); it != pl.end(); ++it)
}
emit buildProgress( ++step, featureCount );
} // while( vl->nextFeature(feature) )
if ( feedback )
{
feedback->setProgress( 100.0 * static_cast< double >( ++step ) / featureCount );
}

} // while( mSource->nextFeature(feature) )
} // makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPointXY >& additionalPoints, QVector< QgsPointXY >& tiedPoint )
@@ -22,7 +22,7 @@
#include "qgis_analysis.h"

class QgsGraphBuilderInterface;
class QgsVectorLayer;
class QgsFeatureSource;

/**
* \ingroup analysis
@@ -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,
@@ -74,12 +74,13 @@ class ANALYSIS_EXPORT QgsVectorLayerDirector : public QgsGraphDirector
*/
void makeGraph( QgsGraphBuilderInterface *builder,
const QVector< QgsPointXY > &additionalPoints,
QVector< QgsPointXY> &snappedPoints SIP_OUT ) const override;
QVector< QgsPointXY> &snappedPoints SIP_OUT,
QgsFeedback *feedback = nullptr ) const override;

QString name() const override;

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

0 comments on commit 6c0cb2f

Please sign in to comment.
You can’t perform that action at this time.