Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #49 from stopa85/network-analysis
Network analysis and road-graph-plugin
  • Loading branch information
mhugent committed Sep 30, 2011
2 parents a2713fd + a950830 commit ee19294
Show file tree
Hide file tree
Showing 41 changed files with 1,893 additions and 994 deletions.
1 change: 1 addition & 0 deletions Doxyfile
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions doc/modules.dox
Expand Up @@ -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.
*/
7 changes: 7 additions & 0 deletions python/CMakeLists.txt
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions python/analysis/network/networkanalysis.sip
@@ -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
43 changes: 43 additions & 0 deletions python/analysis/network/qgsarcproperter.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;
};
12 changes: 12 additions & 0 deletions python/analysis/network/qgsdistancearcproperter.sip
@@ -0,0 +1,12 @@

class QgsDistanceArcProperter : QgsArcProperter
{
%TypeHeaderCode
#include <qgsdistancearcproperter.h>
%End

public:
virtual QVariant property( double distance, const QgsFeature& ) const;

};

130 changes: 130 additions & 0 deletions python/analysis/network/qgsgraph.sip
@@ -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;
};

27 changes: 27 additions & 0 deletions python/analysis/network/qgsgraphanalyzer.sip
@@ -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 );
};

33 changes: 33 additions & 0 deletions python/analysis/network/qgsgraphbuilder.sip
@@ -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/;
};

64 changes: 64 additions & 0 deletions python/analysis/network/qgsgraphbuilderintr.sip
@@ -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 );

};

0 comments on commit ee19294

Please sign in to comment.