Commit 923449be authored by Eric Duminil's avatar Eric Duminil
Browse files

Adding color and description

parent 9c29c9e4
...@@ -110,10 +110,9 @@ def place_trees(forest, ways, region, to_local, tree_distance, min_distance_2): ...@@ -110,10 +110,9 @@ def place_trees(forest, ways, region, to_local, tree_distance, min_distance_2):
else: else:
color = 'gray' color = 'gray'
local_xy_s = [to_local.transform(node.lon, node.lat) road_xy_s = [to_local.transform(node.lon, node.lat) for node in way.nodes]
for node in way.nodes]
tree_path = LineString(local_xy_s) tree_path = LineString(road_xy_s)
if width: if width:
road_as_polygon = tree_path.buffer(width / 2, cap_style='flat') road_as_polygon = tree_path.buffer(width / 2, cap_style='flat')
...@@ -123,9 +122,8 @@ def place_trees(forest, ways, region, to_local, tree_distance, min_distance_2): ...@@ -123,9 +122,8 @@ def place_trees(forest, ways, region, to_local, tree_distance, min_distance_2):
# NOTE: Could try to guess width depending on highway type. # NOTE: Could try to guess width depending on highway type.
displayed_width = 1 displayed_width = 1
xs, ys = zip(*local_xy_s) road_xs, road_ys = zip(*road_xy_s)
plt.plot(xs, ys, linewidth=displayed_width, plt.plot(road_xs, road_ys, linewidth=displayed_width, c=color, alpha=0.8, zorder=-1)
c=color, alpha=0.8, zorder=-1)
distances = np.arange(0, tree_path.length, tree_distance) distances = np.arange(0, tree_path.length, tree_distance)
potential_trees = [tree_path.interpolate( potential_trees = [tree_path.interpolate(
...@@ -137,7 +135,10 @@ def place_trees(forest, ways, region, to_local, tree_distance, min_distance_2): ...@@ -137,7 +135,10 @@ def place_trees(forest, ways, region, to_local, tree_distance, min_distance_2):
x = potential_tree.x x = potential_tree.x
y = potential_tree.y y = potential_tree.y
if local_region.contains(geometry.Point(x, y)): if local_region.contains(geometry.Point(x, y)):
forest.add_tree_if_possible(min_distance_2, x, y) forest.add_tree_if_possible(min_distance_2, x, y,
color='red',
description='fake_tree'
)
return forest.xs_ys return forest.xs_ys
...@@ -213,7 +214,7 @@ def main(wkt_polygon, epsg_id, tree_distance, min_distance, import_tree_shp): ...@@ -213,7 +214,7 @@ def main(wkt_polygon, epsg_id, tree_distance, min_distance, import_tree_shp):
set_plot(bounds, to_local) set_plot(bounds, to_local)
tree_xs, tree_ys = place_trees(existing_forest, ways, region, to_local, tree_distance, min_distance**2) tree_xs, tree_ys = place_trees(existing_forest, ways, region, to_local, tree_distance, min_distance**2)
print(existing_forest) print(repr(existing_forest))
plot_trees(bounds, tree_xs, tree_ys, tree_distance) plot_trees(bounds, tree_xs, tree_ys, tree_distance)
export_map(bounds, tree_xs, tree_ys, epsg_id) export_map(bounds, tree_xs, tree_ys, epsg_id)
......
...@@ -11,6 +11,7 @@ class Tree: ...@@ -11,6 +11,7 @@ class Tree:
radius: float = None radius: float = None
description: str = None description: str = None
type: str = None type: str = None
color: str = 'green'
def __len__(self): def __len__(self):
return 2 # x & y return 2 # x & y
...@@ -28,11 +29,11 @@ class Forest: ...@@ -28,11 +29,11 @@ class Forest:
self.trees = existing_trees self.trees = existing_trees
def add_tree_if_possible(self, min_distance_2, x, y, *params): def add_tree_if_possible(self, min_distance_2, x, y, **kparams):
_nearest_tree, distance_2 = self.kd_tree.search_nn((x, y)) _nearest_tree, distance_2 = self.kd_tree.search_nn((x, y))
if distance_2 > min_distance_2: if distance_2 > min_distance_2:
self.kd_tree.add((x, y)) self.kd_tree.add((x, y))
self.trees.append(Tree(x, y, *params)) self.trees.append(Tree(x, y, **kparams))
@property @property
def xs_ys(self): def xs_ys(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment