[QGIS Commit] r15239 - trunk/qgis/src/plugins/roadgraph
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue Feb 22 03:53:02 EST 2011
Author: stopa85
Date: 2011-02-22 00:53:02 -0800 (Tue, 22 Feb 2011)
New Revision: 15239
Modified:
trunk/qgis/src/plugins/roadgraph/CMakeLists.txt
trunk/qgis/src/plugins/roadgraph/roadgraphplugin.cpp
trunk/qgis/src/plugins/roadgraph/roadgraphplugin.h
trunk/qgis/src/plugins/roadgraph/settingsdlg.cpp
trunk/qgis/src/plugins/roadgraph/settingsdlg.h
trunk/qgis/src/plugins/roadgraph/shortestpathwidget.cpp
trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.cpp
trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.h
Log:
add topology tolerance
Modified: trunk/qgis/src/plugins/roadgraph/CMakeLists.txt
===================================================================
--- trunk/qgis/src/plugins/roadgraph/CMakeLists.txt 2011-02-21 22:41:55 UTC (rev 15238)
+++ trunk/qgis/src/plugins/roadgraph/CMakeLists.txt 2011-02-22 08:53:02 UTC (rev 15239)
@@ -30,7 +30,8 @@
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${GEOS_INCLUDE_DIR}
- ../../core
+ ../../core
+ ../../core/spatialindex/
../../gui
..
)
Modified: trunk/qgis/src/plugins/roadgraph/roadgraphplugin.cpp
===================================================================
--- trunk/qgis/src/plugins/roadgraph/roadgraphplugin.cpp 2011-02-21 22:41:55 UTC (rev 15238)
+++ trunk/qgis/src/plugins/roadgraph/roadgraphplugin.cpp 2011-02-22 08:53:02 UTC (rev 15239)
@@ -77,6 +77,7 @@
mSettings = new RgLineVectorLayerSettings();
mTimeUnitName = "h";
mDistanceUnitName = "km";
+ mTopologyToleranceFactor = 0.0;
}
RoadGraphPlugin::~RoadGraphPlugin()
@@ -174,17 +175,19 @@
dlg.setTimeUnitName( mTimeUnitName );
dlg.setDistanceUnitName( mDistanceUnitName );
+ dlg.setTopologyTolerance( mTopologyToleranceFactor );
if ( !dlg.exec() )
return;
mTimeUnitName = dlg.timeUnitName();
mDistanceUnitName = dlg.distanceUnitName();
+ mTopologyToleranceFactor = dlg.topologyTolerance();
mSettings->write( QgsProject::instance() );
QgsProject::instance()->writeEntry( "roadgraphplugin", "/pluginTimeUnit", mTimeUnitName );
QgsProject::instance()->writeEntry( "roadgraphplugin", "/pluginDistanceUnit", mDistanceUnitName );
-
+ QgsProject::instance()->writeEntry( "roadgraphplugin", "/topologyToleranceFactor", mTopologyToleranceFactor );
setGuiElementsToDefault();
} //RoadGraphPlugin::property()
@@ -244,6 +247,8 @@
mSettings->read( QgsProject::instance() );
mTimeUnitName = QgsProject::instance()->readEntry( "roadgraphplugin", "/pluginTimeUnit", "h" );
mDistanceUnitName = QgsProject::instance()->readEntry( "roadgraphplugin", "/pluginDistanceUnit", "km" );
+ mTopologyToleranceFactor =
+ QgsProject::instance()->readDoubleEntry( "roadgraphplugin", "/topologyToleranceFactor", 0.0 );
setGuiElementsToDefault();
}// RoadGraphplguin::projectRead()
@@ -344,6 +349,10 @@
return mDistanceUnitName;
}
+double RoadGraphPlugin::topologyToleranceFactor()
+{
+ return mTopologyToleranceFactor;
+}
//////////////////////////////////////////////////////////////////////////
//
//
Modified: trunk/qgis/src/plugins/roadgraph/roadgraphplugin.h
===================================================================
--- trunk/qgis/src/plugins/roadgraph/roadgraphplugin.h 2011-02-21 22:41:55 UTC (rev 15238)
+++ trunk/qgis/src/plugins/roadgraph/roadgraphplugin.h 2011-02-22 08:53:02 UTC (rev 15239)
@@ -71,6 +71,11 @@
*/
QString distanceUnitName();
+ /**
+ * get topology tolerance factor
+ */
+ double topologyToleranceFactor();
+
public slots:
void render( QPainter *painter );
//! init the gui
@@ -155,6 +160,12 @@
* distance unit for results presentation
*/
QString mDistanceUnitName;
+
+ /**
+ * topology tolerance factor
+ */
+ double mTopologyToleranceFactor;
+
private:
static const int mArrowSize = 5;
};
Modified: trunk/qgis/src/plugins/roadgraph/settingsdlg.cpp
===================================================================
--- trunk/qgis/src/plugins/roadgraph/settingsdlg.cpp 2011-02-21 22:41:55 UTC (rev 15238)
+++ trunk/qgis/src/plugins/roadgraph/settingsdlg.cpp 2011-02-22 08:53:02 UTC (rev 15239)
@@ -18,8 +18,8 @@
#include <QVBoxLayout>
#include <qdialogbuttonbox.h>
#include <qmessagebox.h>
+#include <QDoubleSpinBox>
-
// Qgis includes
#include "settings.h"
@@ -47,6 +47,15 @@
h->addWidget( mcbPluginsDistanceUnit );
v->addLayout( h );
+ h = new QHBoxLayout();
+ l = new QLabel( tr( "Topology tolerance" ), this );
+ h->addWidget( l );
+ msbTopologyTolerance = new QDoubleSpinBox( this );
+ msbTopologyTolerance->setMinimum( 0.0 );
+ msbTopologyTolerance->setDecimals( 5 );
+ h->addWidget( msbTopologyTolerance );
+ v->addLayout( h );
+
/*
h = new QHBoxLayout();
l = new QLabel( tr("Select graph source:"), this);
@@ -118,3 +127,13 @@
mcbPluginsDistanceUnit->setCurrentIndex( i );
}
}
+
+void RgSettingsDlg::setTopologyTolerance( double f )
+{
+ msbTopologyTolerance->setValue( f );
+}
+
+double RgSettingsDlg::topologyTolerance()
+{
+ return msbTopologyTolerance->value();
+}
Modified: trunk/qgis/src/plugins/roadgraph/settingsdlg.h
===================================================================
--- trunk/qgis/src/plugins/roadgraph/settingsdlg.h 2011-02-21 22:41:55 UTC (rev 15238)
+++ trunk/qgis/src/plugins/roadgraph/settingsdlg.h 2011-02-22 08:53:02 UTC (rev 15239)
@@ -19,6 +19,7 @@
// forward declaration QT-classes
class QComboBox;
+class QDoubleSpinBox;
// forward declaration Qgis-classes
@@ -47,6 +48,9 @@
void setDistanceUnitName( const QString& );
+ void setTopologyTolerance( double f );
+
+ double topologyTolerance();
private:
static const int context_id = 0;
@@ -75,5 +79,10 @@
* plugin time unit
*/
QComboBox *mcbPluginsTimeUnit;
+
+ /**
+ * topology tolerance factor
+ */
+ QDoubleSpinBox *msbTopologyTolerance;
};
#endif
Modified: trunk/qgis/src/plugins/roadgraph/shortestpathwidget.cpp
===================================================================
--- trunk/qgis/src/plugins/roadgraph/shortestpathwidget.cpp 2011-02-21 22:41:55 UTC (rev 15238)
+++ trunk/qgis/src/plugins/roadgraph/shortestpathwidget.cpp 2011-02-22 08:53:02 UTC (rev 15239)
@@ -223,7 +223,8 @@
{
if ( mFrontPointLineEdit->text().isNull() || mBackPointLineEdit->text().isNull() )
return false;
- RgSimpleGraphBuilder builder( mPlugin->iface()->mapCanvas()->mapRenderer()->destinationSrs() );
+ RgSimpleGraphBuilder builder( mPlugin->iface()->mapCanvas()->mapRenderer()->destinationSrs(),
+ mPlugin->topologyToleranceFactor() );
{
const RgGraphDirector *director = mPlugin->director();
if ( director == NULL )
Modified: trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.cpp
===================================================================
--- trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.cpp 2011-02-21 22:41:55 UTC (rev 15238)
+++ trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.cpp 2011-02-22 08:53:02 UTC (rev 15239)
@@ -18,6 +18,8 @@
#include "utils.h"
// Qgis includes
+#include <qgsfeature.h>
+#include <qgsgeometry.h>
RgSimpleGraphBuilder::RgSimpleGraphBuilder( const QgsCoordinateReferenceSystem& crs, double topologyTolerance ) :
RgGraphBuilder( crs, topologyTolerance )
@@ -26,21 +28,27 @@
QgsPoint RgSimpleGraphBuilder::addVertex( const QgsPoint& pt )
{
- // I cann't use QgsSpatialIndex in this time.
- // QgsSpatialIndex::nearestNeighbor() return only features id not geometry
- //
- // This code is very slow and need me for a tests.
-
- double t = topologyTolerance();
- if ( t > 0.0 )
+ double f = topologyTolerance();
+ if ( f > 0 )
{
- AdjacencyMatrix::iterator it;
- for ( it = mMatrix.begin(); it != mMatrix.end(); ++it )
+ QgsRectangle r( pt.x() - f, pt.y() - f, pt.x() + f, pt.y() + f );
+ QList< int > searchResult = mPointIndex.intersects( r );
+ if ( !searchResult.empty() )
{
- if ( it->first.sqrDist( pt ) < t )
- return it->first;
+ int i = searchResult.front();
+ if ( mPointMap[ i ].sqrDist( pt ) < topologyTolerance() )
+ {
+ return mPointMap[ i ];
+ }
}
+ int newId = mPointMap.size() + 1;
+
+ QgsFeature f( newId );
+ f.setGeometry( QgsGeometry::fromPoint( pt ) );
+ mPointIndex.insertFeature( f );
+ mPointMap.insert( newId, pt );
}
+
mMatrix[ pt ];
return pt;
}
Modified: trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.h
===================================================================
--- trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.h 2011-02-21 22:41:55 UTC (rev 15238)
+++ trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.h 2011-02-22 08:53:02 UTC (rev 15239)
@@ -21,6 +21,7 @@
//QT4 includes
//QGIS includes
+#include <qgsspatialindex.h>
//forward declarations
class QgsDistanceArea;
@@ -51,5 +52,9 @@
AdjacencyMatrix adjacencyMatrix();
private:
AdjacencyMatrix mMatrix;
+
+ QgsSpatialIndex mPointIndex;
+
+ QMap< int, QgsPoint> mPointMap;
};
#endif //SIMPLEGRAPHBUILDER
More information about the QGIS-commit
mailing list