New answers tagged

0

It's because plot3D is just scaling the z values to deal with the radically different scales in plotting "heights" against longitude/latitude values. It's better to scale the aspect ratio since you don't then have to fake anything. Try this, see how everything is perfect with adjust = FALSE - it's just that degrees and metres don't belong in the same ...


0

Spacedman ist probably right but you could subset your dataframe before plotting like: df <- df[df$Z < 300,] spplot(df, "Z")


0

writeOGR should be the way to go. I believe you were pretty close with the code you provided in the comments. However, adding a couple of things to the writeOGR function will help ensure that the file is written. If you add dataset_options="GPX_USE_EXTENSIONS=yes", then you will no longer get the error, "Creating Name field failed". Below is my example ...


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


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 ...


0

Merge the attribute table back to the fortified geometry: # by.y=0 join by row.names roads.df <- merge(fortify(roads), as.data.frame(roads), by.x="id", by.y=0) p <- ggplot() + geom_path(data=roads.df, aes(x=long, y=lat, group=group, colour=MIN), size=1)


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

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

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 ...


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,]) ...


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) ...


0

I found a possible solution with the raster package combined together with the input of the STFDF function which are n spatial locations, m times and n x m observations. This input is computed by the function mySTGrid and then used for the "rasterplot", properly performed in the RasterPlot function: library(raster) # 51, 101, 101 grid dimensions - 1 (time ...


0

If you return a query with 'ST_AsText(geom) as geomwkt' and fetch the result into data, you can use: library(rgeos);library(sp) wkt_to_sp <- function(data) { #data is data.frame from postgis with geomwkt as only geom SpP <- SpatialPolygons(lapply(1:length(data$geomwkt), function(x) ...


0

The short answer is that if you can use raster package to read these as index-referenced layers then you can simply treat the coordinates as "values". Raster still makes this much easier than juggling NetCDF calls, but you need to know what's going on. It may be that the coordinate values are actually just stored redundantly, and you can collapse to the ...


0

Extending on @Spacedman's answer, creating a stacked map like the one shown in the question becomes quite simple. You just need to add another map layer and displace its y axis: e.g. aes(x=x, y=y+5) : ggplot(data= ofort) + geom_polygon( aes(x=x, y=y, group=id), fill= "white", color="gray30") + # layer 1 geom_polygon( aes(x=x, y=y+5, group=id, ...


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 ...


0

There are some multiple regressions (including GWR) functions in SAGA GIS that offer many options of rasters as predictors, dependent variables and outputs. I hope it can help you.


0

actually, i worked something out; following the line; rc.d <- disaggregate(ras.coarse,fact=2) do not create any rasters of disagreement or that sort of thing but stack the base raster and the disaggregated raster and extract the raster cell values in the stack as a data frame, and then shrink this new data frame by counting each unique row; st <- ...


0

The National Snow and Ice Data Center has a dataset along these lines. NSIDC Dataset The problem now becomes, how do you convert a .dat into a usable raster. I tried writeRaster but this wont work for me. Any suggestions?


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 ...


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 ...


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


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 ...


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 = ...


0

osm2shp.ru here you can download openstreetmap data in shapefiles format. Data divided by regions: North and South America, Australia and Oceania, Africa, Europa and Asia.61 layers for download. Data filtered by "Map Features" conditions.


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 = ...


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 ...


0

The histograms are different. head(table(one)) ##one ##31 32 33 34 35 36 ## 1 2 1 2 2 2 head(table(two)) ##two ##18 19 22 23 24 25 ## 2 1 3 4 2 5 stem(one, 0.5) # The decimal point is 1 digit(s) to the right of the | # 3 | 1223445566778888999 # 4 | 00012223333344444444455555555566666667777777778888888888899999999999 # 5 | ...


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

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

+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

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 ...


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 = ...


0

Here is how you can do that, I think. I am following this example: library(raster) library(rgeos) library(rgdal) # example data p <- shapefile(system.file("external/lux.shp", package="raster"))[, 1] p$Color <- rep(c('blue', 'green', 'red'), 4) p <- p[,2] z <- raster(p, nrow=2, ncol=2, vals=1:4) names(z) <- 'Zone' z <- as(z, ...


0

One way would be to get a list of the state names and add them like this library(XML) library(ggplot2) doc <- htmlParse(readLines("https://www.countries-ofthe-world.com/countries-of-africa.html")) countries <- tolower(xpathSApply(doc, "/html/body/div/div/div/div/div/ul/li[not(@class)]", xmlValue)) ggplot() + borders(regions = countries) Some names ...


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)) ...


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 ...


0

So I was able to take the data from the GPW link above and load that into R with simply raster("path to .bil file"). Converting resolution and dealing with the extent was pretty simple too. Here's how it originally looked: class : RasterLayer dimensions : 3432, 8640, 29652480 (nrow, ncol, ncell) resolution : 0.04166667, 0.04166667 (x, y) extent ...


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 ...


0

It looks like you have a single point in the shapefile you are trying to crop to and the error message isn't exactly right. Lets' try and simulate that with a reproducible example: b <- brick(system.file("external/rlogo.grd", package="raster")) p=data.frame(x=50,y=35) # a point in the middle of b coordinates(p)=~x+y Then: > extent(b) class : ...


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 # ...


0

There is a couple of things wrong with this: mat <- matrix(1/25,ncol=5, nrow=5) raster_res <- focal(raster1, mat, FUN="mean", na.rm=T) The argument to supply the function is called fun, not FUN. You give each value a weight of 1/25, and then you want to use "mean". However, you should use "sum" in that case! (which is the default, and because you ...


3

Yeah, this is a tricky one. The "dsn" argument is the output file and the "layer" argument is the GPX feature type (eg., waypoints). This is how ESRI file geodatabases work as well. There is no clear direction in this anywhere but you also have to use the "dataset_options" argument with "GPX_USE_EXTENSIONS=yes". I got this example to work. library(rgdal) ...


0

I know this does not answer the question in R. but if you have ArcGIS you can download this tool to convert and feature to GPX http://www.arcgis.com/home/item.html?id=067d6ab392b24497b8466eb8447ea7eb. Then you can upload those GPX coordinates to an app called http://www.gpxnavigator.com/.


1

You can use the writeOGR module to export to any geospatial format supported by OGR, including GPX. It is part of the rgdal package. Here's an article covering the writeOGR module and here's the OGR manual's GPX driver page



Top 50 recent answers are included