Commit 49ec3120 authored by Eric Duminil's avatar Eric Duminil
Browse files

Output OSM table

parent 2f4477c0
%% Cell type:code id:4888de6c tags:
``` python
from pathlib import Path
```
%% Cell type:code id:bb724cab tags:
``` python
import pickle
```
%% Cell type:code id:b584ca38 tags:
``` python
import pandas as pd
```
%% Cell type:code id:e74c7f88 tags:
``` python
from pyproj import Transformer
from shapely import LineString
```
%% Cell type:code id:9eac1a09 tags:
``` python
EPSG_ID = 25832
to_local = Transformer.from_crs("EPSG:4326", f"EPSG:{EPSG_ID}", always_xy=True)
```
%% Cell type:code id:0fed9052 tags:
``` python
pd.set_option('display.max_columns', None)
```
%% Cell type:code id:89e9aff8 tags:
``` python
list(Path('cache').glob('*.pickle'))
```
%% Output
[WindowsPath('cache/48_864071__48_866928__9_196641__9_203522.pickle'),
WindowsPath('cache/49_80081__49_803063__9_947011__9_95511.pickle'),
WindowsPath('cache/49_802665__49_804083__9_942116__9_945581.pickle'),
WindowsPath('cache/49_802698__49_804055__9_942167__9_945563.pickle'),
WindowsPath('cache/49_802704__49_803486__9_944034__9_945488.pickle')]
%% Cell type:code id:8aac3681 tags:
``` python
def load_cache(cache_path):
with open(Path('cache') / '49_802698__49_804055__9_942167__9_945563.pickle', 'rb') as f:
return pickle.load(f)
```
%% Cell type:code id:d050a116 tags:
``` python
def get_way_dict(way):
# Length
url = f'https://www.openstreetmap.org/way/{way.id}'
xy_s = [to_local.transform(node.lon, node.lat) for node in way.nodes]
path = LineString(xy_s)
other_info = {'id': way.id,
'URL': f'=HYPERLINK("{url}"; "{url}")',
'length [m]': round(path.length, 1)}
return other_info | way.tags
```
%% Cell type:code id:7a9f108b tags:
``` python
numerical_columns = ['maxspeed [km/h]', 'width [m]', 'length [m]']
```
%% Cell type:code id:741fa825 tags:
``` python
def create_table(ways):
df = pd.DataFrame([get_way_dict(way) for way in ways]).set_index('id').rename(columns={'width': 'width [m]', 'maxspeed': 'maxspeed [km/h]'})
for col in numerical_columns:
df[col] = pd.to_numeric(df[col])
df.fillna('')
return df
```
%% Cell type:code id:a12d5684 tags:
``` python
for cache_path in Path('cache').glob('*.pickle'):
df = create_table(load_cache(cache_path))
df.to_csv(Path('output') / f'OSM_infos_{cache_path.stem}.csv',
sep=';',
decimal=',',
encoding='utf-8-sig'
)
```
%% Cell type:code id:328d048f tags:
``` python
```
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment