Skip to content
Permalink
Browse files

add topology tolerance

git-svn-id: http://svn.osgeo.org/qgis/trunk@15239 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
stopa85
stopa85 committed Feb 22, 2011
1 parent b642e80 commit f6eea72bad12ec9bc8775d4c1ccb3d661ee98729
@@ -30,7 +30,8 @@ SET (VRP_RCCS roadgraph.qrc)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${GEOS_INCLUDE_DIR}
../../core
../../core
../../core/spatialindex/
../../gui
..
)
@@ -77,6 +77,7 @@ RoadGraphPlugin::RoadGraphPlugin( QgisInterface * theQgisInterface ):
mSettings = new RgLineVectorLayerSettings();
mTimeUnitName = "h";
mDistanceUnitName = "km";
mTopologyToleranceFactor = 0.0;
}

RoadGraphPlugin::~RoadGraphPlugin()
@@ -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()

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

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

double RoadGraphPlugin::topologyToleranceFactor()
{
return mTopologyToleranceFactor;
}
//////////////////////////////////////////////////////////////////////////
//
//
@@ -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
@@ -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;
};
@@ -18,7 +18,7 @@
#include <QVBoxLayout>
#include <qdialogbuttonbox.h>
#include <qmessagebox.h>

#include <QDoubleSpinBox>

// Qgis includes
#include "settings.h"
@@ -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);
@@ -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();
}
@@ -19,6 +19,7 @@

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

// forward declaration Qgis-classes

@@ -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;

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

/**
* topology tolerance factor
*/
QDoubleSpinBox *msbTopologyTolerance;
};
#endif
@@ -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 )
@@ -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 @@ 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;
}
@@ -21,6 +21,7 @@
//QT4 includes

//QGIS includes
#include <qgsspatialindex.h>

//forward declarations
class QgsDistanceArea;
@@ -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 f6eea72

Please sign in to comment.
You can’t perform that action at this time.