TransWikia.com

Generate a stars object from tabular spatial temporal data?

Geographic Information Systems Asked by cboettig on July 21, 2021

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, 
             date = today() : (today() + 9), 
             intensity = rnorm(10))

In reality, it is a collection of ~ 230 compressed tab-separated text files, 10 MB each, in the above format.

I am trying to go from this tabular representation (e.g. reading this data with readr::read_tsv()) to a stars object (eventually/ideally a stars_proxy object, given the data size).

One thing I’ve considered is converting to an st object first:

star1 <- ex %>% 
  st_as_sf(coords = c("longitude", "latitude"), 
         crs = 4326) %>% 
  st_as_stars()

but this creates a stars object with only one dimension, which is a geometry. Since I have a point geometry, I’d rather have this as x and y dimensions in the 4326 (WGS84) CRS, and I’d like time to be a dimension. I can coerce the dimension (I think), with:

star2 <- st_set_dimensions(star1, 1, star1$date, "date")

though I still see only 1 listed dimension:

star2
stars object with 1 dimensions and 2 attributes
attribute(s):
     date          intensity      
 Min.   :18332   Min.   :-1.3239  
 1st Qu.:18334   1st Qu.:-0.9127  
 Median :18336   Median :-0.1671  
 Mean   :18336   Mean   :-0.1405  
 3rd Qu.:18339   3rd Qu.: 0.4975  
 Max.   :18341   Max.   : 1.0076  
dimension(s):
         from to offset delta refsys point values
geometry    1 10  18332     1     NA  date   NULL

So, given data in this tabular format, how do I generate a proper a stars object (ideally stars_proxy object), with proper x,y, and time dimension attributes?

One Answer

Not full answer but

ex_star <- st_as_stars(ex) 

will create a stars with the first two columns from the tibble as the first two dimensions of the stars, so make sure you pass a tibble with the correct arrangement of columns. There is a dimensions argument which I honestly till now I thought that giving a number would tell st_stars to keep adding columns as dimensions but i tested it and does not seem to work.

Answered by Capture OSM1 on July 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP