Hot answers tagged

5

The examples in your link look like the coordinates have been transformed via a shear and a scale matrix. You can easily apply this to the coordinates you get from the usual fortify/join data that ggplot requires. Need a unique character ID value: oregon.tract$id=as.character(1:nrow(oregon.tract)) Fortify on that ID and join attribute data: ofort = ...


4

You are confusing terms and thus, confusing us. The expected input for kriging prediction in the gstat krige function is a systematic array of points and not polygons. It would also be nice if you provided a reproducible code example of what you have tried. You can use the extent of an sp object to create an array of points for the kriging prediction using ...


4

You can use the extract function with the cellnumbers = TRUE argument. This will return the cellnumbers and associated values for each polygon. First, add require libraries and create some example data, raster with NAs and polygons. library(sp) library(raster) set.seed(0) r <- raster(ncols=10, nrows=10) r[] <- runif(ncell(r)) ...


4

Some simple raster arithmetic should sort this out for you. First make a raster where its NA anywhere except where the original was equal to 2: > rp2 = rp ; rp2[rp2[]!=2]=NA > plot(rp2) Now we can buffer that to 20m: > rp2b = buffer(rp2, 20) > plot(rp2b) Now the ring of the buffer is where rp2 is NA and rp2b is not NA: > rbuff = ...


3

