knn_graph: Build a nearest neighbor graph and filter the edges.

View source: R/knn_graph.R

knn_graphR Documentation

Build a nearest neighbor graph and filter the edges.

Description

Build a nearest neighbor graph and filter the edges.

Usage

knn_graph(
  las,
  k = 10L,
  local_filter = NULL,
  global_filter = NULL,
  max_edge_length = NULL
)

Arguments

las

a LAS file.

k

integer. The number of neighbors to use to construct the graph.

local_filter

numeric (optional). If declared, applies a local edge filter that, allow to remove, for each node, the edges that are longer than the mean edge distance+local_filter*sd(mean(distance)).

global_filter

numeric between 0 and 1 (optional). If declared, applies a global edge filter by removing all edges longer than the global_filter^{th} quantile of all edges length.

max_edge_length

numeric (optional). If declared, removes all edges longer than max_edge_length.<

Value

an data.table containing the nodes ID (their position within the LAS data) and the length of the edge.

Examples


# import data
file = system.file("extdata", "tree_no_leaves.las", package="lidUrb")
las = lidR::readLAS(file)

# build the knn graph with no filter
KNN = lidUrb::knn_graph(las, k = 5L)

# plot the graph
lidUrb::plot_graph(las = las, graph = KNN)

# build the knn graph with local filter and all edges longer than 5cm removed
KNN = lidUrb::knn_graph(las, k = 5L,local_filter = 0.5,max_edge_length = 0.05)

# plot the new graph
lidUrb::plot_graph(las = las, graph = KNN)


Blecigne/lidUrb documentation built on Feb. 19, 2024, 9:12 a.m.