"""Inland network map
"""
import os
import sys
from collections import OrderedDict
import pandas as pd
import geopandas as gpd
import cartopy.crs as ccrs
import cartopy.io.shapereader as shpreader
import matplotlib.pyplot as plt
from vtra.utils import *
[docs]def main():
config = load_config()
output_file = os.path.join(config['paths']['figures'], 'inland-map.png')
inland_edge_file_path = os.path.join(
config['paths']['data'], 'post_processed_networks', 'inland_edges.shp')
inland_flow_file_path = os.path.join(config['paths']['output'], 'flow_mapping_combined',
'weighted_flows_national_inland_100_percent.csv')
inland_node_file = os.path.join(config['paths']['data'],
'post_processed_networks', 'inland_nodes.shp')
inland_edge_file = gpd.read_file(inland_edge_file_path,encoding='utf-8')
inland_flow_file = pd.read_csv(inland_flow_file_path)
inland_edge_file = pd.merge(inland_edge_file,inland_flow_file,how='left', on=['edge_id']).fillna(0)
remove_routes_ids = [
('watern_149', 'watern_429'),
('watern_429', 'watern_520'),
('watern_700', 'watern_520'),
('watern_210', 'watern_700'),
('watern_209', 'watern_210'),
('watern_1057', 'watern_1050'),
('watern_1050', 'watern_1051'),
('watern_1051', 'watern_183'),
('watern_183', 'watern_354'),
('watern_176', 'watern_354'),
]
color_by_type = {'Inland route': '#0689d7', 'Inland port': '#d95f0e'}
ax = get_axes()
plot_basemap(ax, config['paths']['data'],highlight_region=[])
scale_bar(ax, location=(0.8, 0.05))
plot_basemap_labels(ax, config['paths']['data'])
proj_lat_lon = ccrs.PlateCarree()
geoms = []
for iter_,record in inland_edge_file.iterrows():
flow = record['max_tons']
edge_id = (record['from_node'],record['to_node'])
if flow > 0 and (edge_id not in remove_routes_ids):
geom = record.geometry
geoms.append(geom)
ax.add_geometries(
geoms,
crs=proj_lat_lon,
linewidth=1.5,
edgecolor='#0689d7',
facecolor='none',
zorder=3
)
# Stations
xs = []
ys = []
for record in shpreader.Reader(inland_node_file).records():
port_type = record.attributes['port_type']
if port_type == 'inland':
geom = record.geometry
x = geom.x
y = geom.y
xs.append(x)
ys.append(y)
ax.scatter(xs, ys, transform=proj_lat_lon, facecolor='#d95f0e', s=12, zorder=5)
# Legend
legend_handles = [
mpatches.Patch(color=color, label=line)
for line, color in color_by_type.items()
]
plt.legend(handles=legend_handles, loc='lower left')
save_fig(output_file)
if __name__ == '__main__':
main()