Skip to content

Commit

Permalink
Merge pull request #3773 from alexbruy/network-analysis
Browse files Browse the repository at this point in the history
Network analysis
nyalldawson authored Nov 21, 2016
2 parents 8c8be00 + 82082b4 commit 3dcf03c
Showing 55 changed files with 797 additions and 899 deletions.
2 changes: 1 addition & 1 deletion cmake/QsciAPI.cmake
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ ENDIF(EXISTS "${CMAKE_BINARY_DIR}/python/qgis.gui.api")
# add qgis.core.NULL attribute defined in <src>/python/__init__.py for QPyNullVariant
FILE(APPEND "${QGIS_PYTHON_API_FILE}" "qgis.core.NULL?7\n")

FOREACH(apiFile qgis.core.api qgis.gui.api qgis.analysis.api qgis.networkanalysis.api qgis.server.api)
FOREACH(apiFile qgis.core.api qgis.gui.api qgis.analysis.api qgis.server.api)
SET(api "${CMAKE_BINARY_DIR}/python/${apiFile}")
IF(EXISTS "${api}")
FILE(READ "${api}" FILE_CONTENT)
14 changes: 0 additions & 14 deletions debian/control
Original file line number Diff line number Diff line change
@@ -129,18 +129,6 @@ Description: QGIS - shared analysis library
.
This package contains the shared analysis library.

Package: libqgis-networkanalysis2.99.0
Architecture: any
Section: libs
Depends:
${shlibs:Depends},
${misc:Depends}
Description: QGIS - shared network analysis library
QGIS is a Geographic Information System (GIS) which manages, analyzes and
display databases of geographic information.
.
This package contains the shared network analysis library.

Package: libqgisgrass7-2.99.0
Architecture: any
Section: libs
@@ -204,7 +192,6 @@ Depends:
libqgis-core2.99.0 (= ${binary:Version}),
libqgis-gui2.99.0 (= ${binary:Version}),
libqgis-analysis2.99.0 (= ${binary:Version}),
libqgis-networkanalysis2.99.0 (= ${binary:Version}),
libqgisgrass7-2.99.0 (= ${binary:Version}),
libqgispython2.99.0 (= ${binary:Version}),
libsqlite3-dev,
@@ -241,7 +228,6 @@ Depends:
libqgis-core2.99.0 (= ${binary:Version}),
libqgis-gui2.99.0 (= ${binary:Version}),
libqgis-analysis2.99.0 (= ${binary:Version}),
libqgis-networkanalysis2.99.0 (= ${binary:Version}),
libqgisgrass7-2.99.0 (= ${binary:Version}),
libqgispython2.99.0 (= ${binary:Version}),
${misc:Depends}
14 changes: 0 additions & 14 deletions debian/control.in
Original file line number Diff line number Diff line change
@@ -132,18 +132,6 @@ Description: QGIS - shared analysis library
.
This package contains the shared analysis library.

Package: libqgis-networkanalysis{QGIS_ABI}
Architecture: any
Section: libs
Depends:
${shlibs:Depends},
${misc:Depends}
Description: QGIS - shared network analysis library
QGIS is a Geographic Information System (GIS) which manages, analyzes and
display databases of geographic information.
.
This package contains the shared network analysis library.

Package: libqgisgrass{GRASSVER}-{QGIS_ABI}
Architecture: any
Section: libs
@@ -207,7 +195,6 @@ Depends:
libqgis-core{QGIS_ABI} (= ${binary:Version}),
libqgis-gui{QGIS_ABI} (= ${binary:Version}),
libqgis-analysis{QGIS_ABI} (= ${binary:Version}),
libqgis-networkanalysis{QGIS_ABI} (= ${binary:Version}),
libqgisgrass{GRASSVER}-{QGIS_ABI} (= ${binary:Version}),
libqgispython{QGIS_ABI} (= ${binary:Version}),
libsqlite3-dev,
@@ -244,7 +231,6 @@ Depends:
libqgis-core{QGIS_ABI} (= ${binary:Version}),
libqgis-gui{QGIS_ABI} (= ${binary:Version}),
libqgis-analysis{QGIS_ABI} (= ${binary:Version}),
libqgis-networkanalysis{QGIS_ABI} (= ${binary:Version}),
libqgisgrass{GRASSVER}-{QGIS_ABI} (= ${binary:Version}),
libqgispython{QGIS_ABI} (= ${binary:Version}),
${misc:Depends}
1 change: 0 additions & 1 deletion debian/libqgis-dev.install.in
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ usr/lib/libqgis_app.so
usr/lib/libqgis_core.so
usr/lib/libqgis_gui.so
usr/lib/libqgis_analysis.so
usr/lib/libqgis_networkanalysis.so
#server#usr/lib/libqgis_server.so
usr/lib/libqgisgrass{GRASSVER}.so
usr/lib/libqgispython.so
1 change: 0 additions & 1 deletion debian/libqgis-networkanalysis{QGIS_ABI}.install

This file was deleted.

1 change: 0 additions & 1 deletion debian/libqgis-networkanalysis{QGIS_ABI}.lintian-overrides

This file was deleted.

1 change: 0 additions & 1 deletion debian/python-qgis.install.in
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ usr/lib/python*/*-packages/qgis/*.so
usr/lib/python*/*-packages/qgis/core/*
usr/lib/python*/*-packages/qgis/gui/*
usr/lib/python*/*-packages/qgis/analysis/*
usr/lib/python*/*-packages/qgis/networkanalysis/*
usr/lib/python*/*-packages/qgis/PyQt/*
usr/lib/python*/*-packages/qgis/testing/*
usr/lib/python*/*-packages/pyspatialite/*
17 changes: 16 additions & 1 deletion doc/api_break.dox
Original file line number Diff line number Diff line change
@@ -180,6 +180,9 @@ Renamed Classes {#qgis_api_break_3_0_renamed_classes}
<tr><td>QgsVectorRandomColorRampV2Dialog<td>QgsLimitedRandomColorRampDialog
<tr><td>QgsVectorRandomColorRampV2DialogBase<td>QgsLimitedRandomColorRampDialogBase
<tr><th>QgsSymbolV2<th>QgsSymbol
<tr><th>QgsArcProperter<th>QgsStrategy
<tr><th>QgsDistanceArcProperter<th>QgsDistanceStrategy
<tr><th>QgsGraphArc<th>QgsGraphEdge
</table>

<table>
@@ -205,6 +208,17 @@ Renamed Classes {#qgis_api_break_3_0_renamed_classes}
<tr><td>QgsVectorLayerEditUtils<td>deleteVertexV2<td>deleteVertex
<tr><td>QgsComposerSymbolItem<td>symbolV2<td>symbol
<tr><td>QgsServerInterface<td>capabiblitiesCache<td>capabilitiesCache
<tr><td>QgsGraphEdge<td>property<td>cost
<tr><td>QgsGraphEdge<td>properties<td>strategies
<tr><td>QgsGraphVertex<td>outArc<td>outEdges
<tr><td>QgsGraphVertex<td>inArc<td>inEdges
<tr><td>QgsGraph<td>addArc<td>addEdges
<tr><td>QgsGraph<td>arcCount<td>edgeCount
<tr><td>QgsGraph<td>arc<td>edge
<tr><td>QgsGraphBuilder<td>addArc<td>addEdge
<tr><td>QgsGraphBuilderInterface<td>addArc<td>addEdge
<tr><td>QgsGraphDirectory<td>addProperter<td>addStrategy
<tr><td>QgsStrategy<td>addProperter<td>addStrategy
</table>


@@ -251,6 +265,7 @@ General changes {#qgis_api_break_3_0_global}
- All importXML() methods have been renamed to importXml()
- All methods taking or returning QGis::WkbType have been changed to use QgsWkbTypes::Type
- All methods taking or returning QGis::GeometryType have been changed to use QgsWkbTypes::GeometryType
- Network analysis library has been merged into analysis library


Data Providers {#qgis_api_break_3_0_DataProviders}
@@ -768,7 +783,7 @@ QgsEditFormConfig {#qgis_api_break_3_0_QgsEditFormConfig}
- widgetType() and widgetConfig() now reflect only the user configured values.
QgsEditorWidgetRegistry::instance()->findBest() must be used instead.
- widgetType(), widgetConfig(), setWidgetType(), setWidgetConfig() and removeWidgetConfig() now only take a string as first parameter. Access by index has been removed.
- expression(), setExpression(), expressionDescription() and setExpressionDescription()
- expression(), setExpression(), expressionDescription() and setExpressionDescription()
have been removed. Use QgsVectorLayer.setConstraintExpression()/constraintExpression(),
or QgsField.constraintExpression()/QgsField.constraintDescription() instead.
- notNull() and setNotNull() have been removed. Use QgsVectorLayer.setFieldConstraint()/fieldConstraints(), or QgsField.constraints() instead.
10 changes: 3 additions & 7 deletions doc/modules.dox
Original file line number Diff line number Diff line change
@@ -12,14 +12,10 @@ The GUI library is build on top of the CORE library and adds reusable GUI widget

/** @defgroup analysis analysis library

The ANALYSIS library is built on top of CORE library and provides
The ANALYSIS library is built on top of CORE library and provides
high level tools for carrying out spatial analysis on vector and raster data.
*/

/** @defgroup networkanalysis network analysis library

The NETWORK_ANALYSIS library provides high level tools for building network
topologies and analysing them.
It also contains high level tools for building network topologies and analysing
them.
*/

