3

I am trying to run Fusion's GridMetrics from R, I wrote this for one las file:

#First set up directories to keep the raw data 
#separate from that produced by the analysis, Input (.las) and (.dtm), 
#and output (.csv) directory in a dropbox folder.  
mainDir <- "F:/Dropbox/LiDAR_Prj"
inDir <- "inputDirectory"
outDir<- "outputDirectory"
dir.create(file.path(mainDir, outDir), showWarnings = FALSE)
#Run grid metrics in FUSION
#Read in the .las files and use FUSION to produce the .csv files with values for 14 m pixel.

system(paste(file.path("C:","Fusion", "gridmetrics.exe"),
"/outlier:-5,250 /minht:1.64 /strata:8.2,16.40",
file.path(mainDir, inDir, "*.dtm"), 13.1,45.93,
file.path(mainDir, outDir, "2H8546.csv"),
file.path(mainDir, inDir, "2H8546.las"),
sep=" "))

It worked very well. However, I would like to automate it because I have more than 400 tiles to process (file names are not a sequence).

I attempted to use a txt file listing the data files instead of the file names:

mainDir <- "F:/Dropbox/LiDAR_Prj"
inDir <- "inputDirectory"
outDir<- "outputDirectory"
dir.create(file.path(mainDir, outDir), showWarnings = FALSE)

#Run grid metrics in FUSION
#Read in the .las files and use FUSION to produce the .csv files with values for 14 m pixel.
system(paste(file.path("C:","Fusion", "gridmetrics.exe"),
"/outlier:-5,250 /minht:1.64 /strata:8.2,16.40",
file.path(mainDir, inDir, "*.dtm"), 13.1,45.93,
file.path(mainDir, outDir, "halistcsv.txt"),
file.path(mainDir, inDir, "halist.txt"),
sep=" "))

but a warning message pops up:

Too many points (couldn't allocate memory for point list)...no metrics computed
Run finished: Tue Nov 22 19:39:35 2016 (elapsed time: 21 seconds)
***There were errors during the run
Done
Warning message:
running command 'C:/Fusion/gridmetrics.exe ... halist.txt' had status 5

Could any of you help me to figure out an efficient way to automate this process?

  • Are you running 32 or 64 bit R? How much RAM do you have? What happens when you run memory.limit()? Have you looked into increasing the memory limit? stackoverflow.com/q/1395229/1446289 – Aaron Nov 23 '16 at 5:50
  • Hi Aaron, I'm running 64 bit R, my laptop has 8 GB of RAM, and the number 8139 results after I run memory.limit (). – Rodri Nov 23 '16 at 6:21
  • Another option is to try the Fusion's LTK processor. See: gis.stackexchange.com/questions/91892/… – Andre Silva Nov 23 '16 at 11:44
4

The issue you are trying to solve has nothing to do with R. You are running application that is independent of R with the system() function.

The error that you got originates in program gridmetrics.exe. You can verify that by just printing the outcome of your paste() function and running that through command line. You should get the same error message as you are getting in R.

While I don't know the program gridmetrics.exe, I assume that the problem is that in your second example you are trying to run the program against a file that lists all your files instead of running the program for each file separately.

Assuming that your file "halist.txt" contains one filename per line, then you need to use this code:

mainDir <- "F:/Dropbox/LiDAR_Prj"
inDir <- "inputDirectory"
outDir<- "outputDirectory"
dir.create(file.path(mainDir, outDir), showWarnings = FALSE)

# path to the file with list of files
list_path = file.path(mainDir, inDir, "halist.txt")
# read the file as csv
files = read.csv(list_path, header = FALSE)


for (i in 1:nrow(files)){
  # split the file name by dot
  file_name = strsplit(files[i,1], "[.]")

  system(paste(file.path("C:","Fusion", "gridmetrics.exe"),
"/outlier:-5,250 /minht:1.64 /strata:8.2,16.40",
file.path(mainDir, inDir, "*.dtm"), 13.1,45.93,
file.path(mainDir, outDir, paste0(file_name[1],"csv.txt")),
file.path(mainDir, inDir, files[i,1]),
sep=" "))
}

This code will create one csv file for each file in your list. If you need to merge those files together it might be problematic due to the size.

  • Hi Jan, it is ok to get one csv for each file, I will eventually merge them using other porograms. I just run the code suggested but I got this warning: Error in strsplit(files[i, 1], ".") : non-character argument – Rodri Nov 23 '16 at 17:04
  • Oh, I see. I forgot that the (strsplit()) function requires regular expression for splitting the string. So you need to use (strsplit(files[i,1], "[.]")) in order to get the result you want. – Jan Caha Nov 24 '16 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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