16 from datetime
import datetime
19 import geopandas
as gpd
23 file_prefix = sys.argv[1]
24 edges = gpd.read_file(sys.argv[2])
25 nodes = gpd.read_file(sys.argv[3])
27 raise Exception(
'Incorrect arguments provide')
30 nodes = nodes.rename(columns={
'start_node':
'startid'})
31 edges = edges.rename(columns={
'start_node':
'startid'})
32 nodes = nodes.rename(columns={
'end_node':
'endid'})
33 edges = edges.rename(columns={
'end_node':
'endid'})
36 edges = edges.rename(columns={
'edge_id':
'id'})
39 if 'id' in nodes.columns:
40 nodes[
'id'] = nodes[
'id'].astype(int)
41 if 'id' in edges.columns:
42 edges[
'id'] = edges[
'id'].astype(int)
46 graph = pd.concat([nodes, edges])
49 if 'startid' in graph.columns:
50 graph[
'startid'] = graph[
'startid'].fillna(-1).astype(int)
51 if 'endid' in graph.columns:
52 graph[
'endid'] = graph[
'endid'].fillna(-1).astype(int)
53 if 'startid' in graph.columns:
54 graph[
'startid'] = graph[
'startid'].astype(int)
55 if 'endid' in graph.columns:
56 graph[
'endid'] = graph[
'endid'].astype(int)
58 file_name = file_prefix +
'_' + now.strftime(
'%m_%d_%Y_%H_%M_%S') +
'.geojson'
60 graph.to_file(file_name, driver=
'GeoJSON')