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 _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)
def convertFile(tilename, inputfolder, outputfolder, filetype, Xorigin, Yorigin, Xoffset, Yoffset, costheta, sintheta): 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, ) tic = time.perf_counter() X = inFile.get_x_scaled() Y = inFile.get_y_scaled() X, Y = Translate(X, Y, -1 * Xorigin, -1 * Yorigin) X, Y = Rotate(X, Y, sintheta, costheta) X, Y = Translate(X, Y, Xorigin, Yorigin) X, Y = Translate(X, Y, Xoffset, Yoffset) outfile.points = inFile.points outfile.set_x_scaled(X) outfile.set_y_scaled(Y) 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)
file2='F:/temp/SW_502000_6965000_1k_class_AHD.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") 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]={}
def convertFile(tilename, inputfolder, xorigin, yorigin, scalar, xshift, yshift, 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, ) tic = time.perf_counter() xvalues = inFile.get_x_scaled() newxvals = shiftNscale(xvalues, xshift, xorigin, scalar) yvalues = inFile.get_y_scaled() newyvals = shiftNscale(yvalues, yshift, yorigin, scalar) outfile.points = inFile.points outfile.set_x_scaled(newxvals) outfile.set_y_scaled(newyvals) 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)