Skip to content

Commit

Permalink
pre topology tolerance changeset
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@15232 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
stopa85 committed Feb 21, 2011
1 parent 8c64657 commit 1d9aaa2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
9 changes: 7 additions & 2 deletions src/plugins/roadgraph/graphbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

// Qgis includes

RgGraphBuilder::RgGraphBuilder( const QgsCoordinateReferenceSystem& crs ) :
mCrs( crs )
RgGraphBuilder::RgGraphBuilder( const QgsCoordinateReferenceSystem& crs, double topologyTolerance ) :
mCrs( crs ), mTopologyToleraceFactor( topologyTolerance )
{

}
Expand All @@ -33,3 +33,8 @@ QgsCoordinateReferenceSystem& RgGraphBuilder::destinationCrs()
{
return mCrs;
}

double RgGraphBuilder::topologyTolerance()
{
return mTopologyToleraceFactor;
}
11 changes: 9 additions & 2 deletions src/plugins/roadgraph/graphbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RgGraphBuilder
{
public:
//! Constructor
RgGraphBuilder( const QgsCoordinateReferenceSystem& crs );
RgGraphBuilder( const QgsCoordinateReferenceSystem& crs, double topologyTolerance = 0.0 );

//! Destructor
virtual ~RgGraphBuilder();
Expand All @@ -43,10 +43,15 @@ class RgGraphBuilder
*/
QgsCoordinateReferenceSystem& destinationCrs();

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

/**
* add vertex
*/
virtual void addVertex( const QgsPoint& pt ) = 0;
virtual QgsPoint addVertex( const QgsPoint& pt ) = 0;

/**
* add arc
Expand All @@ -55,5 +60,7 @@ class RgGraphBuilder

private:
QgsCoordinateReferenceSystem mCrs;

double mTopologyToleraceFactor;
};
#endif //GRAPHBUILDER
5 changes: 3 additions & 2 deletions src/plugins/roadgraph/linevectorlayerdirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void RgLineVectorLayerDirector::makeGraph( RgGraphBuilder *builder, const QVecto
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;
Expand All @@ -105,6 +105,7 @@ void RgLineVectorLayerDirector::makeGraph( RgGraphBuilder *builder, const QVecto

if ( pointLengthMap[ i ].mLength > info.mLength )
{
info.mTiedPoint = builder->addVertex( info.mTiedPoint );
info.mFirstPoint = pt1;
info.mLastPoint = pt2;

Expand Down Expand Up @@ -181,7 +182,7 @@ void RgLineVectorLayerDirector::makeGraph( RgGraphBuilder *builder, const QVecto
QgsPolyline::iterator pointIt;
for ( pointIt = pl.begin(); pointIt != pl.end(); ++pointIt )
{
pt2 = ct.transform( *pointIt );
pt2 = builder->addVertex( ct.transform( *pointIt ) );

std::map< double, QgsPoint > pointsOnArc;
pointsOnArc[ 0.0 ] = pt1;
Expand Down
22 changes: 19 additions & 3 deletions src/plugins/roadgraph/simplegraphbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,30 @@

// Qgis includes

RgSimpleGraphBuilder::RgSimpleGraphBuilder( const QgsCoordinateReferenceSystem& crs ) :
RgGraphBuilder( crs )
RgSimpleGraphBuilder::RgSimpleGraphBuilder( const QgsCoordinateReferenceSystem& crs, double topologyTolerance ) :
RgGraphBuilder( crs, topologyTolerance )
{
}

void RgSimpleGraphBuilder::addVertex( const QgsPoint& pt )
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 )
{
AdjacencyMatrix::iterator it;
for ( it = mMatrix.begin(); it != mMatrix.end(); ++it )
{
if ( it->first.sqrDist( pt ) < t )
return it->first;
}
}
mMatrix[ pt ];
return pt;
}

void RgSimpleGraphBuilder::addArc( const QgsPoint& pt1, const QgsPoint& pt2, double cost, double speed )
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/roadgraph/simplegraphbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class RgSimpleGraphBuilder : public RgGraphBuilder
/**
* default constructor
*/
RgSimpleGraphBuilder( const QgsCoordinateReferenceSystem& crs );
RgSimpleGraphBuilder( const QgsCoordinateReferenceSystem& crs, double topologyTolerance = 0.0 );

/**
* MANDATORY BUILDER PROPERTY DECLARATION
*/
void addVertex( const QgsPoint& pt );
QgsPoint addVertex( const QgsPoint& pt );
void addArc( const QgsPoint& pt1, const QgsPoint& pt2, double cost, double speed );

/**
Expand Down

0 comments on commit 1d9aaa2

Please sign in to comment.