Skip to content

Commit

Permalink
Remove additional dimensions in main script
Browse files Browse the repository at this point in the history
  • Loading branch information
leavauchier committed Jul 17, 2024
1 parent f487135 commit 92c07f6
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ __pycache__

*.egg-info
*.idea

# test output
tmp
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ The code is structured as:
├── macro # Python module with ready-to-use filters combinations
│   ├── __init__.py
│   ├── macro.py
│   └── version.py
├── scripts
│   ├── *.py # Example scripts to use the plugin filters + the filters combinations contained in `macro`
│   ├── version.py
│   └── *.py # Example scripts to use the plugin filters + the filters combinations contained in `macro`
├── test
├── CMakeLists.txt
├── environment*.yml
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ dependencies:
# --------- pip & pip libraries --------- #
- pip
- pip:
- ign-pdal-tools
- ign-pdal-tools==1.7.1
4 changes: 2 additions & 2 deletions environment_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ dependencies:
# --------- pip & pip libraries --------- #
- pip
- pip:
- ign-pdal-tools
- ign-pdal-tools==1.7.1

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import argparse
import shutil
import tempfile

import pdal
from pdaltools.las_remove_dimensions import remove_dimensions_from_las

from pdal_ign_macro import macro

Expand Down Expand Up @@ -39,23 +42,22 @@ def parse_args():
parser.add_argument(
"--output_dtm", "-t", type=str, required=False, default="", help="Output dtm tiff file"
)
parser.add_argument(
"--keep_temporary_dims",
"-k",
action="store_true",
help="If set, do not delete temporary dimensions",
)
return parser.parse_args()


def mark_points_to_use_for_digital_models_with_new_dimension(
input_las, output_las, dsm_dimension, dtm_dimension, output_dsm, output_dtm
):
def define_marking_pipeline(input_las, output_las, dsm_dimension, dtm_dimension):
pipeline = pdal.Pipeline() | pdal.Reader.las(input_las)

# 0 - ajout de dimensions temporaires et de sortie
added_dimensions = [
dtm_dimension,
dsm_dimension,
"PT_VEG_DSM",
"PT_ON_BRIDGE",
"PT_ON_BUILDING",
"PT_ON_VEGET",
]
temporary_dimensions = ["PT_VEG_DSM", "PT_ON_BRIDGE", "PT_ON_BUILDING", "PT_ON_VEGET"]
added_dimensions = [dtm_dimension, dsm_dimension] + temporary_dimensions

pipeline |= pdal.Filter.ferry(dimensions="=>" + ", =>".join(added_dimensions))

# 1 - recherche des points max de végétation (4,5) sur une grille régulière, avec prise en
Expand Down Expand Up @@ -220,29 +222,53 @@ def mark_points_to_use_for_digital_models_with_new_dimension(
)
# ERREUR EN 4!###############################################################################################!
# 5 - export du nuage et des DSM
# TODO: n'ajouter que les dimensions de sortie utiles !

pipeline |= pdal.Writer.las(extra_dims="all", forward="all", filename=output_las)

if output_dtm:
pipeline |= pdal.Writer.gdal(
gdaldriver="GTiff",
output_type="max",
resolution=0.5,
filename=output_dtm,
where=f"{dtm_dimension}==1",
)
return pipeline, temporary_dimensions

if output_dsm:
pipeline |= pdal.Writer.gdal(
gdaldriver="GTiff",
output_type="max",
resolution=0.5,
filename=output_dsm,
where=f"{dsm_dimension}==1",

def 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=False,
):
with tempfile.NamedTemporaryFile(suffix="_with_buffer.las", dir=".") as tmp_las:
pipeline, temporary_dimensions = define_marking_pipeline(
input_las,
tmp_las.name,
dsm_dimension,
dtm_dimension,
)

pipeline.execute()
if output_dtm:
pipeline |= pdal.Writer.gdal(
gdaldriver="GTiff",
output_type="max",
resolution=0.5,
filename=output_dtm,
where=f"{dtm_dimension}==1",
)

if output_dsm:
pipeline |= pdal.Writer.gdal(
gdaldriver="GTiff",
output_type="max",
resolution=0.5,
filename=output_dsm,
where=f"{dsm_dimension}==1",
)

pipeline.execute()

if keep_temporary_dimensions:
shutil.copy(tmp_las.name, output_las)
else:
remove_dimensions_from_las(tmp_las.name, temporary_dimensions, output_las)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
)


def test_main():
def test_mark_points_to_use_for_digital_models_with_new_dimension():
ini_las = "test/data/4_6.las"
dsm_dimension = "dsm_marker"
dtm_dimension = "dtm_marker"
Expand All @@ -18,8 +18,16 @@ def test_main():
)
pipeline = pdal.Pipeline()
pipeline |= pdal.Reader.las(las_output.name)
assert dsm_dimension in pipeline.quickinfo["readers.las"]["dimensions"].split(", ")
assert dtm_dimension in pipeline.quickinfo["readers.las"]["dimensions"].split(", ")
output_dimensions = 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
for dim in ["PT_VEG_DSM", "PT_ON_BRIDGE", "PT_ON_BUILDING", "PT_ON_VEGET"]
]
)

pipeline.execute()
arr = pipeline.arrays[0]
Expand Down

0 comments on commit 92c07f6

Please sign in to comment.