Re: [R-sig-Geo] LiDAR LAS file import into R via RSAGA
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.00 TOL_CURVE=0.1 EXPONENT=0.00 ZSCALE=1.00)) # 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 Sumnerwrote: 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 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]
Re: [R-sig-Geo] LiDAR LAS file import into R via RSAGA
In case it's of any use to others, I've been scripting some LiDAR processing from R using LASTools, focused on dealing with many individual las files. At this point we've just been extracting a bunch of metadata fields to get a sense of what we have, fixing some metadata errors that we're aware of, and reprojecting data. We've got lots of data for a region that are in various projections, and sometimes the LAS metadata are just incorrect, so the functions as written are designed to help us deal with those issues, but can easily be adapted for other purposes. These functions use foreach and doparallel to use multi-core processors to speed things along, running LasTools via system commands. This work is still in fairly early stages and admittedly needs some better organization and documentation. At this point, we've exclusively been calling on LasTools functions that do not require a paid license, and plan to keep it as such for now. Also, we were exploring use on both linux and windows systems on an external server, and the linux setups have been a lot faster, so functions ending in unix.R are the most up to date [the changes to go back to windows are pretty simple]. (as I said, we need to organize, but it is functional for our purposes now...). The code is available in a github repository: https://github.com/mltConsEcol/OK_LiDAR_Processing Feel free to contact me with questions on this code, suggestions, or want to contribute any additions (and I'd be curious to hear if anybody does end up using it). I think some future functions will call on the rLidar package, and we'll see where our next steps take us... Best, mike On Fri, Feb 12, 2016 at 2:32 AM, Chris Reudenbachwrote: > 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.00 > TOL_CURVE=0.1 > EXPONENT=0.00 > ZSCALE=1.00)) > > # 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 >> 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 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
Re: [R-sig-Geo] LiDAR LAS file import into R via RSAGA
Another option would be to create a SAGA tool chain XML file following the tutorials by Michael Bock, Olaf Conrad, Volker Wichmann, and drag that XML file into the SAGA module library. Does anyone know if you can access your own SAGA tool chains with the RSAGA::rsaga.geoprocessor command? I suppose the parameters for each module in the chain would be set according to the XML file. If that is the case, then I also suppose you could edit the XML file with R before you run the tool chain. But I am getting ahead of myself. Unfortunately, the most recent version of SAGA that the OSGeo4W is 2.1.2-1, which does not have the tool chains feature. That was added in SAGA 2.1.3. Does anyone know when OSGeo4W will get updated? On Fri, Feb 12, 2016 at 7:51 PM, Clay Swrote: > 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 > 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 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@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@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo