Questions tagged [terra]

This tag refers to the R Terra package. For questions about NASA's Terra satellite, use the tags of its censors like Aster, Ceres, or Modis.

Filter by
Sorted by
Tagged with
-1 votes
0 answers
32 views

SDM predict function error with 0.5 resolution

I have a little issue while running predict function for my SDM model, I get the following error message: Predict the number of values returned by the predict does not match the number of cells in ...
Kamel's user avatar
  • 1
0 votes
1 answer
23 views

Values of ordinary kriging with gstat and terra are equal as the input data

I am trying to interpolate a raster using ordinary kriging. When I use the data from meuse to try the model, I get an interpolated output. However, when I run the code with my own data, the ...
Raksha's user avatar
  • 3
0 votes
1 answer
23 views

Sampling 10% of cells in terra raster in R

(I am new to spatial analysis so please excuse if this is an obvious question) In terra, I have a SpatRaster of the world at 1km resolution (3006072000 cells, 5 layers). I would like to randomly ...
LeeJonesEco's user avatar
0 votes
1 answer
13 views

Rasterizing misaligned grids [r - terra]

I'm working with satellite data and trying to convert it to a raster in R. The downloaded product from NASA was vectorized on their end which is frustrating. The problem is that the satellite is ...
Kevin F's user avatar
0 votes
1 answer
39 views

Some polygons are loading incorrectly as terra SpatVect but not SpatialPolygonsDataFrames

I am seeing an issue with some polygon features loading incorrectly as terra SpatVectors. I cannot replicate this issue yet, but here is an example polygon as an rds on Google Drive. If I load this ....
Scott Z's user avatar
  • 141
0 votes
0 answers
26 views

terra::project seems to be changing the values of a raster

I am trying to calculate the proportion of a land use category in R just like it's explained here: Calculating continuous raster representing land cover proportion from categorical raster using QGIS? ...
c roc's user avatar
  • 29
0 votes
1 answer
66 views

Clipping sf vector by terra raster extent with R

I am trying to do something fairly simple: I want to clip a vector with point features down to only features that are contained within a raster extent. For raster I am using the package terra, for ...
Honeybear's user avatar
  • 2,386
0 votes
1 answer
73 views

lidR: Writing output from pixel_metrics() from "multiple-output-function" to separate raster files

First some background from the original question: I'm using the lidR package to make rasters of metrics calculated on point clouds. I have a custom function that calculates 9 metrics outputed as a ...
Martin Stjernman's user avatar
1 vote
0 answers
53 views

From points to raster - how do I set a gaussian function with a cutoff

Context SMAP's user guide states: "We use Gaussian weighting to interpolate the L2B estimates onto the map grid with a search radius of approx. 45 km and a half-power radius of 30 km.". ...
J Lal's user avatar
  • 11
2 votes
1 answer
107 views

Leaflet in R mangling terra RGB rasters

I'm working with an RGB raster in leaflet (some Landsat data). I'm stretching and sampling it down so that it's small enough. The following works great. # stretch and then resample like ...
jebyrnes's user avatar
  • 473
1 vote
0 answers
57 views

Georeferencing rasters using GCPs in R: stars/terra equivalent of gdal_translate / gdalwarp?

With the retirement of rgdal and transition to sf/stars/terra functions in October 2023 now passed, is there a way of georeferencing raster images with GCPs (Ground Control Points) other than using ...
Thomas Moore's user avatar
1 vote
1 answer
80 views

How to calculate the area percentage of polygons overlapping with cells of raster using terra, R

I have a raster with 1 km x 1km cells and some Points, then create 600 m buffers for each point. Now I would like to calculate the area percentage of the buffers for each cell. Finally get a raster ...
Wei Liao's user avatar
0 votes
1 answer
133 views

Use lookup table to create new raster layer based on values in multi-layer SpatRaster using R terra

