def load_LAS(las_fname, dtype='float32'): """ Load LAS or LAZ file (only coordinates) and return pc_xyz and xy vectors. Converts float64 to float32 by default, unless you set dtype='float64' """ from laspy.file import File inFile = File(las_fname, mode='r') pc_pc_xyz = np.vstack((inFile.get_x()*inFile.header.scale[0]+inFile.header.offset[0], inFile.get_y()*inFile.header.scale[1]+inFile.header.offset[1], inFile.get_z()*inFile.header.scale[2]+inFile.header.offset[2])).transpose() #setting datatype to float32 to save memory. if dtype == 'float32': pc_pc_xyz = pc_pc_xyz.astype('float32') return pc_pc_xyz
import numpy as np import time from PIL import Image from laspy.file import File start_time = time.time() # time the process so we can keep it quick inFile = File("c:/development/python/sample.las", mode="r") # Grab all of the points from the file. point_records = inFile.points data = np.histogram2d(inFile.get_x(), inFile.get_y(), weights=inFile.get_z()) img = Image.fromarray(data) img.show() print("%d" % len(inFile)) print("read duration %.3fs" % (time.time() - start_time)) # time the process # img.save('my.png')
if os.path.exists(bootstrap_dir) == False: os.mkdir(bootstrap_dir) figure_dir = os.path.join(args.outputdir, 'figure') if os.path.exists(figure_dir) == False: os.mkdir(figure_dir) pickle_dir = os.path.join(args.outputdir, 'pickle') if os.path.exists(pickle_dir) == False: os.mkdir(pickle_dir) ### Loading data and filtering print('\nLoading input file: %s'%args.inlas) inFile = File(args.inlas, mode='r') pc_xyzic = np.vstack((inFile.get_x()*inFile.header.scale[0]+inFile.header.offset[0], inFile.get_y()*inFile.header.scale[1]+inFile.header.offset[1], inFile.get_z()*inFile.header.scale[2]+inFile.header.offset[2], inFile.get_intensity(), inFile.get_classification())).transpose() #pc_xyzic is now a point cloud with x, y, z, intensity, and classification #if args.store_color == True: # pc_i = inFile.get_intensity().copy() # pc_blue = inFile.get_blue().copy() # pc_green = inFile.get_green().copy() # pc_red = inFile.get_red().copy() print('Loaded %s points'%"{:,}".format(pc_xyzic.shape[0])) if args.ground_only == True: print('\nFiltering points to only work with ground points (class == 2)... ',end='\n') #get only ground points: idx_ground = np.where(pc_xyzic[:,4] == 2)[0] pc_xyzig = pc_xyzic[idx_ground,0:4] pc_xyzg = pc_xyzic[idx_ground,0:3] #pc_xyzg is a point cloud with x, y, z, and for class == 2 only