Skip to content

Commit

Permalink
Use temporary buffer to calculate markers
Browse files Browse the repository at this point in the history
  • Loading branch information
leavauchier committed Jul 17, 2024
1 parent 92c07f6 commit 961ee33
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tempfile

import pdal
from pdaltools.las_add_buffer import run_on_buffered_las
from pdaltools.las_remove_dimensions import remove_dimensions_from_las

from pdal_ign_macro import macro
Expand Down Expand Up @@ -48,6 +49,39 @@ def parse_args():
action="store_true",
help="If set, do not delete temporary dimensions",
)
parser.add_argument(
"--skip_buffer",
"-s",
action="store_true",
help="If set, skip adding a buffer from the neighbor tiles based on their name",
)
parser.add_argument(
"--buffer_width",
type=float,
default=25,
help="width of the border to add to the tile (in meters)",
)
parser.add_argument(
"--spatial_ref",
type=str,
default="EPSG:2154",
help="spatial reference for the writer (required when running with a buffer)",
)
parser.add_argument(
"--tile_width",
type=int,
default=1000,
action="store_true",
help="width of tiles in meters (required when running with a buffer)",
)
parser.add_argument(
"--tile_coord_scale",
type=int,
default=1000,
action="store_true",
help="scale used in the filename to describe coordinates in meters (required when running with a buffer)",
)

return parser.parse_args()