Reproducible example, just fix the script to make a dummy data.frame. voronoipolygons = function(layer) { require(deldir) crds = layer@coords z = deldir(crds[,1], crds[,2]) w = tile.list(z) polys = vector(mode='list', length=length(w)) require(sp) for (i in seq(along=polys)) { pcrds = cbind(w[[i]]$x, w[[i]]$y) pcrds = rbind(pcrds, pcrds[1,]) ...


3

Well, your projection is "longlat", ellipsoid "GRS80" and datum "NAD83", so the data is unprojected and in decimal degrees. This is why is projected is returning FALSE. If you want your data to be projected you first need to choose a projection then use spTransfrom to reproject it. Since we know nothing about your data, like where it is, it is difficult to ...


3

Yes, it is possible to launch the GRASS GUI from R within a running GRASS session. It did not work because the environment variables where not correctly set. Modifiying the environment variables as follows solved the problem: # Set PYTHONPATH Sys.setenv(PYTHONPATH = ...


3

Here is an example. library(raster) # example data x <- raster(system.file("external/test.grd", package="raster")) To get the rectangular extent e <- extent(x) # coerce to a SpatialPolygons object p <- as(e, 'SpatialPolygons') To get a polygon that surrounds cells that are not NA # make all values the same. Either do r <- x > -Inf # ...


2

Speed up extracting raster (raster stack) from point, XY or Polygon Great answer Luke. You must be a R wizard! Here is a very minor tweak to simplify your code (may improve performance slightly in some cases). You can avoid some operations by using cellFromPolygon (or cellFromXY for points) and then clip and getValues. Extract polygon or points data from ...


2

With the updates in the packages I would suggest the following: shape <- shape[!is.na(shape@data$col),]


2

Use the corrected script Bug report #14608: Processing: Kriging rscripts/Kriging.rsx Automap problem and correction, accepted in the master (Kriging.rsx) It is not a problem of QGIS, it is a problem with you R packages installation. 1) Processing use the Python subprocess module to execute directly the R commands 2) it use an intermediate file named ...


2

The proj string does not contain an EPSG code. You can use EPSG:4269 or +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs. Some softwares try to guess the EPSG code from the string, and sometimes they fail, and treat it as a custom CRS. EPSG:4269 has degrees as units, and is not a projected coordinate system, but rather a geographic coordinate ...


2

Simply overlay a reclassified focal mean or distance grid of the polygon indicator. The focal mean requires a circular neighborhood w. Here is a way to create it in terms of the radius, 20. It starts with constant values (line 4). Values beyond the desired radius are zeroed out (line 5). The result is normalized to sum to unity (line 6). radius <- ...


1

Here are some examples, on this forum, that provide some approaches that could be adapted to your problem. Randomly sampling points in R with minimum distance constraint Distance to nearest point for every point same SpatialPointsDataFrame in R Find clusters of points based distance rule


1

Since you cannot really define contingency based on common boundaries (using something like spdep::poly2nb), you could use the polygon centroids to build a k nearest neighbor relationship. This will unfortunately not account for polygon size but is a good place to start. require(spdep) require(rgdal) polys <- readOGR(system.file("etc/shapes/", ...


1

If your projection of your points are the same as the raster then you can just pull the proj4string slot from the raster and assign it to the raster. Reading the data, coercing the csv to a SpatialPointsDataFrame and assigning the projection from the raster, would look something like this (not tested): library(sp) library(raster) r <- ...


1

Are you trying to do something as simple as this? > FRAl = as(FRA,"SpatialLines") > FRAp = as(FRAl, "SpatialPoints") > FRAr = rasterize(FRAp, residual_grid, mask=TRUE) > plot(FRAr) The conversion to points before rasterisation should be unneccesary, I think rasterize(FRAl,....) should work, but is very slow on my machine. So slow I was too ...


1

Figuring out the GPX driver options for rgdal is headache-inducing. Writing a linestring as you've done here will cause it to write a route layer - if you write a multilinestring it should create a track layer. According to the documentation you should be able to make it be a track layer regardless using FORCE_GPX_TRACK=true but I've not been able to make ...


1

Why don't you take a sampling approach? Using sampleRandom or sampleRegular with sp = TRUE, you could draw samples from each raster and then just use table. If you used two different sample sizes with sampleRegular you can unalign the sampling grid to revel potential error at representing different scale variation or anisotropy. You could also use spsample ...


1

fmt has nothing to do with the spacing of legend items. For a detailed description of fmt please see Use C-style String Formatting Commands. Simply paste the following code snippet in your R console to see the differences (pi ~ 3.14): sprintf("%f", pi) sprintf("%.3f", pi) sprintf("%1.0f", pi) sprintf("%5.1f", pi) sprintf("%05.1f", pi) sprintf("%+f", pi) ...


1

So i finally made it ! with the following code map<- ggplot(data = plot.data, aes(x = long, y = lat, fill = value, group = group)) + geom_polygon() + coord_equal() + facet_wrap(~variable,labeller = as_labeller(names)) then map+geom_path(data=africa.f, aes(x=long, y=lat, group=group), lwd = 0.01,inherit.aes = F) The trick was the ...


1

R spatial objects don't follow the Simple Features standard so the features types don't map to things like wkbMultiPolygon etc. Note: Examples that follow use sample data sets defined from help(readOGR) R spatial objects are either (usually) points, lines, or polygons. You can get the class of the object to see which it is. > class(cities) [1] ...


1

The problem you are experiencing is actually twofold. Firstly, and as pointed out by @EdzerPebesma, you are not loading the required packages on each of the 4 nodes separately. You have to use clusterEvalQ to tell each node which packages it is going to need to fulfill the required (spatial) tasks. Secondly, you need to assign a proj4string to the polygon ...


1

I'm having a hard time understanding your exact question, but it is certainly possible to mix and match esri-leaflet with other leaflet plugins. you can find an example that mashes up with Leaflet.Elevation here: http://johngravois.com/esri-leaflet-gp/elevation.html https://github.com/jgravois/esri-leaflet-gp/blob/master/elevation.html


1

+no_defs - Don't use the defaults from the defaults file. +proj=longlat - This refers to a geodetic/geographic CRS. This means the longitude is the X axis and latitude is the Y axis.


1

You are providing spurious information and omitting important information. I do not care that you are plotting over the "wrld_simpl" data but would like to know what the resulting object classes are and if there are any attributes in the SpatialPixelsDataFrame and resulting raster objects. I would ask, why are you projecting to the same projection? The ...


1

Just for the record (as I pointed out above, your leaflet code should work just fine): you could use mapview (which, at least when dealing with small datasets like yours, serves as a convenient wrapper around leaflet) to accomplish this. Note that you are required to create a proper 'sp' object from your sample data using coordinates and proj4string prior to ...



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