Questions tagged [stars]

The R package providing classes and methods for reading, manipulating, plotting and writing spatiotemporal data cubes.

Filter by
Sorted by
Tagged with
0 votes
1 answer
31 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 ...
user avatar
1 vote
1 answer
70 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/...
user avatar
  • 1,282
1 vote
1 answer
34 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()...
user avatar
  • 1,282
0 votes
1 answer
47 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): ...
user avatar
1 vote
2 answers
47 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 ...
user avatar
1 vote
1 answer
39 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 ...
user avatar
  • 657
0 votes
1 answer
52 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) ...
user avatar
  • 2,256
0 votes
1 answer
54 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 ...
user avatar
  • 144
1 vote
1 answer
25 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(...
user avatar
  • 144
0 votes
2 answers
251 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 ...
user avatar
3 votes
1 answer
49 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 ...
user avatar
1 vote
1 answer
113 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", ...
user avatar
  • 443
1 vote
1 answer
74 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 ...
user avatar
0 votes
1 answer
239 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 ...
user avatar
  • 1,699
0 votes
0 answers
48 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 ...
user avatar
2 votes
0 answers
133 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 ...
user avatar
  • 1,733
5 votes
1 answer
790 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 ...
user avatar
  • 657
0 votes
1 answer
255 views

Combine named list of stars object into one new stars object with the names being a 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&...
user avatar
  • 657
1 vote
1 answer
626 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 ...
user avatar
0 votes
0 answers
147 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 &...
user avatar
  • 657
0 votes
1 answer
225 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); ...
user avatar
  • 828
1 vote
0 answers
93 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. ...
user avatar
  • 657
1 vote
0 answers
46 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 ...
user avatar
  • 657
1 vote
1 answer
127 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 ...
user avatar
  • 119
0 votes
1 answer
206 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 Does ...
user avatar
  • 125
2 votes
1 answer
236 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 ...
user avatar
1 vote
0 answers
123 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 ...
user avatar
  • 165
1 vote
1 answer
402 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 ...
user avatar
1 vote
1 answer
222 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(...
user avatar
  • 19
1 vote
1 answer
240 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&...
user avatar
  • 131
1 vote
1 answer
449 views

Exporting ASCII file from 'stars' package

I'm playing around with the stars package (0.4-1) in R, but I can't get how to export a grid object in ASCII format, as the traditional writeRaster(r, filename=file.path(dir.list[j], 'test.asc'), ...
user avatar
  • 133
2 votes
1 answer
190 views

Raster file statistics in R (stars and raster package) don't match gdalinfo

I'm trying to read a gridded binary file in R using read_stars. Comparing the stats from stars package to the stats from gdalinfo, I could see differences in min/max values. Below is the sample code. ...
user avatar
  • 123
1 vote
1 answer
439 views

Read NetCDF file with read_stars in R

I am trying to work with cordex climatic data (curvelinear and rotated data) in the stars package, and I am having a lot of issues, so decided to simply reproduce online example, and I fail reading in ...
user avatar
6 votes
1 answer
192 views

Generate a stars object from tabular spatial temporal data?

I have tabular data with columns longitude, latitude, time, and intensity, like so: library(lubridate) ## mock example data ex <- tibble(longitude = 1:10, latitude = 10:1, ...
user avatar
  • 161
2 votes
1 answer
200 views

r stars: calculate ndvi for every time step on stars proxy

I would like to calculate the ndvi on every time step of a 4d data cube (x, y, bands, time) in on an stars proxy object. Do you have any ideas of how to achieve this on the proxy object? My current ...
user avatar
  • 31
1 vote
0 answers
207 views

Copernicus ERA5 crs/projecition for NetCDF

i'm trying to work from netCDF from this link: https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels?tab=form but i can't find the correct EPSG. In documentation page i ...
user avatar
  • 409
4 votes
1 answer
992 views

stars package in R. How to add time dimension in a stars object?

I have a raster stack (my_stack) and I converted it into a stars object: mystar <- st_as_stars(my_stack) That results in: stars object with 3 dimensions and 1 attribute attribute(s), summary of ...
user avatar
  • 453
2 votes
1 answer
301 views

Stratified ordinary kriging using gstat and stars packages

The gstat package supports stratified ordinary kriging using sp objects as shown at https://github.com/r-spatial/gstat/blob/master/demo/examples.R (the code below). This year (https://r-spatial.github....
user avatar
  • 826
1 vote
2 answers
732 views

NetCDF time aggregation using R stars package

I have a monthly temperature netCDF dataset with aprox 20 years and I'd like to calculate a monthly climatology (average of all Jan, Feb, Mar...). I know I can do this with stackapply from package ...
user avatar
  • 2,256
4 votes
1 answer
529 views

Convert XYZ to stars curvilinear grid and plot

I have data in XYZ format (long, lat, elevation) that does not fit on a rectangular grid, but I would like to plot it as grid cells of different sizes. To illustrate what I mean, the last two plots ...
user avatar
  • 309
1 vote
0 answers
400 views

Creating map projection for net of geodesic dome?

I am working on a project that involves mapping the night sky's northern hemisphere onto the exterior surface of a small (16 cm radius) geodesic dome. The problem is, I don't know what map projection ...
user avatar
1 vote
0 answers
449 views

R stars package and set dimensions to a NetCDF file

Related: GDAL and reprojecting a NetCDF file Following above, I would like to reproject a NetCDF ( NOAA GOES-16 file ) using R stars package. However, I have been unsuccessful at the first step; I ...
user avatar
  • 29k
2 votes
1 answer
2k views

Error from aggregate function from the R package sf

I am currently reading the new (and free!) book by Edzer Pebesma and Roger Bivand (you can find it here). In chapter four they describe how one can aggregate all the measurement stations within one ...
user avatar
  • 31