如何在LAScatalog内修改建筑类的高度值

huangapple go评论94阅读模式
英文:

How to modify height value of building class within LAScatalog

问题

I am working with a collection of classified LAZ files located over an urban area. I would like to create a canopy height model (CHM) for the urban tree extent. Filtering out and only keeping ground and tree classified points, the resulting CHM has some artifacts created during triangulation due to the missing points. I address this by retaining all the building points and modifying their heights to be 0. Working with a single LAZ file this is simple:

# Read
las <- readLAS("path/to/file.laz")

# Filter points
las <- filter_poi(las, las$Classification %in% c(6, 5, 2))

# Normalize
las <- normalize_height(las, tin(), use_class = c(2L))

# Modify building height
las_buildings <- filter_poi(las, las$Classification %in% c(6))
las_buildings$Z <- 0
las_trees_ground <- filter_poi(las, las$Classification %in% c(5, 2))
las <- rbind(las_buildings, las_trees_ground)

# Create chm
chm <- rasterize_canopy(las, 0.5, pitfree(subcircle = 0.5))

However, doing this while working with a LAScatalog is unclear to me. This is what I have so far:

# Load laz catalog
ctg <- readLAScatalog("path/to/")

# Create buffer
opt_chunk_buffer(ctg) <- 50

# Filter points
opt_filter(ctg) <- "-keep_first -keep_class 6 -keep_class 5 -keep_class 2"

# Normalize heights
opt_output_files(ctg) <- paste0(tempdir(), "/{*}_norm")
ctg_norm <- normalize_height(ctg, tin())

# How to change building height to 0 ???

# Create CHM
opt_output_files(ctg_norm) <- paste0(tempdir(), "/{*}_chm")
chm <- rasterize_canopy(ctg_norm, 0.5, pitfree(subcircle = 0.5), pkg = "terra")
terra::writeRaster(chm, "chm.tif")

Any guidance on how I can achieve this would be very much appreciated.

英文:

I am working with a collection of classified LAZ files located over an urban area. I would like to create a canopy height model (CHM) for the urban tree extent. Filtering out and only keeping ground and tree classified points, the resulting CHM has some artifacts created during triangulation due to the missing points. I address this by retaining all the building points and modifying their heights to be 0. Working with a single LAZ file this is simple:

# Read
las&lt;-readLAS(&quot;path/to/file.laz&quot;)

# Filter points
las&lt;-filter_poi(las,las$Classification  %in% c(6,5,2))

# Normalize
las&lt;-normalize_height(las,tin(),use_class=c(2L))

# Modify building height
las_buildings&lt;-filter_poi(las,las$Classification %in% c(6))
las_buildings$Z&lt;-0
las_trees_ground&lt;-filter_poi(las,las$Classification %in% c(5,2))
las&lt;-rbind(las_buildings,las_trees_ground)

# Create chm
chm&lt;-rasterize_canopy(las,0.5,pitfree(subcircle=0.5))

However, doing this while working with a LAScatalog is unclear to me. This is what I have so far:

# Load laz catalog
ctg&lt;-readLAScatalog(&quot;path/to/&quot;)

# Create buffer
opt_chunk_buffer(ctg)&lt;-50

# Filter points
opt_filter(ctg)&lt;-&quot;-keep_first -keep_class 6 -keep_class 5 -keep_class 2&quot;

# Normalize heights
opt_output_files(ctg)&lt;-paste0(tempdir(),&quot;/{*}_norm&quot;)
ctg_norm&lt;-normalize_height(ctg,tin())

# How to change building height to 0 ???

# Create CHM
opt_output_files(ctg_norm)&lt;-paste0(tempdir(),&quot;/{*}_chm&quot;)
chm&lt;-rasterize_canopy(ctg_norm,0.5,pitfree(subcircle=0.5),pkg=&quot;terra&quot;)
terra::writeRaster(chm,&quot;chm.tif&quot;)

Any guidance on how I can achieve this would be very much appreciated.

答案1

得分: 0

好的,这是翻译好的部分:

这是我的解决方案:

# 更改高度的函数
myfun <- function(las) {
  las_buildings <- filter_poi(las, las$Classification %in% c(6))
  las_buildings$Z <- 0
  las_trees_ground <- filter_poi(las, las$Classification %in% c(5,2))
  output <- rbind(las_buildings, las_trees_ground)
  return(output)
}

# 更改建筑物高度
ctg_norm <- catalog_map(ctg_norm, myfun)
英文:

Ok, after doing more reading I found the catalog_map function, which applies a custom function to the catalog.

Here is my solution:

# Function to change heights
myfun &lt;- function(las) {
  las_buildings&lt;-filter_poi(las,las$Classification %in% c(6))
  las_buildings$Z&lt;-0
  las_trees_ground&lt;-filter_poi(las,las$Classification %in% c(5,2))
  output&lt;-rbind(las_buildings,las_trees_ground)
  return(output)
}

# Change building height
ctg_norm&lt;-catalog_map(ctg_norm,myfun)

huangapple
  • 本文由 发表于 2023年8月10日 19:59:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76875564.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定