All Questions
1,780 questions
6
votes
1
answer
2k
views
Conversion of raster features to polylines: skeletonization?
I would like to identify linear features, such as roads and rivers, on raster maps and convert them to a linear vector features (i.e. polylines). I typically use R as my primary GIS, and have posed ...
6
votes
1
answer
4k
views
Plotting multiple raster stacks with rasterVis::gplot and ggplot2::facet_wrap
I'm trying to ggplot2::facet_wrap a stack of rasters, and then call geom_raster to add more rasters on top of the previously mapped raster stack.
Here is a very simple example dataset to re-create ...
6
votes
1
answer
2k
views
NA values in my raster after changing the resolution, extent, and origin
I'm working with two rasters that differ in their origin, extent, and resolution. I have a bathymetry raster, with a very high resolution (x=0.0008333333, y=0.0008333333) and a MUCH great spatial ...
6
votes
2
answers
916
views
extract() in R raster package slow with non-native format
I've noticed that running extract takes very different amounts of time depending on whether or not the raster is in memory, on disk in the Native format (.grd), or on disk in another format (e.g., ...
6
votes
1
answer
5k
views
Area-weighted average raster values within each SpatialPolygonsDataFrame polygon (R)
I'm working in R. I wish to find the average value of all rasters cntrystack overlaid by each polygon within a SpatialPolygonsDataFrame cntryshp. The raster object is actually a RasterBrick. So I want ...
6
votes
1
answer
647
views
Krovak projection EPSG 5514: Correct data transfer between R and ArcGIS?
I have a problem which many ArcGIS, QGIS and R users from Czech Republic and Slovakia may encounter. In ArcGIS, I am working EPSG: 5514, Projected Coordinate System, defined as:
S-...
6
votes
1
answer
3k
views
How to download the MODIS data from R using MODISTools library
I want to download MODIS product MOD13Q1 to use the Scientific Data Sets (SDS) layers of "250m_16_days_EVI", "250m_16_days_pixel_reliability". MODISTools library in R software provides the capability ...
6
votes
2
answers
4k
views
Create raster with grid cells values based on area covered by polygons
I have a polygon data with area covered by the forests (data is here - https://www.dropbox.com/s/zgckliydalljw6a/sp_data.zip?dl=0). I want to convert polygons to raster. The value of each grid cell ...
6
votes
1
answer
2k
views
How to perform a non-linear regression pixel by pixel?
Using nlsLM from Package ‘minpack.lm’ is straightforward for a simple example like this:
MODEL:y=(exp(a*x+b*z+c)+d)^f
x=c(0.5,0.3,0.2,0.4)
z=c(0.1,0.6,1,0.9)
y=c(0.2,0.3,0.9,0.9)
fit=nlsLM(y~(exp(a*x+...
6
votes
1
answer
231
views
How to apply mean/min/max merge functions on a vector layer to create a stars raster?
Problem
I would like to stars::st_rasterize a vector layers of an sf object using aggregation functions such as mean/median/max/min.
raster::rasterize lets me use mean, min etc. and even define ...
6
votes
1
answer
1k
views
Circular focal means with raster and NAs
I am trying to understand circular focal means using rasters having NA values. I made a couple of scenarios to better understand how to combine weight matrices and functions to summarize values. I am ...
6
votes
1
answer
892
views
How can I conduct Geographically Weighted Analysis using an exponential decay function?
I have some points (representing 30 study sites) and I want to calculate the weighted mean of several variables (landscape layers) using a negative exponential decay (weights function) to give more ...
6
votes
2
answers
3k
views
Create a 3D topographic map with locations marked on the map using R
I am currently trying to create an interactive 3D surface plot using plotly in R. My dataset includes a matrix of Latitude and Longitude and I have a DEM for the region I would like to make this ...
5
votes
2
answers
5k
views
Plotting a categorical terra raster with a colour map
I'm trying to plot a categorical terra raster object with an explicit colour for each level, like you'd do with a land cover raster, but running into problems when the raster doesn't have every level ...
5
votes
2
answers
6k
views
Reclassifying raster stack based on condition and other layers using R?
I want to reclassify raster r1 in the following form:
all the values that are larger than r2 to be 1
all the values that are less than r3 to be 0
all the rest of the values to be equal to r4
I ...
5
votes
2
answers
2k
views
How to write the results of lidR grid_metrics to a georeferenced raster?
I'm using the lidR package to calculate LiDAR grid metrics (p.18 documentation) for forestry applications. For example, the following calculates the mean elevation within a 20m cell:
library(lidR)
...
5
votes
1
answer
1k
views
Configuring lidR catalog to overwrite raster output (with different extension)?
I have a small issue with configuring the lidR package for parametrizing the extracted raster files with grid_metrics() function.
My question is how to set in the catalog options that:
be able to ...
5
votes
2
answers
2k
views
rasterVis polygon under raster layer in R
I want to plot both a raster layer and a polygon layer using rasterVis::levelplot(), however, I want to have the polygon layer appear under the raster layer.
library(sp)
library(rgeos)
library(raster)...
5
votes
2
answers
2k
views
Problem overlapping shapefile and raster in R?
I want to plot a shapefile over a raster file in R but I can't make them overlap perfectly: the raster appears to be rotated of few degrees counter-clockwise. Is it a problem with the projection?
...
5
votes
2
answers
3k
views
Create presence/absence (0/1) rasters for every value in categorical raster in R?
I am conducting a logistic regression analysis of spatial data for a project using STAN MCMC within R. The regression analysis itself is done, but now I need a way to apply the parameter estimates for ...
5
votes
2
answers
6k
views
Performing deep learning land cover classification using R? [closed]
I am really new to Deep Learning and, unfortunately, I can't find example codes on land cover classification other than this one where the author wrote a script in R for a large dataset.
The main ...
5
votes
2
answers
6k
views
R: aggregate raster with 'mode' function - how does it work?
I want to aggregate a very fine resolution raster at various coarser resolutions (that represents many 1000s of categorical polygons).
The aggregate{raster} function is what i've traditionally used, ...
5
votes
2
answers
1k
views
Changing raster calculation values - shorten this script?
i'm doing something quite straightforward regarding raster algebra but am struggling either to find the correct function or make a function work correctly;
Basically I have 2 rasters, representing ...
5
votes
3
answers
2k
views
Dissolving/Unifying Ill Behaved/Irregular Polygons in R
I'm working on a project involving bringing together multiple subjects circling difficult to find parts of an image. The output from users is pretty awesome.
Cool, right?
However, what I want is to ...
5
votes
2
answers
15k
views
Create Raster file in R from Matrix and latlons
I could use some advice on how to create a Raster file in R with a Matrix of data points and the coordinates stored in a separate file.
Both, data and coordinates come from a NetCDF file. I extracted ...
5
votes
2
answers
1k
views
Calculate raster cell area as function of latitude?
Raster used available here: https://www.dropbox.com/s/xn7hdll2op5zcc9/MAP_global.tif?dl=0.
INTRODUCTION:
The resolution of a raster is commonly related in degrees, e.g.:
library(raster)
r <- ...
5
votes
2
answers
9k
views
extract() function from r raster package returns different cells if "weights" parameter is TRUE or FALSE
I am trying to extract cell values from a RasterLayer based on a SpatialPolygons object. I create the raster with
library(raster)
rasterValues <- matrix(rnorm(20),4,5)
r <- raster(rasterValues)...
5
votes
1
answer
2k
views
Convert sf::st polygon into raster
I have WGS84 coordinates that form a closed polygon. I need to turn this polygon into a raster, but the different solutions to similar questions I found don't work for some reason I don't understand. ...
5
votes
3
answers
1k
views
Comparing two rasters, based on a complex set of rules
I am trying to compare two rasters, say A.tif and B.tif. Both correspond to river bed level changes under two different flow conditions. Now I want to produce a comparison raster having values based ...
5
votes
1
answer
784
views
Rescale NDVI (-1:1) to 0-255 using R
I am trying to rescale my NDVI band (-1:1) to 0:255. I am trying to follow the approach in this post: Rescale raster in R , but I am getting NA values.
# my ndvi
ndvi
class : RasterLayer
band ...
5
votes
1
answer
368
views
Re-project raster from dismo::gmap without losing colors
I downloaded a 'Google Map' terrain map using dismo::gmap. The raster comes with a Mercator projection. I tried to re-project it to UTM but in doing so, all the colors are lost and the raster is not ...
5
votes
1
answer
4k
views
Creating a multiband raster from netcdf in R
I have a netcdf file of downward longwave radiation for the whole of China dated 1979 - December. It has got three dimensions namely: longitude , latitude and time. The file contains the data for ...
5
votes
2
answers
5k
views
Checking whether two rasters intersect using R?
I would like a method for checking whether two rasters (or a raster and an extent) overlap that returns a Boolean and doesn't involve an if/then statement. Something like the gIntersects function. ...
5
votes
2
answers
13k
views
Unable to find an inherited method for function ‘writeRaster’ for signature ‘"SpatialGridDataFrame", "character"’
I have the following error when trying to use the writeraster function in R:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘writeRaster’ for ...
5
votes
3
answers
1k
views
Create Zonal Grid in R
Suppose I have a n*n raster, and I want to create k square blocks (k can be divided exactly by n*n ) for zonal analysis:
for example, when n = 4 and k = 4
a 4*4 raster is create with value
1 1 2 2
...
5
votes
2
answers
12k
views
R - NetCDF to Raster
I've recently started working with spatial data in R. I am currently working on a project that uses data in both raster and netcdf formats, and I'd be happy to convert the latter to the former, ...
5
votes
1
answer
3k
views
R - multicore approach to extract raster values using spatial points
It might look like this question is duplicated, but I'm asking about data extraction by points, rather than by polygons, and I couldn't find hints about point extraction. Therefore, please bare with ...
5
votes
1
answer
1k
views
Project raster to new extent
I have some data in a raster stack (CCSM4 climate projections from 2010 - 2300) that I've done some processing on, but now I would like to change the extent. I'm not 100% sure how to do this in R. So ...
5
votes
1
answer
4k
views
Plot many rasters on the same graph, one on top of the other, using a certain angle in R
I wish to create a plot with multiple raster layers in R, but plot them in a certain angle so that all layers can be properly seen. What I have in mind is a plot like the following, taken from here: ...
5
votes
3
answers
4k
views
Sample points randomly within raster cells in R
I would like to generate one random point for each cell in a raster, while excluding NAs. I can use sampleRandom however this just gives me the centroid of each cell:
library(raster)
ras <-...
5
votes
1
answer
11k
views
combine raster and polygon values in R
My question is similar to this one Get Raster Values from a Polygon Overlay in Opensource GIS Solutions but I think I need another step.
I have a polygon layer of ecoregions which I brought into R ...
5
votes
1
answer
983
views
Writing categorial rasters with color and attribute symbology info in R
I am generating landscape classification output rasters and adapted the code from WAF’s stackoverflow answer to the this question to generate GeoTIFFs with embedded standardized color and attribute ...
5
votes
1
answer
3k
views
Plot two layers (raster and polygon-vector) with ggplot and use the fill-scale* for both layers
I am a little lost. I have a stars object where I would like to use the first attribute and map it to the
scale_fill*-function in ggplot.
I also have an polygon-object of class sf that has an ...
5
votes
1
answer
2k
views
Problem projecting lat/long into the CRS of my raster in R
I am working with a raster in the .e00 format, located here:
ftp://ftp.epa.gov/castnet/tdep/grids/n_dw/n_dw-2000.zip
I unzip, and then load this raster in R:
require(raster)
require(rgdal)
require(...
5
votes
2
answers
494
views
substitue raster values duplicate error
I have a raster (seg) whose values I want to substitute, and am getting an error from function subs from the raster package that I don't understand at all.
I get the following error
Error in .local(...
5
votes
1
answer
843
views
raster::rasterize set wrong values with enclosed polygons
Similarly to this post
rasterize (R package raster) fail to rasterize island polygons?
the rasterize function in the raster package is giving me problems with enclosed polygons. In my case, some ...
5
votes
1
answer
3k
views
Identifying value of closest non-NA pixel
I have a raster representing a large landscape, where pixel values indicate particular land classes. I have been using the "distance" function in Package 'raster' in R to calculate the distance from ...
5
votes
1
answer
2k
views
Speeding up band math in R 'raster' package
I have some GeoTiff rasters with over 100 bands in total, but they are not huge: resolution is about 1200x600 and total size is less than 7 mb. I'm trying to do a simple NDVI calculation:
raster <-...
5
votes
1
answer
2k
views
r Terra Mosaic Raster uses huge amounts of memory and takes too long - any alternatives?
I built a process using google earth engine code editor to output a raster of urban land cover in Wisconsin. Google exports these as 210 shard which are geotiffs ranging from 2-100mb in size. Most are ...
5
votes
1
answer
1k
views
Interpolate temperature data (shapefile) using R
The answer below solved my fist question, so I edit my question as follows:
I have a shapefile given with the attributes lat, lon, elevation and temperature.
So far I have a script that interpolates ...