[QGIS Commit] r15232 - trunk/qgis/src/plugins/roadgraph

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Feb 21 08:17:07 EST 2011


Author: stopa85
Date: 2011-02-21 05:17:07 -0800 (Mon, 21 Feb 2011)
New Revision: 15232

Modified:
   trunk/qgis/src/plugins/roadgraph/graphbuilder.cpp
   trunk/qgis/src/plugins/roadgraph/graphbuilder.h
   trunk/qgis/src/plugins/roadgraph/linevectorlayerdirector.cpp
   trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.cpp
   trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.h
Log:
pre topology tolerance changeset

Modified: trunk/qgis/src/plugins/roadgraph/graphbuilder.cpp
===================================================================
--- trunk/qgis/src/plugins/roadgraph/graphbuilder.cpp	2011-02-21 12:15:38 UTC (rev 15231)
+++ trunk/qgis/src/plugins/roadgraph/graphbuilder.cpp	2011-02-21 13:17:07 UTC (rev 15232)
@@ -18,8 +18,8 @@
 
 // Qgis includes
 
-RgGraphBuilder::RgGraphBuilder( const QgsCoordinateReferenceSystem& crs ) :
-    mCrs( crs )
+RgGraphBuilder::RgGraphBuilder( const QgsCoordinateReferenceSystem& crs, double topologyTolerance ) :
+    mCrs( crs ), mTopologyToleraceFactor( topologyTolerance )
 {
 
 }
@@ -33,3 +33,8 @@
 {
   return mCrs;
 }
+
+double RgGraphBuilder::topologyTolerance()
+{
+  return mTopologyToleraceFactor;
+}

Modified: trunk/qgis/src/plugins/roadgraph/graphbuilder.h
===================================================================
--- trunk/qgis/src/plugins/roadgraph/graphbuilder.h	2011-02-21 12:15:38 UTC (rev 15231)
+++ trunk/qgis/src/plugins/roadgraph/graphbuilder.h	2011-02-21 13:17:07 UTC (rev 15232)
@@ -33,7 +33,7 @@
 {
   public:
     //! Constructor
-    RgGraphBuilder( const QgsCoordinateReferenceSystem& crs );
+    RgGraphBuilder( const QgsCoordinateReferenceSystem& crs, double topologyTolerance = 0.0 );
 
     //! Destructor
     virtual ~RgGraphBuilder();
@@ -44,9 +44,14 @@
     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
@@ -55,5 +60,7 @@
 
   private:
     QgsCoordinateReferenceSystem mCrs;
+
+    double mTopologyToleraceFactor;
 };
 #endif //GRAPHBUILDER

Modified: trunk/qgis/src/plugins/roadgraph/linevectorlayerdirector.cpp
===================================================================
--- trunk/qgis/src/plugins/roadgraph/linevectorlayerdirector.cpp	2011-02-21 12:15:38 UTC (rev 15231)
+++ trunk/qgis/src/plugins/roadgraph/linevectorlayerdirector.cpp	2011-02-21 13:17:07 UTC (rev 15232)
@@ -94,7 +94,7 @@
     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;
@@ -105,6 +105,7 @@
 
           if ( pointLengthMap[ i ].mLength > info.mLength )
           {
+            info.mTiedPoint = builder->addVertex( info.mTiedPoint );
             info.mFirstPoint = pt1;
             info.mLastPoint = pt2;
 
@@ -181,7 +182,7 @@
     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;

Modified: trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.cpp
===================================================================
--- trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.cpp	2011-02-21 12:15:38 UTC (rev 15231)
+++ trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.cpp	2011-02-21 13:17:07 UTC (rev 15232)
@@ -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 )

Modified: trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.h
===================================================================
--- trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.h	2011-02-21 12:15:38 UTC (rev 15231)
+++ trunk/qgis/src/plugins/roadgraph/simplegraphbuilder.h	2011-02-21 13:17:07 UTC (rev 15232)
@@ -37,12 +37,12 @@
     /**
      * 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 );
 
     /**



More information about the QGIS-commit mailing list