Skip to content
Permalink
Browse files

New topology tolerance implementation. Some bug fix.

  • Loading branch information
Sergey Yakushevs
Sergey Yakushevs committed May 26, 2011
1 parent dd01e40 commit 0564e47b221c5f9347c5fa3b8564a674adfe72ae
@@ -39,19 +39,15 @@ QgsPoint QgsGraphBuilder::addVertex( const QgsPoint& pt )
if ( id != -1 )
return mGraph->vertex( id ).point();

QgsPoint newPoint = pt;
if ( topologyTolerance() > 0 )
{
int newId = mGraph->addVertex( pt );

QgsFeature f( newId );
f.setGeometry( QgsGeometry::fromPoint( pt ) );
mPointIndex.insertFeature( f );

return pt;
newPoint = QgsPoint( ceil( pt.x() / topologyTolerance() ) * topologyTolerance(),
ceil( pt.y() / topologyTolerance() ) * topologyTolerance() );
}
int newId = mGraph->addVertex( pt );

mPointMap[ pt ] = newId;
mPointMap[ newPoint ] = newId;
return pt;
}

@@ -82,22 +78,18 @@ QgsGraph* QgsGraphBuilder::graph()

int QgsGraphBuilder::pointId( const QgsPoint& pt )
{
QgsPoint findPoint = pt;
if ( topologyTolerance() > 0.0 )
{
QgsRectangle r( pt.x() - topologyTolerance(), pt.y() - topologyTolerance(), pt.x() + topologyTolerance(), pt.y() + topologyTolerance() );
QList< int > searchResult = mPointIndex.intersects( r );
if ( !searchResult.empty() )
{
return searchResult.front();
}

}else
findPoint = QgsPoint( ceil( pt.x() / topologyTolerance() ) * topologyTolerance() ,
ceil( pt.y() / topologyTolerance() ) * topologyTolerance() ) ;
}

std::map< QgsPoint, int, QgsPointCompare >::iterator it = mPointMap.find( findPoint );
if ( it != mPointMap.end() )
{
std::map< QgsPoint, int, QgsPointCompare >::iterator it = mPointMap.find( pt );
if ( it != mPointMap.end() )
{
return it->second;
}
return it->second;
}

return -1;
}
@@ -66,7 +66,7 @@ class ANALYSIS_EXPORT QgsGraphBuilderInterface
}

//! get topology tolerance
bool topologyTolerance()
double topologyTolerance()
{
return mTopologyTolerance;
}
@@ -98,14 +98,22 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
QgsPolyline::iterator pointIt;
for ( pointIt = pl.begin(); pointIt != pl.end(); ++pointIt )
{
pt2 = ct.transform( *pointIt );
pt2 = builder->addVertex( ct.transform( *pointIt ) );
if ( !isFirstPoint )
{
int i = 0;
for ( i = 0; i != additionalPoints.size(); ++i )
{
TiePointInfo info;
info.mLength = additionalPoints[ i ].sqrDistToSegment( pt1.x(), pt1.y(), pt2.x(), pt2.y(), info.mTiedPoint );
if ( pt1 == pt2 )
{
info.mLength = additionalPoints[ i ].sqrDist( pt1 );
info.mTiedPoint = pt1;
}else
{
info.mLength = additionalPoints[ i ].sqrDistToSegment( pt1.x(), pt1.y(),
pt2.x(), pt2.y(), info.mTiedPoint );
}

if ( pointLengthMap[ i ].mLength > info.mLength )
{
@@ -264,7 +264,7 @@ bool RgShortestPathWidget::getPath( QgsGraph* shortestTree, QgsPoint& p1, QgsPoi
// not need
delete director;
}

if ( p1 == QgsPoint( 0.0, 0.0 ) )
{
QMessageBox::critical( this, tr( "Tie point failed" ), tr( "Start point doesn't tie to the road!" ) );
@@ -275,11 +275,12 @@ bool RgShortestPathWidget::getPath( QgsGraph* shortestTree, QgsPoint& p1, QgsPoi
QMessageBox::critical( this, tr( "Tie point failed" ), tr( "Stop point doesn't tie to the road!" ) );
return false;
}
QgsGraph* graph = builder.graph();

QVector< int > pointIdx(0,0);
QVector< double > pointCost(0,0.0);

int startVertexIdx = graph->findVertex( p1 );
std::cout << " startVertexIdx " << startVertexIdx << "\n";
int criterionNum = 0;
if ( mCriterionName->currentIndex() > 0 )
criterionNum = 1;

0 comments on commit 0564e47

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