Skip to content

Gap between tiles from LAScatalog #811

@kiblerchris

Description

@kiblerchris

When I specify a SpatRaster template for the res argument in pixel_metrics, there is a one-pixel gap between the raster tile outputs. When I specify an integer for res, there is no gap between the tiles.

This is the underlying function I am using:

vegStructureLAS <- function(las, dtm_res = 1, out_res = 20){ 
  dtm <- rasterize_terrain(las, res = dtm_res, algorithm = knnidw())
  nlas <- normalize_height(las, dtm)
  nlas_veg <- filter_poi(nlas, Classification == 1L) 
  heightMetrics <- pixel_metrics(nlas_veg, ~mean(Z), res = out_res)
  return(heightMetrics)
}

This code produces a one-pixel gap between the output tiles:

# Create template
rast_template <- rast(
  nrows = 3420,
  ncols = 3857,
  nlyrs = 1,
  xmin = 624135,
  xmax = 739845,
  ymin = 4413555,
  ymax = 4516155,
  crs = "EPSG:32610"
)

rast_template[] <- NA

# Process LAScatalog
las <- readLAScatalog("./catalog", filter = "-drop_withheld")
opt_output_files(las) <- "{ORIGINALFILENAME}_processed"
opt_chunk_buffer(las) <- 100

new_ctg <- catalog_map(las, 
                       vegStructureLAS,
                       out_res = rast_template)

Image

This code produces the correct output with no gap between the tiles:

# Process LAScatalog
las <- readLAScatalog("./catalog", filter = "-drop_withheld")
opt_output_files(las) <- "{ORIGINALFILENAME}_processed"
opt_chunk_buffer(las) <- 100

new_ctg <- catalog_map(las, 
                       vegStructureLAS,
                       out_res = 20)

Image

The tiles used in the example can be found here:

Metadata

Metadata

Assignees

Labels

BugA bug in the package

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions