def create_citygml(zone_shp_path, district_shp_path, input_terrain, output_folder): # local variables citygml_writer = pycitygml.Writer() # transform terrain to CityGML terrain_face_list = terrain_2d_to_3d(citygml_writer, input_terrain) # transform buildings to bsolid_list = building_2d_to_3d(citygml_writer, zone_shp_path, district_shp_path, terrain_face_list, height_col='height_ag', nfloor_col="floors_ag") #construct.visualise([terrain_face_list,bsolid_list], ["GREEN","WHITE"], backend = "wx") #install Wxpython # write to citygml citygml_writer.write(output_folder)
#=================================================================================================== indexes = [101] landuses = [landuses[x] for x in indexes] #find all the buildings inside the landuse bldgs_2_write = [] for landuse in landuses: bldgs_on_luse = gml3dmodel.buildings_on_landuse(landuse,buildings,read_citygml) bldgs_2_write.extend(bldgs_on_luse) #=================================================================================================== #only write the specific plot and the buildings into a new citygml file #write the citygml from scratch #=================================================================================================== print "WRITING CITYGML FILE ... ..." citygml_writer = pycitygml.Writer() for luse in landuses: cityobj = citygml_writer.create_cityobjectmember() cityobj.append(luse) citygml_writer.citymodel_node.append(cityobj) for building in bldgs_2_write: cityobj = citygml_writer.create_cityobjectmember() cityobj.append(building) citygml_writer.citymodel_node.append(cityobj) citygml_writer.write(result_citygml_filepath) time2 = time.clock() time = (time2-time1)/60.0
shpfile4 = os.path.join(parent_path, "example_files", "shpfiles", "boundary_file", "punggol_boundary.shp") #specify the result citygml file citygml_filepath = os.path.join(parent_path, "example_files", "citygml", "results", "punggol.gml") #========================================================================================================================================= #SPECIFY ALL THE NECCESSARY INPUTS #========================================================================================================================================= #========================================================================================================================================= #main SCRIPT #========================================================================================================================================= print "CONVERTING ... ..." time1 = time.clock() #initialise the citygml writer citygml_writer = pycitygml.Writer() citygml_writer_origlvl = pycitygml.Writer() #convert the shpfiles into 3d citygml using the citygmlenv library convert_origlvl([shpfile1, shpfile2, shpfile3, shpfile4], citygml_writer_origlvl) citygml_writer_origlvl.write(citygml_filepath) convert([shpfile1, shpfile2, shpfile3], citygml_writer) citygml_writer.write(citygml_filepath) time2 = time.clock() time = (time2 - time1) / 60.0 print "TIME TAKEN:", time print "CityGML GENERATED"
def parameterise_citygml(ref_citygml_file, parameterlist, citygml_resultpath): #================================================== #PARAMETERISE THE CITYGML FILE #================================================== #this model has 75 parameters #height, position, orientation read_citygml = pycitygml.Reader() read_citygml.load_filepath(ref_citygml_file) buildings = read_citygml.get_buildings() landuses = read_citygml.get_landuses() lpolygon = read_citygml.get_polygons(landuses[0])[0] landuse_pts = read_citygml.polygon_2_pyptlist(lpolygon) lface = py3dmodel.construct.make_polygon(landuse_pts) changed_bldglist = [] bcnt = 0 for building in buildings: bsolid = gmlbuilding2buildingsolid(building, read_citygml) #move, rotate and change the height of the building bfaces = py3dmodel.fetch.topo_explorer(bsolid, "face") for bface in bfaces: fnormal = py3dmodel.calculate.face_normal(bface) fnormal = py3dmodel.modify.round_pypt(fnormal, 3) if fnormal == (0, 0, -1): #must be the footprint #get the midpt midpt = py3dmodel.calculate.face_midpt(bface) #change the building height height_parm = parameterlist[bcnt + ((bcnt * 2) + 0)] orig_height = 90.0 height_ratio = float(height_parm) / orig_height scaled_shape = py3dmodel.modify.uniform_scale(bsolid, 1, 1, height_ratio, midpt) #change the positions: there are 4 options, 0 - positive y, 1 - neg y, 2 - positive x, 3 - neg x pos_parm = parameterlist[bcnt + ((bcnt * 2) + 1)] if pos_parm == 0: moved_shape = scaled_shape locpt = midpt else: if pos_parm == 1: dir2mv = (0, 1, 0) if pos_parm == 2: dir2mv = (0, -1, 0) if pos_parm == 3: dir2mv = (1, 0, 0) if pos_parm == 4: dir2mv = (-1, 0, 0) locpt = py3dmodel.modify.move_pt(midpt, dir2mv, 10) moved_shape = py3dmodel.modify.move(midpt, locpt, scaled_shape) #change the orientation of the building orient_parm = parameterlist[bcnt + ((bcnt * 2) + 2)] rotat_shape = py3dmodel.modify.rotate(moved_shape, locpt, (0, 0, 1), orient_parm) changed_bldglist.append(py3dmodel.fetch.topo2topotype(rotat_shape)) bcnt += 1 #write the design variant as a citygml file citygml_writer = pycitygml.Writer() daebldglist2gmlbuildings(changed_bldglist, citygml_writer) daeluse2gmlluse(lface, citygml_writer) citygml_writer.write(citygml_resultpath) return changed_bldglist