Skip to content

ArefAghajani/tehran_network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

interactive route finder for tehran (co-op project by Aref Aghagani and Mahdi Najafi Sani)


required packages:

  1. pyrosm (load and process pbf map)
  2. ipyleaflet (display and interactivemap interface)
  3. osmnx (convert to graph and find shortest path)
  4. geopandas (for geodata)
  5. mapclassify (for classification)
  6. igraph (for generating the graph)

installing pyrosm: conda install -c conda-forge pyrosm

installing ipyleaflet: conda install -c conda-forge ipyleaflet

installing osmnx: conda install osmnx

installing geopandas pip install geopandas

installing mapclassify pip install mapclassify

installing igraph pip install igraph


how it works?

Interactive Map

First load tehran osm.pbf file which we use it to access the maps network(nodes and roads) with osm.get_network(nodes=True,...). Convert osm map to networkx graph using osm.to_ghraph(). Then locate the start and end markers and get the X,Y coordinate to calculate the nearest nodes for them using osmnx.distance.nearest_nodes(). For calculating the shortest path use the networkx library networkx.shortest_path(). OSMnx generate the list of nodes for the shortest path. Access the X,Y coordinate of each nodes in graph using graph.nodes['each_node']['X' or 'Y']. After that draw the nodes as polylines with ipyleaflets PolyLine() function. For the logic of not showing shortest paths repeatedly when changing marker locations, define line variable with None value a first (which is going to contain PolyLine() func output) and we delete the previous line variable every time we want to create a new one.

first image second image

University Accessibility

First load the tehran roads network using OSM and get network using osm.get_network(nodes = True,...). Then get the buildings and universities locations using osm.get_buldings() and osm.get_pois(). In osm.get_pois() use custom filters to get universities locations. Convert the osm to graph using osm.to_graph(node , edge) and get nodes using get_igraph_nodes(G). Then set the universities variable's (geopandas geodataframe) "geometry" column (which contains original polygon geometries like boundaries or shapes) into the exact polygons centroid point object. Then find the nearest node-id to each university using find_nearest_nodeids(nodes, universities) and store them in src_ids. Then iterate over all unversities to calculate the path lengths of university to all nodes with Dijkstra algorithm using G.shortest_paths_dijkstra(source=src_id,...)(we can atually dont use the dijkstra and just do it with modules own algorithm) & attach the distances to the node-id with creating a new column for nodes data. Then find the center location of each building and set to centroid column in buildings variable(geopands) and after that, set the active geometry to the centroid using buildings.set_geometry("centroid") so any operations will be performed on the centroid points and not the full polygon shapes. Then store the closest node and its distance to each building using nearest_neighbor(buildings, nodes, return_dist=True). Then merge the nodes ["distance_to_closest", "node_id"] columns to bulidings dataframe & store it in "access" dataframe which is going to contain buildings information along with the complete travel distance from each building to universities. Then classify the distance to 8 levels with width of 1 using mapclassify module. At the end use matplootlib module to show the graph.

University Accessibility


written by Aref Aghajni and Mahdi Najafi Sani

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •