Skip to content

Commit f6a6da9

Browse files
author
stopa85
committedFeb 21, 2011
pre topology tolerance changeset
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15232 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed
 

‎src/plugins/roadgraph/graphbuilder.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
// Qgis includes
2020

21-
RgGraphBuilder::RgGraphBuilder( const QgsCoordinateReferenceSystem& crs ) :
22-
mCrs( crs )
21+
RgGraphBuilder::RgGraphBuilder( const QgsCoordinateReferenceSystem& crs, double topologyTolerance ) :
22+
mCrs( crs ), mTopologyToleraceFactor( topologyTolerance )
2323
{
2424

2525
}
@@ -33,3 +33,8 @@ QgsCoordinateReferenceSystem& RgGraphBuilder::destinationCrs()
3333
{
3434
return mCrs;
3535
}
36+
37+
double RgGraphBuilder::topologyTolerance()
38+
{
39+
return mTopologyToleraceFactor;
40+
}

‎src/plugins/roadgraph/graphbuilder.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class RgGraphBuilder
3333
{
3434
public:
3535
//! Constructor
36-
RgGraphBuilder( const QgsCoordinateReferenceSystem& crs );
36+
RgGraphBuilder( const QgsCoordinateReferenceSystem& crs, double topologyTolerance = 0.0 );
3737

3838
//! Destructor
3939
virtual ~RgGraphBuilder();
@@ -43,10 +43,15 @@ class RgGraphBuilder
4343
*/
4444
QgsCoordinateReferenceSystem& destinationCrs();
4545

46+
/**
47+
* get topology tolerance factor
48+
*/
49+
double topologyTolerance();
50+
4651
/**
4752
* add vertex
4853
*/
49-
virtual void addVertex( const QgsPoint& pt ) = 0;
54+
virtual QgsPoint addVertex( const QgsPoint& pt ) = 0;
5055

5156
/**
5257
* add arc
@@ -55,5 +60,7 @@ class RgGraphBuilder
5560

5661
private:
5762
QgsCoordinateReferenceSystem mCrs;
63+
64+
double mTopologyToleraceFactor;
5865
};
5966
#endif //GRAPHBUILDER

‎src/plugins/roadgraph/linevectorlayerdirector.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void RgLineVectorLayerDirector::makeGraph( RgGraphBuilder *builder, const QVecto
9494
QgsPolyline::iterator pointIt;
9595
for ( pointIt = pl.begin(); pointIt != pl.end(); ++pointIt )
9696
{
97-
pt2 = ct.transform( *pointIt );
97+
pt2 = builder->addVertex( ct.transform( *pointIt ) );
9898
if ( !isFirstPoint )
9999
{
100100
int i = 0;
@@ -105,6 +105,7 @@ void RgLineVectorLayerDirector::makeGraph( RgGraphBuilder *builder, const QVecto
105105

106106
if ( pointLengthMap[ i ].mLength > info.mLength )
107107
{
108+
info.mTiedPoint = builder->addVertex( info.mTiedPoint );
108109
info.mFirstPoint = pt1;
109110
info.mLastPoint = pt2;
110111

@@ -181,7 +182,7 @@ void RgLineVectorLayerDirector::makeGraph( RgGraphBuilder *builder, const QVecto
181182
QgsPolyline::iterator pointIt;
182183
for ( pointIt = pl.begin(); pointIt != pl.end(); ++pointIt )
183184
{
184-
pt2 = ct.transform( *pointIt );
185+
pt2 = builder->addVertex( ct.transform( *pointIt ) );
185186

186187
std::map< double, QgsPoint > pointsOnArc;
187188
pointsOnArc[ 0.0 ] = pt1;

‎src/plugins/roadgraph/simplegraphbuilder.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,30 @@
1919

2020
// Qgis includes
2121

22-
RgSimpleGraphBuilder::RgSimpleGraphBuilder( const QgsCoordinateReferenceSystem& crs ) :
23-
RgGraphBuilder( crs )
22+
RgSimpleGraphBuilder::RgSimpleGraphBuilder( const QgsCoordinateReferenceSystem& crs, double topologyTolerance ) :
23+
RgGraphBuilder( crs, topologyTolerance )
2424
{
2525
}
2626

27-
void RgSimpleGraphBuilder::addVertex( const QgsPoint& pt )
27+
QgsPoint RgSimpleGraphBuilder::addVertex( const QgsPoint& pt )
2828
{
29+
// I cann't use QgsSpatialIndex in this time.
30+
// QgsSpatialIndex::nearestNeighbor() return only features id not geometry
31+
//
32+
// This code is very slow and need me for a tests.
33+
34+
double t = topologyTolerance();
35+
if ( t > 0.0 )
36+
{
37+
AdjacencyMatrix::iterator it;
38+
for ( it = mMatrix.begin(); it != mMatrix.end(); ++it )
39+
{
40+
if ( it->first.sqrDist( pt ) < t )
41+
return it->first;
42+
}
43+
}
2944
mMatrix[ pt ];
45+
return pt;
3046
}
3147

3248
void RgSimpleGraphBuilder::addArc( const QgsPoint& pt1, const QgsPoint& pt2, double cost, double speed )

‎src/plugins/roadgraph/simplegraphbuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ class RgSimpleGraphBuilder : public RgGraphBuilder
3737
/**
3838
* default constructor
3939
*/
40-
RgSimpleGraphBuilder( const QgsCoordinateReferenceSystem& crs );
40+
RgSimpleGraphBuilder( const QgsCoordinateReferenceSystem& crs, double topologyTolerance = 0.0 );
4141

4242
/**
4343
* MANDATORY BUILDER PROPERTY DECLARATION
4444
*/
45-
void addVertex( const QgsPoint& pt );
45+
QgsPoint addVertex( const QgsPoint& pt );
4646
void addArc( const QgsPoint& pt1, const QgsPoint& pt2, double cost, double speed );
4747

4848
/**

0 commit comments

Comments
 (0)
Please sign in to comment.