def load_gml(path, prj): '''This function loads buildings from a CityGML file Parameters ---------- path: string path of CityGML file prj: Project() Teaser instance of Project() ''' xml_file = open(path, 'r') gml_bind = citygml.CreateFromDocument(xml_file.read()) for i, city_object in enumerate(gml_bind.featureMember): if city_object.Feature.consistsOfBuildingPart: for part in city_object.Feature.consistsOfBuildingPart: if part.BuildingPart.function: if part.BuildingPart.function[0].value() == "1000": bldg = SingleFamilyDwelling(parent=prj, name=part.BuildingPart.id) elif part.BuildingPart.function[0].value() == "1120": bldg = Office(parent=prj, name=part.BuildingPart.id) else: bldg = Building(parent=prj, name=part.BuildingPart.id) else: bldg = Building(parent=prj, name=part.BuildingPart.id) _create_building_part(bldg=bldg, part=part) _set_attributes(bldg=bldg, gml_bldg=part.BuildingPart) bldg.set_height_gml() else: if city_object.Feature.function: if city_object.Feature.function[0].value() == "1000": bldg = SingleFamilyDwelling(parent=prj, name=city_object.Feature.id) elif city_object.Feature.function[0].value() == "1120": bldg = Office(parent=prj, name=city_object.Feature.id) else: bldg = Building(parent=prj, name=city_object.Feature.id) else: bldg = Building(parent=prj, name=city_object.Feature.id) _create_building(bldg=bldg, city_object=city_object) _set_attributes(bldg=bldg, gml_bldg=city_object.Feature) bldg.set_height_gml() try: bldg.set_gml_attributes() except: pass
def _convert_bldg(bldg, function): """converts the instance to a specific archetype building DANGEROUS function, should only be used in combination with CityGML and if you know what you are doing Parameters ---------- bldg : Building() TEASER instance of a building function : str function from CityGML code list 1000 is residential 1120 is office """ parent_help = bldg.parent name_help = bldg.name gml_surfaces_help = bldg.gml_surfaces year_of_construction_help = bldg.year_of_construction bldg_height_help = bldg.bldg_height if function == "1000": from teaser.logic.archetypebuildings.bmvbs.singlefamilydwelling \ import SingleFamilyDwelling bldg.__class__ = SingleFamilyDwelling elif function == "1120": from teaser.logic.archetypebuildings.bmvbs.office import Office bldg.__class__ = Office bldg.__init__(parent=None) bldg.gml_surfaces = gml_surfaces_help bldg.parent = parent_help bldg.name = name_help bldg.year_of_construction = year_of_construction_help bldg.bldg_height = bldg_height_help bldg.set_gml_attributes() bldg.generate_from_gml()