Permalink
Browse files

Merge pull request #49 from stopa85/network-analysis

Network analysis and road-graph-plugin
  • Loading branch information...
2 parents a2713fd + a950830 commit ee19294562b00c6ce957945f14c1727210cffdf7 @mhugent mhugent committed Sep 30, 2011
Showing with 1,893 additions and 994 deletions.
  1. +1 −0 Doxyfile
  2. +5 −0 doc/modules.dox
  3. +7 −0 python/CMakeLists.txt
  4. +13 −0 python/analysis/network/networkanalysis.sip
  5. +43 −0 python/analysis/network/qgsarcproperter.sip
  6. +12 −0 python/analysis/network/qgsdistancearcproperter.sip
  7. +130 −0 python/analysis/network/qgsgraph.sip
  8. +27 −0 python/analysis/network/qgsgraphanalyzer.sip
  9. +33 −0 python/analysis/network/qgsgraphbuilder.sip
  10. +64 −0 python/analysis/network/qgsgraphbuilderintr.sip
  11. +54 −0 python/analysis/network/qgsgraphdirector.sip
  12. +41 −0 python/analysis/network/qgslinevectorlayerdirector.sip
  13. +1 −1 src/analysis/CMakeLists.txt
  14. +67 −0 src/analysis/network/CMakeLists.txt
  15. +54 −0 src/analysis/network/qgsarcproperter.h
  16. +18 −0 src/analysis/network/qgsdistancearcproperter.cpp
  17. +30 −0 src/analysis/network/qgsdistancearcproperter.h
  18. +139 −0 src/analysis/network/qgsgraph.cpp
  19. +180 −0 src/analysis/network/qgsgraph.h
  20. +114 −0 src/analysis/network/qgsgraphanalyzer.cpp
  21. +53 −0 src/analysis/network/qgsgraphanalyzer.h
  22. +51 −0 src/analysis/network/qgsgraphbuilder.cpp
  23. +22 −20 src/{plugins/roadgraph/simplegraphbuilder.h → analysis/network/qgsgraphbuilder.h}
  24. +111 −0 src/analysis/network/qgsgraphbuilderintr.h
  25. +26 −13 src/{plugins/roadgraph/graphdirector.h → analysis/network/qgsgraphdirector.h}
  26. +399 −0 src/analysis/network/qgslinevectorlayerdirector.cpp
  27. +26 −34 src/{plugins/roadgraph/linevectorlayerdirector.h → analysis/network/qgslinevectorlayerdirector.h}
  28. +4 −6 src/plugins/roadgraph/CMakeLists.txt
  29. +0 −45 src/plugins/roadgraph/graphbuilder.cpp
  30. +0 −73 src/plugins/roadgraph/graphbuilder.h
  31. +0 −291 src/plugins/roadgraph/linevectorlayerdirector.cpp
  32. +2 −2 src/plugins/roadgraph/linevectorlayerwidget.cpp
  33. +28 −83 src/plugins/roadgraph/roadgraphplugin.cpp
  34. +2 −9 src/plugins/roadgraph/roadgraphplugin.h
  35. +57 −45 src/plugins/roadgraph/shortestpathwidget.cpp
  36. +3 −3 src/plugins/roadgraph/shortestpathwidget.h
  37. +0 −64 src/plugins/roadgraph/simplegraphbuilder.cpp
  38. +42 −0 src/plugins/roadgraph/speedproperter.cpp
  39. +34 −0 src/plugins/roadgraph/speedproperter.h
  40. +0 −167 src/plugins/roadgraph/utils.cpp
  41. +0 −138 src/plugins/roadgraph/utils.h
View
@@ -603,6 +603,7 @@ INPUT = doc \
src/analysis/interpolation \
src/analysis/raster \
src/analysis/vector \
+ src/analysis/network \
src/plugins
# This tag can be used to specify the character encoding of the source files
View
@@ -17,3 +17,8 @@ high level tools for carrying out spatial analysis on vector and raster data.
*/
/** @defgroup MapComposer */
+
+/** @defgroup networkanalysis QGIS network analysis library.
+
+The network analysis library provides high level tool for build topology and analysis it.
+*/
View
@@ -80,14 +80,21 @@ ADD_SIP_PYTHON_MODULE(qgis.gui gui/gui.sip qgis_core qgis_gui)
# additional analysis includes
INCLUDE_DIRECTORIES(
../src/analysis/vector
+ ../src/analysis/network
${CMAKE_BINARY_DIR}/src/analysis/vector
+ ${CMAKE_BINARY_DIR}/src/analysis/network
)
# analysis module
FILE(GLOB sip_files_analysis analysis/*.sip)
SET(SIP_EXTRA_FILES_DEPEND ${sip_files_core} ${sip_files_analysis})
ADD_SIP_PYTHON_MODULE(qgis.analysis analysis/analysis.sip qgis_core qgis_analysis)
+# network-analysis module
+FILE(GLOB sip_files_network_analysis analysis/network/*.sip)
+SET(SIP_EXTRA_FILES_DEPEND ${sip_files_core} ${sip_files_network_analysis})
+ADD_SIP_PYTHON_MODULE(qgis.networkanalysis analysis/network/networkanalysis.sip qgis_core qgis_networkanalysis)
+
SET (QGIS_PYTHON_DIR ${PYTHON_SITE_PACKAGES_DIR}/qgis)
ADD_CUSTOM_TARGET(compile_python_files ALL)
@@ -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
@@ -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;
+};
@@ -0,0 +1,12 @@
+
+class QgsDistanceArcProperter : QgsArcProperter
+{
+%TypeHeaderCode
+#include <qgsdistancearcproperter.h>
+%End
+
+ public:
+ virtual QVariant property( double distance, const QgsFeature& ) const;
+
+};
+
@@ -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;
+};
+
@@ -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 );
+};
+
@@ -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/;
+};
+
@@ -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.

0 comments on commit ee19294

Please sign in to comment.