-1

I need to obtain the metrics for a denoised normalized dataset. This is part of the code that I am using:

ctg_denoised <- readLAScatalog("G:/NoBackUp/denoised/")
opt_chunk_buffer(ctg_denoised) <- 10
opt_output_files(ctg_denoised) <- "G:/NoBackUp/metrics/*_metrics"

#METRICS CALCULATION
metrics <- grid_metrics(ctg_denoised, .stdmetrics_z , sqrt(250))

When I apply grid_metrics to the catalog of normalized als data it completes the processing but does not manage to merge all the rasters created into a single .vrt file. The catalog consists in 1773 files and the result of grid_metrics is a list of 1773. The error after running grid metrics says the following and the warnings are repetitive, the repeat the following warnings (1-13):

CreateProcess' failed to run 'C:\PROGRA~3\ANACON~1\Library\bin\gdalbuildvrt.exe "G:/NoBackUp/grid_metrics.vrt" "G:/NoBackUp/33-1-456-133-76_gf_norm_p95_p95.tif" "G:/NoBackUp/33-1-456-133-77_gf_norm_p95_p95.tif" "G:/NoBackUp/33-1-456-133-79_gf_norm_p95_p95.tif"There were 50 or more warnings (use warnings() to see the first 50)
>Warnings()
1: In min(x, na.rm = TRUE) : no non-missing arguments to min; returning Inf
2: In max(x, na.rm = TRUE) : no non-missing arguments to max; returning -Inf
3: In min(x, na.rm = TRUE) : no non-missing arguments to min; returning Inf
4: In max(x, na.rm = TRUE) : no non-missing arguments to max; returning -Inf
5: In min(x) : no non-missing arguments to min; returning Inf
6: In max(x) : no non-missing arguments to max; returning -Inf
7: In min(x, na.rm = TRUE) : no non-missing arguments to min; returning Inf
8: In max(x, na.rm = TRUE) : no non-missing arguments to max; returning -Inf
9: In min(x, na.rm = TRUE) : no non-missing arguments to min; returning Inf
10: In max(x, na.rm = TRUE) : no non-missing arguments to max; returning -Inf
11: In min(x) : no non-missing arguments to min; returning Inf
12: In max(x) : no non-missing arguments to max; returning -Inf
13: In points2grid(points, tolerance, round) :
  grid has empty column/rows in dimension 1

When I run the code with a small dataset the .vrt file is created so I don´t know if when treating big dataset is there a specific way of doing it. So far I have tried to apply info from this question but it didn´t work:

library(raster)
r <- stack(metrics[[1]])
for(i in 2:length(metrics)) r <- addLayer(r, metrics[[i]])
class(r)

also I have tried from this question but an error occurred:

metrics_merge <- do.call(raster::merge, metrics)
Error in as.data.frame(x) : argument "x" is missing, with no default
4
  • What's the code you are running to get that error? What are the warnings we're not seeing? What do you see if you type warnings() like it says in the error message? If it works with a small data set and fails with a big one, where's the point where it fails? Divide your big data into chunks and see where it fails.
    – Spacedman
    Commented Feb 2, 2020 at 18:36
  • The building of a the virtual mosaic failed for a unknown reason which is impossible to say without a reproducible example. Anyway your rasters were written on disk.
    – JRR
    Commented Feb 3, 2020 at 11:44
  • 2
    When I say "divide into chunks" I mean try it with some subset of the catalog: grid_metrics(ctg_denoised[1:10,], .stdmetrics_z , sqrt(250)) should apply it to the first 10, for example. If that works, then double the "10" until you hit a problem. It could just be one rogue element in your catalog. Hunt it down.
    – Spacedman
    Commented Feb 3, 2020 at 16:37
  • So, I tried to detect where the problem could be by dividing the catalog as @spacedman suggested but the building of the .vrt file was succesful for all subsets, it only fails to create it when is applied for the whole catalog. When so, the result in the R environment is a list of the .tif files created in the opt_output_files(ctg_denoised). I have manage to run gdalbuildvrt for all the .tifs as in this question and it works so i don´t understand what is the problem is Commented Feb 4, 2020 at 13:56

1 Answer 1

1

I did not manage to solve why grid_metrics fails to create the .vrt file when applied to a big catalog but I managed to be able to create the same output. I solved my problem by usig the gdalUtils tools from QGIS instead of Anaconda as the error said "CreateProcess' failed to run 'C:\PROGRA~3\ANACON~1\Library\bin\gdalbuildvrt.exe" and also the gdalbuildvrtcommand failed every time I tried to run it for the denoised normalized catalog, which led me to believed that this Anaconda´s gdalUtils was the reason. I changed the directory of gdalUtilsby following this question:

library(usethis)
edit_r_profile()
gdalUtils::gdal_setInstallation("C:\\Program Files\\QGIS 3.4\\bin")

Although it did not make grid_metrics generate the .vrtfile, I was able to run gdalbuildvrtfor the catalog:

library(gdalUtils)
vrt <- gdalUtils::gdalbuildvrt(gdalfile = "G:/NoBackUp/metrics/*.tif", 
                               output.vrt = "G:/NoBackUp/metrics/grid_metrics.vrt"
                               , overwrite = TRUE)

vrt.file <- stack("G:/NoBackUp/metrics/grid_metrics.vrt")

It takes considerably longer to create this .vrt file by this method and to read it as a stack or brick also takes really long but it manages to create the same output.

5
  • 1
    The next time please mention that you are not working in a regular environment but within a container. I'm not surprised it does not work in a container. Using gdalUtils::gdal_setInstallation is probably the good answer. Then, using gdalUtils::gdalbuildvrt is exacly what is done internally in lidR.
    – JRR
    Commented Feb 6, 2020 at 14:49
  • I was not aware that I was working within a container. I do not really know what that means Commented Feb 7, 2020 at 6:38
  • 1
    You are working within anaconda. anaconda is a kind of container of something similar I don't really know actually. What I know is that you are not the first one to encounter troubles because not mastering enough the tools you are using. Imo a regular R installation is preferable if you are not 100% sure of what you are doing.
    – JRR
    Commented Feb 7, 2020 at 11:26
  • Thanks for your clarification. Unfortunetly I can not do much about it because I do not have complete access to the computer I work with. Most softwares are pre-installed or have default sets when installing that I can´t change. Can I ask you something else about the processing time? can you imagine why does it takes so long (like 3 times more) when I create the .vrt file in comparison to when it is created with grid_metrics? Commented Feb 10, 2020 at 12:09
  • 1
    I don't know. I guess it depends on the size of the raster and I guess that gdalbuildvrt takes time. This should be reproduced and benchmarked to be answered. 3 times seems to be a lot.
    – JRR
    Commented Feb 10, 2020 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.