tiagodc / TreeLS

R functions for processing individual tree TLS point clouds
GNU General Public License v3.0
82 stars 27 forks source link

treeMap.merge - Not working #30

Closed sweco-sekrsv closed 3 years ago

sweco-sekrsv commented 3 years ago

I can't get the treeMap.merge to work as I expect. I'm using these values:

map = treeMap(tls, map.hough(h_step = 1, max_h = 6, min_h = 5),merge = 1.0)
xymap = treeMap.positions(map, plot = FALSE)
add_treeMap(x, xymap, color='yellow')

I was thinking that with a merge value of 1 all treeMap.positions within a meter distance would merge to one. But I don't see any points being merged at all, even when setting the merge to very high values like 100.

Maybe I misunderstood what it does? This image shows the result: stamsegmentering_TreeLS_02

tiagodc commented 3 years ago

Thanks for the comment,

that merge function is not so straight forward, I'll consider writing a better description for it. Right now it is:

The d parameter is a relative measure of close neighbors. Sorting all possible pairs by distance from a tree map, the merge criterion is that none of the closest pairs should be distant less than the next closest pair's distance minus d. This method is useful when merging forked stems or point clusters from plots with too much understory, especially if those are from forest stands with regularly spaced trees.

This method is particularly useful for clouds of regularly spaced trees in forest plantations. The d parameter is a ratio, and the lower it is, the more inclusive the merging is, i.e. more trees will be merged the lower d is.

I'll consider adding another simpler merge function on next version, with straightforward distance inputs. In the meantime, you can try to filter out or merge the trees from your map with a custom method using a distance matrix as a criterion. This snippet gets the distance from every tree in a map to its nearest neighbor:

map = treeMap(las, positions_only=T)
map$d_nn = map[,.(X,Y)] %>% dist %>% as.matrix %>% as.data.table %>% sapply(function(x) sort(x)[2])

Cheers