-
-
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.
Launch python bindings for network analysis library
- Loading branch information
1 parent
abb5f4c
commit 776d7df
Showing
7 changed files
with
298 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
%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 |
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 out() const; | ||
|
||
/** | ||
* return index of incoming vertex | ||
*/ | ||
int in() 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,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(); | ||
}; | ||
|
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 ); | ||
|
||
}; | ||
|