Skip to content

Commit

Permalink
add comment to example + try to recode example
Browse files Browse the repository at this point in the history
  • Loading branch information
alavenant committed May 22, 2024
1 parent fef4da0 commit c436a0c
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 22 deletions.
83 changes: 61 additions & 22 deletions macro/ex_filtering_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
def parse_args():
parser = argparse.ArgumentParser("Tool to apply pdal pipelines to modify classification")
parser.add_argument("--input", "-i", type=str, required=True, help="Input las file")
parser.add_argument("--output", "-o", type=str, required=True, help="Output las file")
parser.add_argument("--output_las", "-o", type=str, required=True, help="Output cloud las file")
parser.add_argument("--output_dsm", "-s", type=str, required=True, help="Output dsm tiff file")
parser.add_argument("--output_dtm", "-t", type=str, required=True, help="Output dtm tiff file")
return parser.parse_args()


Expand All @@ -18,38 +20,75 @@ def parse_args():

pipeline = pdal.Reader.las(args.input)

# step 1 a 9
pipeline = macro.add_radius_assign(pipeline, 1, False, "Classification==2", macro.build_condition("Classification", [4,5]), "Classification=102")
pipeline = macro.add_radius_assign(pipeline, 1, False, "Classification==102", "Classification==2", "Classification=2")
pipeline = macro.add_radius_assign(pipeline, 1, False, "Classification==3", "Classification==5", "Classification=103")
## 1 - recherche des points max de végétation (4,5) sur une grille régulière, avec prise en compte des points sol (2) et basse
## vegetation (3) proche de la végétation : on les affecte en 100

# bouche trou : assigne les points sol en 102 à l'intérieur de la veget (4,5)
pipeline = macro.add_radius_assign(pipeline, 1, False, condition_src="Classification==2", condition_ref=macro.build_condition("Classification", [4,5]), condition_out="Classification=102")
pipeline = macro.add_radius_assign(pipeline, 1, False, condition_src="Classification==102", condition_ref="Classification==2", condition_out="Classification=2")

# selection des points de veget basse proche de la veget haute : assigne 103
pipeline = macro.add_radius_assign(pipeline, 1, False, condition_src="Classification==3", condition_ref="Classification==5", condition_out="Classification=103")

# max des points de veget (et surement veget - 102,103) sur une grille régulière : assigne 100
pipeline |= pdal.Filter.gridDecimation(resolution=0.75, value="Classification=100", output_type="max", where=macro.build_condition("Classification", [4,5,102,103]))

# remise à zero des codes 102 et 103
pipeline |= pdal.Filter.assign(value="Classification=2", where="Classification==102")
pipeline |= pdal.Filter.assign(value="Classification=3", where="Classification==103")

## 2 - sélection des points pour DTM et DSM

# selection de points DTM (max) sur une grille régulière
pipeline |= pdal.Filter.gridDecimation(resolution=0.5, value="Classification=102", output_type="max", where="Classification==2")

# selection de points DSM (max) sur une grille régulière
pipeline |= pdal.Filter.gridDecimation(resolution=0.5, value="Classification=200", output_type="max", where=macro.build_condition("Classification", [2,3,4,5,6,9,17,64,100]))
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==102", macro.build_condition("Classification", [4,5,6,9,17,64,100]), "Classification=100")

# assigne des points sol sélectionnés (102) en 100 : les points proches de la végaétation, des ponts, de l'eau et 64
pipeline = macro.add_radius_assign(pipeline, 1.5, False, condition_src="Classification==102",
condition_ref=macro.build_condition("Classification", [4,5,6,9,17,64,100]), condition_out="Classification=100")

# remise à zero du code 102
pipeline |= pdal.Filter.assign(value="Classification=2", where="Classification==102")

# step 10
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==2", "Classification==17", "Classification=102")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==102", macro.build_condition("Classification", [2,3,4,5]), "Classification=2")
## 3 - gestion des ponts



# bouche trou : on élimine les points sol (2) au milieu du pont en les mettant à 102
pipeline = macro.add_radius_assign(pipeline, 1.5, False, condition_src="Classification==2", condition_ref="Classification==17", condition_out="Classification=102")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, condition_src="Classification==102",
condition_ref=macro.build_condition("Classification", [2,3,4,5]), condition_out="Classification=2")

# bouche trou : on élimine les points basse végétation (3) au milieu du pont en les mettant à 103
pipeline = macro.add_radius_assign(pipeline, 1.5, False, condition_src="Classification==3", condition_ref="Classification==17", condition_out="Classification=103")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, condition_src="Classification==103",
condition_ref=macro.build_condition("Classification", [2,3,4,5]), condition_out="Classification=3")

# bouche trou : on élimine les points moyenne végétation (4) au milieu du pont en les mettant à 104
pipeline = macro.add_radius_assign(pipeline, 1.5, False, condition_src="Classification==4", condition_ref="Classification==17", condition_out="Classification=104")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, condition_src="Classification==104",
condition_ref=macro.build_condition("Classification", [2,3,4,5]), condition_out="Classification=4")

# bouche trou : on élimine les points haute végétation (5) au milieu du pont en les mettant à 105
pipeline = macro.add_radius_assign(pipeline, 1.5, False, condition_src="Classification==5", condition_ref="Classification==17", condition_out="Classification=105")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, condition_src="Classification==105",
condition_ref=macro.build_condition("Classification", [2,3,4,5]), condition_out="Classification=5")

# step 11
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==3", "Classification==17", "Classification=103")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==103", macro.build_condition("Classification", [2,3,4,5]), "Classification=3")
# bouche trou : on élimine les points eau (9) au milieu du pont en les mettant à 109
pipeline = macro.add_radius_assign(pipeline, 1.5, False, condition_src="Classification==9", condition_ref="Classification==17", condition_out="Classification=109")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, condition_src="Classification==109",
condition_ref="Classification==9", condition_out="Classification=9")

# step 12
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==4", "Classification==17", "Classification=104")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==104", macro.build_condition("Classification", [2,3,4,5]), "Classification=4")
# step 15 et supression des points ??

# step 13
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==5", "Classification==17", "Classification=105")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==105", macro.build_condition("Classification", [2,3,4,5]), "Classification=5")
# 4 - export du nuage
pipeline |= pdal.Writer.las(extra_dims="all",minor_version=4,dataformat_id=6,filename=args.output_las)

# step 14
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==9", "Classification==17", "Classification=109")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, "Classification==109", "Classification==9", "Classification=9")
# export des DSM/DTM
pipeline |= pdal.Writer.gdal(gdaldriver="GTiff", output_type="max", resolution=2.0, filename=args.output_dtm, where=macro.build_condition("Classification", [2,66]))
pipeline |= pdal.Writer.gdal(gdaldriver="GTiff", output_type="max", resolution=2.0, filename=args.output_dsm, where=macro.build_condition("Classification", [2,3,4,5,5,17,64]))

pipeline |= pdal.Writer.las(extra_dims="all",minor_version=4,dataformat_id=6,filename=args.output)
pipeline.execute()

72 changes: 72 additions & 0 deletions macro/ex_filtering_points2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import argparse
import pdal
import macro

"""
This tool shows how to use functions of macro in a pdal pipeline
"""

def parse_args():
parser = argparse.ArgumentParser("Tool to apply pdal pipelines to modify classification")
parser.add_argument("--input", "-i", type=str, required=True, help="Input las file")
parser.add_argument("--output_las", "-o", type=str, required=True, help="Output cloud las file")
parser.add_argument("--output_dsm", "-s", type=str, required=True, help="Output dsm tiff file")
parser.add_argument("--output_dtm", "-t", type=str, required=True, help="Output dtm tiff file")
return parser.parse_args()


if __name__ == "__main__":
args = parse_args()

pipeline = pdal.Reader.las(args.input)

## 1 - recherche des points max de végétation (4,5) sur une grille régulière, avec prise en compte des points sol (2) et basse
## vegetation (3) proche de la végétation
## pour le calcul du DSM

pipeline |= pdal.Filter.ferry(dimensions=f"=>PT_GRID_DSM, =>PT_DSM, =>PT_GRID_DTM")
pipeline |= pdal.Filter.assign(value=["PT_DSM = 1 WHERE " + macro.build_condition("Classification", [4,5])])

# bouche trou : assigne les points sol à l'intérieur de la veget (4,5)
pipeline = macro.add_radius_assign(pipeline, 1, False, condition_src="Classification==2", condition_ref=macro.build_condition("Classification", [4,5]), condition_out="PT_DSM=1")
pipeline = macro.add_radius_assign(pipeline, 1, False, condition_src="PT_DSM==1 && Classification==2", condition_ref="Classification==2", condition_out="Classification=2")

# selection des points de veget basse proche de la veget haute
pipeline = macro.add_radius_assign(pipeline, 1, False, condition_src="Classification==3", condition_ref="Classification==5", condition_out="PT_DSM=1")

# max des points de veget (et surement veget) sur une grille régulière :
pipeline |= pdal.Filter.gridDecimation(resolution=0.75, value="PT_GRID_DSM=1", output_type="max", where="PT_DSM==1")


## 2 - sélection des points pour DTM et DSM

# selection de points DTM (max) sur une grille régulière
pipeline |= pdal.Filter.gridDecimation(resolution=0.5, value="PT_GRID_DTM=1", output_type="max", where="Classification==2")

# selection de points DSM (max) sur une grille régulière
pipeline |= pdal.Filter.gridDecimation(resolution=0.5, value="PT_GRID_DSM=1", output_type="max", where=macro.build_condition("Classification", [2,3,4,5,6,9,17,64,100]))

# assigne des points sol sélectionnés : les points proches de la végétation, des ponts, de l'eau, 64 et 100
pipeline = macro.add_radius_assign(pipeline, 1.5, False, condition_src="PT_GRID_DTM==1",
condition_ref= "(" + macro.build_condition("Classification", [4,5,6,9,17,64]) + ") && PT_GRID_DSM==1",
condition_out="PT_DSM=1")


## 3 - gestion des ponts
# bouche trou : on filtre les points (2,3,4,5,9) au milieu du pont en les mettant à PT_ON_BRIDGE=1
pipeline |= pdal.Filter.ferry(dimensions=f"=>PT_ON_BRIDGE")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, condition_src=macro.build_condition("Classification", [2,3,4,5,9]), condition_ref="Classification==17", condition_out="PT_ON_BRIDGE=1")
pipeline = macro.add_radius_assign(pipeline, 1.5, False, condition_src="PT_ON_BRIDGE==1",
condition_ref=macro.build_condition("Classification", [2,3,4,5]), condition_out="PT_ON_BRIDGE=0")

# step 15 et supression des points ??

# 4 - export du nuage
pipeline |= pdal.Writer.las(extra_dims="all", minor_version=4, dataformat_id=6, filename=args.output_las)

# export des DSM/DTM
pipeline |= pdal.Writer.gdal(gdaldriver="GTiff", output_type="max", resolution=2.0, filename=args.output_dtm, where=macro.build_condition("Classification", [2,66]))
pipeline |= pdal.Writer.gdal(gdaldriver="GTiff", output_type="max", resolution=2.0, filename=args.output_dsm, where=macro.build_condition("Classification", [2,3,4,5,5,17,64]))

pipeline.execute()

0 comments on commit c436a0c

Please sign in to comment.