def main(): ''' read data from file ''' print('Reading files') file1='F:/temp/Brisbane_2014_LGA_SW_502000_6965000_1K_Las.laz' tic = time.perf_counter() inFile1 = File(file1, mode='r') toc = time.perf_counter() print(f"{len(inFile1.points):d} records read from {file1:s} in {toc - tic:0.4f} seconds") print('permuting data') tic = time.perf_counter() xvalues=inFile1.get_x_scaled() yvalues=inFile1.get_y_scaled() zvalues=inFile1.get_z_scaled() tvalues=inFile1.get_gps_time() pointclasses=inFile1.get_classification() #tile lower left corner originx, originy=502000,6965000 xoffset=randrange(-500000,500000) yoffset=randrange(-500000,500000) zoffset=randrange(-200,200)``
def z_adjustData(tile, source_data,target_data,filetype,outputfolder): tilename = tile.name source_tile = os.path.join(source_data, '{0}.{1}'.format(tilename,filetype)).replace('\\','/') target_tile = os.path.join(target_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 sourcefile = File(source_tile, mode='r') targetfile = File(target_tile, mode='r') #get z values from source z_values=sourcefile.get_z_scaled() outfile = File(temp_outputfile, mode="w", header=targetfile.header) outfile.points=targetfile.points #Replace the z values from source file outfile.set_z_scaled(z_values) outfile.close() sourcefile.close() targetfile.close() #lascopy all x,y,z,classification based on the corrected gps time 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): #read the obfuscated tile log = f'Z replaced from {source_tile} -> {target_tile}' os.remove(temp_outputfile) print(log) return(True,outputfile,log) else: log = f'Failed replacing Z from {source_tile} -> {target_tile}' #os.remove(temp_outputfile) print(log) return(False,None,log)
def _update(self): f = FileLAS(self.filename_, mode='r') points = f.get_points() name = points.dtype.fields.keys() x = f.get_x_scaled() y = f.get_y_scaled() z = f.get_z_scaled() #Check is the LAS File contains red property if 'red' in points.dtype.fields[name[0]][0].fields.keys(): red = np.int32(255.0 * f.red / 65536.0) green = np.int32(255.0 * f.green / 65536.0) blue = np.int32(255.0 * f.blue / 65536.0) self.data_ = np.c_[x, y, z, red, green, blue] else: N = f.X.shape[0] color = 128 * np.ones((N, ), dtype=np.int32) self.data_ = np.c_[x, y, z, color, color, color]
def _update(self): f = FileLAS(self.filename_, mode='r') points = f.get_points() name = points.dtype.fields.keys() x = f.get_x_scaled() y = f.get_y_scaled() z = f.get_z_scaled() #Check is the LAS File contains red property if 'red' in points.dtype.fields[name[0]][0].fields.keys(): red = np.int32(255.0*f.red/65536.0) green = np.int32(255.0*f.green/65536.0) blue = np.int32(255.0*f.blue/65536.0) self.data_ = np.c_[x, y, z, red, green, blue] else: N = f.X.shape[0] color = 128*np.ones((N,), dtype=np.int32) self.data_ = np.c_[x, y, z, color, color, color]
def convertFile(tilename, inputfolder, outputfolder, filetype): inputfile = os.path.join(inputfolder, '{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('\\', '/') try: inFile = File(inputfile, mode='r') header = inFile.header outfile = File( temp_outputfile, mode="w", header=header, ) outfile.header.offset = [0.0, 0.0, 0.0] tic = time.perf_counter() X = inFile.get_x_scaled() Y = inFile.get_y_scaled() Z = inFile.get_z_scaled() E, N = transGDA94_to_ArgyleGrid(X, Y) outfile.points = inFile.points outfile.set_x_scaled(E) outfile.set_y_scaled(N) print(E, N, Z) toc = time.perf_counter() outfile.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) log = f"{tilename} : Convertion completed in {toc - tic:0.4f}s" print(log) if os.path.isfile(outputfile): os.remove(temp_outputfile) return (True, outputfile, log) except: log = f"{tilename} : Convertion Failed" print(log) outfile.close() return (False, tilename, 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)
tic = time.perf_counter() inFile1 = File(file1, mode='r') toc = time.perf_counter() print(f"{len(inFile1.points):d} records read from {file1:s} in {toc - tic:0.4f} seconds") tic = time.perf_counter() inFile2 = File(file2, mode='r') toc = time.perf_counter() print(f"{len(inFile2.points):d} records read from {file2:s} in {toc - tic:0.4f} seconds") print('Creating voxels') tic = time.perf_counter() xvalues1=inFile1.get_x_scaled() yvalues1=inFile1.get_y_scaled() zvalues1=inFile1.get_z_scaled() classvalues1=inFile1.get_classification() vox1={} for i in range(0, len(xvalues1)): if i%10000==0: print(i) x=xvalues1[i] y=yvalues1[i] z=zvalues1[i] key=(math.floor(x/voxelsize)*voxelsize,math.floor(y/voxelsize)*voxelsize,math.floor(z/voxelsize)*voxelsize) if not key in vox1.keys(): vox1[key]={} vox1[key]['x']=[] vox1[key]['y']=[]