Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CircularGreenSimCity
CircularGreenSimCity
Commits
88750074
Commit
88750074
authored
Nov 20, 2024
by
Eric Duminil
Browse files
removing notebook
parent
97ec5d80
Changes
2
Hide whitespace changes
Inline
Side-by-side
python_scripts/add_trees_to_open_street_map/Parse OSM data.ipynb
deleted
100644 → 0
View file @
97ec5d80
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "4888de6c",
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "bb724cab",
"metadata": {},
"outputs": [],
"source": [
"import pickle"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "b584ca38",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e74c7f88",
"metadata": {},
"outputs": [],
"source": [
"from pyproj import Transformer\n",
"from shapely import LineString"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "9eac1a09",
"metadata": {},
"outputs": [],
"source": [
"EPSG_ID = 25832\n",
"to_local = Transformer.from_crs(\"EPSG:4326\", f\"EPSG:{EPSG_ID}\", always_xy=True)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "0fed9052",
"metadata": {},
"outputs": [],
"source": [
"pd.set_option('display.max_columns', None)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "89e9aff8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[WindowsPath('cache/48_864071__48_866928__9_196641__9_203522.pickle'),\n",
" WindowsPath('cache/49_80081__49_803063__9_947011__9_95511.pickle'),\n",
" WindowsPath('cache/49_802665__49_804083__9_942116__9_945581.pickle'),\n",
" WindowsPath('cache/49_802698__49_804055__9_942167__9_945563.pickle'),\n",
" WindowsPath('cache/49_802704__49_803486__9_944034__9_945488.pickle')]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(Path('cache').glob('*.pickle'))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "8aac3681",
"metadata": {},
"outputs": [],
"source": [
"def load_cache(cache_path):\n",
" with open(Path('cache') / '49_802698__49_804055__9_942167__9_945563.pickle', 'rb') as f:\n",
" return pickle.load(f)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "d050a116",
"metadata": {},
"outputs": [],
"source": [
"def get_way_dict(way):\n",
" # Length\n",
" url = f'https://www.openstreetmap.org/way/{way.id}'\n",
" xy_s = [to_local.transform(node.lon, node.lat) for node in way.nodes]\n",
" path = LineString(xy_s)\n",
" other_info = {'id': way.id,\n",
" 'URL': f'=HYPERLINK(\"{url}\"; \"{url}\")',\n",
" 'length [m]': round(path.length, 1)}\n",
" return other_info | way.tags"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "7a9f108b",
"metadata": {},
"outputs": [],
"source": [
"numerical_columns = ['maxspeed [km/h]', 'width [m]', 'length [m]']"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "741fa825",
"metadata": {},
"outputs": [],
"source": [
"def create_table(ways):\n",
" df = pd.DataFrame([get_way_dict(way) for way in ways]).set_index('id').rename(columns={'width': 'width [m]', 'maxspeed': 'maxspeed [km/h]'})\n",
" for col in numerical_columns:\n",
" df[col] = pd.to_numeric(df[col])\n",
" df.fillna('')\n",
" return df"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "a12d5684",
"metadata": {},
"outputs": [],
"source": [
"for cache_path in Path('cache').glob('*.pickle'):\n",
" df = create_table(load_cache(cache_path))\n",
" df.to_csv(Path('output') / f'OSM_infos_{cache_path.stem}.csv',\n",
" sep=';',\n",
" decimal=',',\n",
" encoding='utf-8-sig'\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "328d048f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% 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
```
python_scripts/flow_chart/cgsc - paper.dot
0 → 100644
View file @
88750074
digraph
G
{
ratio
=
"fill"
;
size
=
"10,6!"
;
margin
=
0
;
dpi
=
180
;
rankdir
=
"LR"
;
graph
[
fontname
=
"Ubuntu"
]
;
node
[
fontname
=
"Ubuntu"
]
;
edge
[
fontname
=
"Ubuntu"
]
;
node
[
shape
=
ellipse
]
;
compound
=
true
;
citygml
[
label
=
"CityGML"
,
shape
=
box3d
]
;
a
[
label
=
"OpenStreetMap"
,
shape
=
note
]
;
b
[
label
=
"Cadastre"
,
shape
=
note
]
;
c
[
label
=
"Custom DB"
,
shape
=
note
]
;
trees
[
label
=
"Trees.shp"
,
shape
=
note
]
;
# floors [label="Floors.csv", shape=note];
# dreso [label="DreSo.csv", shape=note];
# lib [label="Physics.lib", shape=component];
weather
[
label
=
"Weather data"
,
shape
=
component
]
;
subgraph
cluster_sim
{
label
=
"Simulation"
;
node
[
shape
=
note
,
style
=
rounded
]
;
simstadt
[
label
=
"<sim>SimStadt | <green> Green-Water analysis | <heat>Heating & Cooling demand"
,
shape
=
record
]
;
green
[
label
=
"Green library"
,
shape
=
cylinder
]
;
# archetypes [label="Quarter archetypes", shape=cylinder];
color
=
lightgrey
;
# green -> simstadt;
}
# green -> simstadt;
a
->
trees
;
b
->
trees
;
c
->
trees
;
citygml
->
simstadt
:
sim
;
trees
->
citygml
;
# dreso -> citygml [label="?"];
# floors -> citygml [label="add-floor.py"];
# lib -> simstadt:sim [label="window_ratio.py"];
weather
->
simstadt
:
green
;
weather
->
simstadt
:
heat
;
#shp [label="Results.shp", shape=note];
subgraph
cluster_1
{
label
=
"Outputs"
;
node
[
shape
=
record
]
;
csv1
[
label
=
"Heating.csv"
]
;
csv2
[
label
=
"Cooling.csv"
]
;
csv3
[
label
=
"Water.csv |{ Missing water | Evapotranspiration | Cooling effect}"
]
;
color
=
lightgrey
;
}
# optimizer [label="TUM optimizer.py", style=filled, shape=cylinder];
# gis [label="ArcGIS", style=filled, shape=cylinder];
#csv3 -> optimizer [ltail=cluster_1];
#csv3 -> gis [ltail=cluster_1];
simstadt
:
heat
->
csv1
;
simstadt
:
heat
->
csv2
;
simstadt
:
green
->
csv3
;
#shp -> gis;
#optimizer -> lib [style=dotted];
#optimizer -> floors [style=dotted];
#gis -> trees [style=dotted];
{
rank
=
min
;
a
;
b
;
c
}
{
rank
=
max
;
csv1
;
csv2
;
csv3
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment