diff --git a/gml_extrusion/build_up_geonmetries.py b/gml_extrusion/build_up_geonmetries.py index ee956678ce150de7bf2fb5154bebbbb328ebccba..c30e6e8a19e268250fdadcc1911446276c10af8b 100644 --- a/gml_extrusion/build_up_geonmetries.py +++ b/gml_extrusion/build_up_geonmetries.py @@ -11,7 +11,7 @@ class bldg_extrusion: self.output_file_path = output_file_path self.floor_high = floor_high self.residential_code = residential_code - + # Function to extrude buildings def bldg_extrusion(self): gml_par = self.gml_par @@ -21,12 +21,12 @@ class bldg_extrusion: bldg_function = self.residential_code extrusion_height = 1000.0 # Default extrusion height if measuredHeight is not found - + # get building IDs from gml_par and number of floors to extrude from gml_par['extruded'] bldg_IDs = gml_par['id'][gml_par['extruded'] > 0].tolist() #nr_of_floors = gml_par['extruded'][gml_par['extruded'] > 0].tolist() - + tree = etree.parse(file_path) # Define the namespaces @@ -71,7 +71,7 @@ class bldg_extrusion: roof_type_element = building.xpath('./bldg:roofType', namespaces=namespaces)[0] roof_type_element.text = '1000' #print('roof type changed to flat') - + # change measured height to + extra_building_hight measured_height_element = building.xpath('./bldg:measuredHeight', namespaces=namespaces)[0] measured_height_element.text = str(measured_height + extra_building_hight) @@ -90,7 +90,7 @@ class bldg_extrusion: extruded_coord_triplets = [(x, y, z + measured_height + extra_building_hight) for x, y, z in coord_triplets] # Assuming one WallSurface for each ground edge for simplicity for i, new_wall in enumerate(coord_triplets[:-1]): - + if i < len(wall_surfaces): # Ensure there is a corresponding wall wall_surface = wall_surfaces[i] multi_surfaces = wall_surface.xpath('.//gml:MultiSurface', namespaces=namespaces) @@ -132,7 +132,7 @@ class bldg_extrusion: new_wall_surface_linear_ring = new_wall_surface_linear_rings[0] new_wall_surface_linear_ring.attrib['{http://www.opengis.net/gml}id'] = new_wall_surface_linear_ring.attrib['{http://www.opengis.net/gml}id'][:-1] + str(i) #print(new_wall_surface_linear_ring.attrib['{http://www.opengis.net/gml}id']) - + # Add the new wall surface as a child to the boundedBy element bounded_by.append(new_wall_surface) @@ -159,7 +159,7 @@ class bldg_extrusion: # replace roof surfaces with extruded ground surface for y, roof_surface in enumerate(roof_surfaces): - + if y == 0: # If MultiSurface exists, assume the first one is the primary surface multi_surfaces_roof = roof_surface.xpath('.//gml:MultiSurface', namespaces=namespaces) @@ -201,16 +201,16 @@ class bldg_extrusion: # Create a gml:surfaceMember element for each polygon id for polygon_id in polygon_ids: etree.SubElement(composite_surface, '{http://www.opengis.net/gml}surfaceMember', attrib={'{http://www.w3.org/1999/xlink}href': '#' + polygon_id}) - + # Append the lod2Solid to the building building.append(lod2Solid) - + else: print('function is not residential: '+function) pass # Write the modified CityGML back to a new file - tree.write(output_file_path, pretty_print=True, xml_declaration=True, encoding='utf-8') if building_id not in bldg_IDs: continue - return print('Building extrusion completed and safed in:\n'+output_file_path) \ No newline at end of file + tree.write(output_file_path, pretty_print=True, xml_declaration=True, encoding='utf-8') + return print('Building extrusion completed and saved in:\n'+output_file_path)