Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mayer
CircularGreenSimCity
Commits
0054e195
Commit
0054e195
authored
Jul 22, 2024
by
Eric Duminil
Browse files
Extrusion: only write CityGML once
parent
f723fabe
Changes
1
Hide whitespace changes
Inline
Side-by-side
gml_extrusion/build_up_geonmetries.py
View file @
0054e195
...
@@ -11,7 +11,7 @@ class bldg_extrusion:
...
@@ -11,7 +11,7 @@ class bldg_extrusion:
self
.
output_file_path
=
output_file_path
self
.
output_file_path
=
output_file_path
self
.
floor_high
=
floor_high
self
.
floor_high
=
floor_high
self
.
residential_code
=
residential_code
self
.
residential_code
=
residential_code
# Function to extrude buildings
# Function to extrude buildings
def
bldg_extrusion
(
self
):
def
bldg_extrusion
(
self
):
gml_par
=
self
.
gml_par
gml_par
=
self
.
gml_par
...
@@ -21,12 +21,12 @@ class bldg_extrusion:
...
@@ -21,12 +21,12 @@ class bldg_extrusion:
bldg_function
=
self
.
residential_code
bldg_function
=
self
.
residential_code
extrusion_height
=
1000.0
# Default extrusion height if measuredHeight is not found
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']
# 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
()
bldg_IDs
=
gml_par
[
'id'
][
gml_par
[
'extruded'
]
>
0
].
tolist
()
#nr_of_floors = gml_par['extruded'][gml_par['extruded'] > 0].tolist()
#nr_of_floors = gml_par['extruded'][gml_par['extruded'] > 0].tolist()
tree
=
etree
.
parse
(
file_path
)
tree
=
etree
.
parse
(
file_path
)
# Define the namespaces
# Define the namespaces
...
@@ -71,7 +71,7 @@ class bldg_extrusion:
...
@@ -71,7 +71,7 @@ class bldg_extrusion:
roof_type_element
=
building
.
xpath
(
'./bldg:roofType'
,
namespaces
=
namespaces
)[
0
]
roof_type_element
=
building
.
xpath
(
'./bldg:roofType'
,
namespaces
=
namespaces
)[
0
]
roof_type_element
.
text
=
'1000'
roof_type_element
.
text
=
'1000'
#print('roof type changed to flat')
#print('roof type changed to flat')
# change measured height to + extra_building_hight
# change measured height to + extra_building_hight
measured_height_element
=
building
.
xpath
(
'./bldg:measuredHeight'
,
namespaces
=
namespaces
)[
0
]
measured_height_element
=
building
.
xpath
(
'./bldg:measuredHeight'
,
namespaces
=
namespaces
)[
0
]
measured_height_element
.
text
=
str
(
measured_height
+
extra_building_hight
)
measured_height_element
.
text
=
str
(
measured_height
+
extra_building_hight
)
...
@@ -90,7 +90,7 @@ class bldg_extrusion:
...
@@ -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
]
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
# Assuming one WallSurface for each ground edge for simplicity
for
i
,
new_wall
in
enumerate
(
coord_triplets
[:
-
1
]):
for
i
,
new_wall
in
enumerate
(
coord_triplets
[:
-
1
]):
if
i
<
len
(
wall_surfaces
):
# Ensure there is a corresponding wall
if
i
<
len
(
wall_surfaces
):
# Ensure there is a corresponding wall
wall_surface
=
wall_surfaces
[
i
]
wall_surface
=
wall_surfaces
[
i
]
multi_surfaces
=
wall_surface
.
xpath
(
'.//gml:MultiSurface'
,
namespaces
=
namespaces
)
multi_surfaces
=
wall_surface
.
xpath
(
'.//gml:MultiSurface'
,
namespaces
=
namespaces
)
...
@@ -132,7 +132,7 @@ class bldg_extrusion:
...
@@ -132,7 +132,7 @@ class bldg_extrusion:
new_wall_surface_linear_ring
=
new_wall_surface_linear_rings
[
0
]
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
)
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'])
#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
# Add the new wall surface as a child to the boundedBy element
bounded_by
.
append
(
new_wall_surface
)
bounded_by
.
append
(
new_wall_surface
)
...
@@ -159,7 +159,7 @@ class bldg_extrusion:
...
@@ -159,7 +159,7 @@ class bldg_extrusion:
# replace roof surfaces with extruded ground surface
# replace roof surfaces with extruded ground surface
for
y
,
roof_surface
in
enumerate
(
roof_surfaces
):
for
y
,
roof_surface
in
enumerate
(
roof_surfaces
):
if
y
==
0
:
if
y
==
0
:
# If MultiSurface exists, assume the first one is the primary surface
# If MultiSurface exists, assume the first one is the primary surface
multi_surfaces_roof
=
roof_surface
.
xpath
(
'.//gml:MultiSurface'
,
namespaces
=
namespaces
)
multi_surfaces_roof
=
roof_surface
.
xpath
(
'.//gml:MultiSurface'
,
namespaces
=
namespaces
)
...
@@ -201,16 +201,16 @@ class bldg_extrusion:
...
@@ -201,16 +201,16 @@ class bldg_extrusion:
# Create a gml:surfaceMember element for each polygon id
# Create a gml:surfaceMember element for each polygon id
for
polygon_id
in
polygon_ids
:
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
})
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
# Append the lod2Solid to the building
building
.
append
(
lod2Solid
)
building
.
append
(
lod2Solid
)
else
:
else
:
print
(
'function is not residential: '
+
function
)
print
(
'function is not residential: '
+
function
)
pass
pass
# Write the modified CityGML back to a new file
# 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
:
if
building_id
not
in
bldg_IDs
:
continue
continue
return
print
(
'Building extrusion completed and safed in:
\n
'
+
output_file_path
)
tree
.
write
(
output_file_path
,
pretty_print
=
True
,
xml_declaration
=
True
,
encoding
=
'utf-8'
)
\ No newline at end of file
return
print
(
'Building extrusion completed and saved in:
\n
'
+
output_file_path
)
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