/** @defgroup server server library
1 change: 0 additions & 1 deletion ms-windows/osgeo4w/package.cmd
Original file line number Diff line number Diff line change
@@ -299,7 +299,6 @@ tar -C %OSGEO4W_ROOT% -cjf %ARCH%/release/qgis/%PACKAGENAME%-common/%PACKAGENAME
--exclude "*.pyc" ^
"apps/%PACKAGENAME%/bin/qgispython.dll" ^
"apps/%PACKAGENAME%/bin/qgis_analysis.dll" ^
"apps/%PACKAGENAME%/bin/qgis_networkanalysis.dll" ^
"apps/%PACKAGENAME%/bin/qgis_core.dll" ^
"apps/%PACKAGENAME%/bin/qgis_gui.dll" ^
"apps/%PACKAGENAME%/doc/" ^
20 changes: 7 additions & 13 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -138,20 +138,20 @@ IF(NOT QT_MOBILITY_LOCATION_FOUND)
SET(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} MOBILITY_LOCATION)
ENDIF(NOT QT_MOBILITY_LOCATION_FOUND)

IF(PYQT4_VERSION_NUM LESS 263680) # 0x040600
IF(PYQT4_VERSION_NUM LESS 263680) # 0x040600
SET(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} PROXY_FACTORY)
ENDIF(PYQT4_VERSION_NUM LESS 263680)

#
IF(NOT PYQT4_VERSION_NUM LESS 264194) # 0x040802
IF(NOT PYQT4_VERSION_NUM LESS 264194) # 0x040802
SET(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} QSETTYPE_CONVERSION)
ENDIF(NOT PYQT4_VERSION_NUM LESS 264194)

IF(PYQT4_VERSION_NUM LESS 264196) # 0x040804
SET(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} QLISTCONSTPTR_CONVERSION)
ENDIF(PYQT4_VERSION_NUM LESS 264196)

IF(NOT PYQT4_VERSION_NUM LESS 264453) # 0x040905
IF(NOT PYQT4_VERSION_NUM LESS 264453) # 0x040905
SET(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} QVECTORINT_CONVERSION)
ENDIF(NOT PYQT4_VERSION_NUM LESS 264453)

@@ -200,7 +200,7 @@ ENDIF(UNIX AND NOT SIP_VERSION_NUM LESS 265984)
GENERATE_SIP_PYTHON_MODULE_CODE(qgis._gui gui/gui.sip cpp_files)
BUILD_SIP_PYTHON_MODULE(qgis._gui gui/gui.sip ${cpp_files} "" qgis_core qgis_gui)

SET(PY_MODULES core gui analysis networkanalysis)
SET(PY_MODULES core gui analysis)

# server module
IF (WITH_SERVER AND WITH_SERVER_PLUGINS)
@@ -228,8 +228,8 @@ INCLUDE_DIRECTORIES(
../src/analysis/interpolation
../src/analysis/openstreetmap
${CMAKE_BINARY_DIR}/src/analysis/vector
${CMAKE_BINARY_DIR}/src/analysis/network
${CMAKE_BINARY_DIR}/src/analysis/raster
${CMAKE_BINARY_DIR}/src/analysis/network
${CMAKE_BINARY_DIR}/src/analysis/interpolation
${CMAKE_BINARY_DIR}/src/analysis/openstreetmap
)
@@ -239,6 +239,7 @@ FILE(GLOB sip_files_analysis
analysis/*.sip
analysis/raster/*.sip
analysis/vector/*.sip
analysis/network/*.sip
analysis/interpolation/*.sip
analysis/openstreetmap/*.sip
)
@@ -247,21 +248,14 @@ SET(SIP_EXTRA_OPTIONS ${PYQT_SIP_FLAGS} -o -a ${CMAKE_BINARY_DIR}/python/qgis.an
GENERATE_SIP_PYTHON_MODULE_CODE(qgis._analysis analysis/analysis.sip cpp_files)
BUILD_SIP_PYTHON_MODULE(qgis._analysis analysis/analysis.sip ${cpp_files} "" qgis_core qgis_analysis)

# network-analysis module
FILE(GLOB_RECURSE sip_files_network_analysis analysis/network/*.sip)
SET(SIP_EXTRA_FILES_DEPEND ${sip_files_core} ${sip_files_network_analysis})
SET(SIP_EXTRA_OPTIONS ${PYQT_SIP_FLAGS} -o -a ${CMAKE_BINARY_DIR}/python/qgis.networkanalysis.api)
GENERATE_SIP_PYTHON_MODULE_CODE(qgis._networkanalysis analysis/network/networkanalysis.sip cpp_files)
BUILD_SIP_PYTHON_MODULE(qgis._networkanalysis networkanalysis/networkanalysis.sip ${cpp_files} "" qgis_core qgis_networkanalysis)

SET(QGIS_PYTHON_DIR ${PYTHON_SITE_PACKAGES_DIR}/qgis)

IF(WITH_QSCIAPI)
# wait until after python module builds for api files to be available
SET(QGIS_PYTHON_API_FILE "${CMAKE_BINARY_DIR}/python/qsci_apis/PyQGIS.api")

ADD_CUSTOM_TARGET(qsci-api ALL
DEPENDS python_module_qgis__gui python_module_qgis__core python_module_qgis__analysis python_module_qgis__networkanalysis)
DEPENDS python_module_qgis__gui python_module_qgis__core python_module_qgis__analysis)

# run update/concatenate command
ADD_CUSTOM_COMMAND(TARGET qsci-api
10 changes: 10 additions & 0 deletions python/analysis/analysis.sip
Original file line number Diff line number Diff line change
@@ -52,3 +52,13 @@
%Include raster/qgsruggednessfilter.sip
%Include raster/qgsslopefilter.sip
%Include raster/qgstotalcurvaturefilter.sip

%Include network/qgsgraph.sip
%Include network/qgsnetworkstrategy.sip
%Include network/qgsnetworkspeedstrategy.sip
%Include network/qgsnetworkdistancestrategy.sip
%Include network/qgsgraphbuilderinterface.sip
%Include network/qgsgraphbuilder.sip
%Include network/qgsgraphdirector.sip
%Include network/qgsvectorlayerdirector.sip
%Include network/qgsgraphanalyzer.sip
15 changes: 0 additions & 15 deletions python/analysis/network/networkanalysis.sip

This file was deleted.

45 changes: 0 additions & 45 deletions python/analysis/network/qgsarcproperter.sip

This file was deleted.

10 changes: 0 additions & 10 deletions python/analysis/network/qgsdistancearcproperter.sip

This file was deleted.

69 changes: 35 additions & 34 deletions python/analysis/network/qgsgraph.sip
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
/**
* \ingroup networkanalysis
* \class QgsGraphArc
* \brief This class implement a graph edge
* \ingroup analysis
* \class QgsGraphEdge
* \brief This class implements a graph edge
*/
class QgsGraphArc
class QgsGraphEdge
{
%TypeHeaderCode
#include <qgsgraph.h>
%End

public:
QgsGraphArc();
QgsGraphEdge();

/**
* return property value
* @param propertyIndex property index
* Returns edge cost calculated using specified strategy
* @param strategyIndex strategy index
*/
QVariant property( int propertyIndex ) const;
QVariant cost( int strategyIndex ) const;

/**
* get array of properties
* Returns array of available strategies
*/
QVector< QVariant > properties() const;
QVector< QVariant > strategies() const;

/**
* return index of outgoing vertex
* Returns index of the outgoing vertex
*/
int outVertex() const;

/**
* return index of incoming vertex
* Returns index of the incoming vertex
*/
int inVertex() const;
};


typedef QList< int > QgsGraphArcIdList;
typedef QList< int > QgsGraphEdgeIds;

/**
* \ingroup networkanalysis
* \ingroup analysis
* \class QgsGraphVertex
* \brief This class implement a graph vertex
* \brief This class implements a graph vertex
*/
class QgsGraphVertex
{
@@ -50,7 +50,7 @@ class QgsGraphVertex

public:
/**
* default constructor. It need for QT's container, e.g. QVector
* Default constructor. It is needed for Qt's container, e.g. QVector
*/
QgsGraphVertex();

@@ -61,25 +61,25 @@ class QgsGraphVertex
QgsGraphVertex( const QgsPoint& point );

/**
* return outgoing edges
* Returns outgoing edges ids
*/
QgsGraphArcIdList outArc() const;
QgsGraphEdgeIds outEdges() const;

/**
* return incoming edges
* Return incoming edges ids
*/
QgsGraphArcIdList inArc() const;
QgsGraphEdgeIds inEdges() const;

/**
* return vertex point
* Returns point associated with graph vertex
*/
QgsPoint point() const;
};

/**
* \ingroup networkanalysis
* \ingroup analysis
* \class QgsGraph
* \brief Mathematics graph representation
* \brief Mathematical graph representation
*/

class QgsGraph
@@ -91,39 +91,40 @@ class QgsGraph
public:
QgsGraph();

// begin graph constructing methods
// Graph constructing methods

/**
* add vertex to a grap
* Add a vertex to the graph
*/
int addVertex( const QgsPoint& pt );

/**
* add edge to a graph
* Add an edge to the graph
*/
int addArc( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& properties );
int addEdge( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& strategies );

/**
* return vertex count
* Returns number of graph vertices
*/
int vertexCount() const;

/**
* return vertex at index
* Returns vertex at given index
*/
const QgsGraphVertex& vertex( int idx ) const;

/**
* return edge count
* Returns number of graph edges
*/
int arcCount() const;
int edgeCount() const;

/**
* return edge at index
* Returns edge at given index
*/
const QgsGraphArc& arc( int idx ) const;
const QgsGraphEdge& edge( int idx ) const;

/**
* find vertex by point
* Find vertex by associated point
* \return vertex index
*/
int findVertex( const QgsPoint& pt ) const;
8 changes: 4 additions & 4 deletions python/analysis/network/qgsgraphbuilder.sip
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* \ingroup networkanalysis
* \ingroup analysis
* \class QgsGraphBuilder
* \brief This class making the QgsGraph object
*/
@@ -12,7 +12,7 @@ class QgsGraphBuilder : QgsGraphBuilderInterface

public:
/**
* default constructor
* Default constructor
*/
QgsGraphBuilder( const QgsCoordinateReferenceSystem& crs, bool otfEnabled = true, double topologyTolerance = 0.0, const QString& ellipsoidID = "WGS84" );

@@ -23,10 +23,10 @@ class QgsGraphBuilder : QgsGraphBuilderInterface
*/
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 );
virtual void addEdge( int pt1id, const QgsPoint& pt1, int pt2id, const QgsPoint& pt2, const QVector< QVariant >& prop );

/**
* return QgsGraph result;
* Returns generated QgsGraph
*/
QgsGraph* graph() /Factory/;
};
Original file line number Diff line number Diff line change
@@ -3,14 +3,15 @@
%End

/**
* \ingroup networkanalysis
* \ingroup analysis
* \class QgsGraphBuilderInterface
* \brief Determine interface for creating a graph. Contains the settings of the graph. QgsGraphBuilder and QgsGraphDirector is a Builder pattern
* \brief Determine interface for creating a graph. Contains the settings of the graph.
* QgsGraphBuilder and QgsGraphDirector both use a "builder" design pattern
*/
class QgsGraphBuilderInterface
{
%TypeHeaderCode
#include <qgsgraphbuilderintr.h>
#include <qgsgraphbuilderinterface.h>
%End

%ConvertToSubClassCode
@@ -22,42 +23,45 @@ class QgsGraphBuilderInterface

public:
/**
* QgsGraphBuilderInterface constructor
* Default 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" );

//! Destructor
virtual ~QgsGraphBuilderInterface();

//! Returns destinaltion CRS
QgsCoordinateReferenceSystem destinationCrs() const;

//! get coordinate transformation enabled
//! Returns coordinate transformation enabled
bool coordinateTransformationEnabled();

//! get topology tolerance
//! Returns topology tolerance
double topologyTolerance();

//! get measurement tool
//! Returns measurement tool
QgsDistanceArea* distanceArea();

/**
* add vertex
* Add vertex to the graph
* @param id vertex identifier
* @param pt vertex coordinate
* @param pt vertex coordinates
* @note id and pt are redundant. You can use pt or id to identify the vertex
*/
virtual void addVertex( int id, const QgsPoint &pt );

/**
* add arc
* Add edge to the graph
* @param pt1id first vertex identificator
* @param pt1 first vertex coordinate
* @param pt1 first vertex coordinates
* @param pt2id second vertex identificator
* @param pt2 second vertex coordinate
* @param properties arc properties
* @param pt2 second vertex coordinates
* @param strategies optimization strategies
* @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 );

virtual void addEdge( int pt1id, const QgsPoint& pt1, int pt2id, const QgsPoint& pt2, const QVector< QVariant >& strategies );
};
33 changes: 15 additions & 18 deletions python/analysis/network/qgsgraphdirector.sip
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
%ModuleHeaderCode
#include <qgslinevectorlayerdirector.h>
#include <qgsvectorlayerdirector.h>
%End

/**
* \ingroup networkanalysis
* \ingroup analysis
* \class QgsGraphDirector
* \brief Determine making the graph. QgsGraphBuilder and QgsGraphDirector is a builder patter.
* \brief Determine making the graph. QgsGraphBuilder and QgsGraphDirector
* are implemented using "builder" design patter.
*/
class QgsGraphDirector : QObject
{
@@ -14,8 +15,8 @@ class QgsGraphDirector : QObject
%End

%ConvertToSubClassCode
if ( dynamic_cast< QgsLineVectorLayerDirector* > ( sipCpp ) != NULL )
sipType = sipType_QgsLineVectorLayerDirector;
if ( dynamic_cast< QgsVectorLayerDirector* > ( sipCpp ) != NULL )
sipType = sipType_QgsVectorLayerDirector;
else
sipType = NULL;
%End
@@ -30,25 +31,21 @@ class QgsGraphDirector : QObject
virtual ~QgsGraphDirector();

/**
* Make a graph using RgGraphBuilder
* Make a graph using QgsGraphBuilder
*
* @param builder The graph builder
*
* @param additionalPoints Vector of points that must be tied to the graph
*
* @param tiedPoints Vector of tied points
*
* @note if tiedPoints[i]==QgsPoint(0.0,0.0) then tied failed.
* @param builder the graph builder
* @param additionalPoints list of points that should be snapped to the graph
* @param snappedPoints list of snapped points
* @note if snappedPoints[i] == QgsPoint(0.0,0.0) then snapping failed.
*/
virtual void makeGraph( QgsGraphBuilderInterface *builder,
const QVector< QgsPoint > &additionalPoints,
QVector< QgsPoint> &tiedPoints /Out/ );
QVector< QgsPoint > &snappedPoints /Out/ ) const;

void addProperter( QgsArcProperter* prop /Transfer/ );
//! Add optimization strategy
void addStrategy( QgsNetworkStrategy* prop /Transfer/);

/**
* return Director name
*/
//! Returns director name
virtual QString name() const = 0;
};

41 changes: 0 additions & 41 deletions python/analysis/network/qgslinevectorlayerdirector.sip

This file was deleted.

9 changes: 9 additions & 0 deletions python/analysis/network/qgsnetworkdistancestrategy.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class QgsNetworkDistanceStrategy : QgsNetworkStrategy
{
%TypeHeaderCode
#include <qgsnetworkdistancestrategy.h>
%End

public:
virtual QVariant cost( double distance, const QgsFeature& ) const;
};
13 changes: 13 additions & 0 deletions python/analysis/network/qgsnetworkspeedstrategy.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class QgsNetworkSpeedStrategy : QgsNetworkStrategy
{
%TypeHeaderCode
#include <qgsnetworkspeedstrategy.h>
%End

public:
QgsNetworkSpeedStrategy( int attributeId, double defaultValue, double toMetricFactor );

QVariant cost( double distance, const QgsFeature& f ) const;

QgsAttributeList requiredAttributes() const;
};
50 changes: 50 additions & 0 deletions python/analysis/network/qgsnetworkstrategy.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
%ModuleHeaderCode
#include <qgsnetworkspeedstrategy.h>
#include <qgsnetworkdistancestrategy.h>
%End

/**
* \ingroup analysis
* \class QgsNetworkStrategy
* \brief QgsNetworkStrategy defines strategy used for calculation of the edge cost. For example it can
* take into account travel distance, amount of time or money. Currently there are two strategies
* implemented in the analysis library: QgsNetworkDistanceStrategy and QgsNetworkSpeedStrategy.
* QgsNetworkStrategy implemented using "strategy" design pattern.
*/
class QgsNetworkStrategy
{
%TypeHeaderCode
#include <qgsnetworkstrategy.h>
%End

%ConvertToSubClassCode
if ( dynamic_cast< QgsNetworkDistanceStrategy* > ( sipCpp ) != NULL )
sipType = sipType_QgsNetworkDistanceStrategy;
else if ( dynamic_cast< QgsNetworkSpeedStrategy* > ( sipCpp ) != NULL )
sipType = sipType_QgsNetworkSpeedStrategy;
else
sipType = NULL;
%End


public:

/**
* Default constructor
*/
QgsNetworkStrategy();

virtual ~QgsNetworkStrategy();

/**
* Returns list of the source layer attributes needed for cost calculation.
* This method called by QgsGraphDirector.
* \return list of required attributes
*/
virtual QgsAttributeList requiredAttributes() const;

/**
* Returns edge cost
*/
virtual QVariant cost( double distance, const QgsFeature &f ) const = 0;
};
55 changes: 55 additions & 0 deletions python/analysis/network/qgsvectorlayerdirector.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* \ingroup analysis
* \class QgsVectorLayerDirector
* \brief Determine making the graph from vector line layer
*/
class QgsVectorLayerDirector : QgsGraphDirector
{
%TypeHeaderCode
#include <qgsvectorlayerdirector.h>
%End

public:
/** Edge direction
* Edge can be one-way with direct flow (one can move only from the start
* point to the end point), one-way with reversed flow (one can move only
* from the end point to the start point) and bidirectional or two-way
* (one can move in any direction)
*/
enum Direction
{
DirectionForward, //!< One-way direct
DirectionBackward, //!< One-way reversed
DirectionBoth, //!< Two-way
};

/**
* @param myLayer source vector layer
* @param directionFieldId feield contain road direction value
* @param directDirectionValue value for one-way road
* @param reverseDirectionValue value for reverse one-way road
* @param bothDirectionValue value for road
* @param defaultDirection default direction. Will be used if corresponding
* attribute value is not set or does not equal to the given values
*/
QgsVectorLayerDirector( QgsVectorLayer* myLayer,
int directionFieldId,
const QString& directDirectionValue,
const QString& reverseDirectionValue,
const QString& bothDirectionValue,
const Direction defaultDirection
);

//! Destructor
virtual ~QgsVectorLayerDirector();

/*
* MANDATORY DIRECTOR PROPERTY DECLARATION
*/
void makeGraph( QgsGraphBuilderInterface *builder,
const QVector< QgsPoint >& additionalPoints,
QVector< QgsPoint>& snappedPoints /Out/ ) const;

QString name() const;
};

28 changes: 0 additions & 28 deletions python/networkanalysis/__init__.py

This file was deleted.

9 changes: 4 additions & 5 deletions rpm/qgis.spec.template
Original file line number Diff line number Diff line change
@@ -134,11 +134,11 @@ Requires: %{name}%{?_isa} = %{version}-%{release}
# the soname might stay the same, it won't work anymore.
#http://hub.qgis.org/issues/5274
Requires: grass = 6.4.4

%description grass
GRASS plugin for QGIS required to interface with the GRASS system.

%package python
%package python
Summary: Python integration and plug-ins for QGIS
Group: Applications/Engineering
Requires: %{name}%{?_isa} = %{version}-%{release}
@@ -158,7 +158,7 @@ Requires: qscintilla-python
%description python
Python integration and plug-ins for QGIS.

%package server
%package server
Summary: FCGI-based OGC web map server
Group: Applications/Engineering
Requires: %{name}%{?_isa} = %{version}-%{release}
@@ -167,7 +167,7 @@ Provides: mapserver = %{version}-%{release}
Obsoletes: mapserver < 2.8.1-1

%description server
This FastCGI OGC web map server implements OGC WMS 1.3.0 and 1.1.1.
This FastCGI OGC web map server implements OGC WMS 1.3.0 and 1.1.1.
The services are prepared as regular projects in QGIS. They're rendered using
the QGIS libraries. The server also supports SLD (Styled Layer Descriptor)
for styling. Sample configurations for Httpd and Lighttpd are included.
@@ -343,7 +343,6 @@ update-mime-database %{?fedora:-n} %{_datadir}/mime &> /dev/null || :
%{_libdir}/lib%{name}_analysis.so.*
%{_libdir}/lib%{name}_core.so.*
%{_libdir}/lib%{name}_gui.so.*
%{_libdir}/lib%{name}_networkanalysis.so.*
%{_libdir}/lib%{name}_server.so.*
%{_libdir}/%{name}/
%{_qt4_prefix}/plugins/sqldrivers/libqsqlspatialite.so
2 changes: 1 addition & 1 deletion scripts/replacev2.sh
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

set -e

