Generate network from city
This commit is contained in:
parent
d383725bc8
commit
e9a05f4bc2
Binary file not shown.
Binary file not shown.
@ -1,6 +1,9 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import xmltodict
|
import xmltodict
|
||||||
|
|
||||||
|
import geopandas as gpd
|
||||||
|
from shapely.geometry import Point
|
||||||
|
|
||||||
from matsim_activity_to_matsim_schedule import MatsimActivityToMatsimSchedule
|
from matsim_activity_to_matsim_schedule import MatsimActivityToMatsimSchedule
|
||||||
from hub_function_to_matsim_activity import HubFunctionToMatsimActivity
|
from hub_function_to_matsim_activity import HubFunctionToMatsimActivity
|
||||||
|
|
||||||
@ -19,6 +22,11 @@ class MatSimEngine:
|
|||||||
hub_function_to_matsim = HubFunctionToMatsimActivity()
|
hub_function_to_matsim = HubFunctionToMatsimActivity()
|
||||||
matsim_schedule = MatsimActivityToMatsimSchedule()
|
matsim_schedule = MatsimActivityToMatsimSchedule()
|
||||||
|
|
||||||
|
buildings_shape_data = {
|
||||||
|
'id': [],
|
||||||
|
'geometry': []
|
||||||
|
}
|
||||||
|
|
||||||
# 1- Facilities
|
# 1- Facilities
|
||||||
# TODO: Add the ability for a building to have multiple activities
|
# TODO: Add the ability for a building to have multiple activities
|
||||||
for building in city.buildings:
|
for building in city.buildings:
|
||||||
@ -26,6 +34,13 @@ class MatSimEngine:
|
|||||||
schedule = matsim_schedule.dictionary[activity]
|
schedule = matsim_schedule.dictionary[activity]
|
||||||
start_time, end_time = schedule.split('-')
|
start_time, end_time = schedule.split('-')
|
||||||
|
|
||||||
|
new_id = 0
|
||||||
|
for surface in building.surfaces:
|
||||||
|
for coord in surface.solid_polygon.coordinates:
|
||||||
|
new_id += 1
|
||||||
|
buildings_shape_data['id'].append(f"{new_id}_building.name")
|
||||||
|
buildings_shape_data['geometry'].append(Point(coord[0], coord[1]))
|
||||||
|
|
||||||
facility = {
|
facility = {
|
||||||
'@id': building.name,
|
'@id': building.name,
|
||||||
'@x': str(building.centroid[0]),
|
'@x': str(building.centroid[0]),
|
||||||
@ -44,6 +59,13 @@ class MatSimEngine:
|
|||||||
}
|
}
|
||||||
facilities_dict['facilities']['facility'].append(facility)
|
facilities_dict['facilities']['facility'].append(facility)
|
||||||
|
|
||||||
|
gdf = gpd.GeoDataFrame(
|
||||||
|
buildings_shape_data,
|
||||||
|
crs="EPSG:26911"
|
||||||
|
)
|
||||||
|
|
||||||
|
gdf.to_file("input_files/buildings_shapefile.shp")
|
||||||
|
|
||||||
# Convert the Python dictionary to an XML string
|
# Convert the Python dictionary to an XML string
|
||||||
xml_content = xmltodict.unparse(facilities_dict, pretty=True)
|
xml_content = xmltodict.unparse(facilities_dict, pretty=True)
|
||||||
|
|
||||||
@ -52,6 +74,12 @@ class MatSimEngine:
|
|||||||
file.write(xml_content)
|
file.write(xml_content)
|
||||||
|
|
||||||
# 2- Network
|
# 2- Network
|
||||||
|
# First get only the part of the network necessary for the simulation
|
||||||
|
java_path = "java"
|
||||||
|
jar_path = "matsim-network-from-osm.jar"
|
||||||
|
command = [java_path, "-jar", jar_path, "input_files/merged-network.osm.pbf", "input_files/buildings_shapefile.shp", f"{output_file_path}/network.xml.gz"]
|
||||||
|
subprocess.run(command)
|
||||||
|
|
||||||
# 3- Population
|
# 3- Population
|
||||||
# 4- Config Generation
|
# 4- Config Generation
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user