mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Launch python bindings for network analysis library
This commit is contained in:
parent
abb5f4c670
commit
776d7dfbd4
@ -71,7 +71,9 @@ 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
|
||||
@ -79,6 +81,10 @@ 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)
|
||||
|
||||
|
10
python/analysis/network/networkanalysis.sip
Normal file
10
python/analysis/network/networkanalysis.sip
Normal file
@ -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
|
43
python/analysis/network/qgsarcproperter.sip
Normal file
43
python/analysis/network/qgsarcproperter.sip
Normal file
@ -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
python/analysis/network/qgsdistancearcproperter.sip
Normal file
12
python/analysis/network/qgsdistancearcproperter.sip
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
class QgsDistanceArcProperter : QgsArcProperter
|
||||
{
|
||||
%TypeHeaderCode
|
||||
#include <qgsdistancearcproperter.h>
|
||||
%End
|
||||
|
||||
public:
|
||||
virtual QVariant property( double distance, const QgsFeature& ) const;
|
||||
|
||||
};
|
||||
|
130
python/analysis/network/qgsgraph.sip
Normal file
130
python/analysis/network/qgsgraph.sip
Normal file
@ -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;
|
||||
};
|
||||
|
33
python/analysis/network/qgsgraphbuilder.sip
Normal file
33
python/analysis/network/qgsgraphbuilder.sip
Normal file
@ -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();
|
||||
};
|
||||
|
64
python/analysis/network/qgsgraphbuilderintr.sip
Normal file
64
python/analysis/network/qgsgraphbuilderintr.sip
Normal file
@ -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 );
|
||||
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user