[R-sig-Geo] LiDAR LAS file import into R via RSAGA

Chris Reudenbach reudenbach at uni-marburg.de
Fri Feb 12 09:32:46 CET 2016


Hi Clay,

RSAGA provides a comfortable platform independent system wrapper for 
SAGA but as stated  no two-way bindings.

If you want to make use of SAGA algorithms () it is IMHO the most 
straightforward way to import and export the raster files using the e.g. 
gdalUtils. If you use raster() directly please note that it may produce 
problems writing SAGA files directly. To avoid format complications  I 
use  most of the time GTiff. You can easily integrate the power of 
rLidar in this workaround concept.
A typical work flow may look like:


  # gdalwarp is used to convert the data format to SAGA
  # you may assign the projection information to the data (like example 
or change it with t_srs=)
   gdalwarp(file.in, file.out, overwrite=TRUE, 
s_srs=paste0('EPSG:',epsg.code), of='SAGA')

  # do something in SAGA using the files on the disk storage as "interface"
  # note SAGA works much more stable under differnet platforms when you 
provide the env settings

   # e.g. calculate wood's terrain indices   wood= 
1=planar,2=pit,3=channel,4=pass,5=ridge,6=peak
     rsaga.geoprocessor('ta_morphometry',"Morphometric Features",env=myenv,
                        list(DEM='mp_dem.sgrd',
                             FEATURES='mp_wood.sgrd',
                             SLOPE='mp_slope.sgrd',
                             LONGC='mp_longcurv.sgrd',
                             CROSC='mp_crosscurv.sgrd',
                             MINIC='mp_mincurv.sgrd',
                             MAXIC='mp_maxcurv.sgrd',
                             TOL_SLOPE=14.000000
                             TOL_CURVE=0.00001
                             EXPONENT=0.000000
                             ZSCALE=1.000000))

     # read whatever you wand directly using raster()
     peak.area<-raster('mp_wood.sdat')

For using SAGA and/or GRASS in a "mixed" environment with R you may find 
some help at our course pages:
  http://moc.environmentalinformatics-marburg.de/doku.php?id=courses:msc:advanced-gis:lecture-notes:ag-ln-06

cheers Chris


Am 12.02.2016 um 07:51 schrieb Clay S:
> Thanks Michael Sumner
>
> rLidar works well.  But how do I pass the lidar data to another SAGA module
> within R without saving the output of each step as a file in a whole series
> of SAGA module calls from R?
>
> I would like something like the dplyr %>% pipe command.
>
> Thanks
> Clay
>
> On Fri, Feb 12, 2016 at 7:44 PM, Michael Sumner <mdsumner at gmail.com> wrote:
>
>> Try rLidar::readLAS as a straightforward alternative, it's not bullet
>> proof but works fine for a lot of examples. Happy to help extend it if your
>> format is not supported.
>>
>> Cheers, Mike
>>
>> On Fri, 12 Feb 2016 7:41 am Clay S <clayms at gmail.com> wrote:
>>
>>> Hi
>>>
>>> Is it possible to import a Lidar LAS file into R with the
>>> rsaga.geoprocessor function of the RSAGA package.  The following code runs
>>> without an error, but all I get in R is the SAGA console output.
>>>
>>> The R code below does save a SAGA point cloud file called "test" in my
>>> working directory.  If I delete the `POINTS = "test"` parameter, then
>>> nothing happens as expected.  However, I want to work with the data in R,
>>> and pass the point cloud to other SAGA modules. This can be done in SAGA
>>> without having to save the point cloud.  Can the same be done from R?
>>>
>>> How can I get the point cloud imported into the R environment?  Do I need
>>> to coerce it into a matrix, data frame, or Spatial Points object?
>>>
>>>
>>> R code:
>>>
>>> ###############
>>>
>>> library(RSAGA)
>>>
>>>
>>> # Set RSAGA environment.
>>>
>>> env <- rsaga.env()
>>>
>>>
>>> # SET WORKING DIRECTORY FIRST!!
>>>
>>> dir <- getwd()
>>>
>>>
>>> # Get module parameters
>>>
>>> lasfilelist <- list.files(dir, pattern =".las$", full.names=TRUE,
>>> recursive=FALSE)
>>>
>>>
>>> # send command to RSAGA
>>>
>>> test <- rsaga.geoprocessor(lib = "io_shapes_las", module = "Import LAS
>>> Files",
>>>                     param = list(FILES = lasfilelist[1], POINTS = "test",
>>>                                  T=TRUE, i=TRUE, a=FALSE, r=TRUE, c=FALSE,
>>> u=FALSE,
>>>                                  n=TRUE, R=FALSE, G=FALSE, B=FALSE,
>>> e=FALSE,
>>> d=FALSE,
>>>                                  p=FALSE, C=FALSE, VALID=FALSE,
>>> RGB_RANGE=FALSE),
>>>                     env = env)
>>>
>>> ###################
>>>
>>>
>>> Here is the console output (the test variable stores the same thing):
>>>
>>> ###########
>>>
>>> library path: C:\OSGEO4~1\apps\saga\modules\io_shapes_las.dll
>>> library name: Import/Export - LAS
>>> tool name   : Import LAS Files
>>> author      : O. Conrad, V. Wichmann (c) 2009
>>>
>>> Parameters
>>>
>>> Input Files: "C:/Users/whcms0/'.CPT/Tarewa/Lidar/AX300711.las"
>>> Point Clouds: No objects
>>> gps-time: yes
>>> intensity: yes
>>> scan angle: no
>>> number of the return: yes
>>> classification: no
>>> user data: no
>>> number of returns of given pulse: yes
>>> red channel color: no
>>> green channel color: no
>>> blue channel color: no
>>> edge of flight line flag: no
>>> direction of scan flag: no
>>> point source ID: no
>>> rgb color: no
>>> Check Point Validity: no
>>> R,G,B value range: 16 bit
>>>
>>> Parsing AX300711.las ...
>>> Save point cloud: test...
>>>
>>> ################
>>>
>>>
>>> Here is my env:
>>>
>>> ################
>>>
>>>> env
>>> $workspace
>>>
>>> [1] "."
>>>
>>>
>>> $cmd
>>>
>>> [1] "saga_cmd.exe"
>>>
>>>
>>> $path
>>>
>>> [1] "C:\\OSGeo4W64\\apps\\saga"
>>>
>>>
>>> $modules
>>>
>>> [1] "C:\\OSGeo4W64\\apps\\saga/modules"
>>>
>>>
>>> $version
>>>
>>> [1] "2.1.2"
>>>
>>>
>>> $cores
>>>
>>> [1] NA
>>>
>>>
>>> $parallel
>>>
>>> [1] FALSE
>>>
>>>
>>> $lib.prefix
>>>
>>> [1] ""
>>>
>>> #################
>>>
>>>          [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>> --
>> Dr. Michael Sumner
>> Software and Database Engineer
>> Australian Antarctic Division
>> 203 Channel Highway
>> Kingston Tasmania 7050 Australia
>>
>>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list