I am doing an ecosystem classification project where I have 3 raster layers that each correspond to different ecological classes with different numbers of categories. I want to take the unique ...
Meirzev's user avatar
0 votes
1 answer
59 views

Categorical land use raster to continuous values raster in R

I would like to transform categorical land use rasters from ESA CCI (http://maps.elie.ucl.ac.be/CCI/viewer/download.php) to rasters with continuous values. The crs is lon/lat WGS 84 and I would like ...
c roc's user avatar
  • 29
0 votes
1 answer
28 views

Starting cumsum of a rasterfile from value of another rast file in terra

I have one raster and one raster stack. The single raster layer represent day of year when I need to start cumulative sum of the raster stack. Rstart<-rast(nrows=10, ncols=10) Rstart[]<-1:100 ...
Renan le roux's user avatar
0 votes
1 answer
64 views

Transforming categorical land use raster to raster with continuous values

I would like to transform categorical land use rasters from ESA CCI (http://maps.elie.ucl.ac.be/CCI/viewer/download.php) to rasters with continuous values (% of cover of each land use class in each ...
c roc's user avatar
  • 29
0 votes
1 answer
75 views

Finding layer with maximum value for each pixel in terra

I have a raster like this here: https://drive.google.com/drive/u/0/folders/1AEKu4TKpzJg95oXv8dxep24xpXaesr0F The tif has 11 Layers (timestamps). For each pixel I want to find the timestamp with the ...
Lenn's user avatar
  • 1,213
0 votes
2 answers
65 views

R classification of ADM0, ADM1, ADM2 and cities into 1x1 grid [closed]

I want to work on linking temperature to socioeconomic variables. there are wonderful databases offering 1deg x 1deg spatial resolution for temperature (such as CRU and the Berkeley BEST data base). ...
ivo Welch's user avatar
  • 115
0 votes
0 answers
33 views

How to iterate a spatraster faster using 'terra'

I try to use the phenological data and soil moisture data from 2000 to 2018 to judge this question: whether a certain day before a specific phenological period is too wet, the standard is that the ...
gonie's user avatar
  • 13
0 votes
1 answer
53 views

Measure a distance between point and the nearest NA in the raster

I have a set of points placed within one patch. I would like to measure the nearest distance between the point and the closest cell with NA values (eg. outside of my patch). Patch is defined as a ...
maycca's user avatar
  • 3,376
2 votes
1 answer
105 views

Find locations (cell's centroid) of a raster's min and max value using R and terra

I have a raster like this one: https://drive.google.com/drive/u/0/folders/1AEKu4TKpzJg95oXv8dxep24xpXaesr0F I want to find the locations (can be the centroid or the bounding box of these cells) for ...
Lenn's user avatar
  • 1,213
0 votes
0 answers
57 views

Terra/geodata world map cropping issues, possibly due to truncated extent

Cropping geodata world map across Greenwich (not exactly though) or close to the poles gives a "Topology Exception" error on RStudio (Posit) cloud, although not on RStudio desktop. Also, the ...
mlyn's user avatar
  • 3
0 votes
0 answers
44 views

Error using Terra in R to combine Geometries using combineGeoms

I am trying to eliminate polygons in a multipolygon that have an area smaller than x. This is my code: v = terra::vect(f) area <- expanse(v) th <- area < 25 x <- combineGeoms(v[!th], v[th])...
B-C B.'s user avatar
  • 765
2 votes
1 answer
93 views

Is there a comprehensive list of mapnprojections implemented in R?

I would like to experiment a bit with different and less-frequently used projections in R for global maps, but I am playing a guessing game as of which are actually working. I tried to look up ESRI or ...
Herman Toothrot's user avatar
1 vote
0 answers
70 views

Why does Terra's extract(fun= mean) give different values than global(fun = mean) in R?

I am trying to extract mean and quartile ranges from a raster. I normally used terra's extract function to do this, but since I needed quartile numbers as well I tried it a different way. I noticed ...
Lavendarfire's user avatar
1 vote
1 answer
87 views

Terra::extract delivers unexpected values when extracting table from raster using polygons

I have a categorical raster and a polygon vector layer. I want to get a table with the area of each class from the raster layer that is covered by polygons. I tried the following: extr <- terra::...
Manuel Popp's user avatar
0 votes
0 answers
45 views

Plot borders larger than set extent (Terra in R)

I am trying to plot what I think is a very simple map. I have three inputs, map of Canada, map of USA, and a shapefile with rivers. I have set my extent, and when plotting the map I can see a cutoff ...
MHolb's user avatar
  • 1
0 votes
0 answers
153 views

How can I project very large rasters with terra, raster or stars packages in r?

I am trying to project a very large raster (about 7GB each) from NAD 1983 UTM Zone 16N to Wisconsin Transverse Mercator (ESPG:3071) and neither the terra nor the raster package seem to work. Terra ...
Bob SomeAle's user avatar
0 votes
1 answer
109 views

The zonal() function of the Terra package outputting incorrect results

I am attempting to use the zonal() function of the Terra package in R to find out how much population there is for a given municipality. I am using nic_m_0_2020.tif as the source for the population ...
Bushidoenator's user avatar
0 votes
0 answers
52 views

How can I create tiled Shaded Relief rasters from tiled DTM rasters, while avoiding edge artifacts?

I have a series of DTM tiles from which I'd like to create Shaded Relief tiles with the same extent. I am trying to make use of the Virtual Raster Dataset in Terra. The tiles are loaded into a VRT and ...
Ray J's user avatar
  • 549
0 votes
1 answer
97 views

Preprocess daily Black Marble (VNP46A2) nighttime light product

I downloaded NASA's Black Marble daily product (VNP46A2) which is in h5 format (the data can be dowloaded from their website (it's free you just need to create and account)). One needs to preprocess ...
Nikos's user avatar
  • 968
0 votes
0 answers
28 views

In what units do the rasters need to be to use dismo::biovars?

I want to calculate bioclimatic variables from CHELSA monthly data using the biovars function from the dismo package but the help page doesn't mention in what units the precipitation and temperature ...
c roc's user avatar
  • 29
0 votes
1 answer
98 views

Find cells with maximum value per dimension in stars object (R)

I would like to find the cells, and their corresponding centroid, that hold the maximum value for each band in a multiband raster. Converting the stars-object to a sf-dataframe makes this easy somehow....
Lenn's user avatar
  • 1,213
0 votes
0 answers
94 views

Merge overlapping rasters but preserve all original values (R)

I have a SpatRasterCollection, each raster of which has the same resolution and the same set of variables. Some of the variables are numeric and some are categorical. And some cells of some rasters ...
jccborders's user avatar
0 votes
1 answer
226 views

R terra retain labels for categorical raster after writing

My goal is to read in a large landcover dataset (this one: https://www.mrlc.gov/data), crop it, and write the smaller resulting raster to file. This dataset, when downloaded, appears as 3 files with ...
Pascal's user avatar
  • 331
1 vote
2 answers
81 views

Troubleshooting work flow for 10m Sentinel data at large scales (contiguous USA) in [R] using [terra]

I am working with ESRI's Sentinel landcover data at 10meter resoltuion: https://livingatlas.arcgis.com/landcoverexplorer/#mapCenter=-83.21%2C34.332%2C4&mode=step&timeExtent=2017%2C2021&...
Leo Ohyama's user avatar
0 votes
1 answer
588 views

Extracting mean value per layer for raster with terra package in R

I have a stack of monthly temperature raster data and would like to calculate the global spatial mean per area using the terra package in R to obtain a monthly time series. I tried terra::app and ...
LuleSa's user avatar
  • 25
0 votes
1 answer
62 views

Matching coordinates to the closest raster in a stack by date in R

I have downloaded NDVI rasters from luna::getModis, and assigned each raster layer the appropriate date. This was then converted to a rasterstack. I also have a dataframe with coordinates and date. I ...
jwell123's user avatar
1 vote
0 answers
152 views

GDAL error with renv virtual environment in R

I recently started using renv (on a Mac) to manage project environments and I’ve noticed a troublesome problem. When I activate an environment (with sf and terra installed) I cannot set the CRS for or ...
Elise Hellwig's user avatar
0 votes
1 answer
53 views

Pixel level landcover change analysis [closed]

I have two land cover maps in Geotiff format and need guidance on conducting a pixel-level change analysis. library(raster) set.seed(123) raster1 <- raster(nrows = 100, ncols = 100) raster1[] <-...
jmutua's user avatar
  • 373
0 votes
0 answers
158 views

Optimize the resampling and projection of multiple NetCDF files in R using terra

I have a set of 35 NetCDF files (continental scale), each containing 365 daily layers of climate data with a resolution of 5 km, s. I need to do two main tasks: Subset, s_sub, these files based on a ...
Sarash's user avatar
  • 45
0 votes
0 answers
16 views

Exporting raster from R changes the scale of extent

I have converted a shapefile to a raster in R using both terra and raster packages. When I export the raster and try to open it in QGIS the scale has shrunk making the whole shapefile only 1 m across ...
user3390486's user avatar
0 votes
1 answer
36 views

MODIS MCD641 quality bits from TIFF file in R

I have a TIFF file from MODIS MCD64A1 (burned area) which has a quality flag band with documentation like so: I want to just select where bit 0 and bit 1 = 1 or where the flags are a land grid cell ...
Stefano Potter's user avatar
2 votes
1 answer
131 views

Extent not found on NASA's Black Marble monthly images - How to set it?

I downloaded NASA's Black Marble monthly nighttime light (NTL), VNP46A3. The product is in .h5 format and it contains the radiance NTL raster as well as the scientific data sets (SDS) in order to ...
Nikos's user avatar
  • 968
0 votes
0 answers
23 views

Inconsistent polygon transparency with terra::polys

Using terra 1.7-23, when adding polygons to an existing map with the polys function, the alpha argument works as expected when plotting more than one polygon together, but when polygons are plotted ...
Philip Smith's user avatar
2 votes
1 answer
142 views

Filter raster by taking the max of a Gaussian filter

I have a raster which I applied a Gaussian filter. By "default", the Gaussian filter, takes the mean within the kernel. How can I take the max, instead of the mean, within the kernel? Here ...
Nikos's user avatar
  • 968
0 votes
1 answer
69 views

Function applied to Raster cell values also executes to NA values in R

I'm trying to fuzzify a Terra SpatRaster object using a Fuzzy membership function created with FuzzyR package using the method Terra::app, but the function is also aplied to NA values. How can I avoid ...
Armand's user avatar
  • 1
0 votes
1 answer
117 views

Calculating statistic for pixels within specified neighborhood in R

I have a raster with coded values of either 0 or 1. For each pixel, I want to calculate the percentage of 1s within a 500m radius. Using the focal() function in the terra package seems to be my best ...
seak23's user avatar
  • 169
0 votes
0 answers
209 views

Replacing cell values from a SpatRaster to another binary stacked SpatRaster under certain conditions in R (terra Package)

I have a binary stacked SpatRaster bstacked_fht whose 25 layers correspond to presence/absence data for different forest habitat types. Instead of having only values 0 and 1, I want to replace the ...
Fabio Castelli's user avatar
2 votes
1 answer
148 views

Problem with creating elevation cross sections using R and terra

The terra::extract function samples raster data from the top to the bottom and from left to right. This creates an issue if you're using a line to sample a raster with plan of plotting the data as a ...
Adam C's user avatar
  • 217

1
2 3 4 5