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
from pymapd import connect | |
import osmnx as ox | |
import geopandas as gpd |
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
con = connect(user="username", | |
password="password", | |
host="my.host.com", | |
dbname="dbname", | |
protocol="http") | |
print('Connection Successful!') |
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
# Area of Interest Graph | |
G = ox.graph_from_place('Los Angeles, California', network_type='drive') |
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
# Map Preview Graph | |
ox.plot_graph(G) |
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
# Load Edges into GeoDataFrame | |
nodes, edges = ox.graph_to_gdfs(G) | |
# Drop Unwanted Columns | |
edges.drop(['oneway', 'lanes', 'maxspeed'], inplace=True, axis=1) | |
# Preview Data | |
edges |
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
# Check Coordinate Reference System | |
edges.crs |
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
CREATE TABLE la_streets ( | |
osm_id TEXT ENCODING DICT(32), | |
name TEXT ENCODING DICT(32), | |
highway TEXT ENCODING DICT(32), | |
length float, | |
geometry GEOMETRY(LINESTRING, 4326) ENCODING COMPRESSED(32)); |
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
# Load Streets into Existing Table | |
con.load_table_columnar('la_streets', edges) |
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
create table la_street_buffer as ( | |
select | |
osm_id, | |
st_buffer(geometry, 10) as omnisci_geo | |
from | |
la_streets | |
); |
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
create table la_street_collision_pre as ( | |
select | |
sum(number_killed) as number_killed, | |
sum(number_injured) as number_injured, | |
avg(party_count) as avg_party_count, | |
sum(severe_injury_count) as severe_injuries, | |
sum(pedestrian_collision) as ped_collisions, | |
sum(count_ped_killed) as ped_killed, | |
sum(count_ped_injured) as ped_injured, | |
sum(bike_collision) as bike_collisions, |
OlderNewer