Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
also sipify QgsGraphAnalyzer
  • Loading branch information
alexbruy authored and 3nids committed May 4, 2017
1 parent 77d34dd commit f626613
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 20 deletions.
61 changes: 44 additions & 17 deletions python/analysis/network/qgsgraphanalyzer.sip
@@ -1,19 +1,37 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/network/qgsgraphanalyzer.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsGraphAnalyzer
{
%TypeHeaderCode
#include <qgsgraphanalyzer.h>
%Docstring
This class performs graph analysis, e.g. calculates shortest path between two
points using different strategies with Dijkstra algorithm
%End

%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 arc property as optimization criterion
* @param resultTree array represents the shortest path tree. resultTree[ vertexIndex ] == inboundingArcIndex if vertex reacheble and resultTree[ vertexIndex ] == -1 others.
* @param resultCost array of cost paths
*/
static SIP_PYLIST dijkstra( const QgsGraph *source, int startVertexIdx, int criterionNum );

static SIP_PYLIST void dijkstra( const QgsGraph *source, int startVertexIdx, int criterionNum, QVector<int> *resultTree = 0, QVector<double> *resultCost = 0 );
%Docstring
Solve shortest path problem using Dijkstra algorithm
\param source source graph
\param startVertexIdx index of the start vertex
\param criterionNum index of the optimization strategy
\param resultTree array that represents shortest path tree. resultTree[ vertexIndex ] == inboundingArcIndex if vertex reachable, otherwise resultTree[ vertexIndex ] == -1
\param resultCost array of the paths costs
%End

%MethodCode
QVector< int > treeResult;
QVector< double > costResult;
Expand Down Expand Up @@ -43,11 +61,20 @@ class QgsGraphAnalyzer
PyTuple_SET_ITEM( sipRes, 1, l2 );
%End

/**
* 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 );
%Docstring
Returns shortest path tree with root-node in startVertexIdx
\param source source graph
\param startVertexIdx index of the start vertex
\param criterionNum index of the optimization strategy
:rtype: QgsGraph
%End
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/network/qgsgraphanalyzer.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
4 changes: 2 additions & 2 deletions scripts/sipify.pl
Expand Up @@ -22,8 +22,8 @@ sub processDoxygenLine
$line =~ s/::/./g;
# replace nullptr with None (nullptr means nothing to Python devs)
$line =~ s/\bnullptr\b/None/g;
# replace \returns with :return:
$line =~ s/\\return(s)?/:return:/g;
# replace \returns with :return:
$line =~ s/\\return(s)?/:return:/g;

if ( $line =~ m/[\\@](ingroup|class)/ ) {
return ""
Expand Down
33 changes: 32 additions & 1 deletion src/analysis/network/qgsgraphanalyzer.h
Expand Up @@ -38,7 +38,38 @@ class ANALYSIS_EXPORT QgsGraphAnalyzer
* \param resultTree array that represents shortest path tree. resultTree[ vertexIndex ] == inboundingArcIndex if vertex reachable, otherwise resultTree[ vertexIndex ] == -1
* \param resultCost array of the paths costs
*/
static void dijkstra( const QgsGraph *source, int startVertexIdx, int criterionNum, QVector<int> *resultTree = nullptr, QVector<double> *resultCost = nullptr );
static SIP_PYLIST void dijkstra( const QgsGraph *source, int startVertexIdx, int criterionNum, QVector<int> *resultTree = nullptr, QVector<double> *resultCost = nullptr );

#ifdef SIP_RUN
% MethodCode
QVector< int > treeResult;
QVector< double > costResult;
QgsGraphAnalyzer::dijkstra( a0, a1, a2, &treeResult, &costResult );

PyObject *l1 = PyList_New( treeResult.size() );
if ( l1 == NULL )
{
return NULL;
}
PyObject *l2 = PyList_New( costResult.size() );
if ( l2 == NULL )
{
return NULL;
}
int i;
for ( i = 0; i < costResult.size(); ++i )
{
PyObject *Int = PyLong_FromLong( treeResult[i] );
PyList_SET_ITEM( l1, i, Int );
PyObject *Float = PyFloat_FromDouble( costResult[i] );
PyList_SET_ITEM( l2, i, Float );
}

sipRes = PyTuple_New( 2 );
PyTuple_SET_ITEM( sipRes, 0, l1 );
PyTuple_SET_ITEM( sipRes, 1, l2 );
% End
#endif

/**
* Returns shortest path tree with root-node in startVertexIdx
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgis.h
Expand Up @@ -506,3 +506,9 @@ typedef unsigned long long qgssize;
* Class level annotation for abstract classes
*/
#define SIP_ABSTRACT

/*
* This is a PyObject * that is a Python list object
* http://pyqt.sourceforge.net/Docs/sip4/specification_files.html#additional-sip-types
*/
#define SIP_PYLIST

0 comments on commit f626613

Please sign in to comment.