Tag Info

Hot answers tagged

6

Seems to be a simple application of gDifference from the rgeos package: > require(rgeos) > ukhole = gDifference(uk, lnd) Warning message: In RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, "rgeos_difference") : spgeom1 and spgeom2 have different proj4 strings > plot(ukhole) The projection warning is because the LondonBoroughs shapefile doesn't ...


3

I've created a small function for this very purpose and it has been used by others with good reviews! gClip <- function(shp, bb){ if(class(bb) == "matrix") b_poly <- as(extent(as.vector(t(bb))), "SpatialPolygons") else b_poly <- as(extent(bb), "SpatialPolygons") gIntersection(shp, b_poly, byid = T) } This should solve your problem. Further ...


3

The problem was that I had run out of space to write to disk, and the map algebra commands I was using were attempting to generate and write large temporary raster files.


2

After a lot of attempts I have this solution, probably not so clean. Comments, improvements or other way to answer are much welcome! ### Preparing the SpatialPointsDataFrame spdf <- matrix(as.numeric(NA), nlevels(Poly$MatchID), 1) spdf <- as.list(spdf) ### Sample the coordinate, match it with data in spdf. It creates a list fore each factor of the ...


2

The formula for global Moran's I is: where i is an index of analysis units (basically, measurement units of of your map, or in your case pixels in the raster) and j is an index of the neighbors of each map unit. The formula for local Moran's I is extremely similar, except that since local Moran's I is calculated separately for each analysis unit indexed ...


2

To answer your question directly, crime obviously follows population, just like disease or any other human "event" you might be measuring. To directly compare you could normalise both population and crime figures to z-scores, and classify each region as HH, LL, HL, LH, or come up with a way to combine the figures, but I think to answer your question you need ...


2

Edit You can try the following: for(i in seq(from=1, to=length(list.ras), by=4)){ Obj <- levelplot(subset(RAD1998.all, i:(i+3))) png(paste("1998_",outlist[[i]],".png",sep="")) print(Obj) dev.off() }


2

You can control the number of plots per graphic device using the mfrow and mfcol arguments in par(). par(mfrow=c(3,4)) for(i in 1:12) {plot(runif(100),runif(100)*0.05)}


2

Since you didn't provide a reproducible example nor an error message, see if this code snippet gets you started: library("raster") x <- getData('GADM', country='ITA', level=1) class(x) # [1] "SpatialPolygonsDataFrame" # attr(,"package") # [1] "sp" set.seed(1) # sample random points p <- spsample(x, n=300, type="random") p <- ...


2

kappa does not quantifies the level of agreement between two datasets. It represents the level of agreement of two dataset corrected by chance. The reason why you have a large difference between kappa and overall accuracy is that one of the classes (class 1) accounts for the large majority of your map, and this class is well described. Overall accuracy is ...


1

The Kappa index of agreement (KIA) will tell you how much better, or worse, your classifier is than what would be expected by random chance. If you were to randomly assign cases to classes (i.e. a kind of terribly uninformed classifier), you'd get some correct simply by chance. Therefore, you will always find that the Kappa value is lower than the overall ...


1

Use crs function. If r is your raster: crs(r) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" Of course, you need to be sure it is the correct projection for your raster.


1

You should use rgdal, specifically writeOGR (which is for vector data) to write the table to Postgis. Note that you must have a spatialdataframe as designated by the sp package (autoloaded with rgdal), I suspect your results of rasterToContour are the correct format. #R code assumes library(rgdal) writeOGR(x, "PG:dbname='BDDMeteo' user=user ...


1

The following example shows two ways to get at the max raster value in a stack. The first utilizes max() which also gives you a host of other useful information. The second method uses maxValue(), which gives just the max value of both the rasters in the stack library(raster) # Generate some georeferenced raster data x = matrix(rnorm(400),20,20) rast ...


1

This is an example of what you can do with rasterVis and sp packages. You will have to adapt to your own use. library(rasterVis) library(sp) # Download States boundaries (might take time) out <- getData('GADM', country='United States', level=1) # Extract California state California <- out[out$NAME_1 %in% 'California',] # Plot raster and California: ...


1

I have committed changes in the repository that implement the axis. Use this code to install the latest development version: ## install.packages("devtools") devtools::install_github("rastervis", "oscarperpinan") Then, use the new argument axis.margin to enable the axis. f <- system.file("external/test.grd", package="raster") r <- raster(f) ...


1

Use the syntax object_ name[,-(1:5)] to remove columns 1 to 5 or object_name[,-c(1,5)] to drop columns 1 and 5. See the example below (with comments): require(maptools) #load shapefile from maptools package to make a reproducible example. xx <- readShapeSpatial(system.file("shapes/sids.shp", package="maptools")[1], IDvar="FIPSNO", ...


1

Well, the official Python wrappers for NetCDF4 are here: https://github.com/Unidata/netcdf4-python


1

I thought I'd answer this myself just in case anyone else with a similar problem ever stumbles on this. Using the above advice on converting my Cartesian coordinates to polar coordinates, I've made a function which calculates a minimum enclosing circle around the x,y coordinates, and divides this circle into a user-defined number of 'grid' cells with equal ...


1

The Java Topology Suite includes a TopologyPreservingSimplifier. The code does not include a reference for the implementation, beyond stating that it operates in a similar manner to Douglas-Peucker, with additional constraints on altering the topology. This functionality has made it into the Java-to-C++ translation of JTS, libgeos, which is further ...


1

Getting a p value is not that easy. Marcon and Lang (Testing randomness of spatial point patterns with the Ripley statistic, http://arxiv.org/abs/1006.1567) have demonstrated that (K1, K2..Kn) where K1, K2..Kn are the values of the Ripley s K function at different distances is a Gaussian vector. They have then computed its mean and covarianace matrix in the ...



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