Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
24 views

Date in CRU data is starting from 380 instead of 1, since unit is days since 1900-1-1

I ran the following line of command. Below result show that: " time Size:1380 *** is unlimited *** long_name: time units: days since 1900-1-1 calendar: gregorian daily_rain <- "...
crawling_ec's user avatar
0 votes
0 answers
36 views

Date is missing in CRU data

I used the following code to extract "Climate research Unit" climate data. However extracted data showing "Date : NaN, NaN (min, max)". pre <- brick("cru_ts4.06.1901....
crawling_ec's user avatar
2 votes
2 answers
1k views

How to remove NA value of legend when using R tidyterra?

I downloaded the MCD12Q1 data (land cover and category type data) by MODIStsp package, and I want to plot it using tidyterra package. For example, library(terra) library(tidyterra) library(tidyverse) ...
jackywang's user avatar
  • 329
0 votes
1 answer
162 views

Calculate argmax and second argmax of a RasterStack in R

I need to calculate the argmax (index of the maximum) and index of the second maximum of a RasterStack in R. That is, for each pixel of the image, I need to evaluate in which index (layer) is the ...
sermomon's user avatar
  • 1,044
1 vote
0 answers
456 views

Making map with marginal graphics like rasterVis::levelplot(margin=T)

I love rasterVis::levelplot(margin=T) because its marginal graphics show the column (x) and row (y) summaries of the Raster object. I think it is very helpful to visualize the raster. Package ...
jackywang's user avatar
  • 329
1 vote
1 answer
74 views

Assigns geographical locations to the pixels in isolate drone image in R

In my example, I have a single dji image in *JPG: library(terra) single.image <-stack("https://github.com/Leprechault/trash/raw/main/DJI_0274.JPG") plotRGB(single.image, r = 3, g = 2, b =...
Leprechault's user avatar
0 votes
1 answer
2k views

Errors reassigning CRS of SpatRaster using terra::projectRaster and raster::project

I have the following SpatRaster object called pred_th: dimensions : 162, 87, 1 (nrow, ncol, nlyr) resolution : 0.08333333, 0.08333333 (x, y) extent : 43.25, 50.5, -25.58333, -12.08333 (xmin, ...
Sam Thompson's user avatar
1 vote
1 answer
498 views

Create several raster layers based on one layer

The terra::app() function accepts one or more layers and a function, and usually (?) returns just a layer with results. However, how to apply a function to one layer that returns more than one layer? ...
Jot eN's user avatar
  • 992
2 votes
1 answer
147 views

Raster R package, points outside the grid

I am posting my issue in this community as I did not get satisfying answers in stackoverflow, hoping to get a solution here. I am working on a spatial simulation and I created spatial points, but when ...
Sosa's user avatar
  • 23
0 votes
1 answer
234 views

Process WCS data from EMODnet using R

edit: setting mode = "wb" to download the file is crucial for correct reading using solution by Spacedman I'm trying to get raster data on depth from EMODnet into R to analyse, using the WCS ...
Joris Meys's user avatar
0 votes
0 answers
96 views

Reproject netcdf4 raster works for one dataset but not the other in R

I wrote code to reproject the OISST NetCDF to my desired projection, and it works correctly. However, when I run the same code on the NCEP NCAR Reanalysis data, I get something wrong. Not sure why ...
A Diaz's user avatar
  • 1
1 vote
1 answer
387 views

Converting large number of NetCDFs to single raster using R

There are ~87,500 NetCDF files of a global dataset that must be stacked and the values averaged to create 1 raster. My machine does not like this... I've written nested for loops that, despite ...
Eron Raines's user avatar
0 votes
1 answer
353 views

Rolling (moving) window linear regression - extract residuals

I want to perform linear regression with a rolling (moving) window with size 5 using raster data. I tried a code using the raster package and the function localFun, and when I am trying to export the ...
Nikos's user avatar
  • 1,167
1 vote
0 answers
87 views

Calculate by cell statistics of Image Collection in (R) Google Earth Engine?

I am using Google Earth Engine in R via the rgee package. My goal is to calculate median NDVI for each cell in an image collection. I have an image collection gathered via: #This is not a reprex ...
geoscience123's user avatar
1 vote
1 answer
880 views

Aggregate raster in R and get count of contributing pixels

I have a raster with some NULL values. I need to aggregate the raster to a coarser one, and get a count of the pixels that are being aggregated (for every output pixel), excluding the NULLs. I'm ...
jaykay's user avatar
  • 31
0 votes
1 answer
454 views

Raster file with all Bing Maps quadkeys

I'm looking for a raster file that has all quadkeys of Bing Maps for a given zoom level. Does that exist? If not, how could I create it myself in R? I have spatial data as a set of shapefiles (none of ...
noels's user avatar
  • 1
0 votes
0 answers
1k views

Why is coord_sf needed to plot a geom_raster with ggplot2?

Why is coord_sf() needed to plot a geom_raster in ggplot2 and what exactly does coord_sf() do? According to ggplot2's Map project's documentation: coord_map projects a portion of spherical earth onto ...
ENIAC-6's user avatar
  • 916
0 votes
2 answers
337 views

Double indexing and looping over raster lists in R

I have a list of 63 rasters. They are the same extent, resolution, projection, etc. Because I extended 62 rasters to the maximum extent of the 63rd, I introduced NA values. However, these are relative ...
Nick Masto's user avatar
1 vote
0 answers
45 views

Getting equal number of cells within rasterstack using R

I have a raster_stack with 3 rasters. I made them the same resolution, extent, projection so that I could combine them into the stack. So, I expected each raster to have the same number of pixels. The ...
Nick Masto's user avatar
0 votes
1 answer
260 views

Draw a polygon over PNG image R

I have a PNG image wich I have opened in R and in order to give coordinations converted into a SpatRast object with the following code: library(terra) r <- rast("yanomamis.png") #Warning: ...
Aniel's user avatar
  • 15
0 votes
1 answer
464 views

Comparing smoothing algorithms in R

I am comparing smoothing algorithms in R. More specifically, the raster.gaussian.smooth from the spatialEco package and the focal from the terra package. Visually, the results look similar but the ...
Nikos's user avatar
  • 1,167
0 votes
1 answer
653 views

Aggregate raster using gaussian smoothing as a custom function/Units of the sigma

I am trying to aggregate a raster using a custom function and the terra package. For the custom function I am using a Gaussian smoothing. When I try to run the aggregate function I am getting this ...
Nikos's user avatar
  • 1,167
0 votes
1 answer
536 views

Problems extracting ERA5 data with exact_extract in R

I used polygon to extract the nc file, which is the temperature data of ERA5, but when using stack and using the exact_extract function, there were warnings and errors. > rasdata <- stack("....
Hzeros's user avatar
  • 1
3 votes
3 answers
4k views

Create empty raster with dimensions, pixels size and CRS of another raster in R

I am trying to create an empty raster layer and I want this empty raster to have the same dimensions, pixel size and CRS based on another raster, but no pixel values. I am getting errors when I try to ...
Nikos's user avatar
  • 1,167
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 <- ...
Eron Raines's user avatar
0 votes
1 answer
1k views

Unusually formated NetCDF to raster in R

Having issues relating information stored in an NetCDF in a way I haven't seen before. nc file located here: https://www.dropbox.com/s/x1eexenioclwe0l/ISCCP_HXG_total_PAR_1984_01_01_03.nc?dl=0 Can ...
Eron Raines's user avatar
1 vote
1 answer
359 views

Modify raster coordinates (wrong projection) using stars or terra

I downloaded a raster image from the following address, which corresponds to rivers and streams in the Barcelona area. https://geoserveis.icgc.cat/icgc_geotecnicbcn25m/wms/service?REQUEST=GetMap&...
marcbosch's user avatar
  • 157
0 votes
0 answers
58 views

Reproject altitude data to make it coincide with SpatialPolygonsDataFrame

I am trying to get an altitude raster to coincide with a working spatial polygon dataframe that shapes the region with data from an .nc file. The .nc file, and thus the derived spatial polygon ...
Agus camacho's user avatar
1 vote
3 answers
159 views

Forest patch centroids are not located in patches using landscapemetrics in R

I am using the R package landscapemetrics to find forest patch centroids in a landscape. The given function to find patch centroids is get_centroids(). The centroids returned from get_centroids() are ...
geoscience123's user avatar
4 votes
1 answer
1k views

R Focal Function - Terra vs Raster

I'm not sure why the focal function I've been using in Raster does not work with Terra. This simplified example uses a custom function to apply the focal filter only to pixels with a value of 0 and ...
Eric Jeronimus's user avatar
0 votes
2 answers
1k views

How to read and write raster matrix data with R (raster package and image processing)?

I'm using R for morphological operations on geo-rasters. The packages mmnand and EBImage offer morphological operations. However they can't work with georeferenced rasters, but operate on a matrix (or ...
Honeybear's user avatar
  • 2,554
0 votes
1 answer
267 views

I am using BFAST to do a time series analysis of LST and I am getting NaN errors

This is the blog post I refer to, https://philippgaertner.github.io/2018/04/bfast-preparation/, and the author's code is as follows: # NDVI data data(tura) selected_pixel <- 90 represents a ...
angrybob's user avatar
3 votes
2 answers
408 views

Overlay raster (h5 files) with shape files to get night light data in R

I am trying to combine ".h5" nightlight data files of Hawaii with zipcode-shapefile from Hawaii, but I am getting the following error: #Error: [crop] extents do not overlap The R codes are ...
laplaceable's user avatar
2 votes
0 answers
169 views

How to address NA in pixel regression (local computation) with R terra package

For example, I have five NDVI TIFFs and five precipitation TIFFs. I used the code provided by Robert (https://stackoverflow.com/questions/63831287/extracting-p-values-from-lineair-regression-on-raster-...
jackywang's user avatar
  • 329
1 vote
1 answer
4k views

How to produce a gridded map in R where each grid cell represents the sum of points occurring in the grid?

I want to produce a gridded map where each grid cell represents the sum of points falling within the grid using R. I have seen similar questions for R here, here, and here for Phyton. But could not ...
Jhonny's user avatar
  • 11
1 vote
1 answer
255 views

Dimensions and extent changed after rast from 'xyz' data.frame

s #oringinal raster s #check dimensions and extent df <- s %>% as.data.frame(xy=T) #convert to df t <- rast(df,type='xyz')...
jackywang's user avatar
  • 329
0 votes
1 answer
473 views

How can I update a large raster with new values in R with speed?

I have a raster with 2332800 cells. Half of these cells are probably oceans and unneeded. I need to update these cells with new values. Right now I'm using a for loop and it takes a very long time: ...
antR's user avatar
  • 193
0 votes
1 answer
222 views

Raster to SpatialPolygonsDataframe: close/crop polygons at the raster boundary, in R

library(raster) # read in bathymetery raster [https://drive.google.com/file/d/15kAcfQBJh_JiYgH-YrZZTJeeWOPd0Ysh/view?usp=sharing][1] r = raster('./ibcso.tif') plot(r) # set cells above sea level to ...
ChrisO's user avatar
  • 25
0 votes
1 answer
172 views

What are the xmin, xmax, ymin, ymax values for Australia?

I am trying to crop the bioclimatic data from WorldClim.org to get environmental features only for the Australian habitat using the extent() method. Finally, I plan to combine the bioclimatic data ...
PHI's user avatar
  • 13
0 votes
1 answer
146 views

R Reprojecting global forest change rasters

I have been trying to calculate forest cover and forest loss in West Kalimantan Province, Indonesia, during 2000-2020. I use the gfcanalysis package in R for this purpose. Unfortunately, the minimum ...
Ing's user avatar
  • 1
0 votes
1 answer
463 views

Merging/mosaic raster list or raster stack

I am trying to figure out proper solution to combine >100 raster images. These raster images are individual animal utilization distributions (values 0-1) that are modeled using dynamic brownian ...
Nick Masto's user avatar
0 votes
1 answer
225 views

Monte Carlo simulation

I have an equation to calculate z from multiplying several rasters and numbers as seen below: z <- a*b*c*d*e The raster layers and values are as below: library(terra) set.seed(234) r <- rast(...
jmutua's user avatar
  • 373
3 votes
1 answer
4k views

R terra::mask report error ‘Error: [mask] extents do not match’

I have a temperature tif, and I want to extract my study area.But it reports that extents do not match. I want to know how to fix it and why the extents do not match? I think to_be_masked raster's ...
jackywang's user avatar
  • 329
1 vote
1 answer
322 views

Use non-linear regression output to predict values across raster including categorical attributes

We are aiming to correct general snow depth values from publicly available layers at a coarse resolution (~1km) using our vegetation and other parameters collected in the field at point locations ...
kl-higgins's user avatar
  • 2,027
1 vote
0 answers
52 views

Proportional allocation method for translating vector to raster format in R [closed]

My data consists of a shapefile of polygons representing municipalities in a given country. Each polygon has a population value in the shapefile's attribute table. I would like to disaggregate these ...
tlaco's user avatar
  • 11
0 votes
2 answers
1k views

How to extract point data (latitude, longitude) of different soil variables from SoilGrids without actually downloading the TIFF files

Objective I have a dataset of ~200 observations, from scientific papers describing agroforestry, with associated coordinates (lat., lon.) dispersed all over the temperate world (US, Europe, China, etc....
Kamau Lindhardt's user avatar
1 vote
1 answer
722 views

Extracting variables from grid cells using R

I am trying to extract bioclimatic variables from individual grid cells. So i started loading my shapefile: # I used the Admin 0 - Countries (1:10) dataset from Natural Earth shp <- sf::st_read(&...
Non_Praying_Mantis's user avatar
0 votes
1 answer
1k views

How to export(writeRaster) single raster from multi-band stack/brick/spatraster one by one using R?

library(terra) a=rast(nrows=10,ncols=10,vals=1:100) b=rast(nrows=10,ncols=10,vals=1:100) c=rast(nrows=10,ncols=10,vals=1:100) test <- c(a,b,c) for (i in 1:3) { r=test[[i]] writeRaster(r,...
jackywang's user avatar
  • 329
0 votes
1 answer
3k views

R terra: [crop] SpatRaster has no values

I am attempting to use terra::crop() to crop 30 meter NLCD raster data to a bounding box. The final error that R returns is: Error: [crop] SpatRaster has no values despite the raster data containing ...
geoscience123's user avatar
0 votes
1 answer
59 views

Trouble overlaying plots in R

I've produced a raster using IDW to make predictions across California, and now I'm trying to overlay the raster image with the border/shapefile of California. I've ensured the CRS projections are the ...
Dougie G's user avatar

1 2 3
4
5
36