QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
analysis
network
qgsgraph.h
Go to the documentation of this file.
1
/***************************************************************************
2
qgsgraph.h
3
--------------------------------------
4
Date : 2011-04-01
5
Copyright : (C) 2010 by Yakushev Sergey
6
Email : YakushevS <at> list.ru
7
****************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
/*
17
* This file describes the built-in QGIS classes for modeling a mathematical graph.
18
* Vertices are identified by their geographic coordinates and have no additional
19
* properties. Number of strategies for calculating edge cost is not limited.
20
* Graph may have incidence edges.
21
*
22
* \file qgsgraph.h
23
*/
24
25
#ifndef QGSGRAPH_H
26
#define QGSGRAPH_H
27
28
#include "qgis_analysis.h"
29
#include "
qgspointxy.h
"
30
31
#include <QList>
32
#include <QVariant>
33
#include <QVector>
34
35
class
QgsGraphVertex
;
36
37
43
class
ANALYSIS_EXPORT
QgsGraphEdge
44
{
45
public
:
46
QgsGraphEdge
() =
default
;
47
52
QVariant
cost
(
int
strategyIndex )
const
;
53
57
QVector<QVariant>
strategies
()
const
;
58
63
int
toVertex
()
const
;
64
69
int
fromVertex
()
const
;
70
71
private
:
72
QVector<QVariant> mStrategies;
73
74
int
mToIdx = 0;
75
int
mFromIdx = 0;
76
77
friend
class
QgsGraph
;
78
};
79
80
81
typedef
QList<int>
QgsGraphEdgeIds
;
82
88
class
ANALYSIS_EXPORT
QgsGraphVertex
89
{
90
public
:
91
QgsGraphVertex
() =
default
;
92
96
97
QgsGraphVertex
(
const
QgsPointXY
&
point
);
98
103
QgsGraphEdgeIds
incomingEdges
()
const
;
104
109
QgsGraphEdgeIds
outgoingEdges
()
const
;
110
114
QgsPointXY
point
()
const
;
115
116
private
:
117
QgsPointXY
mCoordinate;
118
QgsGraphEdgeIds
mIncomingEdges;
119
QgsGraphEdgeIds
mOutgoingEdges;
120
121
friend
class
QgsGraph
;
122
};
123
129
130
class
ANALYSIS_EXPORT
QgsGraph
131
{
132
public
:
133
QgsGraph
() =
default
;
134
135
// Graph constructing methods
136
142
int
addVertex
(
const
QgsPointXY
&pt );
143
150
int
addEdge
(
int
fromVertexIdx,
int
toVertexIdx,
const
QVector<QVariant> &strategies );
151
155
int
vertexCount
()
const
;
156
157
#ifndef SIP_RUN
158
162
const
QgsGraphVertex
&
vertex
(
int
idx )
const
;
163
#else
164
170
QgsGraphVertex
vertex
(
int
idx )
const
;
171
//%MethodCode
172
if
( sipCpp->hasVertex( a0 ) )
173
{
174
return
sipConvertFromNewType(
new
QgsGraphVertex
( sipCpp->vertex( a0 ) ), sipType_QgsGraphVertex, Py_None );
175
}
176
else
177
{
178
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
179
sipIsErr = 1;
180
}
181
//%End
182
#endif
183
184
#ifndef SIP_RUN
185
193
void
removeVertex(
int
index );
194
#else
195
204
void
removeVertex(
int
index );
205
//%MethodCode
206
if
( sipCpp->hasVertex( a0 ) )
207
{
208
sipCpp->removeVertex( a0 );
209
}
210
else
211
{
212
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
213
sipIsErr = 1;
214
}
215
//%End
216
#endif
217
221
int
edgeCount()
const
;
222
223
#ifndef SIP_RUN
224
228
const
QgsGraphEdge &edge(
int
idx )
const
;
229
#else
230
236
QgsGraphEdge edge(
int
idx )
const
;
237
//%MethodCode
238
if
( sipCpp->hasEdge( a0 ) )
239
{
240
return
sipConvertFromNewType(
new
QgsGraphEdge( sipCpp->edge( a0 ) ), sipType_QgsGraphEdge, Py_None );
241
}
242
else
243
{
244
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
245
sipIsErr = 1;
246
}
247
//%End
248
#endif
249
250
251
#ifndef SIP_RUN
252
261
void
removeEdge(
int
index );
262
#else
263
273
void
removeEdge(
int
index );
274
//%MethodCode
275
if
( sipCpp->hasEdge( a0 ) )
276
{
277
sipCpp->removeEdge( a0 );
278
}
279
else
280
{
281
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
282
sipIsErr = 1;
283
}
284
//%End
285
#endif
286
291
int
findVertex(
const
QgsPointXY &pt )
const
;
292
293
#ifndef SIP_RUN
294
306
int
findOppositeEdge(
int
index )
const
;
307
#else
308
322
int
findOppositeEdge(
int
index )
const
;
323
//%MethodCode
324
if
( sipCpp->hasEdge( a0 ) )
325
{
326
sipRes = sipCpp->findOppositeEdge( a0 );
327
}
328
else
329
{
330
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
331
sipIsErr = 1;
332
}
333
//%End
334
#endif
335
341
bool
hasEdge(
int
index )
const
;
342
348
bool
hasVertex(
int
index )
const
;
349
350
protected
:
351
#ifndef SIP_RUN
353
QHash<int, QgsGraphVertex>
mGraphVertices
;
354
356
QHash<int, QgsGraphEdge>
mGraphEdges
;
357
#endif
358
359
360
private
:
361
int
mNextVertexId = 0;
362
int
mNextEdgeId = 0;
363
};
364
365
#endif
// QGSGRAPH_H
QgsGraphEdge::fromVertex
int fromVertex() const
Returns the index of the vertex at the start of this edge.
Definition
qgsgraph.cpp:180
QgsGraphEdge::strategies
QVector< QVariant > strategies() const
Returns array of available strategies.
Definition
qgsgraph.cpp:175
QgsGraphEdge::toVertex
int toVertex() const
Returns the index of the vertex at the end of this edge.
Definition
qgsgraph.cpp:185
QgsGraphEdge::QgsGraphEdge
QgsGraphEdge()=default
QgsGraphEdge::QgsGraph
friend class QgsGraph
Definition
qgsgraph.h:77
QgsGraphEdge::cost
QVariant cost(int strategyIndex) const
Returns edge cost calculated using specified strategy.
Definition
qgsgraph.cpp:170
QgsGraphVertex
Represents vertex in a graph.
Definition
qgsgraph.h:89
QgsGraphVertex::outgoingEdges
QgsGraphEdgeIds outgoingEdges() const
Returns outgoing edge ids, i.e.
Definition
qgsgraph.cpp:199
QgsGraphVertex::incomingEdges
QgsGraphEdgeIds incomingEdges() const
Returns the incoming edge ids, i.e.
Definition
qgsgraph.cpp:194
QgsGraphVertex::point
QgsPointXY point() const
Returns point associated with graph vertex.
Definition
qgsgraph.cpp:204
QgsGraphVertex::QgsGraphVertex
QgsGraphVertex()=default
QgsGraphVertex::QgsGraph
friend class QgsGraph
Definition
qgsgraph.h:121
QgsGraph::vertex
const QgsGraphVertex & vertex(int idx) const
Returns the vertex at the given index.
Definition
qgsgraph.cpp:48
QgsGraph::addEdge
int addEdge(int fromVertexIdx, int toVertexIdx, const QVector< QVariant > &strategies)
Add an edge to the graph, going from the fromVertexIdx to toVertexIdx.
Definition
qgsgraph.cpp:31
QgsGraph::mGraphVertices
QHash< int, QgsGraphVertex > mGraphVertices
Graph vertices.
Definition
qgsgraph.h:353
QgsGraph::addVertex
int addVertex(const QgsPointXY &pt)
Add a vertex to the graph.
Definition
qgsgraph.cpp:25
QgsGraph::mGraphEdges
QHash< int, QgsGraphEdge > mGraphEdges
Graph edges.
Definition
qgsgraph.h:356
QgsGraph::vertexCount
int vertexCount() const
Returns number of graph vertices.
Definition
qgsgraph.cpp:116
QgsGraph::QgsGraph
QgsGraph()=default
QgsPointXY
Represents a 2D point.
Definition
qgspointxy.h:62
QgsGraphEdgeIds
QList< int > QgsGraphEdgeIds
Definition
qgsgraph.h:81
qgspointxy.h
Generated on
for QGIS API Documentation by
1.17.0