-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgetting_started.py
More file actions
104 lines (81 loc) · 3.64 KB
/
getting_started.py
File metadata and controls
104 lines (81 loc) · 3.64 KB
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
"""
This is an example script shows how you
can load files to the package and get some
basic information about the dataset
"""
# start by importing the Dataset package
from citydpc import Dataset
# important: import Dataset and not dataset
# create a Dataset object
newDataset = Dataset()
# if you want to calculate the volume of the roof on import you need to set:
from citydpc.core import input
input.set_roof_volume_calculation(True)
# to load buildings from a file you need the respective importer
# to add a xml/gml file:
from citydpc.core.input.citygmlInput import load_buildings_from_xml_file
load_buildings_from_xml_file(newDataset, "examples/files/EssenExample.gml")
# get the number of buildings in the Dataset
number_of_buildings = len(newDataset)
# you can get some more info (e.g. gml_version, crs, LoD)
# using the analysis function
from citydpc.tools import cityATB
dict_with_info = cityATB.analysis(newDataset)
# buildings are stored as a dict
# where the key is a gml:id and the value is a building object
# you can iterate over them like this:
for building in newDataset.get_building_list():
# you can get the id by
id = building.gml_id
# check if it has a 3D geometry
is_3D = building.has_3Dgeometry()
if is_3D:
# you can get coordinates as dict like this
# where the key is the id of the surface and
# the value is a surfacegml representation
walls = building.get_surfaces(surfaceTypes=["WallSurface"])
grounds = building.get_surfaces(surfaceTypes=["GroundSurface"])
roofs = building.get_surfaces(surfaceTypes=["RoofSurface"])
print(f"roofVolume: {building.roof_volume}")
# e.g. to get the area of all roof surfaces
# you can use the next two lines
for surface in roofs:
area = surface.surface_area
# I recommend looking at the surfacegml.py
# SurfaceGML object for more surface related info
# get the roof volume
roof_volume = building.roof_volume
# check if it has building parts
has_children = building.has_building_parts()
# and get them using
if has_children:
building_parts = building.get_building_parts()
# building parts have very similar methods and
# and parameters as buildings
# for example
for builidngPart in building_parts:
roof_volume = builidngPart.roof_volume
# searching for a street name can be done like this
# you can use as many or as few key value pairs as you like
dataAddress = cityATB.search_dataset(newDataset, addressRestriciton={"thoroughfareName": "Stakenholt"}, inplace=False)
# with the parameter inplace= False a new Dataset will be created (default)
# when setting the parameter to True the operation will be done on the existing dataset
# you can also create a coordinate border using the borderCoordinates argument
dataCoordinate = cityATB.search_dataset(newDataset, borderCoordinates=[[360057.31, 5706881.64], [360057.31, 5706267.41], [359792.94, 5706267.41], [359792.94, 5706881.64]])
# you can also do both operations at the same time (and even in the load_buildings_from_xml_file function)
dataCombine = cityATB.search_dataset(
newDataset,
borderCoordinates=[
[360057.31, 5706881.64],
[360057.31, 5706267.41],
[359792.94, 5706267.41],
[359792.94, 5706881.64],
],
addressRestriciton={"thoroughfareName": "Stakenholt"},
)
# if you want to save your changes you need the respective exporter
# for CityGML use:
print(len(dataCombine))
from citydpc.core.output.citygmlOutput import write_citygml_file
write_citygml_file(dataCombine, "newFilename.gml")
# you can choose between CityGML 1.0 and 2.0