Commit 84ff6304 authored by Eric Duminil's avatar Eric Duminil
Browse files

Show roads on map too.

parent 0bfefd43
......@@ -28,6 +28,7 @@ from tree import Forest
from import_existing_trees import get_existing_forest
from export_OSM_roads_to_csv import write_roads_to_csv
################################################################################
# USER PARAMETERS #
################################################################################
......@@ -138,7 +139,7 @@ def get_basename(bounds: Bounds, with_tree_distance=True) -> str:
return bounds_description
def get_osm_roads(bounds: Bounds):
def get_osm_roads(bounds: Bounds) -> list:
cache_dir = SCRIPT_DIR / 'cache'
cache_dir.mkdir(exist_ok=True)
......@@ -235,6 +236,7 @@ def place_trees(forest: Forest, ways: list, region: str, to_local, tree_distance
tree_path = LineString(road_xy_s)
if width:
road_as_polygon = tree_path.buffer(width / 2, cap_style='flat')
tree_path = road_as_polygon.exterior
......@@ -284,12 +286,18 @@ def plot_trees(bounds: Bounds, forest: Forest, tree_distance: float) -> None:
print(" DONE!")
def export_map(bounds: Bounds, forest: Forest, epsg_id: int) -> None:
def export_map(bounds: Bounds, forest: Forest, ways: list, epsg_id: int) -> None:
print("Exporting Map...")
to_wgs84 = Transformer.from_crs(f"EPSG:{epsg_id}", "EPSG:4326", always_xy=True)
interactive_map = folium.Map()
interactive_map.fit_bounds([(bounds.S, bounds.W), (bounds.N, bounds.E)])
for way in ways:
folium.PolyLine([(node.lat, node.lon) for node in way.nodes],
color='blue',
weight=5,
opacity=0.5).add_to(interactive_map)
for tree in forest:
lon, lat = to_wgs84.transform(tree.x, tree.y)
folium.Circle(
......@@ -313,6 +321,7 @@ def export_map(bounds: Bounds, forest: Forest, epsg_id: int) -> None:
control=True
).add_to(interactive_map)
interactive_map.save(OUTPUT_DIR / f"{get_basename(bounds)}_trees.html")
print(" DONE!")
......@@ -379,7 +388,7 @@ def main(wkt_polygon: str, epsg_id: int, tree_distance: float, min_distance: flo
print(existing_forest)
plot_trees(bounds, forest, tree_distance)
export_map(bounds, forest, epsg_id)
export_map(bounds, forest, ways, epsg_id)
export_csv(bounds, forest, wkt_polygon, tree_distance, min_distance, epsg_id)
export_shapefile(bounds, forest, epsg_id)
......
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