-
Notifications
You must be signed in to change notification settings - Fork 10
Usage: 3.5. Writing Data: JSON & GeoJSON
Kasia Kozlowska edited this page Jul 14, 2022
·
2 revisions
Available as a jupyter notebook or wiki page.
from genet import read_matsim
import os
path_to_matsim_network = '../example_data/pt2matsim_network'
network = os.path.join(path_to_matsim_network, 'network.xml')
schedule = os.path.join(path_to_matsim_network, 'schedule.xml')
vehicles = os.path.join(path_to_matsim_network, 'vehicles.xml')
n = read_matsim(
path_to_network=network,
epsg='epsg:27700',
path_to_schedule=schedule,
path_to_vehicles=vehicles
)
# you don't need to read the vehicles file, but doing so ensures all vehicles
# in the schedule are of the expected type and the definition of the vehicle
# is preserved
n.print()
Graph info: Name:
Type: MultiDiGraph
Number of nodes: 1662
Number of edges: 3166
Average in degree: 1.9049
Average out degree: 1.9049
Schedule info: Schedule:
Number of services: 9
Number of routes: 68
Number of stops: 118
You can write the Network and it's Schedule (if applicable) to JSON:
n.write_to_json('../example_data/output_json')
2022-07-14 15:38:02,012 - Saving Network to JSON in ../example_data/output_json
2022-07-14 15:38:03,912 - Saving Schedule to JSON in ../example_data/output_json
Writing the Network to JSON preserves all of the Network data - unlike writing the Network to CSV or MATSim format. For limitations of those formats head over to Sections/Notebooks:
- Writing CSV data
- Writing MATSim data
You can also choose to write the network to GeoJSON. This will produce spatial representation of the Network graph and the Schedule graph.
- The main diference for the Network graph outputs is that the link geometry is a
LINESTRING
, whereas in the JSON outputs, this geometry is an encoded polyline. - The biggest difference is for the Schedule graph. With JSON output you get the entire Schedule data saved to file. With GeoJSON you get only the spatial representation of the graph, nodes and edges, where nodes are the Stops in the Schedule and edges are the connections between Stops as defined by the Route and Service objects which use those Stops. It does not include any information about the vehicles, their IDs or modes, vehicle definitions or network routes (the edges are straight lines between the Stops)
n.write_to_geojson('../example_data/output_geojson')
2022-07-14 15:38:05,560 - Saving Network to GeoJSON in ../example_data/output_geojson
2022-07-14 15:38:06,974 - Saving Schedule to GeoJSON in ../example_data/output_geojson