kopia lustrzana https://github.com/anitagraser/ogd-at-lab
Add OSM traces
rodzic
072fc33b5d
commit
f0911295e2
|
@ -25,7 +25,7 @@
|
|||
"import hvplot.pandas\n",
|
||||
"import pandas as pd\n",
|
||||
"import geopandas as gpd\n",
|
||||
"from utils.dataaccess import gdf_from_wfs, get_airquality_df, get_heatvulnerabilityindex_gdf"
|
||||
"from utils.dataaccess import get_gdf_from_wfs, get_airquality_df, get_heatvulnerabilityindex_gdf"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -52,7 +52,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"uhvi.hvplot(geo=True, tiles='OSM', c='AVG_UHVI_A', title='Average Urban Heat Vulnerability Index - All age groups', cmap='Reds').opts(active_tools=['wheel_zoom'])"
|
||||
"uhvi.hvplot(geo=True, tiles='OSM', c='AVG_UHVI_A', title='Average Urban Heat Vulnerability Index - All age groups', cmap='Reds', alpha=0.7).opts(active_tools=['wheel_zoom'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -70,7 +70,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"stations = gdf_from_wfs('LUFTGUETENETZOGD')\n",
|
||||
"stations = get_gdf_from_wfs('LUFTGUETENETZOGD')\n",
|
||||
"stations.set_index('NAME_KURZ', inplace=True)\n",
|
||||
"stations.head()"
|
||||
]
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
"source": [
|
||||
"import hvplot.pandas\n",
|
||||
"from geopy.geocoders import Nominatim\n",
|
||||
"from utils.dataaccess import gdf_from_wfs\n",
|
||||
"from utils.dataaccess import get_gdf_from_wfs\n",
|
||||
"from utils.plotting import hvplot_with_buffer\n",
|
||||
"from utils.converting import location_to_gdf"
|
||||
]
|
||||
|
@ -85,7 +85,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"gdf = gdf_from_wfs('ELADESTELLEOGD')\n",
|
||||
"gdf = get_gdf_from_wfs('ELADESTELLEOGD')\n",
|
||||
"map_plot * gdf.hvplot(geo=True).opts(active_tools=['wheel_zoom']) "
|
||||
]
|
||||
},
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
"outputs": [],
|
||||
"source": [
|
||||
"import hvplot.pandas\n",
|
||||
"from utils.dataaccess import get_uber_movement_gdf"
|
||||
"import movingpandas as mpd\n",
|
||||
"from datetime import timedelta\n",
|
||||
"from utils.dataaccess import get_uber_movement_gdf, get_osm_traces"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -81,7 +83,7 @@
|
|||
"source": [
|
||||
"joined = feb.join(mar, lsuffix='_feb', rsuffix='_mar')\n",
|
||||
"diff = joined[f'{COL}_mar'] - joined[f'{COL}_feb'] \n",
|
||||
"diff.hvplot.hist(title='Histogram of destination area counts (March 2020 - Feb 2020)')"
|
||||
"diff.hvplot.hist(title='Histogram of destination area counts (March 2020 - Feb 2020)', xlim=(-300,300))"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -92,7 +94,61 @@
|
|||
"source": [
|
||||
"joined = jan.join(feb, lsuffix='_jan', rsuffix='_feb')\n",
|
||||
"diff = joined[f'{COL}_feb'] - joined[f'{COL}_jan'] \n",
|
||||
"diff.hvplot.hist(title='Histogram of destination area counts (Feb 2020 - Jan 2020)')"
|
||||
"diff.hvplot.hist(title='Histogram of destination area counts (Feb 2020 - Jan 2020)', xlim=(-300,300))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## OpenStreetMap Traces"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Source: https://www.openstreetmap.org/traces"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"gdf = get_osm_traces()\n",
|
||||
"osm_traces = mpd.TrajectoryCollection(gdf, 'track_fid')\n",
|
||||
"print(f'The OSM traces download contains {len(osm_traces)} tracks')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"for track in osm_traces: print(f'Track {track.id}: length={track.get_length():.0f}m')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"osm_traces = mpd.MinTimeDeltaGeneralizer(osm_traces).generalize(tolerance=timedelta(minutes=1))\n",
|
||||
"osm_traces.hvplot(title='OSM Traces', line_width=7, width=700, height=500)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"osm_traces.get_trajectory(3).hvplot(title='Speed (m/s) along track', c='speed', cmap='RdYlBu',\n",
|
||||
" line_width=7, width=700, height=500, tiles='CartoLight', colorbar=True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
Plik diff jest za duży
Load Diff
|
@ -3,7 +3,7 @@ from urllib.request import urlretrieve
|
|||
import geopandas as gpd
|
||||
import pandas as pd
|
||||
|
||||
def gdf_from_wfs(layer):
|
||||
def get_gdf_from_wfs(layer):
|
||||
"""
|
||||
Get geopandas.GeoDataFrame from data.wien.gv.at WFS service based on layer name
|
||||
|
||||
|
@ -101,10 +101,10 @@ def get_heatvulnerabilityindex_gdf():
|
|||
https://www.wien.gv.at/gogv/l9ogdaverageurbanheatvulnerabilityindex
|
||||
"""
|
||||
df = get_heatvulnerabilityindex_df()
|
||||
districts = gdf_from_wfs('ZAEHLBEZIRKOGD')
|
||||
districts = get_gdf_from_wfs('ZAEHLBEZIRKOGD')
|
||||
districts['SUB_DISTRICT_CODE_VIE'] = districts['ZBEZ'].astype(int) + 90000
|
||||
districts.set_index('SUB_DISTRICT_CODE_VIE', inplace=True)
|
||||
gdf = districts.join(df) #gpd.GeoDataFrame(pd.DataFrame(districts).join(df))
|
||||
gdf = districts.join(df)
|
||||
return gdf
|
||||
|
||||
def get_zaehlsprengel_gdf(year=2020):
|
||||
|
@ -143,3 +143,17 @@ def get_uber_movement_gdf():
|
|||
df.set_index('dstid', inplace=True)
|
||||
|
||||
return gdf.join(df)
|
||||
|
||||
def get_osm_traces(page=0, bbox='16.18,48.09,16.61,48.32'):
|
||||
file = 'osm_traces.gpx'
|
||||
url = f'https://api.openstreetmap.org/api/0.6/trackpoints?bbox={bbox}&page={page}'
|
||||
if not exists(file):
|
||||
urlretrieve(url, file)
|
||||
gdf = gpd.read_file(file, layer='track_points')
|
||||
# dropping empty columns
|
||||
gdf.drop(columns=['ele', 'course', 'speed', 'magvar', 'geoidheight', 'name', 'cmt', 'desc',
|
||||
'src', 'url', 'urlname', 'sym', 'type', 'fix', 'sat', 'hdop', 'vdop',
|
||||
'pdop', 'ageofdgpsdata', 'dgpsid'], inplace=True)
|
||||
gdf['t'] = pd.to_datetime(gdf['time'])
|
||||
gdf.set_index('t', inplace=True)
|
||||
return gdf
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
"outputs": [],
|
||||
"source": [
|
||||
"import hvplot.pandas\n",
|
||||
"from utils.dataaccess import gdf_from_wfs\n",
|
||||
"from utils.dataaccess import get_gdf_from_wfs\n",
|
||||
"from utils.plotting import hvplot_with_buffer"
|
||||
]
|
||||
},
|
||||
|
@ -42,7 +42,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"gdf = gdf_from_wfs('CITYBIKEOGD')"
|
||||
"gdf = get_gdf_from_wfs('CITYBIKEOGD')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -76,7 +76,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"gdf2 = gdf_from_wfs('ELADESTELLEOGD')"
|
||||
"gdf2 = get_gdf_from_wfs('ELADESTELLEOGD')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -101,7 +101,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"election_districts = gdf_from_wfs('WAHLSPRGR2020OGD')\n",
|
||||
"election_districts = get_gdf_from_wfs('WAHLSPRGR2020OGD')\n",
|
||||
"election_districts.hvplot(geo=True, tiles='OSM', alpha=0.5).opts(active_tools=['wheel_zoom'])"
|
||||
]
|
||||
},
|
||||
|
|
Ładowanie…
Reference in New Issue