Skip to content
Permalink
Browse files

[network analysis] expose speed properter in C++ and Python API

This allows users to calculate shortest path using travel time
as optimization criteria in addition to travel distance.
  • Loading branch information
alexbruy committed Nov 21, 2016
1 parent ee71077 commit 3c3e17ac90e7b3b761ac8a081ac53941da06cbc5
@@ -2,14 +2,15 @@
// fix to allow compilation with sip 4.7 that for some reason
// doesn't add these includes to the file where the code from
// ConvertToSubClassCode goes.
#include <qgsspeedarcproperter.h>
#include <qgsdistancearcproperter.h>
%End

/**
* \ingroup networkanalysis
* \class QgsEdgeProperter
* \brief QgsEdgeProperter is a strategy pattern.
* You can use it for customize arc property. For example look at QgsDistanceArcProperter or src/plugins/roadgraph/speedproperter.h
* \class QgsArcProperter
* \brief QgsArcProperter is a strategy pattern.
* You can use it for customize arc property. For example look at QgsDistanceArcProperter or QgsSpeedArcProperter
*/
class QgsArcProperter
{
@@ -1,4 +1,3 @@

class QgsDistanceArcProperter : QgsArcProperter
{
%TypeHeaderCode
@@ -1,7 +1,7 @@
/**
* \ingroup networkanalysis
* \class QgsGraphArc
* \brief This class implement a graph edge
* \brief This class implements a graph edge
*/
class QgsGraphArc
{
@@ -40,7 +40,7 @@ typedef QList< int > QgsGraphArcIdList;
/**
* \ingroup networkanalysis
* \class QgsGraphVertex
* \brief This class implement a graph vertex
* \brief This class implements a graph vertex
*/
class QgsGraphVertex
{
@@ -0,0 +1,13 @@
class QgsSpeedArcProperter : QgsArcProperter
{
%TypeHeaderCode
#include <qgsspeedarcproperter.h>
%End

public:
QgsSpeedArcProperter( int attributeId, double defaultValue, double toMetricFactor );

QVariant property( double distance, const QgsFeature& f ) const;

QgsAttributeList requiredAttributes() const;
};
@@ -6,6 +6,7 @@
SET(QGIS_NETWORK_ANALYSIS_SRCS
qgsgraph.cpp
qgsgraphbuilder.cpp
qgsspeedarcproperter.cpp
qgsdistancearcproperter.cpp
qgslinevectorlayerdirector.cpp
qgsgraphanalyzer.cpp
@@ -27,6 +28,7 @@ SET(QGIS_NETWORK_ANALYSIS_HDRS
qgsgraphbuilderintr.h
qgsgraphbuilder.h
qgsarcproperter.h
qgsspeedarcproperter.h
qgsdistancearcproperter.h
qgsgraphdirector.h
qgslinevectorlayerdirector.h
@@ -1,5 +1,5 @@
/***************************************************************************
qgsedgeproperter.h
qgsarcproperter.h
--------------------------------------
Date : 2011-04-01
Copyright : (C) 2010 by Yakushev Sergey
@@ -13,21 +13,19 @@
* *
***************************************************************************/

#ifndef QGSEDGEPROPERTERH
#define QGSEDGEPROPERTERH
#ifndef QGSARCROPERTER_H
#define QGSARCROPERTER_H

// QT4 includes
#include <QVariant>

// QGIS includes
#include <qgsfeature.h>
#include <qgsfeaturerequest.h>

/**
* \ingroup networkanalysis
* \class QgsArcProperter
* \brief QgsArcProperter is a strategy pattern.
* You can use it for customize arc property. For example look at QgsDistanceArcProperter or src/plugins/roadgraph/speedproperter.h
* You can use it for customize arc property. For example look at QgsDistanceArcProperter and QgsSpeedArcProperter
*/
class ANALYSIS_EXPORT QgsArcProperter
{
@@ -56,4 +54,4 @@ class ANALYSIS_EXPORT QgsArcProperter
return QVariant();
}
};
#endif //QGSEDGEPROPERTYH
#endif // QGSARCROPERTER_H
@@ -1,15 +1,18 @@
/***************************************************************************
* Copyright (C) 2011 by Sergey Yakushev *
* yakushevs <at >list.ru *
* *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
qgsdistancearcproperter.h
--------------------------------------
Date : 2011-04-01
Copyright : (C) 2010 by Yakushev Sergey
Email : YakushevS <at> list.ru
****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

//QGIS includes
#include "qgsdistancearcproperter.h"

QVariant QgsDistanceArcProperter::property( double distance, const QgsFeature& f ) const
@@ -1,5 +1,5 @@
/***************************************************************************
qgsedgeproperter.h
qgsdistancearcproperter.h
--------------------------------------
Date : 2011-04-01
Copyright : (C) 2010 by Yakushev Sergey
@@ -13,8 +13,8 @@
* *
***************************************************************************/

#ifndef QGSEDGEDISTANCEPROPERTERH
#define QGSEDGEDISTANCEPROPERTERH
#ifndef QGSDISTANCEARCPROPERTER_H
#define QGSDISTANCEARCPROPERTER_H

// QT4 includes
#include <QVariant>
@@ -30,4 +30,5 @@ class ANALYSIS_EXPORT QgsDistanceArcProperter : public QgsArcProperter
public:
virtual QVariant property( double distance, const QgsFeature& ) const override;
};
#endif //QGSEDGEDISTANCEPROPERTYH

#endif // QGSDISTANCEARCPROPERTER_H
@@ -23,23 +23,21 @@
* \file qgsgraph.h
*/

#ifndef QGSGRAPHH
#define QGSGRAPHH
#ifndef QGSGRAPH_H
#define QGSGRAPH_H

// QT4 includes
#include <QList>
#include <QVector>
#include <QVariant>

// QGIS includes
#include "qgspoint.h"

class QgsGraphVertex;

/**
* \ingroup networkanalysis
* \class QgsGraphArc
* \brief This class implement a graph edge
* \brief This class implements a graph edge
*/
class ANALYSIS_EXPORT QgsGraphArc
{
@@ -83,14 +81,14 @@ typedef QList< int > QgsGraphArcIdList;
/**
* \ingroup networkanalysis
* \class QgsGraphVertex
* \brief This class implement a graph vertex
* \brief This class implements a graph vertex
*/
class ANALYSIS_EXPORT QgsGraphVertex
{
public:

/**
* default constructor. It need for QT's container, e.g. QVector
* default constructor. It needed for Qt's container, e.g. QVector
*/
QgsGraphVertex() {}

@@ -137,7 +135,7 @@ class ANALYSIS_EXPORT QgsGraph
// begin graph constructing methods

/**
* add vertex to a grap
* add vertex to a graph
*/
int addVertex( const QgsPoint& pt );

@@ -178,4 +176,4 @@ class ANALYSIS_EXPORT QgsGraph
QVector<QgsGraphArc> mGraphArc;
};

#endif //QGSGRAPHH
#endif // QGSGRAPH_H
@@ -14,15 +14,13 @@
* (at your option) any later version. *
* *
***************************************************************************/
// C++ standard includes

#include <limits>

// QT includes
#include <QMap>
#include <QVector>
#include <QPair>

//QGIS-uncludes
#include "qgsgraph.h"
#include "qgsgraphanalyzer.h"

@@ -49,7 +47,7 @@ void QgsGraphAnalyzer::dijkstra( const QgsGraph* source, int startPointIdx, int
}

// QMultiMap< cost, vertexIdx > not_begin
// I use it and not create any struct or class.
// I use it and don't create any struct or class
QMultiMap< double, int > not_begin;
QMultiMap< double, int >::iterator it;

@@ -108,7 +106,7 @@ QgsGraph* QgsGraphAnalyzer::shortestTree( const QgsGraph* source, int startVerte
}
}

// Add arcs to result
// Add arcs to the result
for ( i = 0; i < source->vertexCount(); ++i )
{
if ( tree[ i ] != -1 )
@@ -15,17 +15,15 @@
* *
***************************************************************************/

#ifndef QGSGRAPHANALYZERH
#define QGSGRAPHANALYZERH
#ifndef QGSGRAPHANALYZER_H
#define QGSGRAPHANALYZER_H

//QT-includes
#include <QVector>

// forward-declaration
class QgsGraph;

/** \ingroup networkanalysis
* The QGis class provides graph analysis functions
* QGIS class with graph analysis functions
*/

class ANALYSIS_EXPORT QgsGraphAnalyzer
@@ -34,20 +32,21 @@ class ANALYSIS_EXPORT QgsGraphAnalyzer

/**
* solve shortest path problem using dijkstra algorithm
* @param source The source graph
* @param startVertexIdx index of start vertex
* @param criterionNum index of arc property as optimization criterion
* @param resultTree array represents the shortest path tree. resultTree[ vertexIndex ] == inboundingArcIndex if vertex reacheble and resultTree[ vertexIndex ] == -1 others.
* @param source source graph
* @param startVertexIdx index of the start vertex
* @param criterionNum index of the arc property as optimization criterion
* @param resultTree array represents the shortest path tree. resultTree[ vertexIndex ] == inboundingArcIndex if vertex reachable, otherwise resultTree[ vertexIndex ] == -1
* @param resultCost array of cost paths
*/
static void dijkstra( const QgsGraph* source, int startVertexIdx, int criterionNum, QVector<int>* resultTree = nullptr, QVector<double>* resultCost = nullptr );

/**
* return shortest path tree with root-node in startVertexIdx
* @param source The source graph
* @param startVertexIdx index of start vertex
* @param criterionNum index of edge property as optimization criterion
* @param source source graph
* @param startVertexIdx index of the start vertex
* @param criterionNum index of the edge property as optimization criterion
*/
static QgsGraph* shortestTree( const QgsGraph* source, int startVertexIdx, int criterionNum );
};
#endif //QGSGRAPHANALYZERH

#endif // QGSGRAPHANALYZER_H
@@ -1,13 +1,17 @@
/***************************************************************************
* Copyright (C) 2010 by Sergey Yakushev *
* yakushevs <at> list.ru *
* *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
qgsgraphbuilder.cpp
--------------------------------------
Date : 2010-10-25
Copyright : (C) 2010 by Yakushev Sergey
Email : YakushevS@list.ru
****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/**
* \file qgsgraphbuilder.cpp
@@ -17,7 +21,6 @@
#include "qgsgraphbuilder.h"
#include "qgsgraph.h"

// Qgis includes
#include <qgsfeature.h>
#include <qgsgeometry.h>

@@ -12,25 +12,22 @@
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSGRAPHBUILDERH
#define QGSGRAPHBUILDERH

#include "qgsgraphbuilderintr.h"
#ifndef QGSGRAPHBUILDER_H
#define QGSGRAPHBUILDER_H

//QT4 includes
#include "qgsgraphbuilderintr.h"

//QGIS includes
#include <qgsspatialindex.h>

//forward declarations
class QgsDistanceArea;
class QgsCoordinateTransform;
class QgsGraph;

/**
* \ingroup networkanalysis
* \class QgsGraphBuilder
* \brief This class making the QgsGraph object
* \brief This class is used for making the QgsGraph object
*/

class ANALYSIS_EXPORT QgsGraphBuilder : public QgsGraphBuilderInterface
@@ -60,4 +57,5 @@ class ANALYSIS_EXPORT QgsGraphBuilder : public QgsGraphBuilderInterface

QgsGraph *mGraph;
};
#endif //QGSGRAPHBUILDERH

#endif // QGSGRAPHBUILDER_H

0 comments on commit 3c3e17a

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