building_extension.ipynb 8.3 KB
Newer Older
Ehlers's avatar
Ehlers committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ---------------------------------------------------------------------\n",
    "# File Name: building_extension.py\n",
    "# Purpose: CityGML building objects are randomly choosen and extended in given height  \n",
    "# Author: Nico Ehlers\n",
    "# Created: 2024-07-08\n",
    "# ---------------------------------------------------------------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import os\n",
    "import ipywidgets as widgets\n",
    "from IPython.display import display\n",
    "from choose_extrusion_buildings import choose_building\n",
    "from build_up_geonmetries import bldg_extrusion\n",
    "from gml_parsing import little_parser"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create input widgets\n",
    "residential_code_input = widgets.Text(description='Residential Code:', value='31001_1000')# '31001_1010' Asberg)\n",
    "bldg_extension_input = widgets.IntSlider(description='Building Extension:', min=0, max=5, step=1, value=2)\n",
    "extrusion_percentage_input = widgets.FloatSlider(description='Extrusion Percentage:', min=0.0, max=1.0, step=0.1, value=1.0)\n",
    "floor_height_input = widgets.FloatText(description='Floor Height:', value=3.5)\n",
    "gml_path_input = widgets.Text(description='GML Path:', value=os.getcwd()+'\\GML_files\\\\')\n",
    "gml_file_input = widgets.Text(description='GML File:', value='Grombuehl_LoD2_mini.gml')#Grafenbühl.gml"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create button widget\n",
    "run_button = widgets.Button(description='Run Code')\n",
    "\n",
    "# Create output widget\n",
    "output = widgets.Output()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "gml_path =os.getcwd()+'\\GML_files\\\\'\n",
    "gml_file = 'Grombuehl_LoD2_mini.gml'\n",
    "\n",
    "save_name = gml_file.split('.')[0]+'_'\n",
    "gml_info = little_parser(gml_path+gml_file)\n",
    "gml_par = gml_info.little_parser()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define function to run when button is clicked\n",
    "def run_code(button):\n",
    "    with output:\n",
    "        # Get user inputs\n",
    "        residential_code = residential_code_input.value\n",
    "        bldg_extension = bldg_extension_input.value\n",
    "        extrusion_percentage = extrusion_percentage_input.value\n",
    "        floor_height = floor_height_input.value\n",
    "        gml_path = gml_path_input.value\n",
    "        gml_file = gml_file_input.value\n",
    "        \n",
    "        file_path = gml_path + gml_file\n",
    "        # Run choose_building and bldg_extrusion classes\n",
    "        #----------------------------------------------------------------------------\n",
    "        ### GML PARSING\n",
    "        #----------------------------------------------------------------------------\n",
    "        save_name = gml_file.split('.')[0]+'_'\n",
    "        gml_info = little_parser(file_path)\n",
    "        gml_par = gml_info.little_parser()\n",
    "        #----------------------------------------------------------------------------\n",
    "        ### choose buildings for extrusion\n",
    "        #----------------------------------------------------------------------------\n",
    "        # TODO: at the moment all construction massive\n",
    "        gml_par['construction_type'] = 'massive'\n",
    "        extr = choose_building(gml_par, bldg_extension, residential_code, extrusion_percentage)\n",
    "        gml_par = extr.choose_building()\n",
    "        # filter buildings with residential code\n",
    "        gml_par = gml_par[gml_par['function'] == residential_code].reset_index(drop=True)\n",
    "        #----------------------------------------------------------------------------\n",
    "        ### GML extrusion\n",
    "        #----------------------------------------------------------------------------\n",
    "        # Example usage\n",
    "        output_file_path = gml_path + gml_file.replace('.gml', '_extruded.gml')\n",
    "\n",
    "        extrude_gml = bldg_extrusion(gml_par, file_path, output_file_path, floor_height, residential_code)\n",
    "        extrude_gml.bldg_extrusion()\n",
    "        \n",
    "        # Print confirmation message\n",
    "        print('Code executed successfully!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f3b8a4b0a13049b8b3d4f2b6a5341b37",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Text(value='31001_1000', description='Residential Code:')"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0bf67b5105144554930a549da784f462",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "IntSlider(value=2, description='Building Extension:', max=5)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "46100a95792546249024ad1f86e93d84",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "FloatSlider(value=1.0, description='Extrusion Percentage:', max=1.0)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5abedb2d0f41428fb9b8b12431e279b6",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "FloatText(value=3.5, description='Floor Height:')"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5a5c0fa620444bc9b86e9ffa100fb6a0",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Text(value='c:\\\\Users\\\\ge29duf\\\\Documents\\\\02_Forschung\\\\P62\\\\Tool_ne\\\\gml_changes\\\\GML_files\\\\', description=…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "6e25579ba32a4aadb06b4ef9e9895553",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Text(value='Grombuehl_LoD2_mini.gml', description='GML File:')"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "306f5b8b537b4d288d29f571ea25bf67",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Button(description='Run Code', style=ButtonStyle())"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b77571c755904f1083458c6490b8d738",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Output()"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Attach function to button click event\n",
    "run_button.on_click(run_code)\n",
    "\n",
    "# Display the widgets\n",
    "display(residential_code_input, bldg_extension_input, extrusion_percentage_input, floor_height_input, gml_path_input, gml_file_input, run_button, output)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "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.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}