codepaths=$(echo python/{analysis,console,core,custom_widgets,gui,networkanalysis,plugins,pyplugin_installer,server,sip_helpers,testing} src/ tests/)
codepaths=$(echo python/{analysis,console,core,custom_widgets,gui,plugins,pyplugin_installer,server,sip_helpers,testing} src/ tests/)
repl=

s=$(mktemp -t skipped.XXXX.log)
23 changes: 21 additions & 2 deletions src/analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
SUBDIRS(network)

#############################################################
# sources

@@ -48,12 +46,22 @@ SET(QGIS_ANALYSIS_SRCS
openstreetmap/qgsosmdatabase.cpp
openstreetmap/qgsosmdownload.cpp
openstreetmap/qgsosmimport.cpp

network/qgsgraph.cpp
network/qgsgraphbuilder.cpp
network/qgsnetworkspeedstrategy.cpp
network/qgsnetworkdistancestrategy.cpp
network/qgsvectorlayerdirector.cpp
network/qgsgraphanalyzer.cpp
)

SET(QGIS_ANALYSIS_MOC_HDRS
openstreetmap/qgsosmdownload.h
openstreetmap/qgsosmimport.h
vector/qgsgeometrysnapper.h

network/qgsgraphdirector.h
network/qgsvectorlayerdirector.h
)

INCLUDE_DIRECTORIES(SYSTEM ${SPATIALITE_INCLUDE_DIR})
@@ -134,6 +142,16 @@ SET(QGIS_ANALYSIS_HDRS
openstreetmap/qgsosmdatabase.h
openstreetmap/qgsosmdownload.h
openstreetmap/qgsosmimport.h

network/qgsgraph.h
network/qgsgraphbuilderinterface.h
network/qgsgraphbuilder.h
network/qgsnetworkstrategy.h
network/qgsnetworkspeedstrategy.h
network/qgsnetworkdistancestrategy.h
network/qgsgraphdirector.h
network/qgsvectorlayerdirector.h
network/qgsgraphanalyzer.h
)

INCLUDE_DIRECTORIES(
@@ -143,6 +161,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/../core/raster
${CMAKE_CURRENT_SOURCE_DIR}/../core/symbology-ng
interpolation
network
)
INCLUDE_DIRECTORIES(SYSTEM
${PROJ_INCLUDE_DIR}
98 changes: 0 additions & 98 deletions src/analysis/network/CMakeLists.txt

This file was deleted.

19 changes: 0 additions & 19 deletions src/analysis/network/qgsdistancearcproperter.cpp

This file was deleted.

70 changes: 37 additions & 33 deletions src/analysis/network/qgsgraph.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
/***************************************************************************
* Copyright (C) 2011 by Sergey Yakushev *
* yakushevs <at >list.ru *
* *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
qgsgraph.cpp
--------------------------------------
Date : 2011-04-01
Copyright : (C) 2010 by Yakushev Sergey
Email : YakushevS <at> list.ru
****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/**
* \file qgsgraph.cpp
* \brief implementation QgsGraph, QgsGraphVertex, QgsGraphArc
* \brief implementation QgsGraph, QgsGraphVertex, QgsGraphEdge
*/

#include "qgsgraph.h"
@@ -26,40 +30,40 @@ int QgsGraph::addVertex( const QgsPoint& pt )
return mGraphVertexes.size() - 1;
}

int QgsGraph::addArc( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& properties )
int QgsGraph::addEdge( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& strategies )
{
QgsGraphArc e;
QgsGraphEdge e;

e.mProperties = properties;
e.mStrategies = strategies;
e.mOut = outVertexIdx;
e.mIn = inVertexIdx;
mGraphArc.push_back( e );
int edgeIdx = mGraphArc.size() - 1;
mGraphEdges.push_back( e );
int edgeIdx = mGraphEdges.size() - 1;

mGraphVertexes[ outVertexIdx ].mOutArc.push_back( edgeIdx );
mGraphVertexes[ inVertexIdx ].mInArc.push_back( edgeIdx );
mGraphVertexes[ outVertexIdx ].mOutEdges.push_back( edgeIdx );
mGraphVertexes[ inVertexIdx ].mInEdges.push_back( edgeIdx );

return mGraphArc.size() - 1;
return mGraphEdges.size() - 1;
}

const QgsGraphVertex& QgsGraph::vertex( int idx ) const
{
return mGraphVertexes[ idx ];
}

const QgsGraphArc& QgsGraph::arc( int idx ) const
const QgsGraphEdge& QgsGraph::edge( int idx ) const
{
return mGraphArc[ idx ];
return mGraphEdges[ idx ];
}

int QgsGraph::vertexCount() const
{
return mGraphVertexes.size();
}

int QgsGraph::arcCount() const
int QgsGraph::edgeCount() const
{
return mGraphArc.size();
return mGraphEdges.size();
}

int QgsGraph::findVertex( const QgsPoint& pt ) const
@@ -75,29 +79,29 @@ int QgsGraph::findVertex( const QgsPoint& pt ) const
return -1;
}

QgsGraphArc::QgsGraphArc()
QgsGraphEdge::QgsGraphEdge()
: mOut( 0 )
, mIn( 0 )
{

}

QVariant QgsGraphArc::property( int i ) const
QVariant QgsGraphEdge::cost( int i ) const
{
return mProperties[ i ];
return mStrategies[ i ];
}

QVector< QVariant > QgsGraphArc::properties() const
QVector< QVariant > QgsGraphEdge::strategies() const
{
return mProperties;
return mStrategies;
}

int QgsGraphArc::inVertex() const
int QgsGraphEdge::inVertex() const
{
return mIn;
}

int QgsGraphArc::outVertex() const
int QgsGraphEdge::outVertex() const
{
return mOut;
}
@@ -108,14 +112,14 @@ QgsGraphVertex::QgsGraphVertex( const QgsPoint& point )

}

QgsGraphArcIdList QgsGraphVertex::outArc() const
QgsGraphEdgeIds QgsGraphVertex::outEdges() const
{
return mOutArc;
return mOutEdges;
}

QgsGraphArcIdList QgsGraphVertex::inArc() const
QgsGraphEdgeIds QgsGraphVertex::inEdges() const
{
return mInArc;
return mInEdges;
}

QgsPoint QgsGraphVertex::point() const
96 changes: 47 additions & 49 deletions src/analysis/network/qgsgraph.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
graph.h
qgsgraph.h
--------------------------------------
Date : 2011-04-01
Copyright : (C) 2010 by Yakushev Sergey
@@ -14,62 +14,60 @@
***************************************************************************/

/*
* This file describes the built-in QGIS classes modeling a mathematical graph.
* Vertex is identified by its geographic coordinates (but you can add two vertex
* with unique coordinate), no additional properties it can not be assigned.
* Count the number of properties not limited along the arc. Graph may
* be have incidence arcs.
* This file describes the built-in QGIS classes for modeling a mathematical graph.
* Vertices are identified by their geographic coordinates and have no additional
* properties. Number of strategies for calculating edge cost is not limited.
* Graph may have incidence edges.
*
* \file qgsgraph.h
*/

#ifndef QGSGRAPHH
#define QGSGRAPHH
#ifndef QGSGRAPH_H
#define QGSGRAPH_H

// QT4 includes
#include <QList>
#include <QVector>
#include <QVariant>

// QGIS includes
#include "qgspoint.h"

class QgsGraphVertex;

/**
* \ingroup networkanalysis
* \class QgsGraphArc
* \brief This class implement a graph edge
* \ingroup analysis
* \class QgsGraphEdge
* \note added in QGIS 3.0
* \brief This class implements a graph edge
*/
class ANALYSIS_EXPORT QgsGraphArc
class ANALYSIS_EXPORT QgsGraphEdge
{
public:
QgsGraphArc();
QgsGraphEdge();

/**
* return property value
* @param propertyIndex property index
* Returns edge cost calculated using specified strategy
* @param strategyIndex strategy index
*/
QVariant property( int propertyIndex ) const;
QVariant cost( int strategyIndex ) const;

/**
* get array of properties
* Returns array of available strategies
*/
QVector< QVariant > properties() const;
QVector< QVariant > strategies() const;

/**
* return index of outgoing vertex
* Returns index of the outgoing vertex
*/
int outVertex() const;

/**
* return index of incoming vertex
* Returns index of the incoming vertex
*/
int inVertex() const;

private:

QVector< QVariant > mProperties;
QVector< QVariant > mStrategies;

int mOut;
int mIn;
@@ -78,19 +76,19 @@ class ANALYSIS_EXPORT QgsGraphArc
};


typedef QList< int > QgsGraphArcIdList;
typedef QList< int > QgsGraphEdgeIds;

/**
* \ingroup networkanalysis
* \ingroup analysis
* \class QgsGraphVertex
* \brief This class implement a graph vertex
* \brief This class implements a graph vertex
*/
class ANALYSIS_EXPORT QgsGraphVertex
{
public:

/**
* default constructor. It need for QT's container, e.g. QVector
* Default constructor. It is needed for Qt's container, e.g. QVector
*/
QgsGraphVertex() {}

@@ -101,81 +99,81 @@ class ANALYSIS_EXPORT QgsGraphVertex
QgsGraphVertex( const QgsPoint& point );

/**
* return outgoing edges
* Returns outgoing edges ids
*/
QgsGraphArcIdList outArc() const;
QgsGraphEdgeIds outEdges() const;

/**
* return incoming edges
* Return incoming edges ids
*/
QgsGraphArcIdList inArc() const;
QgsGraphEdgeIds inEdges() const;

/**
* return vertex point
* Returns point associated with graph vertex
*/
QgsPoint point() const;

private:
QgsPoint mCoordinate;
QgsGraphArcIdList mOutArc;
QgsGraphArcIdList mInArc;
QgsGraphEdgeIds mOutEdges;
QgsGraphEdgeIds mInEdges;

friend class QgsGraph;
};

/**
* \ingroup networkanalysis
* \ingroup analysis
* \class QgsGraph
* \brief Mathematics graph representation
* \brief Mathematical graph representation
*/

class ANALYSIS_EXPORT QgsGraph
{
public:
QgsGraph();

// begin graph constructing methods
// Graph constructing methods

/**
* add vertex to a grap
* Add a vertex to the graph
*/
int addVertex( const QgsPoint& pt );

/**
* add edge to a graph
* Add an edge to the graph
*/
int addArc( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& properties );
int addEdge( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& strategies );

/**
* return vertex count
* Returns number of graph vertices
*/
int vertexCount() const;

/**
* return vertex at index
* Returns vertex at given index
*/
const QgsGraphVertex& vertex( int idx ) const;

/**
* return edge count
* Returns number of graph edges
*/
int arcCount() const;
int edgeCount() const;

/**
* return edge at index
* Returns edge at given index
*/
const QgsGraphArc& arc( int idx ) const;
const QgsGraphEdge& edge( int idx ) const;

/**
* find vertex by point
* Find vertex by associated point
* \return vertex index
*/
int findVertex( const QgsPoint& pt ) const;

private:
QVector<QgsGraphVertex> mGraphVertexes;

QVector<QgsGraphArc> mGraphArc;
QVector<QgsGraphEdge> mGraphEdges;
};

#endif //QGSGRAPHH
#endif // QGSGRAPH_H
48 changes: 22 additions & 26 deletions src/analysis/network/qgsgraphanalyzer.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
/***************************************************************************
qgsgraphanlyzer.cpp - QGIS Tools for graph analysis
-------------------
begin : 14 april 2011
copyright : (C) Sergey Yakushev
email : Yakushevs@list.ru
***************************************************************************/
qgsgraphanalyzer.cpp
--------------------------------------
Date : 2011-04-14
Copyright : (C) 2010 by Yakushev Sergey
Email : YakushevS <at> list.ru
****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
// C++ standard includes
#include <limits>

// QT includes
#include <QMap>
#include <QVector>
#include <QPair>

//QGIS-uncludes
#include "qgsgraph.h"
#include "qgsgraphanalyzer.h"

@@ -49,7 +45,7 @@ void QgsGraphAnalyzer::dijkstra( const QgsGraph* source, int startPointIdx, int
}

// QMultiMap< cost, vertexIdx > not_begin
// I use it and not create any struct or class.
// I use it and don't create any struct or class
QMultiMap< double, int > not_begin;
QMultiMap< double, int >::iterator it;

@@ -63,12 +59,12 @@ void QgsGraphAnalyzer::dijkstra( const QgsGraph* source, int startPointIdx, int
not_begin.erase( it );

// edge index list
QgsGraphArcIdList l = source->vertex( curVertex ).outArc();
QgsGraphArcIdList::iterator arcIt;
QgsGraphEdgeIds l = source->vertex( curVertex ).outEdges();
QgsGraphEdgeIds::iterator arcIt;
for ( arcIt = l.begin(); arcIt != l.end(); ++arcIt )
{
const QgsGraphArc arc = source->arc( *arcIt );
double cost = arc.property( criterionNum ).toDouble() + curCost;
const QgsGraphEdge arc = source->edge( *arcIt );
double cost = arc.cost( criterionNum ).toDouble() + curCost;

if ( cost < ( *result )[ arc.inVertex()] )
{
@@ -108,15 +104,15 @@ QgsGraph* QgsGraphAnalyzer::shortestTree( const QgsGraph* source, int startVerte
}
}

// Add arcs to result
// Add arcs to the result
for ( i = 0; i < source->vertexCount(); ++i )
{
if ( tree[ i ] != -1 )
{
const QgsGraphArc& arc = source->arc( tree[i] );
const QgsGraphEdge& arc = source->edge( tree[i] );

treeResult->addArc( source2result[ arc.outVertex()], source2result[ arc.inVertex()],
arc.properties() );
treeResult->addEdge( source2result[ arc.outVertex()], source2result[ arc.inVertex()],
arc.strategies() );
}
}

64 changes: 31 additions & 33 deletions src/analysis/network/qgsgraphanalyzer.h
Original file line number Diff line number Diff line change
@@ -1,53 +1,51 @@
/***************************************************************************
qgsgraphalyzer.h - QGIS Tools for graph analysis
-------------------
begin : 14 april 2010
copyright : (C) Sergey Yakushev
email : yakushevs@list.ru
***************************************************************************/
qgsgraphanalyzer.h
--------------------------------------
Date : 2011-04-14
Copyright : (C) 2010 by Yakushev Sergey
Email : YakushevS <at> list.ru
****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSGRAPHANALYZER_H
#define QGSGRAPHANALYZER_H

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSGRAPHANALYZERH
#define QGSGRAPHANALYZERH

//QT-includes
#include <QVector>

// forward-declaration
class QgsGraph;

/** \ingroup networkanalysis
* The QGis class provides graph analysis functions
/** \ingroup analysis
* This class performs graph analysis, e.g. calculates shortest path between two
* points using different strategies with Dijkstra algorithm
*/

class ANALYSIS_EXPORT QgsGraphAnalyzer
{
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
* 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
*/
static void dijkstra( const QgsGraph* source, int startVertexIdx, int criterionNum, QVector<int>* resultTree = nullptr, QVector<double>* resultCost = nullptr );

/**
* 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
* 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
*/
static QgsGraph* shortestTree( const QgsGraph* source, int startVertexIdx, int criterionNum );
};
#endif //QGSGRAPHANALYZERH

#endif // QGSGRAPHANALYZER_H
29 changes: 16 additions & 13 deletions src/analysis/network/qgsgraphbuilder.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
/***************************************************************************
* Copyright (C) 2010 by Sergey Yakushev *
* yakushevs <at> list.ru *
* *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
qgsgraphbuilder.cpp
--------------------------------------
Date : 2010-10-25
Copyright : (C) 2010 by Yakushev Sergey
Email : YakushevS@list.ru
****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/**
* \file qgsgraphbuilder.cpp
* \brief implementation of QgsGraphBuilder
* \brief implementation of the QgsGraphBuilder
*/

#include "qgsgraphbuilder.h"
#include "qgsgraph.h"

// Qgis includes
#include <qgsfeature.h>
#include <qgsgeometry.h>

@@ -37,9 +40,9 @@ void QgsGraphBuilder::addVertex( int, const QgsPoint& pt )
mGraph->addVertex( pt );
}

void QgsGraphBuilder::addArc( int pt1id, const QgsPoint&, int pt2id, const QgsPoint&, const QVector< QVariant >& prop )
void QgsGraphBuilder::addEdge( int pt1id, const QgsPoint&, int pt2id, const QgsPoint&, const QVector< QVariant >& prop )
{
mGraph->addArc( pt1id, pt2id, prop );
mGraph->addEdge( pt1id, pt2id, prop );
}

QgsGraph* QgsGraphBuilder::graph()
22 changes: 10 additions & 12 deletions src/analysis/network/qgsgraphbuilder.h
Original file line number Diff line number Diff line change
@@ -12,33 +12,30 @@
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSGRAPHBUILDERH
#define QGSGRAPHBUILDERH

#include "qgsgraphbuilderintr.h"
#ifndef QGSGRAPHBUILDER_H
#define QGSGRAPHBUILDER_H

//QT4 includes
#include "qgsgraphbuilderinterface.h"

//QGIS includes
#include <qgsspatialindex.h>

//forward declarations
class QgsDistanceArea;
class QgsCoordinateTransform;
class QgsGraph;

/**
* \ingroup networkanalysis
* \ingroup analysis
* \class QgsGraphBuilder
* \brief This class making the QgsGraph object
* \brief This class used for making the QgsGraph object
*/

class ANALYSIS_EXPORT QgsGraphBuilder : public QgsGraphBuilderInterface
{
public:

/**
* default constructor
* Default constructor
*/
QgsGraphBuilder( const QgsCoordinateReferenceSystem& crs, bool otfEnabled = true, double topologyTolerance = 0.0, const QString& ellipsoidID = "WGS84" );

@@ -49,15 +46,16 @@ class ANALYSIS_EXPORT QgsGraphBuilder : public QgsGraphBuilderInterface
*/
virtual void addVertex( int id, const QgsPoint& pt ) override;

virtual void addArc( int pt1id, const QgsPoint& pt1, int pt2id, const QgsPoint& pt2, const QVector< QVariant >& prop ) override;
virtual void addEdge( int pt1id, const QgsPoint& pt1, int pt2id, const QgsPoint& pt2, const QVector< QVariant >& prop ) override;

/**
* return QgsGraph result;
* Returns generated QgsGraph
*/
QgsGraph* graph();

private:

QgsGraph *mGraph;
};
#endif //QGSGRAPHBUILDERH

#endif // QGSGRAPHBUILDER_H
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
qgsgraphbuilder.h
qgsgraphbuilderinterface.h
--------------------------------------
Date : 2010-10-22
Copyright : (C) 2010 by Yakushev Sergey
@@ -12,31 +12,29 @@
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSGRAPHBUILDERINTERFACE
#define QGSGRAPHBUILDERINTERFACE

//QT4 includes
#ifndef QGSGRAPHBUILDERINTERFACE_H
#define QGSGRAPHBUILDERINTERFACE_H

#include <QVector>
#include <QVariant>

//QGIS includes
#include <qgspoint.h>
#include <qgscoordinatereferencesystem.h>
#include <qgsdistancearea.h>

//forward declarations

/**
* \ingroup networkanalysis
* \ingroup analysis
* \class QgsGraphBuilderInterface
* \brief Determine interface for creating a graph. Contains the settings of the graph. QgsGraphBuilder and QgsGraphDirector is a Builder pattern
* \brief Determine interface for creating a graph. Contains the settings of the graph.
* QgsGraphBuilder and QgsGraphDirector both use a "builder" design pattern
*/
class ANALYSIS_EXPORT QgsGraphBuilderInterface
{
public:

/**
* QgsGraphBuilderInterface constructor
* Default 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
@@ -56,34 +54,34 @@ class ANALYSIS_EXPORT QgsGraphBuilderInterface
virtual ~QgsGraphBuilderInterface()
{ }

//! get destinaltion Crs
//! Returns destinaltion CRS
QgsCoordinateReferenceSystem destinationCrs() const
{
return mCrs;
}

//! get coordinate transformation enabled
//! Returns coordinate transformation enabled
bool coordinateTransformationEnabled()
{
return mCtfEnabled;
}

//! get topology tolerance
//! Returns topology tolerance
double topologyTolerance()
{
return mTopologyTolerance;
}

//! get measurement tool
//! Returns measurement tool
QgsDistanceArea* distanceArea()
{
return &mDa;
}

/**
* add vertex
* Add vertex to the graph
* @param id vertex identifier
* @param pt vertex coordinate
* @param pt vertex coordinates
* @note id and pt are redundant. You can use pt or id to identify the vertex
*/
virtual void addVertex( int id, const QgsPoint &pt )
@@ -93,21 +91,21 @@ class ANALYSIS_EXPORT QgsGraphBuilderInterface
}

/**
* add arc
* Add edge to the graph
* @param pt1id first vertex identificator
* @param pt1 first vertex coordinate
* @param pt1 first vertex coordinates
* @param pt2id second vertex identificator
* @param pt2 second vertex coordinate
* @param properties arc properties
* @param pt2 second vertex coordinates
* @param strategies optimization strategies
* @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 )
virtual void addEdge( int pt1id, const QgsPoint& pt1, int pt2id, const QgsPoint& pt2, const QVector< QVariant >& strategies )
{
Q_UNUSED( pt1id );
Q_UNUSED( pt1 );
Q_UNUSED( pt2id );
Q_UNUSED( pt2 );
Q_UNUSED( properties );
Q_UNUSED( strategies );
}

private:
@@ -120,4 +118,5 @@ class ANALYSIS_EXPORT QgsGraphBuilderInterface
double mTopologyTolerance;

};
#endif //QGSGRAPHBUILDERINTERFACE

#endif // QGSGRAPHBUILDERINTERFACE_H
46 changes: 21 additions & 25 deletions src/analysis/network/qgsgraphdirector.h
Original file line number Diff line number Diff line change
@@ -12,25 +12,24 @@
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSGRAPHDIRECTORH
#define QGSGRAPHDIRECTORH

//QT4 includes
#ifndef QGSGRAPHDIRECTOR_H
#define QGSGRAPHDIRECTOR_H

#include <QObject>
#include <QVector>
#include <QList>

//QGIS includes
#include <qgspoint.h>
#include "qgsarcproperter.h"
#include "qgsnetworkstrategy.h"

//forward declarations
class QgsGraphBuilderInterface;

/**
* \ingroup networkanalysis
* \ingroup analysis
* \class QgsGraphDirector
* \brief Determine making the graph. QgsGraphBuilder and QgsGraphDirector is a builder patter.
* \brief Determine making the graph. QgsGraphBuilder and QgsGraphDirector implemented
* using "builder" design patter.
*/
class ANALYSIS_EXPORT QgsGraphDirector : public QObject
{
@@ -45,36 +44,33 @@ class ANALYSIS_EXPORT QgsGraphDirector : public QObject
virtual ~QgsGraphDirector() { }

/**
* Make a graph using RgGraphBuilder
*
* @param builder The graph builder
*
* @param additionalPoints Vector of points that must be tied to the graph
*
* @param tiedPoints Vector of tied points
* Make a graph using QgsGraphBuilder
*
* @note if tiedPoints[i]==QgsPoint(0.0,0.0) then tied failed.
* @param builder the graph builder
* @param additionalPoints list of points that should be snapped to the graph
* @param snappedPoints list of snapped points
* @note if snappedPoints[i] == QgsPoint(0.0,0.0) then snapping failed.
*/
virtual void makeGraph( QgsGraphBuilderInterface *builder,
const QVector< QgsPoint > &additionalPoints,
QVector< QgsPoint > &tiedPoints ) const
QVector< QgsPoint > &snappedPoints ) const
{
Q_UNUSED( builder );
Q_UNUSED( additionalPoints );
Q_UNUSED( tiedPoints );
Q_UNUSED( snappedPoints );
}

void addProperter( QgsArcProperter* prop )
//! Add optimization strategy
void addStrategy( QgsNetworkStrategy* prop )
{
mProperterList.push_back( prop );
mStrategies.push_back( prop );
}

/**
* return Director name
*/
//! Returns director name
virtual QString name() const = 0;

protected:
QList<QgsArcProperter*> mProperterList;
QList<QgsNetworkStrategy*> mStrategies;
};
#endif //QGSGRAPHDIRECTORH

