This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import geopandas as gpd | |
import numpy as np | |
import os, urllib, json, csv, zipfile, math | |
INPUT='input_ut.csv' | |
OUTPUT='output_ut.csv' | |
OUTPUT_PC='distances_pc4_ut.json' | |
with zipfile.Zipfile('gtfs-nl.zip') as z: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URL = 'http://localhost:8080/otp/routers/default/plan?' | |
outputFile = open(OUTPUT, 'w') | |
writer = csv.writer(outputFile) | |
writer.writerow(['StartDate','StartTime','StartLat','StartLon','EndLat', | |
'EndLon', 'DurationMin']) | |
# Takes CSV input, creates URLs, stores data locally in row array | |
for c, d in df.iterrows(): | |
params = {'date' : d['Date'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pc = gpd.read_file(os.path.join('PC_4-shp','PC4.shp')) | |
df = pd.read_csv(OUTPUT) | |
gdf = gpd.GeoDataFrame(df, | |
geometry=gpd.points_from_xy(df.EndLon, df.EndLat)) | |
[['geometry', 'DurationMin']] | |
def get_avg_traveltime(pc4): | |
v = gdf[gdf.within(pc4['geometry'] )].mean(skipna=True) | |
if math.isnan(v): | |
return np.NaN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pc.to_file(OUTPUT_PC, driver="GeoJSON") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Unreachable? Closest other postal area and add 15 min | |
for index, pcode in pc.iterrows(): | |
if math.isnan(pcode.Traveltime): | |
# get 'not disjoint' countries | |
dst=pc[pc.geometry.touches(pcode.geometry)]['Traveltime'].mean(skipna=True) | |
# add names of neighbors as NEIGHBORS value | |
if ~math.isnan(dst) and (dst > 0): | |
pc.at[index, "Traveltime"] = int(dst + 15) | |
else: | |
pc.at[index, "Traveltime"] = pc.Traveltime.max() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Java -Xmx12G -jar otp-2.0.0-shaded.jar --build --serve . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java -Xmx12G -jar otp-2.0.0-shaded.jar --build --serve . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import geopandas as gpd | |
import numpy as np | |
import urllib, json, csv, zipfile, sys | |
import matplotlib.pyplot as plt | |
from geopandas.tools import sjoin | |
from shapely.geometry import LineString, Point | |
with zipfile.ZipFile('gtfs-nl.zip') as z: | |
with z.open('stops.txt') as f: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
segments_df['line'] = segments_df.apply(lambda x: LineString([Point(x["lon_x"], x["lat_x"]), | |
Point(x["lon_y"], x["lat_y"])]), | |
axis=1) | |
geodata = gpd.GeoDataFrame(segments_df, geometry=segments_df['line']) | |
geodata['width'] = 5 * (geodata['count']) / (geodata['count'].max()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
geodata.plot(figsize=(15, 15), linewidth=np.minimum(np.maximum(df5['width'], 0.1), 2.75)) |