def readNetworkFile(file): """Reads a MATSim network file and converts it to a geo Parameters: file (string): the path of the network file Returns: geo : the MATSim network """ print("Reading network...") net = matsim.read_network(file) print("Read network!") geo = net.as_geo() print("Network ready!") return geo
print("OOPS! Error importing required libraries.") print('try "pip3 install matsim-tools dfply pyproj"') if len(sys.argv) != 3: print( "USAGE: python create-geojson-network.py [network] [coord-system]") sys.exit(1) p_network = sys.argv[1] p_coords = sys.argv[2] out_file = p_network.replace(".xml.", ".geo.json.") coord_transformer = Transformer.from_crs(p_coords, "EPSG:4326") print("reading network:", p_network) network = matsim.read_network(p_network) # Build link x/y lookup nodes = network.nodes >> mutate(to_node=X.node_id, from_node=X.node_id) links = (network.links >> inner_join(nodes, by="from_node") >> select( X.link_id, X.from_node, X.to_node_x, X.x, X.y) >> mutate( x0=X.x, y0=X.y, to_node=X.to_node_x) >> inner_join(nodes, by="to_node") >> select(X.link_id, X.x0, X.y0, X.x_y, X.y_y)) # convert coords to lat/lon print("reprojecting coordinates") converted_links = {} for link in links.values: coords = [] fromY, fromX = coord_transformer.transform(link[1], link[2])
# ] try: import ndjson import sys import matsim from dfply import * except: print("OOPS! Error importing required libraries.") print('try "pip install matsim-tools ndjson dfply"') # outfile hard-coded for now outfile = "drt-vehicles.json" print("reading network", sys.argv[1]) network = matsim.read_network(sys.argv[1]) # Build link x/y lookup -- use 'to_node' (endpoint) of link nodes = network.nodes >> mutate(to_node=X.node_id) links = network.links >> inner_join(nodes, by="to_node") >> select( X.link_id, X.x, X.y) link_coords = {} for link in links.values: link_coords[link[0]] = (float(link[1]), float(link[2])) print("reading events", sys.argv[2]) events = matsim.event_reader(sys.argv[2], types="actstart,actend") # lookups by person's health status, coords, and timepoints agents = {}