import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
/Users/lchen/anaconda3/envs/geo_env/lib/python3.8/site-packages/geopandas/_compat.py:84: UserWarning: The Shapely GEOS version (3.9.1dev-CAPI-1.14.1) is incompatible with the GEOS version PyGEOS was compiled with (3.9.0-CAPI-1.16.2). Conversions between both will be slow. warnings.warn(
data = pd.read_csv('addresses.txt', sep=';')
data.head()
id | addr | |
---|---|---|
0 | 1000 | Itämerenkatu 14, 00101 Helsinki, Finland |
1 | 1001 | Kampinkuja 1, 00100 Helsinki, Finland |
2 | 1002 | Kaivokatu 8, 00101 Helsinki, Finland |
3 | 1003 | Hermannin rantatie 1, 00580 Helsinki, Finland |
4 | 1005 | Tyynenmerenkatu 9, 00220 Helsinki, Finland |
from geopandas.tools import geocode
geo = geocode(data['addr'])
geo.head()
geometry | address | |
---|---|---|
0 | POINT (24.91441 60.16320) | Itämerenkatu 14, 00180 Helsinki, Finland |
1 | POINT (24.93041 60.16860) | Kampinkuja 1, 00100 Helsinki, Finland |
2 | POINT (24.94141 60.16999) | Kaivokatu 8, 00100 Helsinki, Finland |
3 | POINT (24.97441 60.19530) | Hermannin rantatie, Helsinki, Finland |
4 | POINT (24.92154 60.15670) | Tyynenmerenkatu 9, 00220 Helsinki, Finland |
join = geo.join(data)
join.head()
geometry | address | id | addr | |
---|---|---|---|---|
0 | POINT (24.91441 60.16320) | Itämerenkatu 14, 00180 Helsinki, Finland | 1000 | Itämerenkatu 14, 00101 Helsinki, Finland |
1 | POINT (24.93041 60.16860) | Kampinkuja 1, 00100 Helsinki, Finland | 1001 | Kampinkuja 1, 00100 Helsinki, Finland |
2 | POINT (24.94141 60.16999) | Kaivokatu 8, 00100 Helsinki, Finland | 1002 | Kaivokatu 8, 00101 Helsinki, Finland |
3 | POINT (24.97441 60.19530) | Hermannin rantatie, Helsinki, Finland | 1003 | Hermannin rantatie 1, 00580 Helsinki, Finland |
4 | POINT (24.92154 60.15670) | Tyynenmerenkatu 9, 00220 Helsinki, Finland | 1005 | Tyynenmerenkatu 9, 00220 Helsinki, Finland |
import matplotlib.pyplot as plt
join.plot()
plt.tight_layout()
import osmnx as ox
place_name = "Kamppi, Helsinki, Finland"
graph = ox.graph_from_place(place_name)
ox.plot_graph(graph)
(<Figure size 576x576 with 1 Axes>, <AxesSubplot:>)
nodes, edges = ox.graph_to_gdfs(graph) # convert networkx to GeoPandas
nodes.plot()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-9-020683b94c5c> in <module> ----> 1 nodes.plot() NameError: name 'nodes' is not defined
edges.plot()
area = ox.geocode_to_gdf(place_name) # Pandas
buildings = ox.geometries.geometries_from_place(place_name, tags={'building':True}) # Pandas
fig, ax = plt.subplots()
area.plot(ax=ax, facecolor='black')
edges.plot(ax=ax, linewidth=1, edgecolor='#BC8F8F')
buildings.plot(ax=ax, facecolor='khaki', alpha=0.7)
plt.tight_layout()
acc = gpd.read_file('data2/TravelTimes_to_5975375_RailwayStation.shp')
acc = acc[acc['pt_r_tt'] >=0]
acc.plot(column="pt_r_tt", k=9, cmap="RdYlBu", linewidth=0, legend=True);
In [5]: acc.plot(column="walk_d", k=9, cmap="RdYlBu", linewidth=0, legend=True);
import pysal as ps
/Users/lchen/anaconda3/envs/geo_env/lib/python3.8/site-packages/pysal/explore/segregation/network/network.py:15: UserWarning: You need pandana and urbanaccess to work with segregation's network module You can install them with `pip install urbanaccess pandana` or `conda install -c udst pandana urbanaccess` warn( /Users/lchen/anaconda3/envs/geo_env/lib/python3.8/site-packages/pysal/model/spvcm/abstracts.py:10: UserWarning: The `dill` module is required to use the sqlite backend fully. from .sqlite import head_to_sql, start_sql
import mapclassify as mc
classifier = mc.NaturalBreaks.make(k=9)
classifications = acc[['pt_r_tt']].apply(classifier)
acc['nb_pt_r_tt'] = classifications
acc.head()
car_m_d | car_m_t | car_r_d | car_r_t | from_id | pt_m_d | pt_m_t | pt_m_tt | pt_r_d | pt_r_t | pt_r_tt | to_id | walk_d | walk_t | geometry | nb_pt_r_tt | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 32297 | 43 | 32260 | 48 | 5785640 | 32616 | 116 | 147 | 32616 | 108 | 139 | 5975375 | 32164 | 459 | POLYGON ((382000.000 6697750.000, 381750.000 6... | 8 |
1 | 32508 | 43 | 32471 | 49 | 5785641 | 32822 | 119 | 145 | 32822 | 111 | 133 | 5975375 | 29547 | 422 | POLYGON ((382250.000 6697750.000, 382000.000 6... | 8 |
2 | 30133 | 50 | 31872 | 56 | 5785642 | 32940 | 121 | 146 | 32940 | 113 | 133 | 5975375 | 29626 | 423 | POLYGON ((382500.000 6697750.000, 382250.000 6... | 8 |
3 | 32690 | 54 | 34429 | 60 | 5785643 | 33233 | 125 | 150 | 33233 | 117 | 144 | 5975375 | 29919 | 427 | POLYGON ((382750.000 6697750.000, 382500.000 6... | 8 |
4 | 31872 | 42 | 31834 | 48 | 5787544 | 32127 | 109 | 126 | 32127 | 101 | 121 | 5975375 | 31674 | 452 | POLYGON ((381250.000 6697500.000, 381000.000 6... | 7 |
acc.plot(column="nb_pt_r_tt", linewidth=0, legend=True);