For a variety of reasons, I have not been able to do much work on raster
for the past year. And most of my thinking about it, and some work, has
been around a next generation replacement that is simpler in use and much
faster.
But for now, over the coming months, I will make sure that it gets updat
Works for me like this
library(raster)
r1 <- raster (matrix(ncol=3, data = 1,nrow = 3))
r2 <- raster (matrix(ncol=3, data = 21,nrow = 3))
r3 <- raster (matrix(ncol=3, data = 72,nrow = 3))
rst <- stack(r1, r2, r3)
calc (rst, mfri.test)
Here is an improved version (I think) of mfri.test
mfri.te
The raster way would be:
library(raster)
m <- lapply(c("TZA", "UGA", "GHA"), function(x) getData("GADM",
country=x, level=1))
m <- do.call(bind, m)
Robert
On Sat, Jul 23, 2016 at 4:10 AM, Bacou, Melanie wrote:
> Edzer, Rolf,
> Many thanks for the clarification!
> Just to confirm that Rolf's `do
Tim, here is an an approach:
library(raster)
b <- brick(system.file("external/rlogo.grd", package="raster"))
p <- SpatialPoints(cbind(sample(77,10), sample(77,10)))
methods <- c("bilinear","simple","bilinear")
k <- methods == "simple"
x1 <- extract(b[[which(k), drop=F]], p)
x2 <- extract(b[[which
That still misses the point completely. Geopackage is just another
format out of many. For a map you make in R, it normally should not
matter how the data used may have been stored. Perhaps it would be
more appropriate to call it the SpatialPolygons contest; but I think
that what you have in mind i
Here is a solution using optimization
library(raster)
library(rgeos)
set.seed(7)
n <- 4
xy <- cbind(runif(n), runif(n))
f <- function(p) { max(pointDistance(rbind(p), xy, lonlat=FALSE)) }
p <- optim(colMeans(xy), f)
cc <- buffer(SpatialPoints(rbind(p$par)), width=p$value, quadsegs=45)
plot(cc)
Alex,
You should provide a full reproducible example. You can get the
boundaries via raster::getData, and you can create a raster in memory.
Your script should also indicate the packages you use.
To get the area of the polygons, I would do
library(raster)
nga <- getData('GADM', country='NGA', lev
> library(raster)
> library(spatstat)
( ...)
The following objects are masked from ‘package:raster’:
area, rotate, shift
So either do not load spatstat or call the raster function explicitly
raster::area(x)
Best, Robert
On Wed, Jun 8, 2016 at 12:49 PM, Alex Fitz wrote:
> Hi,
>
> I have a
This (zapply passing ellipses arguments to stackApply) was fixed, I
think, in the development version. You can try it if you want:
install.packages("raster", repos="http://R-Forge.R-project.org";)
On Sat, Jun 4, 2016 at 1:59 PM, Thiago V. dos Santos via R-sig-Geo
wrote:
> Thanks again Loïc and
For lon/lat coordinates, you can use the circles function in "dismo":
library(dismo)
r <- raster(system.file("external/rlogo.grd", package="raster"))
pts <- data.frame(x=c(17, 42, 85, 70, 20, 53, 26, 84), y=c(28, 73, 38,
56, 0, 29, 63, 22))
c1 <- circles(pts, lonlat=FALSE, d=9, dissolve=FALSE)
c2
Karla,
You can do
library(raster)
slices <- bind(slice1, slice2)
Robert
On Sun, Apr 3, 2016 at 6:53 AM, Karla Shikev wrote:
> Dear all,
>
> This might be a newbie question, so I'd appreciate your patience with this.
>
> I'm obtaining climatic data from worldclim and generating polygons based on
Here is a more direct (and safer) way:
library(raster)
set.seed(0)
r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
s <- stack(lapply(1:5, function(x) {setValues(r, round(runif(22 * 20,
min=0, max=600), digits=0))}))
intervals <- seq(0, 600, 100)
x <- cut(s, intervals, includ
How about this:
b <- brick(system.file("external/rlogo.grd", package="raster"))
classified <- b / 255
threshs <- c(.1, .3, .5)
x <- classified < threshs
y <- max(x, na.rm=TRUE)
z <- reclassify(y, cbind(0, NA))
Robert
On Tue, Dec 22, 2015 at 1:57 AM, Mathieu Rajerison
wrote:
> Hi,
>
>
> I use
Mark,
Thanks for that clear report. This unexpected order of the layers
returned by stackApply is due to a bug which only reveals itself if
"unique(indices)" is not sorted from 1 to n.
This has been fixed in version 2.5-1 (you can now also use a factor
variable, but that should not matter). This
.) :
> 'ncol(x)' and 'nrow(fobj$par$modq)' should be eaqual
>
>
> Any way to circumvent this?
>
> Greetings,
> -- Thiago V. dos Santos
>
> PhD student
> Land and Atmospheric Science
> University of Minnesota
>
>
>
> On Saturday, October 17,
Thiago,
> Therefore, I need to load data as rasters and iterate through all individual
> gridcells to create a data frame containing:
> date1, cell1, cell2, cell3, ..., cell3600
> date2, cell1, cell2, cell3, ..., cell3600
> date3, cell1, cell2, cell3, ..., cell3600...
> date408, cell1, cell2, cel
Kevin,
I think you can do that like this:
library(raster)
b <- brick(system.file("external/rlogo.grd", package="raster"))
hsv <- overlay(b, fun=rgb2hsv)
Best, Robert
On Fri, Oct 16, 2015 at 3:52 PM, Kevin Wolz wrote:
> Does anyone know if there is any pre-existing functionality to easily
> c
John
Thank you for reporting this. This has now been fixed in raster-devel
install.packages("raster", repos="http://R-Forge.R-project.org";) and
soon on CRAN.
The error (always using the first level on extraction of cell values)
occurred in ncdf files with "levels" as fourth dimension (rather than
Ashraf,
Here is an approach:
# some random points
x <- runif(1)
y <- runif(1)
xy <- cbind(x, y)
# a raster to specficy the extent and resolution
library(raster)
r <- raster(round(extent(xy)), res=0.1)
# find the distance of each point to the center of the cell it falls in
cell <- cellFro
Ana Carolina,
You say you are using ascii because:
> i am trying to process a raster image (the one i transformed to ASCII)
> but it is too big to work with it as a raster in R (i am having memory
> problems)...thats why i am trying to see if its simplier to process it
> in ASCII and then bring i
Hi Agus,
Your example works for me without error.
Can you update.packages() and try this in a clean workspace? (perhaps
another package is interfering?)
Robert
On Wed, Oct 7, 2015 at 2:44 AM, Agustin Lobo wrote:
> According to the help page of raster::boxplot
> x: Raster* object
> y: if x is a Ra
You can also try this:
f <- function(lai) {
emiss_0 <- 0.95 + (0.01 * lai)
emiss_nb <- 0.97 + (0.0033 * lai)
i <- lai >= 1000
emiss_0[i] <- 0.95
emiss_nb[i] <- 0.98
cbind(emiss_0, emiss_nb)
}
library(raster)
rlai <- raster(ncols=360, nrows=180)
rlai[] <- 1:ncell(rlai)
x
There is no need to 'make a copy of the attribute table' of the sp
object. Instead, you should be able to do:
library(sp)
# From https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html
states <- readOGR(dsn = "./cb_2014_us_state_5m.shp", layer =
"cb_2014_us_state_5m")
states <- merge(sta
Thomas,
I do not think it is wishful thinking. Au contraire, I think it is how
it should be done. That is, if you start with a longitude/latitude
raster with elevation values, and want slopes (or similar) also in
that coordinate reference system, then this should be the way to go,
as you skip two t
5,5,4,4)),hole = F)),
> "2_")))
> for (i in 1:4){
> plot(p4[i,],col=cols[i],axes=T,xlim=c(0,5),ylim=c(0,5))
> }
> print("Areas p4:")
> print(gArea(p4, byid=TRUE))
>
>
> On Wed, Aug 12, 2015 at 11:02 AM, Robert J. Hijmans
> wrote:
>>
>> I wo
geosphere functions makeLine and makePoly do this, but only for
lon/lat, not for planar coordinates.
Robert
On Fri, Aug 7, 2015 at 6:30 AM, Michael Sumner wrote:
> This is a nice idea with gBuffer, but testing on a simple case shows you
> need explicit curvature to get any extra verts.
>
> librar
I would think raster::union(polygons) should get you there.
Robert
On Tue, Aug 11, 2015 at 7:58 AM, Michael Sumner wrote:
> On Mon, 10 Aug 2015 at 17:52 nevil amos wrote:
>
>> I am attempting to combine overlapping polygons in a
>> single spatialPolygonsDataFrame so that the output is a set of p
Josep,
I take it you have three variables, and want to create a raster for
the third variable, based on the other two, that are also represented
as rasters. If so, you can
# make a three column data.frame
d <- data.frame( x=c(23,25,27), y=c(33,34,35) , z=c(0.1,0.2,0.3))
# your two rasters, repre
Jerome,
rasterize is indeed a bit slow, it is #1 on the list of functions that
need a rewrite for speed. However, I think your assumption is wrong.
You can rasterize all fields in one step, and it is pretty quick for
the example data:
library(raster)
polyg <- shapefile("polyg.shp")
grain <- 50
ns
Jim
You can try
library(raster)
x <- crop(roads, polygons)
Robert
On Fri, Jul 10, 2015 at 11:17 AM, Jim Burke wrote:
> Clipping a SpatialLinesDataFrame by an envelope "SpatialPolygons" results
> in a bare bones "SpatialLines" with no "@data" slot. The "out" file is a
> roads file which plots fi
Hi Ben,
I would not think this has to do with memory limitations. The error
message suggest that you have a bad file, and, hence, that the problem
is with the software that created the file, or with an interrupted
download.
Robert
On Sat, Jul 4, 2015 at 6:24 PM, Ben Weinstein
wrote:
> Hi all,
>
>
Dominik,
The last part of your example does not run. If I understand you well,
this is what you are after (but it all looks good to me):
library(raster)
# raster data with long and lat values
r <- raster(xmn=-112.25, xmx=-104.125, ymn=33, ymx=43.75, res=1/240)
lat <- init(r, v='y')
lon <- init(r,
And for longitude/latitude data you can use geosphere::dist2Line
Robert
On Tue, Jun 23, 2015 at 8:13 PM, GeoTux Tuxman
wrote:
> Hi Juta, you can do this (only with planar coordinates):
>
> require("maptools")
> coordsLine = cbind(c(1,2,3),c(3,2,2))
> coordsPoint = c(1.2,1.5)
> nearestPointOnLine(
Andrea,
One small addition. To get all layers (one for each day, in stead of
the single layer you get with 'raster'), use the brick function:
b <- brick("tmin_1980.nc4")
Robert
On Fri, Jun 5, 2015 at 4:52 PM, Michael Sumner wrote:
> Just another short comment below
>
> On Sat, 6 Jun 2015 at 09
The problem is with dynatopmodel::upslope.area that uses
xres(x)==yres(x)
where
all.equal(xres(rast), yres(rast))
would be appropriate. One should not compare decimal numbers for
equality using '=='.
rast <- raster(nrows=4072, ncols=3111, xmn=656419.81022503704298,
xmx=730403.8816690669627
Jean-Luc.
It is as you say, intersect returns Spatial*DataFrame objects whereas
gIntersect does not the DataFrame bits.
This pattern is also true for raster functions aggregate, union,
erase, cover and crop (see section XIV in ?'raster-package') which all
have their analogues in rgeos that they bu
These would seem to be plausible, and correct, values. I do not think
there is anything wrong NA values. The extreme values are because you
divide by a fraction. How would you expect the results to be
non-negative if you divide by negative values?
Antonio's answer is incorrect, as division with an
It works for me. I get:
> library(raster)
Loading required package: sp
> library(ncdf4)
> raster("E:/downloads/201407291200", ncdf=T, varname='DSSF')
class : RasterLayer
dimensions : 651, 1701, 1107351 (nrow, ncol, ncell)
resolution : 1, 1 (x, y)
extent : 0.5, 1701.5, 0.5, 651.5
This suggest that most of the time is spend on reading data from disk.
It could be more efficient to do this in one step.
m <- .colMeans(getValues(cmip), nrow(cmip), ncol(cmip), na.rm=FALSE)
I do not think there is much more you can do beyond that --- although
a solid state hard disk could help.
stall from local zip file" in Rgui). Just a tiny bit
of additional effort.
Robert
On Tue, May 5, 2015 at 2:20 PM, Michael Sumner wrote:
>
>
> On Wed, 6 May 2015 at 03:28 Robert J. Hijmans wrote:
>>
>> Even better (renaming not necessary):
>&
There is also a 'scalebar' function in the raster package (I have not
compared the two)
Robert
On Mon, Apr 27, 2015 at 7:59 AM, Gilles Benjamin Leduc wrote:
>
> Not to bad hint :p
>
> So From this one, I modified the function to get it work correctly:
>
> ###
Even better (renaming not necessary):
x <-
raster("E:/downloads/OMI.L2.CloudOMCLDO2Strip200kmAlongCloudSat.2015.05.05.020752Z.v003.he5",
var='Data Fields/ChiSquaredOfFit', ncdf=TRUE)
Best, Robert
On Tue, May 5, 2015 at 10:24 AM, Robert J. Hijmans wrote:
> In whi
In which case you can change the extension to '.nc' and do
library(raster)
library(ncdf4)
x <-
raster("E:/downloads/OMI.L2.CloudOMCLDO2Strip200kmAlongCloudSat.2015.05.05.020752Z.v003.nc",
var='Data Fields/ChiSquaredOfFit')
Robert
On Tue, May 5, 2015 at 5:28 AM, John Baumgartner wrote:
> Not a
Kristin, I think you can do something like this:
lst <- list()
for(i in 1:96) {
Predictors <- stack(stackchl[[i]], stacksst[[i]], stackpar[[i]], lat, lon)
names(Predictos) <- c('chl', 'sst', 'par', 'lat', 'lon')
lst[[i]] <- predict(Predictors, gammodel, na.rm=TRUE, type="response")
}
s <-
If you want to keep the raster cell values, you could do
shapefile(pol2, "polygon2.shp")
and use that file.
On Sat, May 2, 2015 at 2:10 PM, sadaoui wrote:
> Thank you "Robert Hijmans",
>
> it works with this function ;
>
> shapefile(pol3, "polygon3.shp")
>
>
> but I want to have the correspond
" it has not recognized as a polygon!!! I don't know why? "
That is not true:
> class(pol3)
[1] "SpatialPolygons"
attr(,"package")
[1] "sp"
It is not a 'SpatialPolygonsDataFrame'
You can write it with:
shapefile(pol3, "polygon3.shp")
or use the SpatialPolygons object to create a SpatialPolygo
Arnold,
In cases like this you can make a function that computes this for a
vector, test that function, including for a vector of NA values, and,
if it works, use calc.
# counting runs of 255
run <- function(x) {
x[x != 255] <- NA
r <- rle(x)
w <- which(!is.na(r$values))
ifelse(length(w)
Luciano,
The extent you are using to crop is the same as the extent of the
entire extent, so it does not surprise me that there is no change.
Here is an example that works:
library(raster)
library(rgeos)
g <- getData('GADM', country='ARG', level=1)
e <- extent(-63.6, -55.1, -32.8, -27.6)
x <- crop
Mark,
I had not considered the case where the constant is a factor. I need
to fix that. Here is a script that accomplishes what you want, I think
# known presence and absence points
p <- matrix(c(48, 48, 48, 53, 50, 46, 54, 70, 84, 85, 74, 84, 95, 85,
66, 42, 26, 4, 19, 17, 7, 14, 26
Kenny,
Here is an alternative route
library(raster)
states <- shapefile("cb_2013_us_state_20m.shp")
tMaxGrid <- raster(unzippedFiles[1])
x <- extract(tMaxGrid, states)
This returns a list of the length of states. Each list element has a
vector with the grid cell values.
For a mean do
xs <- ext
Walter,
Next time, please try to give as a simple self contained example in R
showing what you have done, and where you are stuck.
Here is how you can intersect lines and polygons, keeping their attributes:
library(raster)
library(rgeos)
# example data
p <- shapefile(system.file("external/lux.s
Forrest, it seems to me that you can simplify and do
output$AC[i] <- length(gIntersection(tmp, ac))
instead of
tmp2 <- as.vector(gIntersects(tmp, ac, byid=TRUE))
output$AC[i] <- length(tmp[tmp2 == TRUE])
Robert
On Tue, Mar 31, 2015 at 11:56 AM, Forrest Stevens wrote:
> I'm guessing based on t
Are these really reasonable reasons? I do not think so, given that the
question had nothing to do with map navigation and the person asking
appears to live in the UK. Moreover, other projections have, or can
have, their units in meters as well (or feet or miles or whatever you
might fancy). UTM ind
Walter,
I think that instead of
gIntersects(buffered_projects, census_blocks, byID=TRUE)
you want
library(raster)
x <- intersect(buffered_projects, census_blocks, byID=TRUE)
and then Step 3
x$newarea <- gArea(x, byid=TRUE)
x$relarea <- x$newarea / x$area
Robert
On Fri, Mar 27, 2015
The raster package 'enhances' as.data.frame for SpatialLines* and
SpatialPolygons*. I am not sure why there is also a function for
SpatialPoints* as it does not add anything, except for setting the
names to 'x' and 'y'. Perhaps that is what I did it for, I cannot
remember. But clearly it is not des
_AGWBC + 1)^(1/0.2626263)-1
> quantile(AGWBC[], c(0.025, 0.5, 0.975), na.rm=TRUE)
> }
>
>
> Check function using calc
> CROP_AGWBC_2 <- calc(testbrick, fun2.CROP_AGWBC)
> plot(CROP_AGWBC_2)
> CROP_AGWBC_2
>
>
> Run function using parallel process
Sean,
fun.CROP_AGWBC refers to objects that are not defined inside the
function ("lm.final" and "lambda_DV"). I assume that this is
intentional and that these represent constants; and that they are
available in your global environment. If so, you need to export these
objects to the cluster nodes.
Karl,
You are using a default RasterLayer which has lon/lat coordinates. In
that case the earth is considered spherical (or similar), not a plane.
The maximum possible distance in longitude is 180 degrees, and the
distance between -120 and 120 is not 240 degrees, but 60+60= 120
degrees, .
To get
The web-service that the function depends on has changed. It should
work with the development version of dismo (version 1.0-8). You should
be able to install it from R-Forge like this:
install.packages("dismo", repos="http://R-Forge.R-project.org";)
Robert
On Sun, Mar 8, 2015 at 11:42 AM, Ahmed
Leo, here is an approach that might work for you:
library(raster)
library(rgdal)
library(rgeos)
library(plyr)
# create some example data.
p <- shapefile(system.file("external/lux.shp", package="raster"))
p <- p[, 'NAME_1']
p <- aggregate(p, 'NAME_1', dissolve=FALSE)
# now we have 3 regions, each
Bastien,
This arises from a change in CRAN policy (the requirement to use
"requireNamespace" instead of "require") which somehow creates a
problem for snow::recvOneData. This is all a bit mysterious to me. The
development version uses require again for the snow package such that
things work as the
MIke, I think you can use the 'calc' function for that:
library(raster)
# example data
set.seed(0)
s <- stack(system.file("external/rlogo.grd", package="raster"))
s <- stack(s, s[[1]]*runif(ncell(s)), s[[2]]*runif(ncell(s))/10,
s[[3]]*runif(ncell(s))+10)
# example vector
v <- 1:6
x <- calc(s, fu
Jean-Luc
I think you can use the disaggregate method (in package sp) for that.
Robert
On Sat, Jan 31, 2015 at 3:17 AM, Jean-Luc DUPOUEY wrote:
> I faced the same question recently: how to tranform a multipart polygon layer
> into single polygons? Here is a little bit more general function to do t
> It seems there is a problem with my R !
It is for a good reason that you are requested to include your
sessionInfo()
information in messages to this list. But even more important is to
first make sure that you are using the current version of R and the
current versions of all relevant package
Your focal weights sum to 1, such that you get the mean value when
using 'fun=sum'
if you want to sum, you can do
fw <- focalWeight(x, 50, type='circle')
fw[fw>0] <- 1
p_focal<-focal(x, w=fw,fun=sum , na.rm=TRUE)
Robert
On Mon, Jan 26, 2015 at 3:17 AM, Vanessa Machault
wrote:
> Hi,
> I have a
This is probably because you are not subtracting areas of holes? To
get areas for SpatialPolygons, use:
library(rgeos)
gArea(vdum)
and in this case for the RasterLayer, I would use
freq(rdum)
Robert
On Mon, Jan 26, 2015 at 7:19 AM, Gregory Duveiller wrote:
> Dear All,
>
> I noticed something
Hi Pascal,
On Wed, Jan 14, 2015 at 11:52 AM, Pascal Title wrote:
> Hi,
>
> I am creating interpolations of global marine diversity via thin plate
> splines, using the interpolate() function in the raster package. The
> problem I am having is that if I plot the spline interpolation and then
> over
P.S. you also need to do:
rf.predict <- predict(rgb.rast, rf.mod)
Not
rf.predict <- predict(rf.mod, rgb.rast)
Robert
On Tue, Jan 13, 2015 at 6:09 PM, Robert J. Hijmans wrote:
> Dave,
>
> The example works if you do
>
> rf.mod <- randomForest(color.frame[, c('r
Dave,
The example works if you do
rf.mod <- randomForest(color.frame[, c('red','green','blue')],response)
instead of
rf.mod <- randomForest(color.frame,response)
color.frame has 4 variables, one with column name "NA". Given that you
use names(color.frame) <- c('red','green','blue') it seems t
David,
I think you could also do this:
library(raster)
a <- disaggregate(aggregate(pols))
ids <- over(pts, a)
Now you have the aggregated polygons and for each point you know which
polygon it belongs to. Perhaps continue with something like this:
tab <- table(ids, as.integer(names(ids)))
tab <
You can also do:
library(raster)
x <- sp1 - sp2
y <- sp2 - sp1
(equivalent to the "erase" function)
On Mon, Jan 5, 2015 at 5:43 AM, Roger Bivand wrote:
> On Mon, 5 Jan 2015, Edzer Pebesma wrote:
>
>>
>> On 01/05/2015 01:53 PM, Roger Bivand wrote:
>>>
>>> On Mon, 5 Jan 2015, Edzer Pebesma wrot
Aseem,
The problem is that you are trying to subset a raster using
latitude/longitude coordinates, while the raster has another CRS.
You can fix this, I think, by assigning the correct crs (you can find
these at http://www.spatialreference.org/)
and then, for example, adjusting your extent, or by
Wade,
I do not think you are doing anything wrong. projectRaster gets
confused because of the uncommon longitude coordinates used by climate
models (0 to 360, rather than -180 to 180)
You can use the 'rotate' function to fix that (ignore the warning), or
by setting the extent, and then proceed. Se
>From the traceback
8: .readCellsGDAL(x, uniquecells, layers)
it seems to me that the error occurs here:
extract(elev, points)
and that it has nothing to do with the size of the raster. I am not
sure what causes it.
Could you perhaps email me the points?
Thanks, Robert
On Wed, Dec 17, 2014
Peter,
This is a simplified version of your script untested, of course, given you
send you no data):
library(gstat)
library(raster)
dat71 <- shapefile("d:/FireDanger/IDW/71stations.shp")
sample.grid <- raster("rawsd_71Stations.tif")
#note that there are parameters you need to choose
m <- gstat(fo
Juta,
I think you can do something along these lines:
library(raster)
library(rgeos)
x <- union(districts, rivers)
a <- gArea(x, byid=TRUE)
head(x)
head(a)
or
x <- intersect(districts, rivers)
and compare to 'districts'
Robert
On Sun, Nov 30, 2014 at 2:59 PM, Juta Kawalerowicz
wrote:
> Hi,
> Since I have your attention Mr. Hijmanns I ask a quick extra question - in
> the cellStats you mention that it will fail "gracefully" for very large
> rasters (not my case here since it gracefully succeeded), do you know what
> is the limit of cells for that failure?
&
Nuno,
> The "hist" function from the raster package uses a maximum of 100 000
> values for generating the histogram
That is the default, but you do not have to use that. Did you read the
help file??
?raster::hist
Shows that you can set the "maxpixels" to any number you want. E.g.
maxpixels=Inf
Steven,
Please do provide a self-contained example when you ask a question
(see my example below) and try to use correct terms. You are dealing
with SpatialPolygonDataFrame objects (shpA, shpB), these objects are
perhaps derived from shapefiles, but it is not what they are. Also,
providing a moti
Steven, I believe you can use something like the below
library(raster)
# example data (p, d)
p <- shapefile(system.file("external/lux.shp", package="raster"))
r <- raster(p)
values(r) <- 1:ncell(r)
d <- as(r, 'SpatialPolygonsDataFrame')
# approach 1
x <- intersect(p, d)
# approach 2
y <- union(p
Alessandra,
This is pretty straightforward but you need to do your part (show us
what you have done) using a simple reproducible example. For example,
you can use the North Carolina data that comes with spdep. That
package also allows you to identify neighbors.
library(spdep)
library(raster)
nc
that...
Robert
On Thu, Oct 23, 2014 at 9:46 AM, Robert J. Hijmans wrote:
> I think the below is a solution:
>
> library(raster)
> # create some lines
> cds1 <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60))
> cds2 <- rbind(c(-10,0), c(140,60), c(160,0), c(140,-55))
I think the below is a solution:
library(raster)
# create some lines
cds1 <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60))
cds2 <- rbind(c(-10,0), c(140,60), c(160,0), c(140,-55))
cds3 <- rbind(c(-125,0), c(0,60), c(40,5), c(15,-45))
lns <- SpatialLines(list(Lines(list(Line(cds1)), "1"),
Chane,
You can use b <- brick(array)
# for example
library(raster)
r <- raster(ncol=3, nrow=3)
r[] <- 1:ncell(r)
s <- stack(r,r*2,r*3)
a <- as.array(s)
brick(a)
Robert
On Mon, Oct 13, 2014 at 3:00 PM, Chane wrote:
> Dear list,
>
> I have a multiple dimension array (9 x 9 x 7) and I would lik
Ruari, You might be able to use gCrosses together with optim or
another optimization function to find the best route. Below is a very
simple example. For more complex polygons you may need to allow for
several intermediate points (perhaps following the polygon boundary at
times). Unless you want to
Leigh,
I am at loss by what you mean with "shapefile" in this context
(SpatalPolygons object? or raster data given your reference to
cells?), but raster::shift is probably the function you are looking
for.
Robert
On Sun, Oct 5, 2014 at 8:18 AM, Leigh Kroeger wrote:
> Hello all,
>
> I have realise
Anna-Marie,
If I (and Frede) understand the problem, then you can use the
raster::pointDistance function or similar functions in the geosphere
package.
dat <- read.table(text =
"lon lat Date Time Speed Direction col_lat col_long dist_col trip_no
bird_id trip_id DT date_time
7.87248 54.1866 '04.07
Tyler,
It is probably useful to study the vignette that comes with the raster
package if you have not done so. Also please provide a reproducible
example, if possible, and report the error message you get. Presumably
it is: "Error in which.min(harvest_area) : not yet implemented for
large objects
Brian,
What you can do in a situation like this (clearly a bug; difficult to
reproduce) is with your list "x":
y <- sapply(x, raster) # remove all valus
save(y, file='mosaic.RData')
and send the file (and explanation of how you get the error) to the
package maintainer (i.e., me, in this case).
Rui,
You could create a matrix (=raster) and a function that creates a
valid set of groups of 4 cells that are not adjacent. The function
should return the solution (output matrix values: TRUE or FALSE) and
the sum of the selected values. Then use the optim function to
optimize based on the sum. Wh
The raster package has a few functions that extend rgeos by also
attempting to handle attribute data as well. In this case, see
raster::intersect
And the list of functions here:
?"raster-package"
(section XIV)
Robert
On Sat, Sep 13, 2014 at 10:04 AM, Bernd Vogelgesang
wrote:
> Dear list,
>
> I'm
The below seems to work correctly (albeit slowly).
library(maptools)
library(raster)
library(geosphere)
data(wrld_simpl)
w <- aggregate(wrld_simpl)
af = cbind(16, 13)
ng <- cbind(139, -4)
p <- rbind(af, ng)
dist2Line(p, w)
On Thu, Sep 11, 2014 at 4:13 PM, Agus Camacho wrote:
> I have two spec
Hi Andrew,
There is no need to loop over rasterize. This should do it:
library(raster)
n = 500
set.seed(232)
x = rnorm(n, -96, 5)
y = rnorm(n, 32, 5)
xy = cbind(x, y)
r = raster(nrow=90, ncol=180)
rr = rasterize(xy, r, fun='count')
Best, Robert
On Thu, Sep 11, 2014 at 4:01 PM, Andrew Vitale w
559 3477
> \--| Mobile: +277 3818 9583
> \-/ Website: www.barnabasdaru.com
>/\
> /--\
>
> #…if you can think it, you can do it.
>
>
>
>
>
> On Sep 7, 2014, at 5:23 AM, Robert J. Hijmans wrote:
>
> Barnabas, ,
> You can try something lik
Maurizio,
One typically cares about collinearity because it can lead to a sub
optimal model. The model is only affected by the data it sees.
Therefore only the values at your presence/absence points matter.
Robert
On Thu, Sep 4, 2014 at 7:40 AM, Maurizio Marchi
wrote:
> Hallo everybody,
> I have
I would extract all values and select the ones I need after that. The
alternative is to extract values layer by layer, that is probably less
efficient.
Robert
On Mon, Sep 8, 2014 at 1:55 AM, Kristin wrote:
> Hi
>
> I have a raster brick of 464 layers, each layer representing time defined as
> num
Justin,
See ?raster::predict
Robert
On Wed, Sep 10, 2014 at 7:42 AM, Justin Michell wrote:
> I have aligned raster layers as follows:
>
>> NDVI1
> class : RasterLayer
> dimensions : 1287, 1321, 1700127 (nrow, ncol, ncell)
> resolution : 0.00833, 0.00833 (x, y)
> extent :
(64-bit)
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> other attached packages:
> [1] raster_2.3-0 sp_1.0-15
>
> loaded via a nam
Barnabas, ,
You can try something like this:
b <- brick("~sst.mnmean.nc", varname="sst")
# loop over species, or combine all species into one data.frame?
mydata <- read.csv("~Species one.csv")
extract.mydata <- extract(b, mydata[,5:6])
write.csv(extract.mydata, file = "Species_one_extracted.csv")
Joseph,
The errors go away if you add ellipses to your functions, to let the
na.rm pass through (even if you ignore it).
r3 <- focal (r,w=matrix.weights,fun = function(x,
...){sample(na.omit(x),size=1)},pad=T,padValue=NA,NAonly=T)
The perhaps surprising error with r3 occurs because when NAonly =
1 - 100 of 659 matches
Mail list logo