All Questions
1,780 questions
7
votes
2
answers
7k
views
R export raster to png without margin
I want to export a raster as a PNG image. I don't want borders, labels, legends, axis... all I want is the map covering the whole image.
The data come from here (vegetation cover) and here (...
7
votes
1
answer
3k
views
Difference between raster() and readGDAL()?
I am new in working with rasters and after having trouble working with them i'd like to know the difference between those two import functions.
for example i did this
library(raster)
s<-...
7
votes
1
answer
5k
views
Access to attribute in rasterlayer in R
I read an ADF file in R:
kommuner <- raster( "../../../10-Data/Kommunne_i_Norge_2000/Kommuner2000_100m_100m/100x100_2k/w001001.adf" )
It contains three attributes:
> kommuner
class :...
7
votes
1
answer
4k
views
Filling in missing values in raster using R
I am looking for a robust way to fill in missing values in some rasters. They all have a single layer. Missing values consist of single pixels to medium sized patches. Rasters are around 1000 x 1000 ...
7
votes
1
answer
2k
views
How to speed up extract(rstr,shp) ? - R
I am trying to create a function that takes in a shapefile and a binary (1's and 0's) raster, with the same extent, and extracts the values from the raster. Once this occurs I desire to sum up those ...
7
votes
2
answers
3k
views
Is it possible to use a raster::click event within an interactive leaflet map?
Data Download: https://www.dropbox.com/s/f849ra8l6umo9d8/crops.tif?dl=0
I have various raster images of the world that I would ultimately like to plot within an interactive leaflet map; an example is ...
7
votes
1
answer
4k
views
Legend of a raster map with categorical data
I would like to plot a raster containing 4 different values (1) with a categorical text legend describing the categories such as 2 but with colour boxes.
I've tried using legend such as :
legend( 1,-...
7
votes
1
answer
4k
views
Downsampling, projecting and aligning a raster to fit another one in R: aggregate(), resample() and/or projectRaster(), and in which order?
TL;DR: I have to downsample, project and align a raster to perfectly fit another one. Is it better to a) use aggregate followed by projectRaster or b) first use projectRaster for reprojection only ...
7
votes
1
answer
939
views
Multiple conditional statements for raster calculation in R
In the context of a RUSLE erosion modelling I would like to calculate the sum of precipitation at the entry date of phenological phases.
Suppose I have 13 grids, one of which is the phenophase entry ...
7
votes
2
answers
342
views
Calculating accumulated walking pace from starting location outwards using R?
Goal
In R, I would like to calculate an accumulated cost surface around a starting location, with the cost representing the time (say, hours) to walk from the location outwards in all directions (say,...
7
votes
1
answer
1k
views
Can extracting raster values work in polygons' CRS without raster resampling?
I am trying to extract raster values using polygon layer with different CRS. Raster is in WGS84 (EPSG:4326) and the polygons in UTM (EPSG:23031).
1. If I want to work in the projection of the ...
7
votes
0
answers
1k
views
Correctly handling climate projection data with R
EDIT: An example setup can be found here: The main file is extract_cordex.R
I need to analyze climate data as part of my thesis, however I am not particularly trained in working with climate data and ...
6
votes
2
answers
11k
views
Fast way to convert raster to polygon shapefile in R
I have a single-band raster showing different land cover classes. I want to convert it to a polygon shapefile. I tried to use the rasterToPolygons function with the option to dissolve neighboring ...
6
votes
2
answers
8k
views
How to produce "SpatialPixelsDataFrame" from stacked RasterLayer?
How to produce "SpatialPixelsDataFrame" from staccked RasterLayer ?
I have a stacked rasterlayer and I want to convert them to SpatialPixelsDataFrame.
RasterLayer information is
> RAD.all[[1]]
...
6
votes
2
answers
8k
views
Mean by month on R stacked raster
I work with MODIS NDVI rasters in 2016. I have 23 rasters stacked in one object. I have 2 raster by month. I would like the average by months and conserve a raster for each month.
ndvi.stack <- ...
6
votes
2
answers
2k
views
Why can R not allocate enough memory even for a small raster file?
I have a raster layer of vegetation cover (range from 1 to 3). The size of the file totals 60 Mb so it is not big at all. I know this is duplicating other questions, but they have not helped me out.
I ...
6
votes
2
answers
9k
views
Summary statistics (sum of raster cell values) are equal in R and QGIS, but different in ArcGIS. Why?
I'm new to GIS and I have a question related to the use of different programs (R, QGIS and ArcGIS) to do summary statistics. I've used R and QGIS to sum the cell values of my raster (using ...
6
votes
4
answers
7k
views
Replace NA's with 0 for large raster data using R?
I want to replace all NA values in a large raster with 0. I found this answer to Replacing NAs with 0 for raster data using R :
#getting a raster
library(raster)
f <- system.file("external/...
6
votes
1
answer
9k
views
Filling/replacing nodata values of a raster layer in R
Is there a way to fill my NoData values in R?
I have a raster that has several nodata pixels, which looks like this:
(each white dot has no data)
For the moment, the no data values are assigned -...
6
votes
1
answer
30k
views
Extracting value of raster with coordinates using R?
i'm currently working on the distribution of different species on an area, for 23 years.
I'll show you a sample of my data, it will be easier to get.
My dataframe, let's call it df.
x y
...
6
votes
2
answers
7k
views
Combine multiple partially overlapping rasters into a single raster in R
I have about 1,000 rasters which are around 10km x 10km and partially overlap to cover a whole country.
I would like to convert these into a single national raster, and where raster overlap, add the ...
6
votes
2
answers
5k
views
Calculating Shannon's diversity using moving window in R
I have a raster where each pixel is a particular vegetation type. I'm interested in the diversity of vegetation types around each pixel.
I'd like to assign a Shannon's diversity index value (see ...
6
votes
2
answers
1k
views
Rasterization of polygons, calculation of the area covered
In R environment I have (1) a SpatialPolygonDataFrame with number of polygons: polys; (2) raster grid of resolution 10'000 m: grid. Both of them are in the LAEA coordination system.
What I need is to ...
6
votes
2
answers
13k
views
Calculate mean value for each raster and convert output array to data frame
How do I calculate mean value for each raster and convert output array to data frame?
r <- as.data.frame(cellStats(x,mean))
6
votes
4
answers
950
views
Create a new GRASS database in R with CRS projection
How to create a new GRASS database in R with CRS projection? I am able to create a new one using the following code but it is not projected
require(raster)
require(spgrass6)
initGRASS("/Applications/...
6
votes
1
answer
13k
views
Error "no method for coercing this S4 class to a vector"
I am trying to reproduce the example posted on
Extracting intersection areas in R
Although, when I try to create the SpatialPolygon "p2", R returns the error:
"Error in as.vector(x) : no method for ...
6
votes
1
answer
5k
views
Create raster in R - distance to line feature
I have some line features (eg. 1000 meter isobath), and I would like to make a raster file for my study area where the value of each cell is the distance to the line feature.
Any idea what function I ...
6
votes
1
answer
4k
views
Round() does not return an integer raster in R
I want to convert the datatype of a raster to integer. For example:
x <- raster(nrow=10,ncol=10)
its datatype is float
dataType(x)
[1] "FLT4S"
then I round the pixel values of x by
y <- ...
6
votes
1
answer
5k
views
How to find the cell location index of a raster using Lat long information?
I have a raster for which I want to find the Cell Location (Row, Col) if I have the Lat-long information.
I know how to get the value of a particular cell using lat long.
extract(ras,SpatialPoints(...
6
votes
1
answer
5k
views
Scatterplot between two rasters in R?
I am very new in programming and I want to ask how can I make a scatterplot of two rasters in R and also get their correlation?
6
votes
1
answer
4k
views
R giving error when attempting map algebra
I'm trying to manipulate some downloaded rasters using R, and keep getting the same error when I try to do any type of map algebra.
The example below uses a raster file downloaded from http://www.csc....
6
votes
3
answers
6k
views
Extracting values from raster according to Lat and long of values?
having 12 files with 12 hdrs for one year: these files are raster (projected WGS84,lat long):
samples = 1440
lines = 720
bands = 1
header offset = 0
...
6
votes
1
answer
802
views
Memory issues projecting a large raster mosaic of USGS DEMs in R
I am trying to project a large raster to UTM (meters), but I keep crashing my laptop (16GB) due to a memory shortage. It seems like using projectRaster tends to deplete the machine's memory, and some ...
6
votes
2
answers
2k
views
Getting the center and boundaries of cell of raster object in R
Raster visualization
Raster information
class : RasterLayer
dimensions : 81808, 37369, 3057083152 (nrow, ncol, ncell)
resolution : 0.0001843661, 0.0001843661 (x, y)
extent : 119.7351, 126....
6
votes
1
answer
3k
views
Clip raster by raster with data extraction and resolution change
I need to stack multiple maps (tif) together and clip them all according to extent of one small raster map (second raster at the top of picture below). However, the size of pixels in each map is ...
6
votes
2
answers
3k
views
Correlation between rasters using R
In R, anyone know a method for measuring correlation between raster and spatialpixels, or between two rasters?. I read something about Kulldorff but do not understand how to use it, and maybe it's not ...
6
votes
1
answer
3k
views
How can I both resample and aggregate a raster using Terra?
I essentially have the same issue described here, but this question has not been answered Can I resample a raster in R using "max" as function?.
I have a elevation raster with a resolution ...
6
votes
1
answer
12k
views
Convert sf data frame to raster in R
I am trying to export landscapemetrics output which is a sf dataframe as a raster, the first column of the df is the grid cell number, the second is the value and the third column has the polygon ...
6
votes
3
answers
8k
views
R - Find "n" closest points to each point in SpatialPointsDataFrame
I am working with a dataset that is similar to this one:
library(raster)
library(sf)
# Define CRSs
crs.latlon <- "+init=epsg:4326"
crs.sirgas <- "+init=epsg:5880"
# define edges in somewhere ...
6
votes
3
answers
27k
views
Unable to read raster into R: 'TIFFReadDirectory:Failed to read directory at offset'
I'm getting a weird error when trying to read a raster into R.
>r <- raster('myraster.tif')
Error in .local(.Object, ...) :
TIFFReadDirectory:Failed to read directory at offset 2606110
...
6
votes
1
answer
1k
views
weighted mean across rasters in R
I have 2 rasters. One raster (bio1) contains temperature information across a continent. The other (sp) contains, for each cell, a probability of occurrence for a species. I would like to calculate ...
6
votes
2
answers
1k
views
Adding raster layers to an existing GeoPackage in R
I have a GPKG file with a few vector layers. I have a few processing steps in my script and every now and then a new layer is added to the file. This works fine for vector layers using something like
...
6
votes
1
answer
3k
views
Pixel-wize trend analysis of an irregular time series stack of NDVI rasters in R
I'm interested in doing a pixel-wize trend analysis of a series of NDVI images from Landsat in R.
The problem is that my images are not exactly happening at regular intervals. But decent imagery of ...
6
votes
2
answers
15k
views
Handling multiple-extent-problem to create raster stack in R?
I am storing ~ 30 raster files in a folder and want to create a raster stack. I know that not all of these rasters have completely the same extent. They do have the same resolution and CRS.
Thus I ...
6
votes
1
answer
911
views
Why covariance values are different in R and ArcGIS?
I've calculated covariance between 7 rasters using R and ArcGIS. It gives me different results. Each times covariance values from R are approximately 1.874 times higher than ArcGIS values.
R - ...
6
votes
1
answer
5k
views
How to cluster Raster data
I have thousands of Raster data concerning the ice coverage at the pole at different times (days) over several years. Now I would like to perform a cluster analysis. I want to split the data into ...
6
votes
1
answer
348
views
Addressing just the outermost cells in a raster?
I have a DEM cropped to the extends of a shapefile with different glaciers (see here for data: https://drive.google.com/open?id=1ERFdsqDGLH1a_FbxwawE_gPm0Au0Q9vT).
DEM <- raster("***Glacier_Clip1....
6
votes
3
answers
7k
views
Merge rasters with different origins in R
I have a list of rasters with the same projection and resolution but different origins and I need to merge them in a single raster file.
Here's my code
l <- list.files('path', full.names=TRUE)
...
6
votes
1
answer
1k
views
Segmentation of a big raster
I'm trying to convert one raster into a SpatialPolygons. I've got a big raster (12 millions pixels) with a lot of zeros, and some negative values (representing some depression in a DEM). I would like ...
6
votes
1
answer
3k
views
Calculating proportion of a polygon covered by each raster category using R?
I am using R.
I have a polygon v that covers multiple raster cells in raster z.
How could I calculate what proportion of the polygon is covered by each category in the raster?
I read a solution on ...