def writeFile(directory,name,header,coords): """Write a laz file using laspy and numpy arrays""" output = File(directory + name, mode = "w", header=header) output.x = coords[0] output.y = coords[1] output.z = coords[2] output.close()
def store_point_cloud(filepath: str, points: np.ndarray, header): outFile = File(filepath, mode="w", header=header) outFile.x = points[:, 0] + header.min[0] outFile.y = points[:, 1] + header.min[1] outFile.z = points[:, 2] + header.min[2] outFile.close()
def write_las_grid(self,filename, lb = -10, ub = 10, granularity = 0.1): out_file = File(filename, mode = "w", header = Header()) out_file.header.scale = (0.001,0.001,0.001) grid = self.get_3d_grid(lb, ub, granularity) out_file.x = grid[:,0]* 300 out_file.y = grid[:,1] * 300 out_file.z = grid[:,2] * 300 out_file.intensity = grid[:,2] * 300 return(out_file)
def write_las_grid(self, filename, lb=-10, ub=10, granularity=0.1): out_file = File(filename, mode="w", header=Header()) out_file.header.scale = (0.001, 0.001, 0.001) grid = self.get_3d_grid(lb, ub, granularity) out_file.x = grid[:, 0] * 300 out_file.y = grid[:, 1] * 300 out_file.z = grid[:, 2] * 300 out_file.intensity = grid[:, 2] * 300 return (out_file)
def make_las_file(data, file_name=''): my_header = header.Header() outFile = File(file_name, mode='w', header=my_header) # outFile.header.offset = np.amin(data, axis=0)[0:3] outFile.header.scale = [1, 1, 1] outFile.x = data[:, 0] outFile.y = data[:, 1] outFile.z = data[:, 2] outFile.raw_classification = data[:, 3] outFile.close()
min_x = np.min(in_pc_nparray[:, 0]) + shift max_x = np.max(in_pc_nparray[:, 0]) + shift step_x = resolution min_y = np.min(in_pc_nparray[:, 1]) + shift max_y = np.max(in_pc_nparray[:, 1]) + shift step_y = resolution bound_x = np.arange(min_x, max_x, step_x) bound_y = np.arange(min_y, max_y, step_y) target_x, target_y = np.meshgrid(bound_x, bound_y, indexing='ij') # export as XYZ pcloud x = np.ravel(target_x) y = np.ravel(target_y) z = np.ones(len(x)) false_intensity = np.zeros(len(x)) out_LAS = File(filename + "_target.las", mode="w", header=in_pc.header) out_LAS.x = x out_LAS.y = y out_LAS.z = z out_LAS.intensity = false_intensity out_LAS.close() end1 = time.time() difftime1 = end1 - start1 print(("create target point: %f sec") % (difftime1))
pointCloud = VtkPointCloud() sliced = naive_slice_from_las( input_file, AxisAlignedBox3D([204.24, -6.7, -1.9], [208.46, -3.24, 3.5])) # sliced = [[1, 1, 1]] print("Number of points sliced: %d" % len(sliced)) # for point in sliced: # pointCloud.addPoint(point) # # outFile.write(point) # pdb.set_trace() allx = np.array([sliced[i][0] for i in range(len(sliced))]) ally = np.array([sliced[i][1] for i in range(len(sliced))]) allz = np.array([sliced[i][2] for i in range(len(sliced))]) outFile.x = allx outFile.y = ally outFile.z = allz # print("Number of points: %d" % len(sliced)) # print('Plotting') # # Renderer # renderer = vtk.vtkRenderer() # renderer.AddActor(pointCloud.vtkActor) # renderer.SetBackground(.2, .3, .4) # renderer.ResetCamera() # # # Render Window # renderWindow = vtk.vtkRenderWindow() # renderWindow.AddRenderer(renderer) # # # Interactor
# Prepare data for writing pred_data = pred_data.assign(preds_write = 0) pred_data.loc[pred_data['preds'] == 'barren', 'preds_write'] = 1 pred_data.loc[pred_data['preds'] == 'cropland', 'preds_write'] = 2 pred_data.loc[pred_data['preds'] == 'grassland', 'preds_write'] = 3 pred_data.loc[pred_data['preds'] == 'road', 'preds_write'] = 4 pred_data.loc[pred_data['preds'] == 'shadow', 'preds_write'] = 5 pred_data.loc[pred_data['preds'] == 'shrubland', 'preds_write'] = 6 pred_data.loc[pred_data['preds'] == 'trees', 'preds_write'] = 7 pred_data.loc[pred_data['preds'] == 'water', 'preds_write'] = 8 pred_data.loc[pred_data['preds'] == 'waterveg', 'preds_write'] = 9 pred_data['preds_write'].value_counts() # Save to las headfile = File(os.path.join(direct, '0-0-0-0.las'), mode="r") header = headfile.header outfile = File("classified_pc.las", mode="w", header=header) outfile.x = pred_data['x'].to_numpy() outfile.y = pred_data['y'].to_numpy() outfile.z = pred_data['z'].to_numpy() outfile.red = pred_data['red'].to_numpy() outfile.green = pred_data['green'].to_numpy() outfile.blue = pred_data['blue'].to_numpy() outfile.classification = pred_data['preds_write'].to_numpy() outfile.close() # Clean del bound, bound_mask, coords, direct, dsm_sd9, pred_X, pred_data, prednames del preds
data_type=9, description="Spatial feature") out_LAS.define_new_dimension(name="eigenentropy" + "_" + str(k), data_type=9, description="Spatial feature") out_LAS.define_new_dimension(name="sum_eigenvalues" + "_" + str(k), data_type=9, description="Spatial feature") out_LAS.define_new_dimension(name="curvature" + "_" + str(k), data_type=9, description="Spatial feature") #out_LAS.define_new_dimension(name="classification"+"_"+str(k),data_type=9, description="reference") print(point_cloud.columns) out_LAS.x = point_cloud['x'] #point_cloud.drop('x') out_LAS.y = point_cloud['y'] out_LAS.z = point_cloud['z'] out_LAS.intensity = point_cloud['intensity'] out_LAS.return_num = point_cloud['return_number'] #print(point_cloud["number_of_returns"]) point_cloud["number_of_returns"] = point_cloud["number_of_returns"] #print(point_cloud["number_of_returns"]) out_LAS.num_returns = point_cloud['number_of_returns'] #Setting attributes Maybe do this with "try" ? setattr(out_LAS, 'delta_z' + "_" + str(k), point_cloud['delta_z']) #point_cloud.drop('delta_z') setattr(out_LAS, 'std_z' + "_" + str(k), point_cloud['std_z'])