#endif // QGSGRAPHDIRECTOR_H
83 changes: 0 additions & 83 deletions src/analysis/network/qgslinevectorlayerdirector.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
qgsedgeproperter.h
qgsdistancestrategy.h
--------------------------------------
Date : 2011-04-01
Copyright : (C) 2010 by Yakushev Sergey
@@ -13,21 +13,10 @@
* *
***************************************************************************/

#ifndef QGSEDGEDISTANCEPROPERTERH
#define QGSEDGEDISTANCEPROPERTERH
#include "qgsnetworkdistancestrategy.h"

// QT4 includes
#include <QVariant>

// QGIS includes
#include <qgsarcproperter.h>

/** \ingroup networkanalysis
* \class QgsDistanceArcProperter
*/
class ANALYSIS_EXPORT QgsDistanceArcProperter : public QgsArcProperter
QVariant QgsNetworkDistanceStrategy::cost( double distance, const QgsFeature& f ) const
{
public:
virtual QVariant property( double distance, const QgsFeature& ) const override;
};
#endif //QGSEDGEDISTANCEPROPERTYH
Q_UNUSED( f );
return QVariant( distance );
}
33 changes: 33 additions & 0 deletions src/analysis/network/qgsnetworkdistancestrategy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/***************************************************************************
qgsnetworkdistancestrategy.h
--------------------------------------
Date : 2011-04-01
Copyright : (C) 2010 by Yakushev Sergey
Email : YakushevS <at> list.ru
****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSNETWORKDISTANCESTRATEGY_H
#define QGSNETWORKDISTANCESTRATEGY_H

#include <qgsnetworkstrategy.h>

/** \ingroup analysis
* \class QgsNetworkDistanceStrategy
* \note added in QGIS 3.0
* \brief Strategy for caclulating edge cost based on its length. Should be
* used for finding shortest path between two points.
*/
class ANALYSIS_EXPORT QgsNetworkDistanceStrategy : public QgsNetworkStrategy
{
public:
virtual QVariant cost( double distance, const QgsFeature& ) const override;
};

#endif // QGSNETWORKDISTANCESTRATEGY_H
44 changes: 44 additions & 0 deletions src/analysis/network/qgsnetworkspeedstrategy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/***************************************************************************
qgsspeedstrategy.h
--------------------------------------
Date : 2011-04-01
Copyright : (C) 2010 by Yakushev Sergey
Email : YakushevS <at> list.ru
****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsnetworkspeedstrategy.h"

QgsNetworkSpeedStrategy::QgsNetworkSpeedStrategy( int attributeId, double defaultValue, double toMetricFactor )
{
mAttributeId = attributeId;
mDefaultValue = defaultValue;
mToMetricFactor = toMetricFactor;
}

QVariant QgsNetworkSpeedStrategy::cost( double distance, const QgsFeature& f ) const
{
QgsAttributes attrs = f.attributes();

if ( mAttributeId < 0 || mAttributeId >= attrs.count() )
return QVariant( distance / ( mDefaultValue * mToMetricFactor ) );

double val = distance / ( attrs.at( mAttributeId ).toDouble() * mToMetricFactor );
if ( val <= 0.0 )
return QVariant( distance / ( mDefaultValue / mToMetricFactor ) );

return QVariant( val );
}

QgsAttributeList QgsNetworkSpeedStrategy::requiredAttributes() const
{
QgsAttributeList l;
l.push_back( mAttributeId );
return l;
}
52 changes: 52 additions & 0 deletions src/analysis/network/qgsnetworkspeedstrategy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/***************************************************************************
qgsnetworkspeedstrategy.h
--------------------------------------
Date : 2011-04-01
Copyright : (C) 2010 by Yakushev Sergey
Email : YakushevS <at> list.ru
****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSNETWORKSPEEDSTRATEGY_H
#define QGSNETWORKSPEEDSTRATEGY_H

#include <qgsnetworkstrategy.h>

/** \ingroup analysis
* \class QgsNetworkSpeedStrategy
* \note added in QGIS 3.0
* \brief Strategy for calcucating edge cost based on travel time. Should be
* used for finding fastest path between two points.
*/
class ANALYSIS_EXPORT QgsNetworkSpeedStrategy : public QgsNetworkStrategy
{
public:

/**
* Default constructor
*/
QgsNetworkSpeedStrategy( int attributeId, double defaultValue, double toMetricFactor );

//! Returns edge cost
QVariant cost( double distance, const QgsFeature& f ) const override;

/**
* Returns list of the source layer attributes needed for cost calculation.
* This method called by QgsGraphDirector.
*/
QgsAttributeList requiredAttributes() const override;

private:
int mAttributeId;
double mDefaultValue;
double mToMetricFactor;

};

#endif // QGSNETWORKSPEEDSTRATEGY_H
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
qgsedgeproperter.h
qgsnetworkstrategy.h
--------------------------------------
Date : 2011-04-01
Copyright : (C) 2010 by Yakushev Sergey
@@ -13,47 +13,45 @@
* *
***************************************************************************/

#ifndef QGSEDGEPROPERTERH
#define QGSEDGEPROPERTERH
#ifndef QGSNETWORKSTRATERGY_H
#define QGSNETWORKSTRATERGY_H

// QT4 includes
#include <QVariant>

// QGIS includes
#include <qgsfeature.h>
#include <qgsfeaturerequest.h>

/**
* \ingroup networkanalysis
* \class QgsArcProperter
* \brief QgsArcProperter is a strategy pattern.
* You can use it for customize arc property. For example look at QgsDistanceArcProperter or src/plugins/roadgraph/speedproperter.h
* \ingroup analysis
* \class QgsNetworkStrategy
* \note added in QGIS 3.0
* \brief QgsNetworkStrategy defines strategy used for calculation of the edge cost. For example it can
* take into account travel distance, amount of time or money. Currently there are two strategies
* implemented in the analysis library: QgsNetworkDistanceStrategy and QgsNetworkSpeedStrategy.
* QgsNetworkStrategy implemented using "strategy" design pattern.
*/
class ANALYSIS_EXPORT QgsArcProperter
class ANALYSIS_EXPORT QgsNetworkStrategy
{
public:

/**
* default constructor
* Default constructor
*/
QgsArcProperter() {}
QgsNetworkStrategy() {}

virtual ~QgsArcProperter() {}
virtual ~QgsNetworkStrategy() {}

/**
* QgsGraphDirector call this method for fetching attribute from source layer
* \return required attributes list
* Returns list of the source layer attributes needed for cost calculation.
* This method called by QgsGraphDirector.
* \return list of required attributes
*/
virtual QgsAttributeList requiredAttributes() const { return QgsAttributeList(); }

/**
* calculate and return adge property
* Returns edge cost
*/
virtual QVariant property( double distance, const QgsFeature &f ) const
{
Q_UNUSED( distance );
Q_UNUSED( f );
return QVariant();
}
virtual QVariant cost( double distance, const QgsFeature &f ) const = 0;
};
#endif //QGSEDGEPROPERTYH

