137 reputation
7
bio website
location
age
visits member for 1 year, 11 months
seen Aug 24 at 3:03

Jul
2
awarded  Curious
Jan
31
comment Flow Accumulation in R
@jirikdlec2 this was just what I needed. It is very powerful, very fast, and can be called directly from R. The results of Dr. Tarboton's model are quite impressive.
Jan
30
comment Flow Accumulation in R
Thank you @jirikadlec2. This looks really promising! This fits with the previous suggestions of using R to call more appropriate tools for the job and gives access to ArcGIS. Also, as discussed here: Lidar DEM the D-infinity flow direction algorithm fixed some of the problems with D8. I hope to get this working shortly.
Jan
30
accepted Flow Accumulation in R
Jan
29
comment Flow Accumulation in R
@whuber, thank you for your thoughts and the link. My ideal would be to use R for the full work flow. Generally [DEM -> flow direction -> accumulation -> >= threshold = stream]. The RSAGA package function rsaga.fill.sinks computes a flow direction using either Planchon and Darboux (2001) or Wang and Liu (2006) [it is only one of those, but the doc says "only for "wang.liu.2001"]. The consensus seems to be that R is a poor choice for this. I see the reason of that argument and they outweigh my desire to contain it within R; I will use python for those bits. Thanks for the help/info!
Jan
29
comment Flow Accumulation in R
Thank you @mace. Your point about the expense of the flow accumulation algorithm is very well taken. Your hunch may be dead on. The spgrass6 package may be a decent alternative.
Jan
29
comment Flow Accumulation in R
Thank you for your help @dklassen. This is a good start, but unfortunately the author uses RpyGEO in this script. They use rpygeo.geoprocessor("FlowAccumulation_sa"... which still requires an ArcGIS license. However, if I do go the RpyGEO route, I will cite that script/poster.
Jan
29
comment Flow Accumulation in R
I would prefer it to be in R, but it is not a deal breaker. I have ArcGIS, Spatial Analyst, and could script it in python, but I like to avoid ArcGIS b/c of license issues. I would like to be able to run this routine on computers without Spatial Analyst licenses. RpyGEO, as you know, still needs the SA license to run sa.FlowAccumulation. The other packages i mentioned, RSAGA, enaR, and vegan do not have a flow accumulation function that I could find, but I would be happy to use them.
Jan
29
revised Flow Accumulation in R
added info
Jan
29
asked Flow Accumulation in R
Jan
28
comment R - How to sampleRandom() from large raster without NA values
@Jeffery, I finally got back around to this. I implemented your raster-in-memory code here, but not with complete success. At first I did such with using raster() instead of readGDAL(). everything worked fine until I tried to take the same r.samp from two different rasters. Each have the same origin, dims, cell size, just different data. The returned samples were different by ~1 cell on the x-coord; so they were unpaired. I then tried it with readGDAL() but it got hung up with no success (64 Gb of ram). I I can add to my OP with code it that would help. Thanks
Jan
23
accepted R - How to sampleRandom() from large raster without NA values
Dec
20
comment R - How to sampleRandom() from large raster without NA values
thank you very much for thinking out this approach. I agree that the aspect of sampling without replacement will be very useful and cut out some waste; this approach executes very quickly. However, I must be misunderstanding part of the code. When I execute this on my raster with real-world coordinates, the matrix a contains coordinates from z, but not r_mask. I see that z <- getValues(r_mask)[z] acquires the correct values based on cell number from runif(m*n), but a <- cbind(x[i], y[i], z[i]) is binding row/column number to those values. Thank you again for helping.
Dec
19
comment R - How to sampleRandom() from large raster without NA values
Thanks again Jeffrey. I have plenty of ram, so loading it into memory is probably doable. That is the approach I took to sampling values from the raster; when X,Y coord were not important. I would appreciate more details on the sp object approach.
Dec
19
revised R - How to sampleRandom() from large raster without NA values
added third example to help reproduce the error, fixed typos
Dec
19
comment R - How to sampleRandom() from large raster without NA values
Whuber, I appreciate your willingness to help with this problem. I have edited my original post to include a third example that when run on my machine recreates the erroneous results.
Dec
19
revised R - How to sampleRandom() from large raster without NA values
added third example to help reproduce the error
Dec
19
comment R - How to sampleRandom() from large raster without NA values
It appears sampleRandom() has a raster ncell() size limit, or a NA to non-NA value ratio limit, after which na.rm=TRUE only returns the list of cells with value and does not dig back in to replace the NA values it sampled. Hence returning a matrix of 117 by 3 with no NA values when sampleRandom(geo.r_mask,2000, na.rm=TRUE, xy=TRUE) is called. geo.r_mask being a 5202, 8182, 42562764 (nrow, ncol, ncell) raster with only 637506 cells with non-NA values.
Dec
19
comment R - How to sampleRandom() from large raster without NA values
Thank you for your observation whuber. You are correct; the simulated data above is to demonstrate how it is supposed to work. Because of file size, I cannot provide the data set for which it does not work. However, I provide the code to show that it is the same method as the working simulated data example. The image at the bottom shows the complexity of the shapefile mask. Everything within the mask has a raster value. The NA values are coming from the region beyond the shapefile mask edges, but within the raster extent.
Dec
19
revised R - How to sampleRandom() from large raster without NA values
edited to fix typo in demo code