Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
# 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