コード例 #1
0
def converting_data_to_graph(folder_path_data_filtered):
    '''
    Transforms GTFS data to a graph using the peartree package

    Parameters
    ----------
    folder_path_data_filtered : string
        Path of the folder containing the zip file comprising
        the cleaned GTFS data.

    Returns
    -------
    G : Graph
        Graph containing all the data from the GTFS files.

    '''
    path = folder_path_data_filtered+'filtered_dfs.zip'

    # Automatically identify the busiest day and
    # read that in as a Partridge feed
    feed = pt.get_representative_feed(path)

    # Set a target time period to
    # use to summarize impedance
    start = 1*60*60  # 1:00 AM
    end = 23*60*60  # 11:00 PM

    # Converts feed subset into a directed
    # network multigraph
    G = pt.load_feed_as_graph(feed, start, end, name='RATP',
                              use_multiprocessing=True,
                              impute_walk_transfers=True,
                              connection_threshold=150)

    return G
コード例 #2
0
def load_data(name):
    # Load the streets
    G_s = ox.load_graphml('{}/{}_walk.graphml'.format(name, name))

    # Load the area
    area = gpd.read_file('../Data/{}/{}_shape'.format(name, name))
    area = ox.project_gdf(area,
                          to_crs={
                              'datum': 'WGS84',
                              'ellps': 'WGS84',
                              'proj': 'utm',
                              'zone': 34,
                              'units': 'm'
                          })

    path = '../Data/{}/budapest_gtfs.zip'.format(name)

    # Automatically identify the busiest day and read that in as a Partidge feed
    #G = ox.load_graphml('{}/{}_bike.graphml'.format(name, name))
    # Automatically identify the busiest day and
    # read that in as a Partidge feed
    feed = pt.get_representative_feed(path)

    # Set a target time period to
    # use to summarize impedance
    start = 7 * 60 * 60  # 7:00 AM
    end = 10 * 60 * 60  # 10:00 AM

    # Converts feed subset into a directed
    # network multigraph
    G = pt.load_feed_as_graph(feed, start, end)

    return G_s, area, G
コード例 #3
0
def main():
    # tl_query = 'https://transit.land/api/v1/feeds?bbox=-73.97339,40.649778,-73.946532,40.670353'
    
    # resp = requests.get(tl_query)
    # rj = resp.json()
    
    # zip_url = None
    # for f in rj['feeds']:
    #     if 'brooklyn' in f['onestop_id']:
    #         zip_url = f['url']
            
    # td = tempfile.mkdtemp()
    # path = os.path.join(td, 'mta_bk.zip')
    
    # resp = requests.get(zip_url)
    # open(path, 'wb').write(resp.content)

    
    feed = pt.get_representative_feed('reduced_stops/updatedv1.zip')
    
    start = 7*60*60  # 7:00 AM
    end = 10*60*60  # 10:00 AM
    
    G = pt.load_feed_as_graph(feed, start, end)
    pt.generate_plot(G)
    nodes = nx.betweenness_centrality(G)
    nids = []
    vals = []
    for k in nodes.keys():
        nids.append(k)
        vals.append(nodes[k])
    vals_adj = []
    
    m = max(vals)
    for v in vals:
        if v == 0:
            vals_adj.append(0)
        else:
            r = (v/m)
            vals_adj.append(r * 0.01)
    
    fig, ax = pt.generate_plot(G)

    ps = []
    for nid, buff_dist in zip(nids, vals_adj):
        n = G.node[nid]
        if buff_dist > 0:
            p = Point(n['x'], n['y']).buffer(buff_dist)
            ps.append(p)
        
    gpd.GeoSeries(ps).plot(ax=ax, color='r', alpha=0.75)
コード例 #4
0
import peartree as pt

pt.utilities.config(log_console=True)

if __name__ == '__main__':
    '''
    Run from command line via:
    python -m cProfile -o profile/cprof-output.py performance/run_etl.py

    And visualize via:
    snakeviz profile/cprof-output.py
    '''
    url_path = 'http://www.actransit.org/wp-content/uploads/GTFS_Fall17.zip'
    tempdir = tempfile.mkdtemp()
    filepath = os.path.join(tempdir, 'perf_gtfs.zip')

    response = urlopen(url_path)
    zipcontent = response.read()
    with open(filepath, 'wb') as f:
        f.write(zipcontent)
    feed = pt.get_representative_feed(filepath)

    start = 7 * 60 * 60  # 7:00 AM
    end = 10 * 60 * 60  # 10:00 AM
    G = pt.load_feed_as_graph(feed,
                              start,
                              end,
                              interpolate_times=True,
                              use_multiprocessing=False)
コード例 #5
0
import peartree as pt
import os
from shapely.geometry import Point, LineString
import psycopg2
from cordon.tabular.records import PresenceFieldsMapping
from cordon.analysis.operation import LocalOperation
import folium

#read transportation network from gtfs file
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
path = os.path.join(BASE_DIR,'gtfs.zip')

feed = pt.get_representative_feed(path)
start = 0
end = 24*60*60
G = pt.load_feed_as_graph(feed,start,end)

#constructe cordon network based on transportation network
cordon = CordonNetwork()
for n, d in G.nodes(data=True):
    name = n.split('_')[-1]
    cordon.add_node(name)
    cordon.set_node_geometry(name,Point(d['x'],d['y']))

for a, b, d in G.edges(data=True):
    from_name = a.split('_')[-1]
    to_name = b.split('_')[-1]
    segment_name = '''{}-{}'''.format(from_name,to_name)
    from_point = cordon.get_node_geometry(from_name)
    to_point = cordon.get_node_geometry(to_name)
    line = LineString([from_point, to_point])
コード例 #6
0
ファイル: feed.py プロジェクト: ZHUYAZI/internship_2019
 def __init__(self, path, the_date):
     self.feed = self.get_representative_feed(path,the_date)
     self.G = pt.load_feed_as_graph(self.feed, 0, 24*60*60)
     self.G_add_walk=self.add_edge_walk()
コード例 #7
0
ファイル: importTPL.py プロジェクト: karafede/viasat_trials
import numpy as np
import osmnx as ox
import pandas as pd
import peartree as pt

path = '/Users/valenti/py_work/romatpl/rome_static_gtfs.zip'

# Automatically identify the busiest day and
# read that in as a Partidge feed
feed = pt.get_representative_feed(path)

# Set a target time period to
# use to summarize impedance
start = 7*60*60  # 7:00 AM
end = 10*60*60  # 10:00 AM

# Converts feed subset into a directed
# network multigraph
#if there are two bus stops that are close together 
#the connection_threshold is defaulted to 50 meters.
#walk_speed_kmph is default to 4.5 kilometers per hour. 
G = pt.load_feed_as_graph(feed, start, end, connection_threshold=200,walk_speed_kmph=4.0)
#G_projected = ox.project_graph(G)
ox.plot_graph(G)
origin = [41.867876, 12.519082]  
destination = [41.889517, 12.506139]  
point1 = (42.891310, -78.871355)
print(ox.get_nearest_node(G, origin))
#G_projected = ox.project_graph(G)
# save street network as GraphML file
#ox.save_graphml(G_projected, filename='networkRM.graphml')