Skip to content

Commit

Permalink
Merge pull request #26 from IGNF/generalize_unlock
Browse files Browse the repository at this point in the history
Generalize copy_and_hack to count_occurences and replace_attribute
  • Loading branch information
leavauchier authored Oct 30, 2023
2 parents bf997a7 + 6f3442c commit a5119c3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# dev
- count_occurences / replace_value: add copy_and_hack decorator to run on tscan output files

# 1.3.1
- fix color: ensure that tmp orthoimages are deleted after use by using the namedTemporaryFile properly.
Expand Down
3 changes: 3 additions & 0 deletions pdaltools/count_occurences/count_occurences_for_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from tqdm import tqdm
from typing import List

from pdaltools.unlock_file import copy_and_hack_decorator


def parse_args():
parser = argparse.ArgumentParser("Count points with each value of an attribute.")
Expand All @@ -25,6 +27,7 @@ def parse_args():
return parser.parse_args()


@copy_and_hack_decorator
def compute_count_one_file(filepath: str, attribute: str = "Classification") -> Counter:
pipeline = pdal.Reader.las(filepath)
pipeline |= pdal.Filter.stats(dimensions=attribute, count=attribute)
Expand Down
8 changes: 5 additions & 3 deletions pdaltools/replace_attribute_in_las.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import tempfile
from typing import List, Dict

from pdaltools.unlock_file import copy_and_hack_decorator


def parse_args():
parser = argparse.ArgumentParser("Replace values of a given attribute in a las/laz file.")
Expand Down Expand Up @@ -65,6 +67,7 @@ def dict_to_pdal_assign_list(d: Dict, output_attribute: str = "Classification",
return assignment_list


@copy_and_hack_decorator
def replace_values(
input_file: str,
output_file: str,
Expand Down Expand Up @@ -109,9 +112,8 @@ def replace_values_clean(
attribute: str = "Classification",
writer_parameters: Dict = {},
):
_, extension = os.path.splitext(output_file)
with tempfile.NamedTemporaryFile(suffix=extension) as tmp:
tmp.close()
filename = os.path.basename(output_file)
with tempfile.NamedTemporaryFile(suffix=filename) as tmp:
replace_values(input_file, tmp.name, replacement_map, attribute, writer_parameters)
exec_las2las(tmp.name, output_file)

Expand Down
5 changes: 2 additions & 3 deletions pdaltools/standardize_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ def exec_las2las(input_file: str, output_file: str):

@copy_and_hack_decorator
def standardize(input_file: str, output_file: str, params_from_parser: Dict) -> None:
_, extension = os.path.splitext(output_file)
with tempfile.NamedTemporaryFile(suffix=extension) as tmp:
tmp.close()
filename = os.path.basename(output_file)
with tempfile.NamedTemporaryFile(suffix=filename) as tmp:
rewrite_with_pdal(input_file, tmp.name, params_from_parser)
exec_las2las(tmp.name, output_file)

Expand Down

0 comments on commit a5119c3

Please sign in to comment.