Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add topology tolerance
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15239 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
stopa85 committed Feb 22, 2011
1 parent f708fe7 commit 99ecdba
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/plugins/roadgraph/CMakeLists.txt
Expand Up @@ -30,7 +30,8 @@ SET (VRP_RCCS roadgraph.qrc)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${GEOS_INCLUDE_DIR}
../../core
../../core
../../core/spatialindex/
../../gui
..
)
Expand Down
11 changes: 10 additions & 1 deletion src/plugins/roadgraph/roadgraphplugin.cpp
Expand Up @@ -77,6 +77,7 @@ RoadGraphPlugin::RoadGraphPlugin( QgisInterface * theQgisInterface ):
mSettings = new RgLineVectorLayerSettings();
mTimeUnitName = "h";
mDistanceUnitName = "km";
mTopologyToleranceFactor = 0.0;
}

RoadGraphPlugin::~RoadGraphPlugin()
Expand Down Expand Up @@ -174,17 +175,19 @@ void RoadGraphPlugin::property()

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()

Expand Down Expand Up @@ -244,6 +247,8 @@ void RoadGraphPlugin::projectRead()
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()

Expand Down Expand Up @@ -344,6 +349,10 @@ QString RoadGraphPlugin::distanceUnitName()
return mDistanceUnitName;
}

double RoadGraphPlugin::topologyToleranceFactor()
{
return mTopologyToleranceFactor;
}
//////////////////////////////////////////////////////////////////////////
//
//
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/roadgraph/roadgraphplugin.h
Expand Up @@ -71,6 +71,11 @@ class RoadGraphPlugin: public QObject, public QgisPlugin
*/
QString distanceUnitName();

/**
* get topology tolerance factor
*/
double topologyToleranceFactor();

public slots:
void render( QPainter *painter );
//! init the gui
Expand Down Expand Up @@ -155,6 +160,12 @@ class RoadGraphPlugin: public QObject, public QgisPlugin
* distance unit for results presentation
*/
QString mDistanceUnitName;

/**
* topology tolerance factor
*/
double mTopologyToleranceFactor;

private:
static const int mArrowSize = 5;
};
Expand Down
21 changes: 20 additions & 1 deletion src/plugins/roadgraph/settingsdlg.cpp
Expand Up @@ -18,7 +18,7 @@
#include <QVBoxLayout>
#include <qdialogbuttonbox.h>
#include <qmessagebox.h>

#include <QDoubleSpinBox>

// Qgis includes
#include "settings.h"
Expand Down Expand Up @@ -47,6 +47,15 @@ RgSettingsDlg::RgSettingsDlg( RgSettings *settings, QWidget* parent, Qt::WFlags
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);
Expand Down Expand Up @@ -118,3 +127,13 @@ void RgSettingsDlg::setDistanceUnitName( const QString& name )
mcbPluginsDistanceUnit->setCurrentIndex( i );
}
}

void RgSettingsDlg::setTopologyTolerance( double f )
{
msbTopologyTolerance->setValue( f );
}

double RgSettingsDlg::topologyTolerance()
{
return msbTopologyTolerance->value();
}
9 changes: 9 additions & 0 deletions src/plugins/roadgraph/settingsdlg.h
Expand Up @@ -19,6 +19,7 @@

// forward declaration QT-classes
class QComboBox;
class QDoubleSpinBox;

// forward declaration Qgis-classes

Expand Down Expand Up @@ -47,6 +48,9 @@ class RgSettingsDlg : public QDialog

void setDistanceUnitName( const QString& );

void setTopologyTolerance( double f );

double topologyTolerance();
private:
static const int context_id = 0;

Expand Down Expand Up @@ -75,5 +79,10 @@ class RgSettingsDlg : public QDialog
* plugin time unit
*/
QComboBox *mcbPluginsTimeUnit;

/**
* topology tolerance factor
*/
QDoubleSpinBox *msbTopologyTolerance;
};
#endif
3 changes: 2 additions & 1 deletion src/plugins/roadgraph/shortestpathwidget.cpp
Expand Up @@ -223,7 +223,8 @@ bool RgShortestPathWidget::getPath( AdjacencyMatrix& matrix, QgsPoint& p1, QgsPo
{
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 )
Expand Down
30 changes: 19 additions & 11 deletions src/plugins/roadgraph/simplegraphbuilder.cpp
Expand Up @@ -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 )
Expand All @@ -26,21 +28,27 @@ RgSimpleGraphBuilder::RgSimpleGraphBuilder( const QgsCoordinateReferenceSystem&

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;
}
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/roadgraph/simplegraphbuilder.h
Expand Up @@ -21,6 +21,7 @@
//QT4 includes

//QGIS includes
#include <qgsspatialindex.h>

//forward declarations
class QgsDistanceArea;
Expand Down Expand Up @@ -51,5 +52,9 @@ class RgSimpleGraphBuilder : public RgGraphBuilder
AdjacencyMatrix adjacencyMatrix();
private:
AdjacencyMatrix mMatrix;

QgsSpatialIndex mPointIndex;

QMap< int, QgsPoint> mPointMap;
};
#endif //SIMPLEGRAPHBUILDER

0 comments on commit 99ecdba

Please sign in to comment.