Expand Down Expand Up @@ -237,7 +271,7 @@ def mark_points_to_use_for_digital_models_with_new_dimension(
output_dtm,
keep_temporary_dimensions=False,
):
with tempfile.NamedTemporaryFile(suffix="_with_buffer.las", dir=".") as tmp_las:
with tempfile.NamedTemporaryFile(suffix="_with_temporary_dims.las", dir=".") as tmp_las:
pipeline, temporary_dimensions = define_marking_pipeline(
input_las,
tmp_las.name,
Expand Down Expand Up @@ -268,9 +302,53 @@ def mark_points_to_use_for_digital_models_with_new_dimension(
if keep_temporary_dimensions:
shutil.copy(tmp_las.name, output_las)
else:
remove_dimensions_from_las(tmp_las.name, temporary_dimensions, output_las)
remove_dimensions_from_las(
tmp_las.name,
temporary_dimensions + ["SRC_DOMAIN", "REF_DOMAIN", "radius_search"],
output_las,
)


def main(
input_las,
output_las,
dsm_dimension,
dtm_dimension,
output_dsm,
output_dtm,
keep_temporary_dimensions=False,
skip_buffer=False,
buffer_width=25,
spatial_ref="EPSG:2154",
tile_width=1000,
tile_coord_scale=1000,
):
if skip_buffer:
mark_points_to_use_for_digital_models_with_new_dimension(
input_las,
output_las,
dsm_dimension,
dtm_dimension,
output_dsm,
output_dtm,
keep_temporary_dimensions,
)
else:
mark_with_buffer = run_on_buffered_las(
buffer_width, spatial_ref, tile_width, tile_coord_scale
)(mark_points_to_use_for_digital_models_with_new_dimension)

mark_with_buffer(
input_las,
output_las,
dsm_dimension,
dtm_dimension,
output_dsm,
output_dtm,
keep_temporary_dimensions,
)


if __name__ == "__main__":
args = parse_args()
mark_points_to_use_for_digital_models_with_new_dimension(**vars(args))
main(**vars(args))
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pdal

from pdal_ign_macro.mark_points_to_use_for_digital_models_with_new_dimension import (
main,
mark_points_to_use_for_digital_models_with_new_dimension,
)

Expand All @@ -17,14 +18,42 @@ def test_mark_points_to_use_for_digital_models_with_new_dimension():
ini_las, las_output.name, dsm_dimension, dtm_dimension, "", ""
)
pipeline = pdal.Pipeline()
pipeline |= pdal.Reader.las(ini_las)
input_dimensions = set(pipeline.quickinfo["readers.las"]["dimensions"].split(", "))
pipeline = pdal.Pipeline()
pipeline |= pdal.Reader.las(las_output.name)
output_dimensions = pipeline.quickinfo["readers.las"]["dimensions"].split(", ")
output_dimensions = set(pipeline.quickinfo["readers.las"]["dimensions"].split(", "))
assert output_dimensions == input_dimensions.union([dsm_dimension, dtm_dimension])

pipeline.execute()
arr = pipeline.arrays[0]
assert np.any(arr[dsm_dimension] == 1)
assert np.any(arr[dtm_dimension] == 1)


def test_mark_points_to_use_for_digital_models_with_new_dimension_keep_dimensions():
ini_las = "test/data/4_6.las"
dsm_dimension = "dsm_marker"
dtm_dimension = "dtm_marker"
with tempfile.NamedTemporaryFile(suffix="_mark_points_output.las") as las_output:
mark_points_to_use_for_digital_models_with_new_dimension(
ini_las,
las_output.name,
dsm_dimension,
dtm_dimension,
"",
"",
keep_temporary_dimensions=True,
)
pipeline = pdal.Pipeline()
pipeline |= pdal.Reader.las(las_output.name)
output_dimensions = set(pipeline.quickinfo["readers.las"]["dimensions"].split(", "))
assert dsm_dimension in output_dimensions
assert dtm_dimension in output_dimensions

assert all(
[
dim not in output_dimensions
dim in output_dimensions
for dim in ["PT_VEG_DSM", "PT_ON_BRIDGE", "PT_ON_BUILDING", "PT_ON_VEGET"]
]
)
Expand All @@ -33,3 +62,60 @@ def test_mark_points_to_use_for_digital_models_with_new_dimension():
arr = pipeline.arrays[0]
assert np.any(arr[dsm_dimension] == 1)
assert np.any(arr[dtm_dimension] == 1)


def test_main_no_buffer():
ini_las = "test/data/4_6.las"
dsm_dimension = "dsm_marker"
dtm_dimension = "dtm_marker"
with tempfile.NamedTemporaryFile(suffix="_mark_points_output.las") as las_output:
main(
ini_las,
las_output.name,
dsm_dimension,
dtm_dimension,
"",
"",
keep_temporary_dimensions=False,
skip_buffer=True,
)
pipeline = pdal.Pipeline()
pipeline |= pdal.Reader.las(las_output.name)
output_dimensions = pipeline.quickinfo["readers.las"]["dimensions"].split(", ")
assert dsm_dimension in output_dimensions
assert dtm_dimension in output_dimensions

pipeline.execute()
arr = pipeline.arrays[0]
assert np.any(arr[dsm_dimension] == 1)
assert np.any(arr[dtm_dimension] == 1)


def test_main_with_buffer():
ini_las = "test/data/buffer/test_data_77055_627755_LA93_IGN69.laz"
dsm_dimension = "dsm_marker"
dtm_dimension = "dtm_marker"
with tempfile.NamedTemporaryFile(suffix="_mark_points_output.las") as las_output:
main(
ini_las,
las_output.name,
dsm_dimension,
dtm_dimension,
"",
"",
keep_temporary_dimensions=False,
skip_buffer=False,
buffer_width=10,
tile_width=50,
tile_coord_scale=10,
)
pipeline = pdal.Pipeline()
pipeline |= pdal.Reader.las(las_output.name)
output_dimensions = pipeline.quickinfo["readers.las"]["dimensions"].split(", ")
assert dsm_dimension in output_dimensions
assert dtm_dimension in output_dimensions

pipeline.execute()
arr = pipeline.arrays[0]
assert np.any(arr[dsm_dimension] == 1)
assert np.any(arr[dtm_dimension] == 1)

0 comments on commit 961ee33

Please sign in to comment.