From 2b041de535550e2d4f641f50ad35969a1b8dc426 Mon Sep 17 00:00:00 2001 From: Antoine Lavenant Date: Thu, 27 Jun 2024 11:12:48 +0200 Subject: [PATCH 1/2] ajout d'une fn de surpression de dimensions --- pdal_ign_macro/macro.py | 38 +++++++++++++++++++++++++++++++++++ test/test_remove_dimension.py | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 test/test_remove_dimension.py diff --git a/pdal_ign_macro/macro.py b/pdal_ign_macro/macro.py index 08739c6..641c368 100755 --- a/pdal_ign_macro/macro.py +++ b/pdal_ign_macro/macro.py @@ -1,4 +1,8 @@ import pdal +import numpy +import json + +import pdaltools.las_info as li """ Some useful filters combinations for complete pdal pipeline @@ -83,6 +87,40 @@ def keep_non_planar_pts(pipeline, condition, condition_out): return pipeline +def remove_dimensions(input_las, dimensions, ouput_las): + """ + export new las whitout some dimensions + """ + pipeline = pdal.Pipeline() | pdal.Reader.las(input_las) + pipeline.execute() + points = pipeline.arrays[0] + + dim_remove = [] + for dim in dimensions: + dim_remove.append(list(points.dtype.fields.keys()).index(dim)) + + new_points = [] + for pt in points: + ptl = list(pt) + ptl = [ptl[i] for i in range(len(ptl)) if i not in dim_remove] + new_points.append(tuple(ptl)) + + new_dtype = {} + for dim in points.dtype.fields.keys(): + if dim in dimensions: + continue + new_dtype[dim] = points.dtype.fields[dim] + + new_las = numpy.array(new_points, dtype=new_dtype) + params = li.get_writer_parameters_from_reader_metadata(pipeline.metadata) + + pipeline_end = pdal.Pipeline(arrays=[new_las], ) + pipeline_end |= pdal.Writer.las(ouput_las, forward="all", **params ) + + pipeline_end.execute() + + + def build_condition(key, values): """ build 'key==values[0] || key==values[1] ...' diff --git a/test/test_remove_dimension.py b/test/test_remove_dimension.py new file mode 100644 index 0000000..8af2cf0 --- /dev/null +++ b/test/test_remove_dimension.py @@ -0,0 +1,38 @@ +import tempfile +import pdal +import numpy + +from macro.macro import remove_dimensions + + +def test_remove_dimension(): + + ini_las = "test/data/4_6.las" + added_dimensions = ["DIM_1", "DIM_2"] + + tmp_las = tempfile.NamedTemporaryFile(suffix="_add.las").name + + # recuperation des données ini + pipeline_read_ini = pdal.Pipeline() | pdal.Reader.las(ini_las) + pipeline_read_ini.execute() + points_ini = pipeline_read_ini.arrays[0] + + # ajout de dimensions supplémentaires + pipeline = pdal.Pipeline() + pipeline |= pdal.Reader.las(ini_las) + pipeline |= pdal.Filter.ferry(dimensions="=>" + ", =>".join(added_dimensions)) + pipeline |= pdal.Writer.las(tmp_las, extra_dims="all", forward="all",) + pipeline.execute() + + # suppression des dimensions + remove_dimensions(tmp_las, added_dimensions, tmp_las) + + # recuperation des données finales + pipeline_read_end = pdal.Pipeline() | pdal.Reader.las(tmp_las) + pipeline_read_end.execute() + points_end = pipeline_read_end.arrays[0] + + # les données ini et finales doivent être identique + assert numpy.array_equal(points_ini, points_end) + + From 0bd6af47517864a659d97ae62430ec26f7695c0f Mon Sep 17 00:00:00 2001 From: Antoine Lavenant Date: Thu, 27 Jun 2024 13:03:13 +0200 Subject: [PATCH 2/2] fix suite rebase --- test/test_remove_dimension.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_remove_dimension.py b/test/test_remove_dimension.py index 8af2cf0..1a9b1ce 100644 --- a/test/test_remove_dimension.py +++ b/test/test_remove_dimension.py @@ -2,7 +2,7 @@ import pdal import numpy -from macro.macro import remove_dimensions +from pdal_ign_macro.macro import remove_dimensions def test_remove_dimension():