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

This commit is contained in:
jpcaram 2015-01-27 18:16:22 -05:00
parent 573581ca80
commit a1345f0a58
2 changed files with 27 additions and 8 deletions

View File

@ -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):

View File

@ -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()