-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from stopa85/network-analysis
Network analysis and road-graph-plugin
- Loading branch information
Showing
41 changed files
with
1,893 additions
and
994 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
%Module qgis.networkanalysis 0 | ||
|
||
%Import QtCore/QtCoremod.sip | ||
%Import core/core.sip | ||
|
||
%Include qgsgraph.sip | ||
%Include qgsarcproperter.sip | ||
%Include qgsdistancearcproperter.sip | ||
%Include qgsgraphbuilderintr.sip | ||
%Include qgsgraphbuilder.sip | ||
%Include qgsgraphdirector.sip | ||
%Include qgslinevectorlayerdirector.sip | ||
%Include qgsgraphanalyzer.sip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
%ModuleHeaderCode | ||
// 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 <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 | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsarcproperter.h> | ||
%End | ||
|
||
%ConvertToSubClassCode | ||
if ( dynamic_cast< QgsDistanceArcProperter* > ( sipCpp ) != NULL ) | ||
sipClass = sipClass_QgsDistanceArcProperter; | ||
else | ||
sipClass = NULL; | ||
%End | ||
|
||
public: | ||
/** | ||
* default constructor | ||
*/ | ||
QgsArcProperter(); | ||
|
||
/** | ||
* QgsGraphDirector call this method for fetching attribute from source layer | ||
* \return required attributes list | ||
*/ | ||
virtual QgsAttributeList requiredAttributes() const; | ||
|
||
/** | ||
* calculate and return adge property | ||
*/ | ||
virtual QVariant property( double distance, const QgsFeature& f ) const; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
class QgsDistanceArcProperter : QgsArcProperter | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsdistancearcproperter.h> | ||
%End | ||
|
||
public: | ||
virtual QVariant property( double distance, const QgsFeature& ) const; | ||
|
||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/** | ||
* \ingroup networkanalysis | ||
* \class QgsGraphEdge | ||
* \brief This class implement a graph edge | ||
*/ | ||
class QgsGraphArc | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsgraph.h> | ||
%End | ||
public: | ||
QgsGraphArc(); | ||
|
||
/** | ||
* return property value | ||
* @param propertyIndex property index | ||
*/ | ||
QVariant property(int propertyIndex ) const; | ||
|
||
/** | ||
* get array of proertyes | ||
*/ | ||
QVector< QVariant > properties() const; | ||
|
||
/** | ||
* return index of outgoing vertex | ||
*/ | ||
int outVertex() const; | ||
|
||
/** | ||
* return index of incoming vertex | ||
*/ | ||
int inVertex() const; | ||
}; | ||
|
||
|
||
typedef QList< int > QgsGraphArcIdList; | ||
|
||
/** | ||
* \ingroup networkanalysis | ||
* \class QgsGraphVertex | ||
* \brief This class implement a graph vertex | ||
*/ | ||
class QgsGraphVertex | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsgraph.h> | ||
%End | ||
public: | ||
/** | ||
* default constructor. It need for QT's container, e.g. QVector | ||
*/ | ||
QgsGraphVertex(); | ||
|
||
/** | ||
* This constructor initializes QgsGraphVertex object and associates a vertex with a point | ||
*/ | ||
|
||
QgsGraphVertex( const QgsPoint& point ); | ||
|
||
/** | ||
* return outgoing edges | ||
*/ | ||
QgsGraphArcIdList outArc() const; | ||
|
||
/** | ||
* return incoming edges | ||
*/ | ||
QgsGraphArcIdList inArc() const; | ||
|
||
/** | ||
* return vertex point | ||
*/ | ||
QgsPoint point() const; | ||
}; | ||
|
||
/** | ||
* \ingroup networkanalysis | ||
* \class QgsGraph | ||
* \brief Mathematics graph representation | ||
*/ | ||
|
||
class QgsGraph | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsgraph.h> | ||
%End | ||
public: | ||
QgsGraph(); | ||
|
||
~QgsGraph(); | ||
|
||
// begin graph constructing methods | ||
/** | ||
* add vertex to a grap | ||
*/ | ||
int addVertex( const QgsPoint& pt ); | ||
|
||
/** | ||
* add edge to a graph | ||
*/ | ||
int addArc( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& properties ); | ||
|
||
/** | ||
* retrun vertex count | ||
*/ | ||
int vertexCount() const; | ||
|
||
/** | ||
* return vertex at index | ||
*/ | ||
const QgsGraphVertex& vertex( int idx ) const; | ||
|
||
/** | ||
* retrun edge count | ||
*/ | ||
int arcCount() const; | ||
|
||
/** | ||
* retrun edge at index | ||
*/ | ||
const QgsGraphArc& arc( int idx ) const; | ||
|
||
/** | ||
* find vertex by point | ||
* \return vertex index | ||
*/ | ||
int findVertex( const QgsPoint& pt ) const; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class QgsGraphAnalyzer | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsgraphanalyzer.h> | ||
%End | ||
|
||
public: | ||
/** | ||
* solve shortest path problem using dijkstra algorithm | ||
* @param source The source graph | ||
* @param startVertexIdx index of start vertex | ||
* @param criterionNum index of edge property as optimization criterion | ||
* @param destPointCost array of vertex indexes. Function calculating shortest path costs for vertices with these indexes | ||
* @param cost array of cost paths | ||
* @param treeResult return shortest path tree | ||
*/ | ||
// static void shortestpath( const QgsGraph* source, int startVertexIdx, int criterionNum, const QVector<int>& destPointCost, QVector<double>& cost, QgsGraph* treeResult ); | ||
|
||
/** | ||
* 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 | ||
*/ | ||
static QgsGraph* shortestTree( const QgsGraph* source, int startVertexIdx, int criterionNum ); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* \ingroup networkanalysis | ||
* \class QgsGraphBuilder | ||
* \brief This class making the QgsGraph object | ||
*/ | ||
|
||
class QgsGraphBuilder : QgsGraphBuilderInterface | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsgraphbuilder.h> | ||
%End | ||
|
||
public: | ||
/** | ||
* default constructor | ||
*/ | ||
QgsGraphBuilder( const QgsCoordinateReferenceSystem& crs, bool otfEnabled = true, double topologyTolerance = 0.0, const QString& ellipsoidID = "WGS84" ); | ||
|
||
~QgsGraphBuilder(); | ||
|
||
/* | ||
* MANDATORY BUILDER PROPERTY DECLARATION | ||
*/ | ||
virtual void addVertex( int id, const QgsPoint& pt ); | ||
|
||
virtual void addArc( int pt1id, const QgsPoint& pt1, int pt2id, const QgsPoint& pt2, const QVector< QVariant >& prop ); | ||
|
||
/** | ||
* return QgsGraph result; | ||
*/ | ||
QgsGraph* graph() /Factory/; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
%ModuleHeaderCode | ||
#include <qgsgraphbuilder.h> | ||
%End | ||
|
||
/** | ||
* \ingroup networkanalysis | ||
* \class QgsGraphBuilderInterface | ||
* \brief Determine interface for creating a graph. Contains the settings of the graph. QgsGraphBuilder and QgsGraphDirector is a Builder pattern | ||
*/ | ||
class QgsGraphBuilderInterface | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsgraphbuilderintr.h> | ||
%End | ||
|
||
%ConvertToSubClassCode | ||
if ( dynamic_cast< QgsGraphBuilder* > ( sipCpp ) != NULL ) | ||
sipClass = sipClass_QgsGraphBuilder; | ||
else | ||
sipClass = NULL; | ||
%End | ||
|
||
public: | ||
/** | ||
* QgsGraphBuilderInterface constructor | ||
* @param crs Coordinate reference system for new graph vertex | ||
* @param ctfEnabled enable coordinate transform from source graph CRS to CRS graph | ||
* @param topologyTolerance sqrt distance between source point as one graph vertex | ||
* @param ellipsoidID ellipsoid for edge measurement | ||
*/ | ||
QgsGraphBuilderInterface( const QgsCoordinateReferenceSystem& crs, bool ctfEnabled = true, double topologyTolerance = 0.0, const QString& ellipsoidID = "WGS84" ); | ||
|
||
QgsCoordinateReferenceSystem& destinationCrs(); | ||
|
||
//! get coordinate transformation enabled | ||
bool coordinateTransformationEnabled(); | ||
|
||
//! get topology tolerance | ||
double topologyTolerance(); | ||
|
||
//! get measurement tool | ||
QgsDistanceArea* distanceArea(); | ||
|
||
/** | ||
* add vertex | ||
* @param id vertex identyficator | ||
* @param pt vertex coordinate | ||
* @note id and pt is a redundant interface. You can use coordinates or id for vertex identyfy | ||
*/ | ||
virtual void addVertex( int id, const QgsPoint& pt ); | ||
|
||
/** | ||
* add arc | ||
* @param pt1id first vertex identificator | ||
* @param pt1 first vertex coordinate | ||
* @param pt2id second vertex identificator | ||
* @param pt2 second vertex coordinate | ||
* @param properties arc properties | ||
* @note pt1id, pt1 and pt2id, pt2 is a redundant interface. You can use vertex coordinates or their identificators. | ||
*/ | ||
virtual void addArc( int pt1id, const QgsPoint& pt1, int pt2id, const QgsPoint& pt2, const QVector< QVariant >& properties ); | ||
|
||
}; | ||
|
Oops, something went wrong.