GeoKL / GeoKL-agis-WS-21-22

Reporsitory for GIS course website
0 stars 0 forks source link

LiDAR script does not run anymore #2

Open GeoKL opened 2 years ago

GeoKL commented 2 years ago

Hello @gisma, as I was trying to calculate more metrics, my script did not run anymore. I can neither plot the las file nor calculate metrics. The script up to that point looks like this:

# activate envimaR package
require(envimaR)

# set root directory
rootDIR = "E:/edu/agis"

appendpackagesToLoad = c("lidR","forestr","lmom", "rLiDAR", "mapview", "raster", "rlas", "sp", "sf", "rgl","future")

# define additional subfolders comment if not needed
appendProjectDirList =  c("data/lidar/","data/lidar/l_raster","data/lidar/l_raw","data/lidar/l_norm")

## define current projection (It is not magic you need to check the meta data or ask your instructor) 
## ETRS89 / UTM zone 32N
proj4 = "+proj=utm +zone=32 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0"
epsg_number = 25832

# load setup Skript
source(file.path(envimaR::alternativeEnvi(root_folder = rootDIR),"src/agis_setup.R"),echo = TRUE)

# loading the data
# NOTE file size is about 12MB
# utils::download.file(url="https://github.com/gisma/gismaData/raw/master/uavRst/data/lidR_data.zip",
#                     destfile=paste0(envrmt$path_tmp,"chm.zip"))
# unzip(paste0(envrmt$path_tmp,"chm.zip"),
#      exdir = envrmt$path_tmp,  
#      overwrite = TRUE)

#---- Get all *.las files of a folder into a list
las_files = list.files(envrmt$path_tmp,
                       pattern = glob2rx("*.las"),
                       full.names = TRUE)

# plotting the data
las = readLAS(las_files[1])
summary(las)
plot(las, bg = "darkblue", color = "Z",backend="rgl")
# colorPalette = mvTop(256) was not included since it provoked an Error: Error in mvTop(256) : could not find function "mvTop"

######### metrics

# example metrics:  average and max. height of points at cloud/grid/voxel level:
cloud_metrics(las, func = ~mean(Z)) 

When plotting, I do not get an Error, but the pop up window just does not open. When trying to calculate the cloud_metrics, I get this Error: Error in UseMethod("cloud_metrics", las) : no applicable method for 'cloud_metrics' applied to an object of class "c('matrix', 'array', 'double', 'numeric')"

I first tried with the data from "https://github.com/gisma/gismaData/raw/master/uavRst/data/lidR_data.zip" and now tried the mof data - both didn't work. I restarted and cleaned up the environment several times. I don't understand this, because I didn't change the script before and it was running..

Best regards

gisma commented 2 years ago

The error occurs at the line?

plot(las, bg = "darkblue", color = "Z",backend="rgl")

if so just drop the argument backend="rgl"

In addition pls check if all packees are up to date.

GeoKL commented 2 years ago

The error occurs at the last line: cloud_metrics(las, func = ~mean(Z))

Okay, I'll do that, thanks.

GeoKL commented 2 years ago

Okay, I found the problem: my las file is a matrix. But putting lidR:: in front of readLAS(las_files[1]) seems to have solved that.