Skip to content

Commit c187fd4

Browse files
authored
Merge pull request #49 from fugro-oss/ModifyRecords
Flexibly Modify Point Contents
2 parents abefc77 + 9b4b9f9 commit c187fd4

File tree

15 files changed

+384
-138
lines changed

15 files changed

+384
-138
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LASDatasets"
22
uuid = "cc498e2a-d443-4943-8f26-2a8a0f3c7cdb"
33
authors = ["BenCurran98 <[email protected]>"]
4-
version = "0.3.3"
4+
version = "0.4.0"
55

66
[deps]
77
BufferedStreams = "e1450e63-4bb3-523b-b2a4-4ffa8c0fd77d"

docs/src/header.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ You can also modify certain fields in the header, but one should note that for s
3838

3939
```@docs; canonical = false
4040
set_las_version!
41+
set_point_format!
4142
set_spatial_info!
4243
set_point_data_offset!
4344
set_point_record_length!

docs/src/interface.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,47 @@ Alternatively, if you just have the point cloud data as a Table:
7070
using StaticArrays
7171
using TypedTables
7272

73-
pc = Table(position = rand(SVector{3, Float64}, 10), classification = rand(UIn8, 10))
73+
pc = Table(position = rand(SVector{3, Float64}, 10), classification = rand(UInt8, 10))
7474
save_las("my_las.las", pc)
7575
```
7676

7777
Note that when you supply just the point cloud outside of a `LASDataset`, *LASDatasets.jl* will automatically construct the appropriate header for you so you don't need to worry about the specifics of appropriate point formats etc.
7878

7979
## Modifying LAS Contents
80-
You can modify point fields in your `LASDataset` by adding new columns or merging in values from an existing vector.
80+
You can modify point fields in your `LASDataset` by adding new columns or merging in values from an existing vector. Additionally, you can add and remove points from a dataset. When adding points, the user is responsible for correctly setting the appropriate fields (e.g. synthetic flags).
8181

8282
```@docs; canonical = false
8383
add_column!
8484
merge_column!
85+
add_points!
86+
remove_points!
87+
```
88+
89+
For example, if you want to add a set of synthetic points to your dataset, you can run:
90+
```julia
91+
las = load_las("my_las.las")
92+
# note - we need to set a synthetic column here for the existing points before we append points with this field
93+
add_column!(las, :synthetic, falses(number_of_points(las)))
94+
synthetic_points = Table(position = rand(SVector{3, Float64}, 5), classification = rand(UInt8, 5), synthetic = trues(5))
95+
add_points!(las, synthetic_points)
96+
```
97+
98+
You can remove points from your data using the `remove_points!` function and specifying the indices of the points you wish to delete (these will be indexing into the list of points in order). E.g.
99+
```julia
100+
remove_points!(las, 11:15)
101+
```
102+
103+
Note that you can also modify the contents of your points by acting directly on the tabular pointcloud data. **Note:** this should **not** be used to add/remove points or point fields, since this will cause a conflict between the data in your points and the file header. Intended use is for operations that preserve the number of points and the existing fields.
104+
For example:
105+
106+
```julia
107+
pc = get_pointcloud(las)
108+
109+
# shuffle the order of the points based on point positions
110+
pc = pc[sortperm(pc.position)]
111+
112+
# set all classifications to 0
113+
pc.classification .= 0
85114
```
86115

87116
You can also add or remove *(E)VLRs* using the following functions, and set an existing *(E)VLR* as *superseded* if it's an old copy of a record.

docs/src/vlrs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ You can then read the *LAS* data and extract the classification lookup:
6262
las = load_las("pc.las")
6363
# look for the classification lookup VLR by checking for its user and record IDs
6464
lookup_vlr = extract_vlr_type(get_vlrs(las), "LASF_Spec", 0)
65-
lookup = get_data(lookup_vlr[1])
65+
lookup = get_data(lookup_vlr)
6666
```
6767

6868
### Text Area Descriptions
@@ -150,7 +150,7 @@ So in our example, we can tell the system that records containing data of type `
150150
@register_vlr_type MyType "My Custom Records" collect(1:100)
151151
```
152152

153-
And now we can save our `MyType` *VLRs* into a *LAS* file in the same way as we did above for the register *VLR* types. Note that you can use the function `extract_vlr_type` on your collection of *VLRs* to pull out any *VLRs* with a specific user ID and record ID.
153+
And now we can save our `MyType` *VLRs* into a *LAS* file in the same way as we did above for the register *VLR* types. Note that you can use the function `extract_vlr_type` on your collection of *VLRs* to pull out the *VLR* with a specific user ID and record ID.
154154

155155
```@docs; canonical = false
156156
extract_vlr_type

src/LASDatasets.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export scan_direction, user_data
3939
# header interface
4040
export LasHeader, is_standard_gps, is_wkt, file_source_id, global_encoding, las_version, system_id, software_id, creation_day_of_year, creation_year
4141
export header_size, point_data_offset, point_record_length, record_format, point_format, number_of_points, number_of_vlrs, number_of_evlrs, evlr_start, spatial_info, scale, num_return_channels
42-
export set_las_version!, set_spatial_info!, set_point_data_offset!, set_point_format!, set_point_record_length!, set_point_record_count!, set_num_vlr!, set_num_evlr!, set_gps_week_time_bit!
42+
export set_las_version!, set_point_format!, set_spatial_info!, set_point_data_offset!, set_point_format!, set_point_record_length!, set_point_record_count!, set_num_vlr!, set_num_evlr!, set_gps_week_time_bit!
4343
export set_gps_standard_time_bit!, is_internal_waveform, is_external_waveform, unset_wkt_bit!
4444
export set_waveform_external_bit!, set_waveform_internal_bit!, set_synthetic_return_numbers_bit!, unset_synthetic_return_numbers_bit!
4545
export set_wkt_bit!, get_number_of_points_by_return, set_number_of_points_by_return!, waveform_record_start
@@ -55,7 +55,7 @@ export get_classes, get_description, set_description!
5555
export @register_vlr_type, read_vlr_data, extract_vlr_type
5656

5757
export LASDataset, get_header, get_pointcloud, get_vlrs, get_evlrs, get_user_defined_bytes, get_unit_conversion
58-
export add_column!, merge_column!, add_vlr!, remove_vlr!, set_superseded!
58+
export add_column!, add_points!, remove_points!, merge_column!, add_vlr!, remove_vlr!, set_superseded!
5959

6060
# I/O methods
6161
export load_las, load_pointcloud, save_las, load_header, load_vlrs

0 commit comments

Comments
 (0)