ign-pdal-tools 1.7.3__py3-none-any.whl → 1.7.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ign_pdal_tools-1.7.3.dist-info → ign_pdal_tools-1.7.5.dist-info}/METADATA +6 -1
- ign_pdal_tools-1.7.5.dist-info/RECORD +17 -0
- {ign_pdal_tools-1.7.3.dist-info → ign_pdal_tools-1.7.5.dist-info}/WHEEL +1 -1
- pdaltools/_version.py +1 -1
- pdaltools/add_points_in_las.py +104 -0
- pdaltools/color.py +13 -9
- pdaltools/las_info.py +27 -1
- pdaltools/las_remove_dimensions.py +2 -2
- pdaltools/pcd_info.py +48 -18
- pdaltools/standardize_format.py +31 -11
- ign_pdal_tools-1.7.3.dist-info/RECORD +0 -16
- {ign_pdal_tools-1.7.3.dist-info → ign_pdal_tools-1.7.5.dist-info}/LICENSE.md +0 -0
- {ign_pdal_tools-1.7.3.dist-info → ign_pdal_tools-1.7.5.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ign-pdal-tools
|
|
3
|
-
Version: 1.7.
|
|
3
|
+
Version: 1.7.5
|
|
4
4
|
Summary: Library for common LAS files manipulation with PDAL
|
|
5
5
|
Author-email: Guillaume Liegard <guillaume.liegard@ign.fr>
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -87,6 +87,11 @@ By default, `xcoord` and `ycoord` are given in kilometers and the shape of the t
|
|
|
87
87
|
`readers.las: Global encoding WKT flag not set for point format 6 - 10.` which is due to TerraSolid
|
|
88
88
|
malformed LAS output for LAS1.4 files with point format 6 to 10.
|
|
89
89
|
|
|
90
|
+
## Add points in Las
|
|
91
|
+
|
|
92
|
+
[add_points_in_las.py](pdaltools/add_points_in_las.py): add points from some vector files (ex: shp, geojson, ...) inside Las. New points will have X,Y and Z coordinates. Other attributes values given by the initial las file are null (ex: classification at 0). These others attributes could be forced by using the '--dimensions/-d' option in the command line (ex : 'add_points_in_las.py -i myLas.las -g myPoints.json -d classification=64' - points will have their classification set to 64). The dimension should be present in the initial las ; this is not allowed to add new dimension.
|
|
93
|
+
|
|
94
|
+
|
|
90
95
|
# Dev / Build
|
|
91
96
|
|
|
92
97
|
## Contribute
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
pdaltools/_version.py,sha256=Jr3d2rnNzq-ZLSjZiEMdSSozTrU6AhKJLKOvXK3-0H0,74
|
|
2
|
+
pdaltools/add_points_in_las.py,sha256=TGbt5JUkszjmbQiA2LCUntsjz6A8DHb7QPIXGDuEgWA,3643
|
|
3
|
+
pdaltools/color.py,sha256=PSdtMMdsapOtgzojdnaKVx6IxbKOaN2xP9mScAbCGm0,8629
|
|
4
|
+
pdaltools/las_add_buffer.py,sha256=sBpTywlfsHHS8KuCUa-eydB2hylshEvjrMQt5TrqXb8,11275
|
|
5
|
+
pdaltools/las_clip.py,sha256=GvEOYu8RXV68e35kU8i42GwSkbo4P9TvmS6rkrdPmFM,1034
|
|
6
|
+
pdaltools/las_info.py,sha256=cVVsOrtwgyOpI093PuXNhs2N7BJIdfW0BgxxRb-XqyQ,8096
|
|
7
|
+
pdaltools/las_merge.py,sha256=tcFVueV9X9nNEaoAl5zCduY5DETlBg63MAgP2SuKiNo,4121
|
|
8
|
+
pdaltools/las_remove_dimensions.py,sha256=u_3VfkabkN_Y3eDLdJwCLVGpondvIx0f0v0RdFDoAFw,1792
|
|
9
|
+
pdaltools/pcd_info.py,sha256=NIAH5KGikVDQLlbCcw9FuaPqe20UZvRfkHsDZd5kmZA,3210
|
|
10
|
+
pdaltools/replace_attribute_in_las.py,sha256=po1F-fi8s7iilqKWaryW4JRbsmdMOUe0yGvG3AEKxtk,4771
|
|
11
|
+
pdaltools/standardize_format.py,sha256=gqm2GJbtDkT4k4oC_NX2LIPh9R2BLh4sMHLKYgfKrMc,3973
|
|
12
|
+
pdaltools/unlock_file.py,sha256=pIThdWMNkTph0xgJVVRaM1o9aUMQhM6804PscScB3JI,1963
|
|
13
|
+
ign_pdal_tools-1.7.5.dist-info/LICENSE.md,sha256=iVzCFZTUXeiqP8bP474iuWZiWO_kDCD4SPh1Wiw125Y,1120
|
|
14
|
+
ign_pdal_tools-1.7.5.dist-info/METADATA,sha256=EqDhgZ2NEpoOr7Whk2RefX9emt_M05l7MGotTplcgkE,5722
|
|
15
|
+
ign_pdal_tools-1.7.5.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
16
|
+
ign_pdal_tools-1.7.5.dist-info/top_level.txt,sha256=KvGW0ZzqQbhCKzB5_Tp_buWMZyIgiO2M2krWF_ecOZc,10
|
|
17
|
+
ign_pdal_tools-1.7.5.dist-info/RECORD,,
|
pdaltools/_version.py
CHANGED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
|
|
3
|
+
import geopandas
|
|
4
|
+
import numpy as np
|
|
5
|
+
import pdal
|
|
6
|
+
|
|
7
|
+
from pdaltools.las_info import get_writer_parameters_from_reader_metadata, las_info_metadata, get_bounds_from_header_info
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def extract_points_from_geo(input_geo: str):
|
|
11
|
+
file = open(input_geo)
|
|
12
|
+
df = geopandas.read_file(file)
|
|
13
|
+
return df.get_coordinates(ignore_index=True, include_z=True)
|
|
14
|
+
|
|
15
|
+
def point_in_bound(bound_minx, bound_maxx, bound_miny, bound_maxy, pt_x, pt_y):
|
|
16
|
+
return pt_x >= bound_minx and pt_x <= bound_maxx and pt_y >= bound_miny and pt_y <= bound_maxy
|
|
17
|
+
|
|
18
|
+
def add_points_in_las(input_las: str, input_geo: str, output_las: str, inside_las: bool, values_dimensions: {}):
|
|
19
|
+
points_geo = extract_points_from_geo(input_geo)
|
|
20
|
+
pipeline = pdal.Pipeline() | pdal.Reader.las(input_las)
|
|
21
|
+
pipeline.execute()
|
|
22
|
+
points_las = pipeline.arrays[0]
|
|
23
|
+
dimensions = list(points_las.dtype.fields.keys())
|
|
24
|
+
|
|
25
|
+
if inside_las:
|
|
26
|
+
mtd = las_info_metadata(input_las)
|
|
27
|
+
bound_minx, bound_maxx, bound_miny, bound_maxy = get_bounds_from_header_info(mtd)
|
|
28
|
+
|
|
29
|
+
for i in points_geo.index:
|
|
30
|
+
if inside_las :
|
|
31
|
+
if not point_in_bound(bound_minx, bound_maxx, bound_miny, bound_maxy, points_geo["x"][i], points_geo["y"][i]):
|
|
32
|
+
continue
|
|
33
|
+
pt_las = np.empty(1, dtype=points_las.dtype)
|
|
34
|
+
pt_las[0][dimensions.index("X")] = points_geo["x"][i]
|
|
35
|
+
pt_las[0][dimensions.index("Y")] = points_geo["y"][i]
|
|
36
|
+
pt_las[0][dimensions.index("Z")] = points_geo["z"][i]
|
|
37
|
+
for val in values_dimensions:
|
|
38
|
+
pt_las[0][dimensions.index(val)] = values_dimensions[val]
|
|
39
|
+
points_las = np.append(points_las, pt_las, axis=0)
|
|
40
|
+
|
|
41
|
+
params = get_writer_parameters_from_reader_metadata(pipeline.metadata)
|
|
42
|
+
pipeline_end = pdal.Pipeline(arrays=[points_las])
|
|
43
|
+
pipeline_end |= pdal.Writer.las(output_las, forward="all", **params)
|
|
44
|
+
pipeline_end.execute()
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def parse_args():
|
|
48
|
+
parser = argparse.ArgumentParser("Add points from geometry file in a las/laz file.")
|
|
49
|
+
parser.add_argument("--input_file", "-i", type=str, help="Las/Laz input file")
|
|
50
|
+
parser.add_argument("--output_file", "-o", type=str, help="Las/Laz output file.")
|
|
51
|
+
parser.add_argument("--input_geo_file", "-g", type=str, help="Geometry input file.")
|
|
52
|
+
parser.add_argument("--inside_las", "-l", type=str, help="Keep points only inside the las boundary.")
|
|
53
|
+
parser.add_argument(
|
|
54
|
+
"--dimensions",
|
|
55
|
+
"-d",
|
|
56
|
+
metavar="KEY=VALUE",
|
|
57
|
+
nargs="+",
|
|
58
|
+
help="Set a number of key-value pairs corresponding to value "
|
|
59
|
+
"needed in points added in the output las; key should be included in the input las.",
|
|
60
|
+
)
|
|
61
|
+
return parser.parse_args()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def is_nature(value, nature):
|
|
65
|
+
if value is None:
|
|
66
|
+
return False
|
|
67
|
+
try:
|
|
68
|
+
nature(value)
|
|
69
|
+
return True
|
|
70
|
+
except:
|
|
71
|
+
return False
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def parse_var(s):
|
|
75
|
+
items = s.split("=")
|
|
76
|
+
key = items[0].strip()
|
|
77
|
+
if len(items) > 1:
|
|
78
|
+
value = "=".join(items[1:])
|
|
79
|
+
if is_nature(value, int):
|
|
80
|
+
value = int(value)
|
|
81
|
+
elif is_nature(value, float):
|
|
82
|
+
value = float(value)
|
|
83
|
+
return (key, value)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def parse_vars(items):
|
|
87
|
+
d = {}
|
|
88
|
+
if items:
|
|
89
|
+
for item in items:
|
|
90
|
+
key, value = parse_var(item)
|
|
91
|
+
d[key] = value
|
|
92
|
+
return d
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if __name__ == "__main__":
|
|
96
|
+
args = parse_args()
|
|
97
|
+
added_dimensions = parse_vars(args.dimensions)
|
|
98
|
+
add_points_in_las(
|
|
99
|
+
input_las=args.input_file,
|
|
100
|
+
input_geo=args.input_geo_file,
|
|
101
|
+
output_las=args.input_file if args.output_file is None else args.output_file,
|
|
102
|
+
inside_las=args.inside_las,
|
|
103
|
+
values_dimensions=added_dimensions,
|
|
104
|
+
)
|
pdaltools/color.py
CHANGED
|
@@ -69,11 +69,11 @@ def is_image_white(filename: str):
|
|
|
69
69
|
def download_image_from_geoplateforme(
|
|
70
70
|
proj, layer, minx, miny, maxx, maxy, pixel_per_meter, outfile, timeout, check_images
|
|
71
71
|
):
|
|
72
|
-
#
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
# Force a 1-pixel margin in the east and south borders
|
|
73
|
+
# to make sure that no point of the pointcloud is on the limit of the last pixel
|
|
74
|
+
# to prevent interpolation issues
|
|
75
|
+
maxx = maxx + 1 / pixel_per_meter
|
|
76
|
+
miny = miny - 1 / pixel_per_meter
|
|
77
77
|
|
|
78
78
|
# for layer in layers:
|
|
79
79
|
URL_GPP = "https://data.geopf.fr/wms-r/wms?"
|
|
@@ -136,22 +136,26 @@ def color(
|
|
|
136
136
|
|
|
137
137
|
tmp_ortho = None
|
|
138
138
|
if color_rvb_enabled:
|
|
139
|
-
tmp_ortho = tempfile.NamedTemporaryFile()
|
|
139
|
+
tmp_ortho = tempfile.NamedTemporaryFile(suffix="_rvb.tif")
|
|
140
140
|
download_image_from_geoplateforme_retrying(
|
|
141
141
|
proj, stream_RGB, minx, miny, maxx, maxy, pixel_per_meter, tmp_ortho.name, timeout_second, check_images
|
|
142
142
|
)
|
|
143
|
-
|
|
143
|
+
# Warning: the initial color is multiplied by 256 despite its initial 8-bits encoding
|
|
144
|
+
# which turns it to a 0 to 255*256 range.
|
|
145
|
+
# It is kept this way because of other dependencies that have been tuned to fit this range
|
|
144
146
|
pipeline |= pdal.Filter.colorization(
|
|
145
147
|
raster=tmp_ortho.name, dimensions="Red:1:256.0, Green:2:256.0, Blue:3:256.0"
|
|
146
148
|
)
|
|
147
149
|
|
|
148
150
|
tmp_ortho_irc = None
|
|
149
151
|
if color_ir_enabled:
|
|
150
|
-
tmp_ortho_irc = tempfile.NamedTemporaryFile()
|
|
152
|
+
tmp_ortho_irc = tempfile.NamedTemporaryFile(suffix="_irc.tif")
|
|
151
153
|
download_image_from_geoplateforme_retrying(
|
|
152
154
|
proj, stream_IRC, minx, miny, maxx, maxy, pixel_per_meter, tmp_ortho_irc.name, timeout_second, check_images
|
|
153
155
|
)
|
|
154
|
-
|
|
156
|
+
# Warning: the initial color is multiplied by 256 despite its initial 8-bits encoding
|
|
157
|
+
# which turns it to a 0 to 255*256 range.
|
|
158
|
+
# It is kept this way because of other dependencies that have been tuned to fit this range
|
|
155
159
|
pipeline |= pdal.Filter.colorization(raster=tmp_ortho_irc.name, dimensions="Infrared:1:256.0")
|
|
156
160
|
|
|
157
161
|
pipeline |= pdal.Writer.las(
|
pdaltools/las_info.py
CHANGED
|
@@ -6,6 +6,8 @@ from typing import Dict, Tuple
|
|
|
6
6
|
import osgeo.osr as osr
|
|
7
7
|
import pdal
|
|
8
8
|
|
|
9
|
+
from pdaltools.pcd_info import infer_tile_origin
|
|
10
|
+
|
|
9
11
|
osr.UseExceptions()
|
|
10
12
|
|
|
11
13
|
|
|
@@ -17,13 +19,37 @@ def las_info_metadata(filename: str):
|
|
|
17
19
|
return metadata
|
|
18
20
|
|
|
19
21
|
|
|
20
|
-
def get_bounds_from_header_info(metadata):
|
|
22
|
+
def get_bounds_from_header_info(metadata: Dict) -> Tuple[float, float, float, float]:
|
|
23
|
+
"""Get bounds from metadata that has been extracted previously from the header of a las file
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
metadata (str): Dictonary containing metadata from a las file (as extracted with pipeline.quickinfo)
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
Tuple[float, float, float, float]: minx, maxx, miny, maxy
|
|
30
|
+
"""
|
|
21
31
|
bounds = metadata["bounds"]
|
|
22
32
|
minx, maxx, miny, maxy = bounds["minx"], bounds["maxx"], bounds["miny"], bounds["maxy"]
|
|
23
33
|
|
|
24
34
|
return minx, maxx, miny, maxy
|
|
25
35
|
|
|
26
36
|
|
|
37
|
+
def get_tile_origin_using_header_info(filename: str, tile_width: int = 1000) -> Tuple[int, int]:
|
|
38
|
+
""" "Get las file theoretical origin (xmin, ymax) for a data that originates from a square tesselation/tiling
|
|
39
|
+
using the tesselation tile width only, directly from its path
|
|
40
|
+
Args:
|
|
41
|
+
filename (str): path to the las file
|
|
42
|
+
tile_width (int, optional): Tesselation tile width (in meters). Defaults to 1000.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
Tuple[int, int]: (origin_x, origin_y) tile origin coordinates = theoretical (xmin, ymax)
|
|
46
|
+
"""
|
|
47
|
+
metadata = las_info_metadata(filename)
|
|
48
|
+
minx, maxx, miny, maxy = get_bounds_from_header_info(metadata)
|
|
49
|
+
|
|
50
|
+
return infer_tile_origin(minx, maxx, miny, maxy, tile_width)
|
|
51
|
+
|
|
52
|
+
|
|
27
53
|
def get_epsg_from_header_info(metadata):
|
|
28
54
|
if "srs" not in metadata.keys():
|
|
29
55
|
raise RuntimeError("EPSG could not be inferred from metadata: No 'srs' key in metadata.")
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import argparse
|
|
2
|
-
import os
|
|
3
2
|
|
|
4
3
|
import pdal
|
|
5
4
|
from pdaltools.las_info import get_writer_parameters_from_reader_metadata
|
|
6
5
|
|
|
6
|
+
|
|
7
7
|
def remove_dimensions_from_las(input_las: str, dimensions: [str], output_las: str):
|
|
8
8
|
"""
|
|
9
9
|
export new las without some dimensions
|
|
@@ -43,7 +43,7 @@ def parse_args():
|
|
|
43
43
|
required=True,
|
|
44
44
|
nargs="+",
|
|
45
45
|
help="The dimension we would like to remove from the point cloud file ; be aware to not remove mandatory "
|
|
46
|
-
|
|
46
|
+
"dimensions of las",
|
|
47
47
|
)
|
|
48
48
|
|
|
49
49
|
return parser.parse_args()
|
pdaltools/pcd_info.py
CHANGED
|
@@ -5,14 +5,52 @@ from typing import Tuple
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
def infer_tile_origin(minx: float, maxx: float, miny: float, maxy: float, tile_width: int) -> Tuple[int, int]:
|
|
9
|
+
"""Get point cloud theoretical origin (xmin, ymax) for a data that originates from a square tesselation/tiling
|
|
10
|
+
using the tesselation tile width only, based on the min/max values
|
|
11
|
+
|
|
12
|
+
Edge values are supposed to be included in the tile
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
minx (float): point cloud min x value
|
|
16
|
+
maxx (float): point cloud max x value
|
|
17
|
+
miny (float): point cloud min y value
|
|
18
|
+
maxy (float): point cloud max y value
|
|
19
|
+
tile_width (int): tile width in meters
|
|
20
|
+
|
|
21
|
+
Raises:
|
|
22
|
+
ValueError: In case the min and max values do not belong to the same tile
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
Tuple[int, int]: (origin_x, origin_y) tile origin coordinates = theoretical (xmin, ymax)
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
minx_tile_index = np.floor(minx / tile_width)
|
|
29
|
+
maxx_tile_index = np.floor(maxx / tile_width) if maxx % tile_width != 0 else np.floor(maxx / tile_width) - 1
|
|
30
|
+
miny_tile_index = np.ceil(miny / tile_width) if miny % tile_width != 0 else np.floor(miny / tile_width) + 1
|
|
31
|
+
maxy_tile_index = np.ceil(maxy / tile_width)
|
|
32
|
+
|
|
33
|
+
if maxx_tile_index == minx_tile_index and maxy_tile_index == miny_tile_index:
|
|
34
|
+
origin_x = minx_tile_index * tile_width
|
|
35
|
+
origin_y = maxy_tile_index * tile_width
|
|
36
|
+
return origin_x, origin_y
|
|
37
|
+
else:
|
|
38
|
+
raise ValueError(
|
|
39
|
+
f"Min values (x={minx} and y={miny}) do not belong to the same theoretical tile as"
|
|
40
|
+
f"max values (x={maxx} and y={maxy})."
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
8
44
|
def get_pointcloud_origin_from_tile_width(
|
|
9
45
|
points: np.ndarray, tile_width: int = 1000, buffer_size: float = 0
|
|
10
46
|
) -> Tuple[int, int]:
|
|
11
47
|
"""Get point cloud theoretical origin (xmin, ymax) for a data that originates from a square tesselation/tiling
|
|
12
|
-
using the tesselation tile width only.
|
|
48
|
+
using the tesselation tile width only, based on the point cloud as a np.ndarray
|
|
13
49
|
|
|
14
50
|
Edge values are supposed to be included in the tile
|
|
15
51
|
|
|
52
|
+
In case buffer_size is provided, the origin will be calculated on an "original" tile, supposing that
|
|
53
|
+
there has been a buffer added to the input tile.
|
|
16
54
|
|
|
17
55
|
Args:
|
|
18
56
|
points (np.ndarray): numpy array with the tile points
|
|
@@ -20,27 +58,19 @@ def get_pointcloud_origin_from_tile_width(
|
|
|
20
58
|
buffer_size (float, optional): Optional buffer around the tile. Defaults to 0.
|
|
21
59
|
|
|
22
60
|
Raises:
|
|
23
|
-
ValueError: Raise an error when the
|
|
61
|
+
ValueError: Raise an error when the initial tile is smaller than the buffer (in this case, we cannot find the
|
|
62
|
+
origin (it can be either in the buffer or in the tile))
|
|
24
63
|
|
|
25
64
|
Returns:
|
|
26
65
|
Tuple[int, int]: (origin_x, origin_y) origin coordinates
|
|
27
66
|
"""
|
|
28
67
|
# Extract coordinates xmin, xmax, ymin and ymax of the original tile without buffer
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
tile_x_min = np.floor(x_min / tile_width)
|
|
34
|
-
tile_x_max = np.floor(x_max / tile_width) if x_max % tile_width != 0 else np.floor(x_max / tile_width) - 1
|
|
35
|
-
tile_y_min = np.ceil(y_min / tile_width) if y_min % tile_width != 0 else np.floor(y_min / tile_width) + 1
|
|
36
|
-
tile_y_max = np.ceil(y_max / tile_width)
|
|
37
|
-
|
|
38
|
-
if not (tile_x_max - tile_x_min) and not (tile_y_max - tile_y_min):
|
|
39
|
-
origin_x = tile_x_min * tile_width
|
|
40
|
-
origin_y = tile_y_max * tile_width
|
|
41
|
-
return origin_x, origin_y
|
|
42
|
-
else:
|
|
68
|
+
minx, miny = np.min(points[:, :2], axis=0) + buffer_size
|
|
69
|
+
maxx, maxy = np.max(points[:, :2], axis=0) - buffer_size
|
|
70
|
+
|
|
71
|
+
if maxx < minx or maxy < miny:
|
|
43
72
|
raise ValueError(
|
|
44
|
-
|
|
45
|
-
f"max values (x={x_max} and y={y_max})."
|
|
73
|
+
"Cannot find pointcloud origin as the pointcloud width or height is smaller than buffer width"
|
|
46
74
|
)
|
|
75
|
+
|
|
76
|
+
return infer_tile_origin(minx, maxx, miny, maxy, tile_width)
|
pdaltools/standardize_format.py
CHANGED
|
@@ -10,14 +10,16 @@
|
|
|
10
10
|
|
|
11
11
|
import argparse
|
|
12
12
|
import os
|
|
13
|
+
import platform
|
|
13
14
|
import subprocess as sp
|
|
14
15
|
import tempfile
|
|
15
|
-
from typing import Dict
|
|
16
|
+
from typing import Dict, List
|
|
16
17
|
|
|
17
18
|
import pdal
|
|
18
19
|
|
|
19
20
|
from pdaltools.unlock_file import copy_and_hack_decorator
|
|
20
21
|
|
|
22
|
+
# Standard parameters to pass to the pdal writer
|
|
21
23
|
STANDARD_PARAMETERS = dict(
|
|
22
24
|
major_version="1",
|
|
23
25
|
minor_version="4", # Laz format version (pdal always write in 1.x format)
|
|
@@ -43,6 +45,13 @@ def parse_args():
|
|
|
43
45
|
"--record_format", choices=[6, 8], type=int, help="Record format: 6 (no color) or 8 (4 color channels)"
|
|
44
46
|
)
|
|
45
47
|
parser.add_argument("--projection", default="EPSG:2154", type=str, help="Projection, eg. EPSG:2154")
|
|
48
|
+
parser.add_argument(
|
|
49
|
+
"--class_points_removed",
|
|
50
|
+
default=[],
|
|
51
|
+
nargs="*",
|
|
52
|
+
type=str,
|
|
53
|
+
help="List of classes number. Points of this classes will be removed from the file",
|
|
54
|
+
)
|
|
46
55
|
parser.add_argument(
|
|
47
56
|
"--extra_dims",
|
|
48
57
|
default=[],
|
|
@@ -51,7 +60,6 @@ def parse_args():
|
|
|
51
60
|
help="List of extra dims to keep in the output (default=[], use 'all' to keep all extra dims), "
|
|
52
61
|
"extra_dims must be specified with their type (see pdal.writers.las documentation, eg 'dim1=double')",
|
|
53
62
|
)
|
|
54
|
-
|
|
55
63
|
return parser.parse_args()
|
|
56
64
|
|
|
57
65
|
|
|
@@ -61,20 +69,28 @@ def get_writer_parameters(new_parameters: Dict) -> Dict:
|
|
|
61
69
|
override the standard ones
|
|
62
70
|
"""
|
|
63
71
|
params = STANDARD_PARAMETERS | new_parameters
|
|
64
|
-
|
|
65
72
|
return params
|
|
66
73
|
|
|
67
74
|
|
|
68
|
-
def rewrite_with_pdal(
|
|
69
|
-
|
|
75
|
+
def rewrite_with_pdal(
|
|
76
|
+
input_file: str, output_file: str, params_from_parser: Dict, classes_to_remove: List = []
|
|
77
|
+
) -> None:
|
|
70
78
|
params = get_writer_parameters(params_from_parser)
|
|
71
|
-
pipeline = pdal.
|
|
79
|
+
pipeline = pdal.Pipeline()
|
|
80
|
+
pipeline |= pdal.Reader.las(input_file)
|
|
81
|
+
if classes_to_remove:
|
|
82
|
+
expression = "&&".join([f"Classification != {c}" for c in classes_to_remove])
|
|
83
|
+
pipeline |= pdal.Filter.expression(expression=expression)
|
|
72
84
|
pipeline |= pdal.Writer(filename=output_file, forward="all", **params)
|
|
73
85
|
pipeline.execute()
|
|
74
86
|
|
|
75
87
|
|
|
76
88
|
def exec_las2las(input_file: str, output_file: str):
|
|
77
|
-
|
|
89
|
+
if platform.processor() == "arm" and platform.architecture()[0] == "64bit":
|
|
90
|
+
las2las = "las2las64"
|
|
91
|
+
else:
|
|
92
|
+
las2las = "las2las"
|
|
93
|
+
r = sp.run([las2las, "-i", input_file, "-o", output_file], stderr=sp.PIPE, stdout=sp.PIPE)
|
|
78
94
|
if r.returncode == 1:
|
|
79
95
|
msg = r.stderr.decode()
|
|
80
96
|
print(msg)
|
|
@@ -86,14 +102,18 @@ def exec_las2las(input_file: str, output_file: str):
|
|
|
86
102
|
|
|
87
103
|
|
|
88
104
|
@copy_and_hack_decorator
|
|
89
|
-
def standardize(input_file: str, output_file: str, params_from_parser: Dict) -> None:
|
|
105
|
+
def standardize(input_file: str, output_file: str, params_from_parser: Dict, class_points_removed: []) -> None:
|
|
90
106
|
filename = os.path.basename(output_file)
|
|
91
107
|
with tempfile.NamedTemporaryFile(suffix=filename) as tmp:
|
|
92
|
-
rewrite_with_pdal(input_file, tmp.name, params_from_parser)
|
|
108
|
+
rewrite_with_pdal(input_file, tmp.name, params_from_parser, class_points_removed)
|
|
93
109
|
exec_las2las(tmp.name, output_file)
|
|
94
110
|
|
|
95
111
|
|
|
96
112
|
if __name__ == "__main__":
|
|
97
113
|
args = parse_args()
|
|
98
|
-
params_from_parser = dict(
|
|
99
|
-
|
|
114
|
+
params_from_parser = dict(
|
|
115
|
+
dataformat_id=args.record_format,
|
|
116
|
+
a_srs=args.projection,
|
|
117
|
+
extra_dims=args.extra_dims,
|
|
118
|
+
)
|
|
119
|
+
standardize(args.input_file, args.output_file, params_from_parser, args.class_points_removed)
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
pdaltools/_version.py,sha256=CIj6_M9SXht6CUH70oDuQQl4_AP2fggn-8tFZbGL0AY,74
|
|
2
|
-
pdaltools/color.py,sha256=7U-SThIKqrfE1xXXnFqpbIhmZEqna29nRiyLW8l8Y1c,8075
|
|
3
|
-
pdaltools/las_add_buffer.py,sha256=sBpTywlfsHHS8KuCUa-eydB2hylshEvjrMQt5TrqXb8,11275
|
|
4
|
-
pdaltools/las_clip.py,sha256=GvEOYu8RXV68e35kU8i42GwSkbo4P9TvmS6rkrdPmFM,1034
|
|
5
|
-
pdaltools/las_info.py,sha256=RE-UBdEUXqKvSrMV3mOlvE_16mhum7bw-p-ERu5bGOc,6979
|
|
6
|
-
pdaltools/las_merge.py,sha256=tcFVueV9X9nNEaoAl5zCduY5DETlBg63MAgP2SuKiNo,4121
|
|
7
|
-
pdaltools/las_remove_dimensions.py,sha256=0zhv9LBvlL69TLmXTJlRQcUBOaBmCRZEQU2Qadx27aM,1805
|
|
8
|
-
pdaltools/pcd_info.py,sha256=d7ukCEdOFBQqaFp3HYM2MNbKDl1hdxUVHI9vSu9jN-M,1897
|
|
9
|
-
pdaltools/replace_attribute_in_las.py,sha256=po1F-fi8s7iilqKWaryW4JRbsmdMOUe0yGvG3AEKxtk,4771
|
|
10
|
-
pdaltools/standardize_format.py,sha256=lUzrjWY22WfxT_2zLtxuXbmWgiAvjy9o7fBXWsAZmDg,3240
|
|
11
|
-
pdaltools/unlock_file.py,sha256=pIThdWMNkTph0xgJVVRaM1o9aUMQhM6804PscScB3JI,1963
|
|
12
|
-
ign_pdal_tools-1.7.3.dist-info/LICENSE.md,sha256=iVzCFZTUXeiqP8bP474iuWZiWO_kDCD4SPh1Wiw125Y,1120
|
|
13
|
-
ign_pdal_tools-1.7.3.dist-info/METADATA,sha256=PfhYtt73bGGZxehInuRGdzwfhfW_1UxMO7K3CrPlDL0,5112
|
|
14
|
-
ign_pdal_tools-1.7.3.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
|
|
15
|
-
ign_pdal_tools-1.7.3.dist-info/top_level.txt,sha256=KvGW0ZzqQbhCKzB5_Tp_buWMZyIgiO2M2krWF_ecOZc,10
|
|
16
|
-
ign_pdal_tools-1.7.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|