Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
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 (...
Rodrigo's user avatar
  • 784
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<-...
gsa's user avatar
  • 1,246
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 :...
Xianwen Chen's user avatar
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 ...
JEquihua's user avatar
  • 1,087
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 ...
Christian Sprague's user avatar
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 ...
Lauren's user avatar
  • 1,912
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,-...
Wraf's user avatar
  • 539
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 ...
Where's my towel's user avatar
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 ...
nilsoleplambeck's user avatar
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,...
NewAtGis's user avatar
  • 1,546
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 ...
Tomas's user avatar
  • 1,262
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 ...
telegott's user avatar
  • 285
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 ...
Alemex's user avatar
  • 83
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]] ...
Nahm's user avatar
  • 871
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 <- ...
delaye's user avatar
  • 729
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 ...
Thomas's user avatar
  • 917
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 ...
rebeca's user avatar
  • 71
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/...
Steffen's user avatar
  • 61
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 -...
M514's user avatar
  • 577
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 ...
Vivien Leonard's user avatar
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 ...
falcs's user avatar
  • 1,111
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 ...
KevinB's user avatar
  • 115
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 ...
Kryštof Chytrý's user avatar
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))
jmutua's user avatar
  • 373
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/...
Jun Folledo's user avatar
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 ...
Ana Carolina Pessoa's user avatar
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 ...
Splash1199's user avatar
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 <- ...
jim's user avatar
  • 191
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(...
maximusyoda's user avatar
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?
Maria Karypidou's user avatar
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....
user1521655's user avatar
  • 1,339
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 ...
Jonsson's user avatar
  • 399
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 ...
Pablo Herreros Cantis's user avatar
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....
Abel Melquiades Callejo's user avatar
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 ...
Ladislav Naďo's user avatar
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 ...
jmbluengo's user avatar
  • 111
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 ...
canderson156's user avatar
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 ...
Buffy Smith's user avatar
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 ...
thiagoveloso's user avatar
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 ...
Amadou Kone's user avatar
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 ...
Pascal's user avatar
  • 331
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 ...
karpfen's user avatar
  • 2,327
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 ...
FlyingMGET's user avatar
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 ...
parallax's user avatar
  • 1,482
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 - ...
Jot eN's user avatar
  • 992
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 ...
Hendrik's user avatar
  • 63
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....
Florian Mlehliv's user avatar
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) ...
Quechua's user avatar
  • 337
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 ...
A.Rogeau's user avatar
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 ...
canderson156's user avatar

1 2
3
4 5
36