def execute(self, pycitygml_reader, nrmlised_parm_list): parm_list = self.map_nrmlise_parms_2_parms(nrmlised_parm_list) citygml_writer = pycitygml.Writer() gml_landuses = pycitygml_reader.get_landuses() gml_bldg_list = pycitygml_reader.get_buildings() bcnt = 0 for gml_landuse in gml_landuses: #echeck which buildings are on this plot gml_bldg_on_luse = gml3dmodel.buildings_on_landuse( gml_landuse, gml_bldg_list, pycitygml_reader) #check which buildings should this parameter be applied to eligibility_bldg_list, non_eligible_bldg_list = self.eligibility_test( gml_bldg_on_luse, pycitygml_reader) n_eligibility_bldgs = len(eligibility_bldg_list) #get the parameters for this landuse plot parms_4_luse = parm_list[bcnt:bcnt + n_eligibility_bldgs] #change the bldgs height bcnt = 0 for eligible_gml_bldg in eligibility_bldg_list: #get the height parm for the bldg height_parm = parms_4_luse[bcnt] #extract the bldg solid bldg_solid = gml3dmodel.get_building_occsolid( eligible_gml_bldg, pycitygml_reader) #change the height of each bldg according to the parameter height, nstorey, storey_height = gml3dmodel.get_building_height_storey( eligible_gml_bldg, pycitygml_reader) bldg_bounding_footprint = gml3dmodel.get_building_bounding_footprint( bldg_solid) midpt = py3dmodel.calculate.face_midpt(bldg_bounding_footprint) height_ratio = float(height_parm) / height scaled_bldg = py3dmodel.modify.uniform_scale( bldg_solid, 1, 1, height_ratio, midpt) new_bldg_occsolid = py3dmodel.fetch.geom_explorer( scaled_bldg, "solid")[0] new_height, new_n_storey = gml3dmodel.calculate_bldg_height_n_nstorey( new_bldg_occsolid, storey_height) gml3dmodel.update_gml_building(eligible_gml_bldg, new_bldg_occsolid, pycitygml_reader, citygml_writer, new_height=new_height, new_nstorey=new_n_storey) bcnt += 1 non_bldg_cityobjs = pycitygml_reader.get_non_xtype_cityobject( "bldg:Building") gml3dmodel.write_citygml(non_bldg_cityobjs, citygml_writer) gml3dmodel.write_non_eligible_bldgs(non_eligible_bldg_list, citygml_writer) citymodel_node = citygml_writer.citymodelnode reader = pycitygml.Reader() reader.load_citymodel_node(citymodel_node) return reader
def add_shadings_4_solar_analysis(self, shading_citygml_file): """ This function adds the CityGML file that is the context/shading of the CityGML file of interest. Parameters ---------- shading_citygml_file : str The file path of the shading CityGML. """ shading_faces = [] reader = pycitygml.Reader() reader.load_filepath(shading_citygml_file) gml_bldgs = reader.get_buildings() for gml_bldg in gml_bldgs: pypolygonlist = reader.get_pypolygon_list(gml_bldg) bsolid = py3dmodel.construct.make_occsolid_frm_pypolygons( pypolygonlist) bldg_face_list = py3dmodel.fetch.topo_explorer(bsolid, "face") shading_faces.extend(bldg_face_list) reliefs = reader.get_relief_feature() for rf in reliefs: pytrianglelist = reader.get_pytriangle_list(rf) for pytriangle in pytrianglelist: occtriangle = py3dmodel.construct.make_polygon(pytriangle) shading_faces.append(occtriangle) self.shading_faces = shading_faces
def __init__(self, citygmlfile): """Initialises the class""" reader = pycitygml.Reader() reader.load_filepath(citygmlfile) self.citygml = reader self.parm_obj_dict_list = [] self.nparameters = None
def __init__(self, citygmlfile): """Initialises the Evals class""" reader = pycitygml.Reader() reader.load_filepath(citygmlfile) self.citygml = reader self.citygmlfilepath = citygmlfile self.buildings = self.citygml.get_buildings() self.landuses = self.citygml.get_landuses() self.stops = self.citygml.get_bus_stops() self.roads = self.citygml.get_roads() self.railways = self.citygml.get_railways() self.relief_features = self.citygml.get_relief_feature() #occ geometries self.building_occsolids = None self.roof_occfaces = None self.facade_occfaces = None self.footprint_occfaces = None self.building_dictlist = None self.buildings_on_plot_2dlist = None #2d list of building dictlist according to the plot they belong to self.landuse_occpolygons = None self.relief_feature_occshells = None self.relief_feature_occfaces = None self.road_occedges = None self.shading_faces = None #radiance parameters self.rad_base_filepath = os.path.join(os.path.dirname(__file__), 'py2radiance', 'base.rad') self.nshffai_folderpath = os.path.join( os.path.dirname(self.citygmlfilepath), 'nshffai_data') self.dffai_folderpath = os.path.join( os.path.dirname(self.citygmlfilepath), 'dffai_data') self.pvefai_folderpath = os.path.join( os.path.dirname(self.citygmlfilepath), 'pvefai_data') self.daysim_folderpath = os.path.join( os.path.dirname(self.citygmlfilepath), 'daysim_data') self.solarxdim = None self.solarydim = None self.rad = None #rad results self.irrad_results = None self.illum_results = None self.facade_grid_srfs = None self.roof_grid_srfs = None
def execute(self, pycitygml_reader, nrmlised_parm_list): citygml_writer = pycitygml.Writer() gml_landuses = pycitygml_reader.get_landuses() gml_bldg_list = pycitygml_reader.get_buildings() bcnt = 0 for gml_landuse in gml_landuses: #echeck which buildings are on this plot gml_bldg_on_luse = gml3dmodel.buildings_on_landuse( gml_landuse, gml_bldg_list, pycitygml_reader) #check which buildings should this parameter be applied to eligibility_bldg_list, non_eligible_bldg_list = self.eligibility_test( gml_bldg_on_luse, pycitygml_reader) n_eligibility_bldgs = len(eligibility_bldg_list) #grid the plot luse_occface = gml3dmodel.gml_landuse_2_occface( gml_landuse, pycitygml_reader) pypt_list, grid_faces = gml3dmodel.landuse_2_grid( luse_occface, self.xdim, self.ydim) npypt_list = len(pypt_list) self.define_int_range(0, npypt_list - 1, 1) #get the parameters for this landuse plot nrmlised_parms_4_luse = nrmlised_parm_list[bcnt:bcnt + n_eligibility_bldgs] parms_4_luse = self.map_nrmlise_parms_2_parms( nrmlised_parms_4_luse) bldg_occsolid_list = [] #get all the occsolid of the buildings for eligible_gml_bldg in eligibility_bldg_list: bldg_occsolid = gml3dmodel.get_building_occsolid( eligible_gml_bldg, pycitygml_reader) bldg_occsolid_list.append(bldg_occsolid) non_bldg_occsolid_list = [] for non_eligible_gml_bldg in non_eligible_bldg_list: non_bldg_occsolid = gml3dmodel.get_building_occsolid( non_eligible_gml_bldg, pycitygml_reader) non_bldg_occsolid_list.append(non_bldg_occsolid) posed_bldg_occsolid_list = gml3dmodel.rearrange_building_position( bldg_occsolid_list, pypt_list, luse_occface, parms_4_luse, other_occsolids=non_bldg_occsolid_list, clash_detection=self.clash_detection, boundary_detection=self.boundary_detection) for up_cnt in range(n_eligibility_bldgs): gml_bldg = eligibility_bldg_list[up_cnt] new_building_solid = posed_bldg_occsolid_list[up_cnt] gml3dmodel.update_gml_building(gml_bldg, new_building_solid, pycitygml_reader, citygml_writer) bcnt += n_eligibility_bldgs non_bldg_cityobjs = pycitygml_reader.get_non_xtype_cityobject( "bldg:Building") gml3dmodel.write_citygml(non_bldg_cityobjs, citygml_writer) gml3dmodel.write_non_eligible_bldgs(non_eligible_bldg_list, citygml_writer) citymodel_node = citygml_writer.citymodelnode reader = pycitygml.Reader() reader.load_citymodel_node(citymodel_node) return reader
def execute(self, pycitygml_reader, nrmlised_parm_list): parm_list = self.map_nrmlise_parms_2_parms(nrmlised_parm_list) citygml_writer = pycitygml.Writer() gml_landuses = pycitygml_reader.get_landuses() gml_bldg_list = pycitygml_reader.get_buildings() bcnt = 0 for gml_landuse in gml_landuses: #echeck which buildings are on this plot gml_bldg_on_luse = gml3dmodel.buildings_on_landuse( gml_landuse, gml_bldg_list, pycitygml_reader) #check which buildings should this parameter be applied to eligibility_bldg_list, non_eligible_bldg_list = self.eligibility_test( gml_bldg_on_luse, pycitygml_reader) n_eligibility_bldgs = len(eligibility_bldg_list) #get the parameters for this landuse plot parms_4_luse = parm_list[bcnt:bcnt + n_eligibility_bldgs] luse_occface = gml3dmodel.gml_landuse_2_occface( gml_landuse, pycitygml_reader) #get all the bldg_occsolid roting_bldg_occsolid_list = [] for gml_bldg in eligibility_bldg_list: bldg_occsolid = gml3dmodel.get_building_occsolid( gml_bldg, pycitygml_reader) roting_bldg_occsolid_list.append(bldg_occsolid) non_roting_bldg_occsolid_list = [] for non_gml_bldg in non_eligible_bldg_list: non_bldg_occsolid = gml3dmodel.get_building_occsolid( non_gml_bldg, pycitygml_reader) non_roting_bldg_occsolid_list.append(non_bldg_occsolid) #rotate the buildings for cnt in range(n_eligibility_bldgs): eligible_gml_bldg = eligibility_bldg_list[cnt] rot_angle = parms_4_luse[cnt] rot_bldg_occsolid = gml3dmodel.rotate_bldg( eligible_gml_bldg, rot_angle, pycitygml_reader) roting_bldg_occsolid_list2 = roting_bldg_occsolid_list[:] del roting_bldg_occsolid_list2[cnt] roting_bldg_occsolid_list2.extend( non_roting_bldg_occsolid_list) if self.clash_detection == True and self.boundary_detection == False: clash_detected = gml3dmodel.detect_clash( rot_bldg_occsolid, roting_bldg_occsolid_list2) if not clash_detected: #there is no clash roting_bldg_occsolid_list[cnt] = rot_bldg_occsolid elif self.boundary_detection == True and self.clash_detection == False: is_in_boundary = gml3dmodel.detect_in_boundary( rot_bldg_occsolid, luse_occface) if is_in_boundary: #it is within the boundary roting_bldg_occsolid_list[cnt] = rot_bldg_occsolid elif self.boundary_detection == True and self.clash_detection == True: clash_detected = gml3dmodel.detect_clash( rot_bldg_occsolid, roting_bldg_occsolid_list2) is_in_boundary = gml3dmodel.detect_in_boundary( rot_bldg_occsolid, luse_occface) if not clash_detected and is_in_boundary: roting_bldg_occsolid_list[cnt] = rot_bldg_occsolid elif self.clash_detection == False and self.boundary_detection == False: roting_bldg_occsolid_list[cnt] = rot_bldg_occsolid for up_cnt in range(n_eligibility_bldgs): gml_bldg = eligibility_bldg_list[up_cnt] new_building_solid = roting_bldg_occsolid_list[up_cnt] gml3dmodel.update_gml_building(gml_bldg, new_building_solid, pycitygml_reader, citygml_writer) bcnt += n_eligibility_bldgs non_bldg_cityobjs = pycitygml_reader.get_non_xtype_cityobject( "bldg:Building") gml3dmodel.write_citygml(non_bldg_cityobjs, citygml_writer) gml3dmodel.write_non_eligible_bldgs(non_eligible_bldg_list, citygml_writer) citymodel_node = citygml_writer.citymodelnode reader = pycitygml.Reader() reader.load_citymodel_node(citymodel_node) return reader
def execute(self, pycitygml_reader, nrmlised_parm_list): parm_list = self.map_nrmlise_parms_2_parms(nrmlised_parm_list) citygml_writer = pycitygml.Writer() gml_landuses = pycitygml_reader.get_landuses() gml_bldg_list = pycitygml_reader.get_buildings() bcnt = 0 for gml_landuse in gml_landuses: #echeck which buildings are on this plot gml_bldg_on_luse = gml3dmodel.buildings_on_landuse( gml_landuse, gml_bldg_list, pycitygml_reader) #check which buildings should this parameter be applied to eligibility_bldg_list, non_eligible_bldg_list = self.eligibility_test( gml_bldg_on_luse, pycitygml_reader) n_eligibility_bldgs = len(eligibility_bldg_list) #calculate the total landuse floor area luse_flr_area = 0 for eligible_gml_bldg in eligibility_bldg_list: height, nstorey, storey_height = gml3dmodel.get_building_height_storey( eligible_gml_bldg, pycitygml_reader) bldg_flr_area, flrplates = gml3dmodel.get_bulding_floor_area( eligible_gml_bldg, nstorey, storey_height, pycitygml_reader) luse_flr_area += bldg_flr_area #get the parameters for this landuse plot parms_4_luse = parm_list[bcnt:bcnt + n_eligibility_bldgs] total_prop = float(sum(parms_4_luse)) #redistribute the flr area new_bldg_flr_area_list = [] for parm in parms_4_luse: new_bldg_flr_area = float(parm) / total_prop * luse_flr_area new_bldg_flr_area_list.append(new_bldg_flr_area) #reconstuct the buildings according to the new distribuition for cnt in range(n_eligibility_bldgs): gml_bldg = eligibility_bldg_list[cnt] bldg_occsolid = gml3dmodel.get_building_occsolid( gml_bldg, pycitygml_reader) height, nstorey, storey_height = gml3dmodel.get_building_height_storey( gml_bldg, pycitygml_reader) new_bldg_flr_area = new_bldg_flr_area_list[cnt] new_building_solid = gml3dmodel.construct_building_through_floorplates( bldg_occsolid, new_bldg_flr_area, storey_height) new_height, new_n_storey = gml3dmodel.calculate_bldg_height_n_nstorey( new_building_solid, storey_height) gml3dmodel.update_gml_building(gml_bldg, new_building_solid, pycitygml_reader, citygml_writer, new_height=new_height, new_nstorey=new_n_storey) bcnt += n_eligibility_bldgs non_bldg_cityobjs = pycitygml_reader.get_non_xtype_cityobject( "bldg:Building") gml3dmodel.write_citygml(non_bldg_cityobjs, citygml_writer) gml3dmodel.write_non_eligible_bldgs(non_eligible_bldg_list, citygml_writer) citymodel_node = citygml_writer.citymodelnode reader = pycitygml.Reader() reader.load_citymodel_node(citymodel_node) return reader
def citygml2collada(citygml_filepath, collada_filepath): """ This function convert a CityGML to Collada. Currently only works with LOD1 buildings, landuses and terrain. LOD0 transportation network. Parameters ---------- citygml_filepath : str The file path of the CityGML file. collada_filepath : str The file path of the Collada file. """ reader = pycitygml.Reader() reader.load_filepath(citygml_filepath) buildings = reader.get_buildings() landuses = reader.get_landuses() stops = reader.get_bus_stops() roads = reader.get_roads() railways = reader.get_railways() relief_features = reader.get_relief_feature() occshell_list = [] occedge_list = [] for building in buildings: pypolgon_list = reader.get_pypolygon_list(building) solid = py3dmodel.construct.make_occsolid_frm_pypolygons(pypolgon_list) bldg_shell_list = py3dmodel.fetch.topo_explorer(solid, "shell") occshell_list.extend(bldg_shell_list) for landuse in landuses: lpolygons = reader.get_polygons(landuse) if lpolygons: for lpolygon in lpolygons: landuse_pts = reader.polygon_2_pyptlist(lpolygon) lface = py3dmodel.construct.make_polygon(landuse_pts) occshell_list.append(lface) rf_face_list = [] for relief in relief_features: pytri_list = reader.get_pytriangle_list(relief) for pytri in pytri_list: rface = py3dmodel.construct.make_polygon(pytri) rf_face_list.append(rface) if rf_face_list: rf_cmpd = py3dmodel.construct.make_compound(rf_face_list) centre_pt = py3dmodel.calculate.get_centre_bbox(rf_cmpd) move_centre_pt = py3dmodel.modify.move_pt(centre_pt, (0, 0, -1), 0.1) moved_cmpd = py3dmodel.modify.move(centre_pt, move_centre_pt, rf_cmpd) occshell_list.append(moved_cmpd) for road in roads: polylines = reader.get_pylinestring_list(road) for polyline in polylines: occ_wire = py3dmodel.construct.make_wire(polyline) edge_list = py3dmodel.fetch.topo_explorer(occ_wire, "edge") occedge_list.extend(edge_list) for rail in railways: polylines = reader.get_pylinestring_list(rail) for polyline in polylines: occ_wire = py3dmodel.construct.make_wire(polyline) edge_list = py3dmodel.fetch.topo_explorer(occ_wire, "edge") occedge_list.extend(edge_list) for stop in stops: pypolgon_list = reader.get_pypolygon_list(stop) solid = py3dmodel.construct.make_occsolid_frm_pypolygons(pypolgon_list) stop_shell_list = py3dmodel.fetch.topo_explorer(solid, "shell") occshell_list.extend(stop_shell_list) py3dmodel.export_collada.write_2_collada(occshell_list, collada_filepath, occedge_list=occedge_list)
def citygml2collada(citygml_filepath, collada_filepath): reader = pycitygml.Reader() reader.load_filepath(citygml_filepath) buildings = reader.get_buildings() landuses = reader.get_landuses() stops = reader.get_bus_stops() roads = reader.get_roads() railways = reader.get_railways() relief_features = reader.get_relief_feature() occshell_list = [] occedge_list = [] for building in buildings: pypolgon_list = reader.get_pypolygon_list(building) solid = py3dmodel.construct.make_occsolid_frm_pypolygons(pypolgon_list) bldg_shell_list = py3dmodel.fetch.geom_explorer(solid, "shell") occshell_list.extend(bldg_shell_list) for landuse in landuses: lpolygons = reader.get_polygons(landuse) if lpolygons: for lpolygon in lpolygons: landuse_pts = reader.polygon_2_pt_list(lpolygon) lface = py3dmodel.construct.make_polygon(landuse_pts) occshell_list.append(lface) rf_face_list = [] for relief in relief_features: pytri_list = reader.get_pytriangle_list(relief) for pytri in pytri_list: rface = py3dmodel.construct.make_polygon(pytri) rf_face_list.append(rface) if rf_face_list: rf_cmpd = py3dmodel.construct.make_compound(rf_face_list) centre_pt = py3dmodel.calculate.get_centre_bbox(rf_cmpd) move_centre_pt = py3dmodel.modify.move_pt(centre_pt, (0, 0, -1), 0.1) moved_cmpd = py3dmodel.modify.move(centre_pt, move_centre_pt, rf_cmpd) occshell_list.append(moved_cmpd) for road in roads: polylines = reader.get_pylinestring_list(road) for polyline in polylines: occ_wire = py3dmodel.construct.make_wire(polyline) edge_list = py3dmodel.fetch.geom_explorer(occ_wire, "edge") occedge_list.extend(edge_list) for rail in railways: polylines = reader.get_pylinestring_list(rail) for polyline in polylines: occ_wire = py3dmodel.construct.make_wire(polyline) edge_list = py3dmodel.fetch.geom_explorer(occ_wire, "edge") occedge_list.extend(edge_list) for stop in stops: pypolgon_list = reader.get_pypolygon_list(stop) solid = py3dmodel.construct.make_occsolid_frm_pypolygons(pypolgon_list) stop_shell_list = py3dmodel.fetch.geom_explorer(solid, "shell") occshell_list.extend(stop_shell_list) utility3d.write_2_collada(occshell_list, collada_filepath, occedge_list=occedge_list)