{ "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": null, "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_geometries import bldg_extrusion\n", "from gml_parsing import little_parser" ] }, { "cell_type": "code", "execution_count": null, "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": null, "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": null, "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": null, "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": null, "metadata": {}, "outputs": [], "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": "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": 2 }