#endif // QGSNETWORKSTRATERGY_H
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
/***************************************************************************
* Copyright (C) 2010 by Sergey Yakushev *
* yakushevs <at> list.ru *
* *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
qgslinevectorlayerdirector.cpp
--------------------------------------
Date : 2010-10-20
Copyright : (C) 2010 by Yakushev Sergey
Email : YakushevS@list.ru
****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/**
* \file qgslinevectorlayerdirector.cpp
* \brief implementation of QgsLineVectorLayerDirector
* \file qgsvectorlayerdirector.cpp
* \brief implementation of QgsVectorLayerDirector
*/

#include "qgslinevectorlayerdirector.h"
#include "qgsgraphbuilderintr.h"
#include "qgsvectorlayerdirector.h"
#include "qgsgraphbuilderinterface.h"

// Qgis includes
#include "qgsfeatureiterator.h"
#include <qgsvectorlayer.h>
#include <qgsvectordataprovider.h>
@@ -26,7 +29,6 @@
#include <qgsdistancearea.h>
#include <qgswkbtypes.h>

// QT includes
#include <QString>
#include <QtAlgorithms>

@@ -100,13 +102,13 @@ bool TiePointInfoCompare( const TiePointInfo& a, const TiePointInfo& b )
return a.mFirstPoint.x() == b.mFirstPoint.x() ? a.mFirstPoint.y() < b.mFirstPoint.y() : a.mFirstPoint.x() < b.mFirstPoint.x();
}

QgsLineVectorLayerDirector::QgsLineVectorLayerDirector( QgsVectorLayer *myLayer,
QgsVectorLayerDirector::QgsVectorLayerDirector( QgsVectorLayer *myLayer,
int directionFieldId,
const QString& directDirectionValue,
const QString& reverseDirectionValue,
const QString& bothDirectionValue,
int defaultDirection
)
const Direction defaultDirection
)
{
mVectorLayer = myLayer;
mDirectionFieldId = directionFieldId;
@@ -116,18 +118,18 @@ QgsLineVectorLayerDirector::QgsLineVectorLayerDirector( QgsVectorLayer *myLayer,
mBothDirectionValue = bothDirectionValue;
}

QgsLineVectorLayerDirector::~QgsLineVectorLayerDirector()
QgsVectorLayerDirector::~QgsVectorLayerDirector()
{

}

QString QgsLineVectorLayerDirector::name() const
QString QgsVectorLayerDirector::name() const
{
return QStringLiteral( "Vector line" );
}

void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPoint >& additionalPoints,
QVector< QgsPoint >& tiedPoint ) const
void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPoint >& additionalPoints,
QVector< QgsPoint >& snappedPoints ) const
{
QgsVectorLayer *vl = mVectorLayer;

@@ -148,7 +150,7 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
ct.setDestinationCrs( vl->crs() );
}

tiedPoint = QVector< QgsPoint >( additionalPoints.size(), QgsPoint( 0.0, 0.0 ) );
snappedPoints = QVector< QgsPoint >( additionalPoints.size(), QgsPoint( 0.0, 0.0 ) );

TiePointInfo tmpInfo;
tmpInfo.mLength = std::numeric_limits<double>::infinity();
@@ -207,7 +209,7 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
info.mLastPoint = pt2;

pointLengthMap[ i ] = info;
tiedPoint[ i ] = info.mTiedPoint;
snappedPoints[ i ] = info.mTiedPoint;
}
}
}
@@ -221,11 +223,11 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c

// add tied point to graph
int i = 0;
for ( i = 0; i < tiedPoint.size(); ++i )
for ( i = 0; i < snappedPoints.size(); ++i )
{
if ( tiedPoint[ i ] != QgsPoint( 0.0, 0.0 ) )
if ( snappedPoints[ i ] != QgsPoint( 0.0, 0.0 ) )
{
points.push_back( tiedPoint [ i ] );
points.push_back( snappedPoints [ i ] );
}
}

@@ -238,8 +240,8 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
for ( i = 0;i < points.size();++i )
builder->addVertex( i, points[ i ] );

for ( i = 0; i < tiedPoint.size() ; ++i )
tiedPoint[ i ] = *( my_binary_search( points.begin(), points.end(), tiedPoint[ i ], pointCompare ) );
for ( i = 0; i < snappedPoints.size() ; ++i )
snappedPoints[ i ] = *( my_binary_search( points.begin(), points.end(), snappedPoints[ i ], pointCompare ) );

qSort( pointLengthMap.begin(), pointLengthMap.end(), TiePointInfoCompare );

@@ -251,10 +253,10 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
tmpAttr.push_back( mDirectionFieldId );
}

QList< QgsArcProperter* >::const_iterator it;
QList< QgsNetworkStrategy* >::const_iterator it;
QgsAttributeList::const_iterator it2;

for ( it = mProperterList.begin(); it != mProperterList.end(); ++it )
for ( it = mStrategies.begin(); it != mStrategies.end(); ++it )
{
QgsAttributeList tmp = ( *it )->requiredAttributes();
for ( it2 = tmp.begin(); it2 != tmp.end(); ++it2 )
@@ -282,21 +284,21 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
fit = vl->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( la ) );
while ( fit.nextFeature( feature ) )
{
int directionType = mDefaultDirection;
Direction directionType = mDefaultDirection;

// What direction have feature?
QString str = feature.attribute( mDirectionFieldId ).toString();
if ( str == mBothDirectionValue )
{
directionType = 3;
directionType = Direction::DirectionBoth;
}
else if ( str == mDirectDirectionValue )
{
directionType = 1;
directionType = Direction::DirectionForward;
}
else if ( str == mReverseDirectionValue )
{
directionType = 2;
directionType = Direction::DirectionBackward;
}

// begin features segments and add arc to the Graph;
@@ -364,21 +366,21 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
{
double distance = builder->distanceArea()->measureLine( pt1, pt2 );
QVector< QVariant > prop;
QList< QgsArcProperter* >::const_iterator it;
for ( it = mProperterList.begin(); it != mProperterList.end(); ++it )
QList< QgsNetworkStrategy* >::const_iterator it;
for ( it = mStrategies.begin(); it != mStrategies.end(); ++it )
{
prop.push_back(( *it )->property( distance, feature ) );
prop.push_back(( *it )->cost( distance, feature ) );
}

if ( directionType == 1 ||
directionType == 3 )
if ( directionType == Direction::DirectionForward ||
directionType == Direction::DirectionBoth )
{
builder->addArc( pt1idx, pt1, pt2idx, pt2, prop );
builder->addEdge( pt1idx, pt1, pt2idx, pt2, prop );
}
if ( directionType == 2 ||
directionType == 3 )
if ( directionType == Direction::DirectionBackward ||
directionType == Direction::DirectionBoth )
{
builder->addArc( pt2idx, pt2, pt1idx, pt1, prop );
builder->addEdge( pt2idx, pt2, pt1idx, pt1, prop );
}
}
pt1idx = pt2idx;
@@ -393,4 +395,3 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
emit buildProgress( ++step, featureCount );
} // while( vl->nextFeature(feature) )
} // makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPoint >& additionalPoints, QVector< QgsPoint >& tiedPoint )

88 changes: 88 additions & 0 deletions src/analysis/network/qgsvectorlayerdirector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/***************************************************************************
qgsvectorlayerdirector.h
--------------------------------------
Date : 2010-10-20
Copyright : (C) 2010 by Yakushev Sergey
Email : YakushevS <at> list.ru
****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSVECTORLAYERDIRECTOR_H
#define QGSVECTORLAYERDIRECTOR_H

#include "qgsgraphdirector.h"

class QgsGraphBuilderInterface;
class QgsVectorLayer;

/**
* \ingroup analysis
* \class QgsVectorLayerDirector
* \note added in QGIS 3.0
* \brief Determine making the graph from vector line layer
*/
class ANALYSIS_EXPORT QgsVectorLayerDirector : public QgsGraphDirector
{
Q_OBJECT

public:

/** Edge direction
* Edge can be one-way with direct flow (one can move only from the start
* point to the end point), one-way with reversed flow (one can move only
* from the end point to the start point) and bidirectional or two-way
* (one can move in any direction)
*/
enum Direction
{
DirectionForward, //!< One-way direct
DirectionBackward, //!< One-way reversed
DirectionBoth, //!< Two-way
};

/**
* Default constructor
* @param myLayer source vector layer
* @param directionFieldId field containing direction value
* @param directDirectionValue value for direct one-way road
* @param reverseDirectionValue value for reversed one-way road
* @param bothDirectionValue value for two-way (bidirectional) road
* @param defaultDirection default direction. Will be used if corresponding
* attribute value is not set or does not equal to the given values
*/
QgsVectorLayerDirector( QgsVectorLayer* myLayer,
int directionFieldId,
const QString& directDirectionValue,
const QString& reverseDirectionValue,
const QString& bothDirectionValue,
const Direction defaultDirection
);

//! Destructor
virtual ~QgsVectorLayerDirector();

/*
* MANDATORY DIRECTOR PROPERTY DECLARATION
*/
void makeGraph( QgsGraphBuilderInterface *builder,
const QVector< QgsPoint >& additionalPoints,
QVector< QgsPoint>& snappedPoints ) const override;

QString name() const override;

private:
QgsVectorLayer *mVectorLayer;
int mDirectionFieldId;
QString mDirectDirectionValue;
QString mReverseDirectionValue;
QString mBothDirectionValue;
Direction mDefaultDirection;
};

#endif // QGSVECTORLAYERDIRECTOR_H
3 changes: 1 addition & 2 deletions src/plugins/roadgraph/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ SET (VRP_SRCS
linevectorlayersettings.cpp
linevectorlayerwidget.cpp
exportdlg.cpp
speedproperter.cpp
)

#SET ([pluginlcasename]_UIS [pluginlcasename]guibase.ui)
@@ -50,7 +49,7 @@ ADD_LIBRARY (roadgraphplugin MODULE ${VRP_SRCS} ${VRP_MOC_SRCS} ${VRP_RCC_SRCS})
TARGET_LINK_LIBRARIES(roadgraphplugin
qgis_core
qgis_gui
qgis_networkanalysis
qgis_analysis
)


32 changes: 9 additions & 23 deletions src/plugins/roadgraph/linevectorlayersettings.cpp
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
//standard includes

RgLineVectorLayerSettings::RgLineVectorLayerSettings()
: mDefaultDirection( Both )
: mDefaultDirection( QgsVectorLayerDirector::Direction::DirectionBoth )
, mDefaultSpeed( 40 )
{
}
@@ -58,31 +58,17 @@ bool RgLineVectorLayerSettings::test()

void RgLineVectorLayerSettings::read( const QgsProject *project )
{
int dd = project->readNumEntry( QStringLiteral( "roadgraphplugin" ), QStringLiteral( "/defaultDirection" ) );
mDirection = project->readEntry( QStringLiteral( "roadgraphplugin" ), QStringLiteral( "/directionField" ) );
mDefaultDirection = static_cast<QgsVectorLayerDirector::Direction>( project->readNumEntry( QStringLiteral( "roadgraphplugin" ), QStringLiteral( "/defaultDirection" ) ) );
mDirection = project->readEntry( QStringLiteral( "roadgraphplugin" ), QStringLiteral( "/directionField" ) );
mFirstPointToLastPointDirectionVal =
project->readEntry( QStringLiteral( "roadgraphplugin" ), QStringLiteral( "/FirstPointToLastPointDirectionVal" ) );
mLastPointToFirstPointDirectionVal =
project->readEntry( QStringLiteral( "roadgraphplugin" ), QStringLiteral( "/LastPointToFirstPointDirectionVal" ) );
mBothDirectionVal = project->readEntry( QStringLiteral( "roadgraphplugin" ), QStringLiteral( "/BothDirectionVal" ) );
mSpeed = project->readEntry( QStringLiteral( "roadgraphplugin" ), QStringLiteral( "/speedField" ) );
mSpeed = project->readEntry( QStringLiteral( "roadgraphplugin" ), QStringLiteral( "/speedField" ) );
mDefaultSpeed = project->readDoubleEntry( QStringLiteral( "roadgraphplugin" ), QStringLiteral( "/defaultSpeed" ) );
mLayerName = project->readEntry( QStringLiteral( "roadgraphplugin" ), QStringLiteral( "/layer" ) );
mLayerName = project->readEntry( QStringLiteral( "roadgraphplugin" ), QStringLiteral( "/layer" ) );
mSpeedUnitName = project->readEntry( QStringLiteral( "roadgraphplugin" ), QStringLiteral( "/speedUnitName" ) );

if ( dd == 1 )
{
mDefaultDirection = FirstPointToLastPoint;
}
else if ( dd == 2 )
{
mDefaultDirection = LastPointToFirstPoint;
}
else if ( dd == 3 )
{
mDefaultDirection = Both;
}

} // RgLineVectorLayerSettings::read( const QgsProject *project )

void RgLineVectorLayerSettings::write( QgsProject *project )
@@ -115,19 +101,19 @@ void RgLineVectorLayerSettings::setFromGui( QWidget *myGui )
mLastPointToFirstPointDirectionVal = w->mleLastPointToFirstPointDirection->text();
mBothDirectionVal = w->mleBothDirection->text();
mDirection = w->mcbDirection->currentText();
mLayerName = w->mcbLayers->currentText();
mLayerName = w->mcbLayers->currentText();

if ( w->mcbDirectionDefault->currentIndex() == 0 )
{
mDefaultDirection = Both;
mDefaultDirection = QgsVectorLayerDirector::Direction::DirectionBoth;
}
else if ( w->mcbDirectionDefault->currentIndex() == 1 )
{
mDefaultDirection = FirstPointToLastPoint;
mDefaultDirection = QgsVectorLayerDirector::Direction::DirectionForward;
}
else if ( w->mcbDirectionDefault->currentIndex() == 2 )
{
mDefaultDirection = LastPointToFirstPoint;
mDefaultDirection = QgsVectorLayerDirector::Direction::DirectionBackward;
}

mSpeed = w->mcbSpeed->currentText();
4 changes: 3 additions & 1 deletion src/plugins/roadgraph/linevectorlayersettings.h
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@
// QT includes
#include <qstring.h>

#include <qgsvectorlayerdirector.h>

// Qgis includes

// standard includes
@@ -93,7 +95,7 @@ class RgLineVectorLayerSettings: public RgSettings
/**
* contained Default direction
*/
DirectionType mDefaultDirection;
QgsVectorLayerDirector::Direction mDefaultDirection;

/**
* contained speed filed name
6 changes: 3 additions & 3 deletions src/plugins/roadgraph/linevectorlayerwidget.cpp
Original file line number Diff line number Diff line change
@@ -143,13 +143,13 @@ RgLineVectorLayerSettingsWidget::RgLineVectorLayerSettingsWidget( RgLineVectorLa

switch ( s->mDefaultDirection )
{
case RgLineVectorLayerSettings::Both:
case QgsVectorLayerDirector::Direction::DirectionBoth:
mcbDirectionDefault->setCurrentIndex( 0 );
break;
case RgLineVectorLayerSettings::FirstPointToLastPoint:
case QgsVectorLayerDirector::Direction::DirectionForward:
mcbDirectionDefault->setCurrentIndex( 1 );
break;
case RgLineVectorLayerSettings::LastPointToFirstPoint:
case QgsVectorLayerDirector::Direction::DirectionBackward:
mcbDirectionDefault->setCurrentIndex( 2 );
break;
}
28 changes: 14 additions & 14 deletions src/plugins/roadgraph/roadgraphplugin.cpp
Original file line number Diff line number Diff line change
@@ -26,17 +26,17 @@
#include <qgsvectorlayer.h>
#include <qgsvectordataprovider.h>

#include <qgslinevectorlayerdirector.h>
#include <qgsvectorlayerdirector.h>
#include <qgsgraphbuilder.h>
#include <qgsgraph.h>
#include <qgsdistancearcproperter.h>
#include <qgsnetworkdistancestrategy.h>
#include <qgsnetworkspeedstrategy.h>
#include "qgsdockwidget.h"

// Road grap plugin includes
#include "roadgraphplugin.h"
#include "shortestpathwidget.h"
#include "settingsdlg.h"
#include "speedproperter.h"
#include "units.h"

#include "linevectorlayersettings.h"
@@ -210,17 +210,17 @@ const QgsGraphDirector* RoadGraphPlugin::director() const
{
SpeedUnit speedUnit = SpeedUnit::byName( mSettings->mSpeedUnitName );

QgsLineVectorLayerDirector * director =
new QgsLineVectorLayerDirector( layer,
layer->fields().lookupField( mSettings->mDirection ),
mSettings->mFirstPointToLastPointDirectionVal,
mSettings->mLastPointToFirstPointDirectionVal,
mSettings->mBothDirectionVal,
mSettings->mDefaultDirection
);
director->addProperter( new QgsDistanceArcProperter() );
director->addProperter( new RgSpeedProperter( layer->fields().lookupField( mSettings->mSpeed ),
mSettings->mDefaultSpeed, speedUnit.multipler() ) );
QgsVectorLayerDirector * director =
new QgsVectorLayerDirector( layer,
layer->fields().lookupField( mSettings->mDirection ),
mSettings->mFirstPointToLastPointDirectionVal,
mSettings->mLastPointToFirstPointDirectionVal,
mSettings->mBothDirectionVal,
mSettings->mDefaultDirection
);
director->addStrategy( new QgsNetworkDistanceStrategy() );
director->addStrategy( new QgsNetworkSpeedStrategy( layer->fields().lookupField( mSettings->mSpeed ),
mSettings->mDefaultSpeed, speedUnit.multipler() ) );
return director;
}
return nullptr;
16 changes: 8 additions & 8 deletions src/plugins/roadgraph/shortestpathwidget.cpp
Original file line number Diff line number Diff line change
@@ -340,13 +340,13 @@ void RgShortestPathWidget::findingPath()
if ( stopVertexIdx < 0 )
break;

QgsGraphArcIdList l = path->vertex( stopVertexIdx ).inArc();
QgsGraphEdgeIds l = path->vertex( stopVertexIdx ).inEdges();
if ( l.empty() )
break;
const QgsGraphArc& e = path->arc( l.front() );
const QgsGraphEdge& e = path->edge( l.front() );

cost += e.property( 0 ).toDouble();
time += e.property( 1 ).toDouble();
cost += e.cost( 0 ).toDouble();
time += e.cost( 1 ).toDouble();

p.push_front( path->vertex( e.inVertex() ).point() );

@@ -414,13 +414,13 @@ void RgShortestPathWidget::exportPath()
if ( stopVertexIdx < 0 )
break;

QgsGraphArcIdList l = path->vertex( stopVertexIdx ).inArc();
QgsGraphEdgeIds l = path->vertex( stopVertexIdx ).inEdges();
if ( l.empty() )
break;
const QgsGraphArc& e = path->arc( l.front() );
const QgsGraphEdge& e = path->edge( l.front() );

cost += e.property( 0 ).toDouble();
time += e.property( 1 ).toDouble();
cost += e.cost( 0 ).toDouble();
time += e.cost( 1 ).toDouble();

p.push_front( ct.transform( path->vertex( e.inVertex() ).point() ) );
stopVertexIdx = e.outVertex();
41 changes: 0 additions & 41 deletions src/plugins/roadgraph/speedproperter.cpp

This file was deleted.

34 changes: 0 additions & 34 deletions src/plugins/roadgraph/speedproperter.h

This file was deleted.

1 change: 0 additions & 1 deletion tests/src/python/test_qgssipcoverage.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@
from qgis.analysis import * # NOQA
from qgis.core import * # NOQA
from qgis.gui import * # NOQA
from qgis.networkanalysis import * # NOQA
try:
from qgis.server import * # NOQA
except:

0 comments on commit 3dcf03c

Please sign in to comment.