Questions tagged [r-raster]

raster is an R package for geographic data analysis and modeling.

Other resources

Related tags

1217 questions
6
votes
1 answer

Problem with import raster package: Unable to load module "spmod"

I have installed R (3.5.1) and R-studio (1.1.456) just now (using Anaconda). Then, I installed the raster package (2.9-5). Everything was okay, but when I tried to import, I got this message: > library(raster) Download required package: sp Error:…
6
votes
2 answers

How to extract xy-coordinates from raster where its highest value is located within a polygon?

given is a raster as well as a SpatialPolygonsDataframe. In order to retrieve the highest value of the raster within the area of a polygon, raster::extract can be used. It works fine. How to get additionally the coordinates of the extracted…
N'ya
  • 347
  • 3
  • 13
6
votes
2 answers

How to compute land cover area in R

Basically, I computed a global distribution probability model in the form of ASCII, say: gdpm. gdpm's values are all between 0 and 1. Then I imported a local map from shape file: shape <- file.choose() map <- readOGR(shape,…
Tianjian Qin
  • 525
  • 4
  • 14
6
votes
1 answer

Fill in gaps (e.g. not single cells) of NA values in raster using a neighborhood analysis

With the raster below, with an increased number of NA values library(raster) filename <- system.file("external/test.grd", package="raster") r <- raster(filename) r[r<300] <- NA summary(getValues(r)) is it possible to 'fill in' only the NA cells? I…
B. Davis
  • 3,391
  • 5
  • 42
  • 78
6
votes
1 answer

Convert raster into matrix with R

I'm currently convert original matrix into a raster to use the focal function, then I would like to convert back the raster into matrix. But I have an error message when I try to use the raster function as.matrix(). Even with this very simple…
6
votes
1 answer

Aggregate raster by a non-integer factor with arbitrary function

I would like to aggregate a population raster by a factor of 1.5, summing the values of the cells. While aggregate() allows me to sum values when aggregating, its factor parameter accepts only integer values. projectRaster() and resample() allow me…
coletl
  • 803
  • 5
  • 17
6
votes
1 answer

how to crop raster based on SpatialPolygons in R

I would like to crop a raster based on SpatialPolygons object. I know that we can use crop function in raster package, raster::crop(rasterFile, SpatialPolygonsObject) but this function is based on the extent of SpatialPolygons object, so the…
just_rookie
  • 873
  • 12
  • 33
6
votes
3 answers

portion of a raster cell covered by one or more polygons: is there a faster way to do this (in R)?

Pictures are better than words, so please have a look at What I have is a RasterLayer object (filled with random values here for illustration purposes only, the actual values don't matter) a SpatialPolygons object with lots and lots of polygons…
Where's my towel
  • 561
  • 2
  • 12
6
votes
1 answer

Swap axis in raster brick

Using R's raster package, I have a brick obtained from a file, with the following ncdump header (I show a small example file, the actual file is much bigger): dimensions: lon = 2 ; lat = 3 ; time = UNLIMITED ; // (125000…
AF7
  • 3,160
  • 28
  • 63
6
votes
2 answers

R: Calculate sill, range and nugget from a raster object

I need to calculate the sill, range and nugget from a raster layer. I have explored gstat, usdm packages where one can create variogram however I couln't find a function which given a raster layer will estimate these parameters.In most of the…
Arihant
  • 589
  • 9
  • 24
6
votes
2 answers

How to extract data from a RasterBrick?

I have a RasterBrick consisting of monthly rainfall data over 7 years, so it has 7 layers with 12 slots each: rainfall <- brick("Rainfall.tif") > rainfall class : RasterBrick dimensions : 575, 497, 285775, 7 (nrow, ncol, ncell,…
James
  • 1,164
  • 2
  • 15
  • 36
6
votes
0 answers

Are there thinning or skeletonization algorithm in R for raster objects similar to GIS thinning algorithm (e.g. r.thin, GRASS GIS)?

I know I could execute r.thin from GRASS GIS within the rgrass7 package, but I don't want to build up a grass gis environment, for this task. So are there other solutions in R? Small example, desired output would be the black…
burbot
  • 175
  • 1
  • 5
6
votes
1 answer

How can I speed up extraction of the proportion of land cover types in a buffer from a raster?

I would like to extract spatial data in a buffer of 10 km around 30 000 objects of class SpatialLines and calculate proportion of each land cover type around buffered lines. In a first time, I used the function crop to crop my raster. Then, I used…
Pierre
  • 435
  • 4
  • 14
6
votes
1 answer

How to invert the colors of a ggmap raster image in R?

I'm assuming the Raster package has what I need... I'm simply wanting to invert the colors in a Raster image. The actual scenario is this: I want to invert the raster image returned by a ggmap call: library(ggmap) ggmap(get_stamenmap(maptype =…
dancow
  • 3,228
  • 2
  • 26
  • 28
6
votes
1 answer

R clip raster with multiple bands

I want to create a subset of an image with four bands. Therefore I am using the crop function in R. A<-raster("L8_stacked.tif") subset<-extent(c(639451, 660104, 5469254, 5489566)) B<-crop(A,subset) As a result I get a raster with only one band in…
ropsi
  • 141
  • 2
  • 8
1 2
3
81 82