def clarifydata(tile, obfuscated_data, original_data, filetype, outputfolder): tilename = tile.name obfuscated_name = tile.params['obfsname'] toffset = tile.params['toffset'] obfuscated_tile = os.path.join(obfuscated_data, '{0}.{1}'.format( obfuscated_name, filetype)).replace('\\', '/') ori_tile = os.path.join(original_data, '{0}.{1}'.format(tilename, filetype)).replace('\\', '/') temp_outputfile = os.path.join(outputfolder, '{0}.{1}'.format(tilename, 'las')).replace('\\', '/') outputfile = os.path.join(outputfolder, '{0}.{1}'.format(tilename, filetype)).replace('\\', '/') #read the obfuscated tile infile = File(obfuscated_tile, mode='r') #get the gps times tvalues = infile.get_gps_time() #reset to original times newtvals = tvalues - toffset outfile = File(temp_outputfile, mode="w", header=infile.header) outfile.points = infile.points outfile.set_gps_time(newtvals) outfile.close() infile.close() #lascopy all x,y,z,classification based on the corrected gps time subprocessargs = [ 'C:/LAStools/bin/lascopy.exe', '-i', temp_outputfile, '-i', ori_tile, '-olaz', '-o', outputfile ] subprocessargs = list(map(str, subprocessargs)) p = subprocess.run(subprocessargs, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False, check=True, universal_newlines=True) if os.path.isfile(outputfile): #read the obfuscated tile nfile = File(outputfile, mode='r') classification = nfile.classification #print(classification) #get the class 0 if not 0 in classification: log = f'Succesfully coverted {obfuscated_name} -> {tilename}' os.remove(temp_outputfile) print(log) ofile = File(ori_tile, mode='r') return (True, outputfile, log) else: log = f'Failed coverting {obfuscated_name} -> {tilename}- class 0 points in tile' #os.remove(temp_outputfile) print(log) return (False, outputfile, log) else: log = f'Failed coverting {obfuscated_name} -> {tilename}' #os.remove(temp_outputfile) print(log) return (False, outputfile, log)
def obfuscate_data(tile, inputfolder, originx, originy, rotation, xoffset, yoffset, zoffset, toffset, outputfolder, filetype, outtilename, buffer): """Rotate a point around a given point. x and y are numpy lists """ tilename = tile.name input_file = os.path.join(outputfolder, '{0}.{1}'.format(tilename, filetype)).replace('\\', '/') buffered_file = os.path.join(outputfolder, '{0}_buff.laz'.format(tilename)).replace( '\\', '/') temp_outputfile = os.path.join(outputfolder, '{0}.{1}'.format(outtilename, 'las')).replace('\\', '/') outputfile = os.path.join(outputfolder, '{0}.{1}'.format(outtilename, filetype)).replace('\\', '/') log = '' try: neighbours = tile.getneighbours(buffer) neighbourfiles = [] for fi in neighbours: nfi = os.path.join(inputfolder, '{0}.{1}'.format(fi, filetype)).replace('\\', '/') if os.path.isfile(nfi): neighbourfiles.append(nfi) keep = '-keep_xy {0} {1} {2} {3}'.format(str(tile.xmin - buffer), str(tile.ymin - buffer), str(tile.xmax + buffer), str(tile.ymax + buffer)) keep = keep.split() subprocessargs = [ 'C:/LAStools/bin/las2las.exe', '-i' ] + neighbourfiles + ['-olaz', '-o', buffered_file, '-merged'] + keep subprocessargs = list(map(str, subprocessargs)) p = subprocess.run(subprocessargs, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False, check=True, universal_newlines=True) infile = File(buffered_file, mode='r') xvalues = infile.get_x_scaled() yvalues = infile.get_y_scaled() zvalues = infile.get_z_scaled() tvalues = infile.get_gps_time() print( f"\ntilename={tilename:s} xoffset={xoffset:0.4f} yoffset={yoffset:0.4f} zoffset={zoffset:0.4f} rotation={rotation:0.4f} toffset={toffset:0.4f}" ) #rotate points xvalues, yvalues = rotate_about_origin(xvalues, yvalues, math.radians(rotation), originx, originy) #print(tilename,xvalues[0],yvalues[0],zvalues[0]) #offset points newxvals = xvalues + xoffset newyvals = yvalues + yoffset newzvals = zvalues + zoffset newtvals = tvalues + toffset #print(tilename,newxvals[0],newyvals[0],newzvals[0]) outfile = File(temp_outputfile, mode="w", header=infile.header) outfile.points = infile.points outfile.set_x_scaled(newxvals) outfile.set_y_scaled(newyvals) outfile.set_z_scaled(newzvals) outfile.set_gps_time(newtvals) outfile.close() infile.close() subprocessargs = [ 'C:/LAStools/bin/las2las.exe', '-i', temp_outputfile, '-olaz', '-o', outputfile ] subprocessargs = list(map(str, subprocessargs)) p = subprocess.run(subprocessargs, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False, check=True, universal_newlines=True) if os.path.isfile(outputfile): log = f'Succesfully Obfuscated {tilename}' os.remove(temp_outputfile) os.remove(buffered_file) return (True, outputfile, log) except: log = f"{tilename} : Obfuscation Failed" print(log) #outfile.close() #infile.close() return (False, tilename, log)