Functional Geometry.path_connect() and added to seed-based painting algorithm.
This commit is contained in:
52
camlib.py
52
camlib.py
@@ -390,8 +390,12 @@ class Geometry(object):
|
|||||||
|
|
||||||
def path_connect(self):
|
def path_connect(self):
|
||||||
"""
|
"""
|
||||||
|
Simplifies a list of paths by joining those whose ends touch.
|
||||||
|
The list of paths of generated from the geometry.flatten()
|
||||||
|
method which writes to geometry.flat_geometry. This list
|
||||||
|
if overwritten by this method with the optimized result.
|
||||||
|
|
||||||
:return:
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
flat_geometry = self.flatten(pathonly=True)
|
flat_geometry = self.flatten(pathonly=True)
|
||||||
@@ -420,35 +424,43 @@ class Geometry(object):
|
|||||||
log.debug('path_connect(), geo not in storage:')
|
log.debug('path_connect(), geo not in storage:')
|
||||||
log.debug(str(e))
|
log.debug(str(e))
|
||||||
|
|
||||||
left = storage.nearest(geo.coords[0])
|
_, left = storage.nearest(geo.coords[0])
|
||||||
|
|
||||||
if left.coords[0] == geo.coords[0]:
|
if type(left) == LineString:
|
||||||
|
if left.coords[0] == geo.coords[0]:
|
||||||
|
storage.remove(left)
|
||||||
|
geo.coords = list(geo.coords)[::-1] + list(left.coords)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if left.coords[-1] == geo.coords[0]:
|
||||||
|
storage.remove(left)
|
||||||
|
geo.coords = list(left.coords) + list(geo.coords)
|
||||||
|
continue
|
||||||
|
else:
|
||||||
storage.remove(left)
|
storage.remove(left)
|
||||||
geo = geo.union(left)
|
optimized_geometry.append(left)
|
||||||
continue
|
|
||||||
|
|
||||||
if left.coords[-1] == geo.coords[0]:
|
_, right = storage.nearest(geo.coords[-1])
|
||||||
storage.remove(left)
|
|
||||||
geo.union(left)
|
|
||||||
continue
|
|
||||||
|
|
||||||
right = storage.nearest(geo.coords[-1])
|
if type(right) == LineString:
|
||||||
|
if right.coords[0] == geo.coords[-1]:
|
||||||
|
storage.remove(right)
|
||||||
|
geo.coords = list(geo.coords) + list(right.coords)
|
||||||
|
continue
|
||||||
|
|
||||||
if right.coords[0] == geo.coords[-1]:
|
if right.coords[-1] == geo.coords[-1]:
|
||||||
|
storage.remove(right)
|
||||||
|
geo.coords = list(geo.coords) + list(right.coords)[::-1]
|
||||||
|
continue
|
||||||
|
else:
|
||||||
storage.remove(right)
|
storage.remove(right)
|
||||||
geo = geo.union(right)
|
optimized_geometry.append(right)
|
||||||
continue
|
|
||||||
|
|
||||||
if right.coords[-1] == geo.coords[-1]:
|
|
||||||
storage.remove(right)
|
|
||||||
geo.union(right)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# No matches on either end
|
# No matches on either end
|
||||||
optimized_geometry.append[geo]
|
optimized_geometry.append(geo)
|
||||||
|
|
||||||
# Next
|
# Next
|
||||||
geo = storage.nearest(geo.coords[0])
|
_, geo = storage.nearest(geo.coords[0])
|
||||||
|
|
||||||
except StopIteration: # Nothing found in storage.
|
except StopIteration: # Nothing found in storage.
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user