Questions tagged [stars]
The R package providing classes and methods for reading, manipulating, plotting and writing spatiotemporal data cubes.
63 questions
0
votes
0
answers
21
views
stars and st_apply: summarise NetCDF for each timestamp and create multiple new attributes
I have a stars-object like this one:
https://drive.google.com/file/d/1qcMATPjSyw-Rk9WpfFTa1rpr7dtOUxsu/view?usp=drive_link
It looks like this:
nc = read_stars("~/Desktop/SPARTACUS - Spatial ...
0
votes
1
answer
67
views
Error when using tmap: Error in if (hover != "" && !hover %in% smeta$vars) rlang::arg_match0(hover, : missing value where TRUE/FALSE needed
I am trying to make a map using the tmap package in R, because I have a continous raster for which I think using Jenks Nature Breaks would be usful for visualisation. Thus far this is what I have:
...
0
votes
0
answers
53
views
"Object which.column not found" when reading in land-cover dataset with stars (R)
I'm not sure where the problem lies--in R, a quirk of the dataset, my own computer?
The dataset in question is a raster dataset of land cover in the United States. It's linked from the MRLC, but for ...
0
votes
1
answer
74
views
Rotate stars raster object around the centroid in st_geotransform
I'd like to use an affine transformation to translate and rotate a stars object around the centroid. As far as I understand, the general approach is to i) translate the object so that the centroid ...
1
vote
0
answers
101
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 ...
0
votes
0
answers
585
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 ...
0
votes
1
answer
211
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....
0
votes
1
answer
200
views
Reading and writing VRTs differ in size and values when using Terra and Stars
I want to use the tree cover density layer from copernicus (https://land.copernicus.eu/pan-european/high-resolution-layers/forests/tree-cover-density/status-maps/tree-cover-density-2018?tab=download)
...
1
vote
0
answers
26
views
Mimic raster output from ArcGIS GWR (raster gradient through NA spaces) in R
I'm trying to mimic the raster style output you get from ArcGIS Geographically Weighted Regression, where instead of simply plotting the coefficient/value in the raster cell that aligns with the ...
0
votes
1
answer
379
views
R: Wrong transformation from SpatRast (terra) to stars object
When I transform my SpatRast object to a stars object, suddenly the the location of my origin changes. I need the location of the origin to be an exact point (376491.4,5875118.5, EPSG:25833), as I am ...
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&...
0
votes
0
answers
93
views
R Leaflet throwing "matrix(): subscript out of bounds" with an addGeoRaster object
I am trying to render a large GeoTIFF (meter-scale urban land cover or MULC from the EPA EnviroAtlas found here) in Leaflet along with other spatial data. Because of the size (approx. 65k x 80k) I'm ...
3
votes
1
answer
577
views
How to properly save netCDF file with stars
I'm trying to save properly formatted stars object to netCDF file with no success. Here is a reproducible example of what I'm doing.
library(tidyverse)
library(stars)
# example data
ex <- tibble(...
0
votes
0
answers
378
views
Apply function at grid cell level across layers of a raster file
I have a netcdf raster object with multiple layers (time: 30 years * 12 month = 360 steps).
The raster is constituted of multiple grid-cells (say 1000). I want to linearly detrend each month ...
1
vote
0
answers
208
views
Recursively mosaic rasters by directory (year) in R
I have hundreds of rasters spanning 10 years, files are stored by year (e.g., 2020, 2019, 2018, etc.). I would like to mosaic all the raster files within a directory, move to the next directory and ...
1
vote
1
answer
668
views
NAs when calculating the mean of raster values per polygon using R (stars & sf)
I am trying to get the mean NDVI value for tree clusters (I've calculated them using DBSCAN) using stars and sf but, I'm getting a lot of NA values, which they don't appear if I use the Zonal ...
4
votes
1
answer
2k
views
Mask a (raster) stars object in R with a vector (sf) object
In this question an stars object is masked with a raster object. But it is not clear to me how the masking can be done with a vector object using the stars pkg.
Consider the following example in terra....
3
votes
2
answers
820
views
What's the most efficient way to calculate line length per raster cell in R?
Problem
I'm looking for an efficient, memory friendly to calculate total line (vector data) length per raster cell.
The question of line length per cell has already been posed here in 2014 and a few ...
2
votes
2
answers
1k
views
Calculate area weighted mean values of polygons for raster cells using R
Problem
I want to rasterize polygon values and assign their weighted mean to raster cells.
Weighting should be done based on the polygons' cell coverage.
Problem visualized
Calculation for grid cell ...
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 ...
0
votes
1
answer
286
views
R stars read_ncdf returns "vector memory exhausted (limit reached?)" when proxy = TRUE
My question involves an error when trying to read a large dataset, so I'm not sure of the best way to provide a reproducible example.
I am trying to read a large netcdf file into R as a stars proxy ...
3
votes
1
answer
2k
views
Rasterizing and resampling a vector object using stars::st_rasterize() and terra::rast() loses values/data
I am currently struggling with rasterizing and later, resampling a vector object using functions from stars and terra.
Let's start with the example dataset here: https://drive.google.com/drive/u/2/...
1
vote
1
answer
299
views
Comparing polygon areas across simple feature collections
I currently have three simple feature objects created from different shapefiles in R using the sf package. These three objects have all been projected to the same coordinate system using st_transform()...
1
vote
1
answer
457
views
Add a calculated band to a R stars object
I use R stars package "read_stars" function to open sentinel bands files yielding the following object (Sentinel):
stars object with 3 dimensions and 1 attribute
attribute(s):
...
1
vote
2
answers
141
views
Is there an equivalent of "isLonLat" function in terra package in R?
I am refactoring my code which extensively relied on raster package to now use the newer and better terra package. I was making use of the isLonLat() function that returns TRUE if the crs of a raster ...
2
votes
1
answer
560
views
Expand stars-raster in R
In the r-package terra there is the function terra::extend. To my understanding it just expands the raster with no data values on each side right?
I wanted to do something similar, but using a stars ...
0
votes
1
answer
461
views
Fix NetCDF dimensions of stars object
I downloaded some CMIP6 data from Copernicus data service and I believe the NetCDF file came with malformed dimension information. When I try to get the lon or lat dimensions (st_get_dimension_values) ...
0
votes
1
answer
386
views
Summarise R stars objects by group
I would like to summarise the bands of a stars object using a band as a grouping variable.
In this small example, I have two bands with information on e.g. species densities. In addition, I have a ...
2
votes
1
answer
184
views
stars: add band based on existing band calculations
I would like to add an additional band to a stars object that includes information from two existing bands.
library(stars)
library(tidyverse)
toy_data <- reduce(rerun(2, {
m <- matrix(sample(...
0
votes
2
answers
2k
views
st_as_sf() of stars object reduces the object extent
I am attempting to do a raster to polygon conversion using the stars package. The workflow i've seen elsewhere (and have used successfully previously) is on my "zones" raster is:
zones_stars ...
4
votes
1
answer
249
views
Convert long datframe in R with each band being in one column to stars object with band as dimension
So I have a dataframe that looks like this:
x y band val
<dbl> <dbl> <int> <dbl>
1 12.5 48.7 1 0
2 14.3 47.3 1 0
3 10.3 48.0 1 0
4 ...
2
votes
1
answer
644
views
Reprojected data from stars R package takes forever with geom_stars and ggplot2
I'm finding very different plotting results with stars objects after I reproject them and use ggplot2. Consider the following:
library(stars)
library(ggplot2)
system.file("tif/L7_ETMs.tif", ...
3
votes
1
answer
753
views
How to test whether the argument passed to an R function is a raster or a vector
I am writing a function that expects two arguments: X and Y. Argument X should be a raster which can be generated by packages such as raster, terra, or stars.
Argument Y should be a polygon from ...
0
votes
1
answer
1k
views
Mask a stars object in R
I am trying to mask a stars object in R, but not sure how to do it. The documentation here says that mask in Raster can be done as [] <- in stars. I am not sure what this means.
Here is code from ...
0
votes
0
answers
170
views
sf st_make_valid silently failing after st_combine
I'm trying to create an object of class 'sf' that is single multipolygon out of a raster. I'm following the procedure in this SE post: https://gis.stackexchange.com/a/357792/191148, but I want to keep ...
3
votes
0
answers
541
views
Merge single- and multi-band rasters with stars
I can easily use c() to merge two single band rasters or two multi-band rasters using the R package stars, however, when I try merging a single band raster with a multi band raster, I get the error ...
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 ...
2
votes
1
answer
868
views
Combining named list of stars object into one new stars object with names being new dimension
I have a list of stars objects that I created in a loop. This little example is more or less replicating my situation.
library(stars)
tif = system.file("tif/lc.tif", package = "stars&...
1
vote
1
answer
2k
views
Handle Curvilinear/rotated grid NetCDF file in R
I have a NetCDF file with a curvilinear (rotated) grid that contains meteorological data.
I am trying to crop the NetCDF based on a mask shapefile in R, but the rotated grid does not project the data ...
2
votes
0
answers
584
views
Compute mean of two stars objects in R
I have two stars-objects and I simply would like to calculate the mean for each pixel.
I am not really sure how to do that and if my approach is correct. At the moment I'm doing the follwing:
I have
&...
1
vote
1
answer
1k
views
Generating Kernel density raster/stars with same dimensions
I would like to generate different rasters from kernel density functions with the same resolution, so that I can compare them.
Take this example from here:
library(MASS)
library(raster)
set.seed(123); ...
1
vote
0
answers
371
views
Focal operations / aggregations on stars_proxy object in R
I have many NetCDF-files that I read in as stars_proxy-object. I also have a geopackage that is a multipolygon. I Would not like to extract the mean value for each polygon for each stars_proxy-object.
...
1
vote
0
answers
217
views
Difference in CRS when reading with read_stars und read_ncdf
I have a NetCDF file that I would like to load into a stars object.
The two functions st::read_stars and st::read_ncdf both load it in, but the data ends up in different locations when I plot it using ...
3
votes
2
answers
648
views
What is the canonical way to perform raster calculations using R stars?
I have a data cube that I am handling in the R stars package. It has 3 dimensions (latitude, longitude and time) and 2 attributes (northwards and eastwards components of wind). A dummy equivalent ...
0
votes
1
answer
511
views
abind Error when converting a .tif raster data object to an sf object using st_as_sf() in R
When I try to convert a .tif raster data object to an sf object using st_as_sf() in R, I get the following error:
Error in abind(x, along = length(dim(x)) + 1) : along must be between 0 and 2
How do ...
2
votes
1
answer
705
views
Why krige function return all NA's values for the prediction when trying to interpolate a variable?
I am trying to build a map with kriging interpolation for a variable. When running the krige function the return is all NA values and the kriged map plot only one value. I couldn't find out why and I ...
1
vote
0
answers
853
views
Getting an sf boundary of a raster or stars object
I am trying to figure out the best approach to convert an raster or stars object into its boundary returned as an sf object. I think I have a pretty decent handle on how to do it with raster (shown ...
1
vote
1
answer
989
views
Convert large stars object to sf object
My ultimate goal is to convert landcover raster (.tif) objects to an sf object representing the raster's grid and the original values of each cell within each geometry. I have been able to do this for ...
2
votes
1
answer
577
views
Temporal rolling mean in stars
I need to find temporal rolling means (or other stats - max, min, etc.) in stars spatial obects. For stars raster cubes, this would be directly analogous to the calc(rasterBrick, function(x) movingFun(...
1
vote
1
answer
415
views
Error while converting raster to ploygon using stars package
I am trying to convert raster to polygon using stars package as suggested in this and this. I have used the following code
library(raster)
library(stars)
library(sf)
library(magrittr)
#read raster
r1&...