Преглед изворни кода

Fixes to path_connect() related to LinearRings. Added test cases.

jpcaram пре 11 година
родитељ
комит
a1345f0a58
2 измењених фајлова са 27 додато и 8 уклоњено
  1. 11 8
      camlib.py
  2. 16 0
      tests/test_pathconnect.py

+ 11 - 8
camlib.py

@@ -583,21 +583,24 @@ class Geometry(object):
 
                 # No matches on either end
                 #optimized_geometry.append(geo)
-                optimized_geometry.append(right)
-                storage.remove(right)
-                geo = right
-                print "stored right, now geo<-right"
 
-                # Next
-                #_, geo = storage.nearest(geo.coords[0])
-                #optimized_geometry.append(geo)
+                storage.remove(right)
+                if type(right) == LinearRing:
+                    # Put the linearring at the beginning so it does
+                    # not iterfere.
+                    optimized_geometry = [right] + optimized_geometry
+                    geo = optimized_geometry[-1]
+                    print "right was LinearRing, getting previous"
+                else:
+                    optimized_geometry.append(right)
+                    geo = right
+                    print "stored right, now geo<-right"
 
         except StopIteration:  # Nothing found in storage.
             pass
 
         print path_count
 
-        #self.flat_geometry = optimized_geometry
         return optimized_geometry
 
     def convert_units(self, units):

+ 16 - 0
tests/test_pathconnect.py

@@ -53,5 +53,21 @@ class PathConnectTest1(unittest.TestCase):
                                                          [1 + offset_x, 1 + offset_y],
                                                          [2 + offset_x, 1 + offset_y]])))
 
+    def test_ring_interfere_connect(self):
+        print
+        print "TEST STARTING ..."
+
+        paths = [
+            LineString([[0, 0], [1, 1]]),
+            LineString([[1, 1], [2, 1]]),
+            LinearRing([[1, 1], [2, 2], [1, 3], [0, 2]])
+        ]
+
+        result = Geometry.path_connect(paths)
+
+        self.assertEqual(len(result), 2)
+        matches = [p for p in result if p.equals(LineString([[0, 0], [1, 1], [2, 1]]))]
+        self.assertEqual(len(matches), 1)
+
 if __name__ == "__main__":
     unittest.main()