def write_cloud(header, point_cloud, output_point_cloud_path, write_extra_dimensions=False): (h, scale, offset, evlrs, vlrs) = header # Open output file output_las_file = File(output_point_cloud_path, mode='w', header=h, evlrs=evlrs, vlrs=vlrs) if write_extra_dimensions: # Create new dimensions for name, dimension in point_cloud.extra_dimensions_metadata.items(): output_las_file.define_new_dimension( name=name, data_type=dimension.get_las_type(), description="Dimension added by Ground Extend") # Assign dimension values for dimension_name, values in point_cloud.extra_dimensions.items(): setattr(output_las_file, dimension_name, values) # Adapt points to scale and offset [x_scale, y_scale, z_scale] = scale [x_offset, y_offset, z_offset] = offset [x, y] = np.hsplit(point_cloud.xy, 2) output_las_file.X = (x.ravel() - x_offset) / x_scale output_las_file.Y = (y.ravel() - y_offset) / y_scale output_las_file.Z = (point_cloud.z - z_offset) / z_scale # Set color [red, green, blue] = np.hsplit(point_cloud.rgb, 3) output_las_file.red = red.ravel() output_las_file.green = green.ravel() output_las_file.blue = blue.ravel() # Set classification output_las_file.Classification = point_cloud.classification.astype( np.uint8) # Set header output_las_file.header.scale = scale output_las_file.header.offset = offset # Close files output_las_file.close()
def save_cloud(inFile, dir_out, filename, classif, conf): # Problème dans les données, certaines labels sont à 0 label = inFile.classification ind = np.argwhere(label != 0) new_header = copy.copy(inFile.header) #Modification du point format id pour accéder au dimensions RGB new_header.data_format_id = 3 #Create outfile outFile = dir_out + filename.replace('.laz', '_classify' + '.laz') outCloud = File(outFile, mode="w", header=new_header, vlrs=inFile.header.vlrs) outCloud.define_new_dimension(name='classif', data_type=9, description="ntd") outCloud.define_new_dimension(name='conf', data_type=9, description="ntd") for dimension in inFile.point_format: if (dimension == inFile.point_format[13]): break dat = inFile.reader.get_dimension(dimension.name)[ind].reshape(-1) # dat = dat[ind] outCloud.writer.set_dimension(dimension.name, dat) multiscale_features_raw = pd.DataFrame() features_raw = np.hstack([classif.reshape(-1, 1), conf.reshape(-1, 1)]) features_raw = pd.DataFrame(features_raw) features_raw.columns = np.array(["classif", "conf"]) multiscale_features_raw = pd.concat( [multiscale_features_raw, features_raw], axis=1) outCloud.classif = multiscale_features_raw.as_matrix(['classif']).ravel() outCloud.conf = multiscale_features_raw.as_matrix(['conf']).ravel() outCloud.close()
def addI_currentfile(inFile): print 'Generating Importance value for %s' % str(inFile) outFile = File('localI.las', mode='w', header=inFile.header) outFile.define_new_dimension(name='gps_time', data_type=10, description='gps_time') for dimension in inFile.point_format: dat = inFile.reader.get_dimension(dimension.name) outFile.writer.set_dimension(dimension.name, dat) outFile.pt_src_id = [random.randint(0, 15) for _ in range(len(outFile))] outFile.gps_time = [] for i in range(len(outFile.X)): outFile.importance_value.append(random.randomint(0, 15)) closeLasFile(outFile) return "localI.las"
point_cloud = point_cloud.loc[:, ~point_cloud.columns.duplicated()] #point_cloud.to_csv(input_file_path[:-4]+'_ascii.csv',sep=',',index=False,header=True) ########### Output ########### print("Outputting to las file") las_path_base = os.path.basename(input_file_path[:-4]) out_filename = '%s_veg_classification_testparams.las' % (las_path_base) print(out_filename) out_LAS = File(out_filename, mode="w", header=in_LAS.header) out_LAS.define_new_dimension(name="delta_z" + "_" + str(k), data_type=9, description="Spatial feature") out_LAS.define_new_dimension(name="std_z" + "_" + str(k), data_type=9, description="Spatial feature") out_LAS.define_new_dimension(name="radius" + "_" + str(k), data_type=9, description="Spatial feature") out_LAS.define_new_dimension(name="density" + "_" + str(k), data_type=9, description="Spatial feature") out_LAS.define_new_dimension(name="norm_z" + "_" + str(k), data_type=9, description="Spatial feature") out_LAS.define_new_dimension(name="linearity" + "_" + str(k), data_type=9,