Tag Info

Hot answers tagged

5

I will offer an R solution that is coded in a slightly non-R way to illustrate how it might be approached on other platforms. The concern in R (as well as some other platforms, especially those that favor a functional programming style) is that constantly updating a large array can be very expensive. Instead, then, this algorithm maintains its own private ...


5

I would drop using the maps package and find a state shapefile. Then load that into R using rgdal, and then do some polygon overlay work. library(raster) # use state bounds from gadm website: # us = shapefile("USA_adm1.shp") us <- getData("GADM", country="USA", level=1) # extract states (need to uppercase everything) nestates <- c("Maine", "Vermont", ...


4

Here is an approach using extract() from the raster package. I tested it with altitude and mean temperature data from the WorldClim website (I limit this example to altitude, temperature works similar), and an appropriate shapefile of the US containing state borders is to be found here. Just download the .zip data and decompress it to your working directory. ...


3

This is a concise way to do that in R --- here without intermediate files: library(raster) raster_data <- list.files(path=getwd()) #promt user for dir containing raster files s <- stack(raster_data) f <- function(x) { rowSums(x >= 4 & x <= 9) } x <- calc(s, f, progress='text', filename='output.tif')


3

Assuming that presencias and variables share the same projection, this should be an easy task. I recommend you to add these lines of code after your read.table() statement in order to convert presencias dataframe to a SpatialPointsDataFrame object (just refine the names of the columns containing x and y coordinates if they differ from my example). ...


3

Looks like the Google reverse geocoding API will break it down for you, take a look at this result: http://maps.googleapis.com/maps/api/geocode/xml?latlng=40.714224,-73.961452&sensor=false If you switch out xml with json, you can get json instead. Another option could be the Nominatim service, which also returns either xml or json.


3

As the name says, a SpatialPolygonsDataFrame is basically just a SpatialPolygons object with data attached (the attribute table). The data must have at least as many rows as there are features library(rgdal) ob <- SpatialPolygons(..)# Your SpatialPolygons Object spp <- ...


2

By making a buffer you approximate the distances (as you do not get a true circle, but a polygonal approximation of one). You can improve the rgeos answer by increasing the number of segments of the circle with the "quadsegs" argument: nbg.bff2 <- gBuffer(nuremberg, quadsegs=50, width = 20000) table( unlist(extract(germany, nbg.bff2)) ) 0 1 118 91 ...


2

Without ever having performed your operation, and no time to spare for play, I can only add these two links to your list: Find the Nearest Raster Cell Value Based on a Vector Point (The first answer (with 4 votes) is what intrigued me). Also: would Hawth's Gridspread help?


2

I'd suggest the spatstat package. Perhaps check out the quadratresample function. They also have several others to simulate random patterns that may fit your need (e.g. rstrat and rsyst). Random sampling should be pretty trivial to accomplish on your own (see the sample function in base R)


2

As I noticed in comments, generally you should avoid using R for non-statistical purposes due to performance issues in certain aspects (working with cycles is an example). Here is code example for you in Pyhton (thanks to this article) for reclassification of a single file with a single band. You will be able to modify it easily for batch processing if you ...


2

"Past and present predictors RasterStack are the same extension, resolution, etc. This is not the problem." Indeed that is not the problem, as that is not a requirement. "The names in the Raster object should exactly match those expected by the model (...) so, according to this, I can't predict my model to another RasterStack that was not used to obtain the ...


2

To summarize the very useful comments by @Spacedman, @JeffreyEvans and @AriB.Friedman, but also to address the questioner's second problem about saving the generated subset and to provide a reproducible example for future audience, let me add a brief example to cover the whole topic. In fact, I'm much more often working with raster data than point or polygon ...


2

You can do library(raster) r <- raster(matrix) # replace with correct coordinates extent(r) <- (0, 1, 0, 1) r <- writeRaster(r, 'filename.tif') But your question suggests that you would have been better of accessing the ncdf file as a RasterLayer object (and avoid creating matrices and keeping track of coordinates) pft <- ...


1

Don't use readGDAL. It reads into a Spatial* object which might not be a good idea.. Use the raster package. It can read GDAL things into Raster objects. These are a good thing. r = raster("/path/to/rasterfile.tif") will read it into r. Your classification is then t = r > 4 & r <= 9 The big question is whether to output these to new raster files ...


1

Welcome to SE-GIS! It is great that you have read the manual (as most people often forget to do it)! As it was said in the instruction - the names of the predictors must be the same that was used for training. The name of the predictors if you use 'raster' package are generated as 'raster_name'(without extension)+'.'+'band_number', e.g. 'imagery.tif' with 2 ...


1

As a footnote to this and a shameless author's plug, the free sDNA (spatial Design Network Analysis) plugin for ArcGIS can do this, among other things that may be of interest to you. You would first need to ensure your network was correctly noded (i.e. all lines breaking where there are junctions; Topology->Planarize can do that).



Only top voted, non community-wiki answers of a minimum length are eligible