diff --git a/CHANGELOG.md b/CHANGELOG.md index 86b43c2..cc650a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +- Add possibility to select extra dimensions to keep in standardization + # 1.7.1 Same as 1.7.0 (new tag needed to publish on pypi due to incorrect package handling) diff --git a/pdaltools/standardize_format.py b/pdaltools/standardize_format.py index b972d93..26324a6 100644 --- a/pdaltools/standardize_format.py +++ b/pdaltools/standardize_format.py @@ -7,6 +7,7 @@ - precision - no extra-dims """ + import argparse import os import subprocess as sp @@ -42,6 +43,14 @@ def parse_args(): "--record_format", choices=[6, 8], type=int, help="Record format: 6 (no color) or 8 (4 color channels)" ) parser.add_argument("--projection", default="EPSG:2154", type=str, help="Projection, eg. EPSG:2154") + parser.add_argument( + "--extra_dims", + default=[], + nargs="*", + type=str, + help="List of extra dims to keep in the output (default=[], use 'all' to keep all extra dims), " + "extra_dims must be specified with their type (see pdal.writers.las documentation, eg 'dim1=double')", + ) return parser.parse_args() @@ -86,5 +95,5 @@ def standardize(input_file: str, output_file: str, params_from_parser: Dict) -> if __name__ == "__main__": args = parse_args() - params_from_parser = dict(dataformat_id=args.record_format, a_srs=args.projection) + params_from_parser = dict(dataformat_id=args.record_format, a_srs=args.projection, extra_dims=args.extra_dims) standardize(args.input_file, args.output_file, params_from_parser) diff --git a/test/data/test_data_77055_627755_LA93_IGN69_extra_dims.laz b/test/data/test_data_77055_627755_LA93_IGN69_extra_dims.laz new file mode 100644 index 0000000..38bb93c Binary files /dev/null and b/test/data/test_data_77055_627755_LA93_IGN69_extra_dims.laz differ diff --git a/test/test_standardize_format.py b/test/test_standardize_format.py index 3c4196f..f96e2f3 100644 --- a/test/test_standardize_format.py +++ b/test/test_standardize_format.py @@ -14,8 +14,10 @@ INPUT_DIR = os.path.join(TEST_PATH, "data") MUTLIPLE_PARAMS = [ - {"dataformat_id": 6, "a_srs": "EPSG:2154"}, - {"dataformat_id": 8, "a_srs": "EPSG:4326"}, + {"dataformat_id": 6, "a_srs": "EPSG:2154", "extra_dims": []}, + {"dataformat_id": 8, "a_srs": "EPSG:4326", "extra_dims": []}, + {"dataformat_id": 8, "a_srs": "EPSG:2154", "extra_dims": ["dtm_marker=double", "dsm_marker=double"]}, + {"dataformat_id": 8, "a_srs": "EPSG:2154", "extra_dims": "all"}, ] @@ -46,14 +48,18 @@ def _test_standardize_format_one_params_set(input_file, output_file, params): assert metadata["dataformat_id"] == params["dataformat_id"] # Check that there is no extra dim dimensions = set([d.strip() for d in json_info["summary"]["dimensions"].split(",")]) - assert dimensions == EXPECTED_DIMS_BY_DATAFORMAT[params["dataformat_id"]] + if params["extra_dims"] == "all": + assert EXPECTED_DIMS_BY_DATAFORMAT[params["dataformat_id"]].issubset(dimensions) + else: + extra_dims_names = [dim.split("=")[0] for dim in params["extra_dims"]] + assert dimensions == EXPECTED_DIMS_BY_DATAFORMAT[params["dataformat_id"]].union(extra_dims_names) # TODO: Check srs # TODO: check precision def test_standardize_format(): - input_file = os.path.join(INPUT_DIR, "test_data_77055_627760_LA93_IGN69.laz") + input_file = os.path.join(INPUT_DIR, "test_data_77055_627755_LA93_IGN69_extra_dims.laz") output_file = os.path.join(TMP_PATH, "formatted.laz") for params in MUTLIPLE_PARAMS: _test_standardize_format_one_params_set(input_file, output_file, params)