quadmesh icon indicating copy to clipboard operation
quadmesh copied to clipboard

terra support?

Open Lvulis opened this issue 3 years ago • 4 comments

Are there any plans to get terra support? I still use one of your stackoverflow answers to generate stacked raster plots and would like to eventually transition that workflow into purely terra, although I'm sure others may have other use cases as well.

Lvulis avatar Jul 22 '22 04:07 Lvulis

thanks for the q, but I don't think so though - in everything I've learned it's better to stay independent of the heavy spatial packages in R, they keep changing and deprecating existing code and complicating things that should be simple (bit more of a rant below if you're interested).

I want to replace this with more straightforward code that just takes information from a raster context (extent, dimension, crs) and provides the mesh, and optionally sets it up with data values. Then someone can very easily formally link this more flexible code to a formal type like terra.

that's actually pretty simple and I'm happy to set up an example if you want - I'll explore an update to my SO answer 👍 I'm not sure what I'll do about quadmesh, I had moved most of this in to anglr but I'd rather be completely separated from sp/terra/sf etc now.

RANT

it's irritating to me that these simple concepts "extent", "dimension" have such complicated format-bound functions, and not a single unifying function across multiple packages - which is how it should be. You can stars a rast, or rast a stars, but you can't st_bbox a rast, or ext a stars - and that is ridiculous, it's what sp was created for imo but those folks have happily burned the farm to the ground and created more and more formats to compete with each other.

mdsumner avatar Jul 22 '22 05:07 mdsumner

First, I'd like to update my question and apologize for it - I had to dig into external hard disk to find the functional code I used and it is in fact using anglr. My laptop and the SSD on board died early last month so I've been recovering old data, I refound this example on the website and then dug up the code on that external disk. Recalling the workflow I believe a lot of the quadmesh functions already suggested using anglr instead so I had made the transition then. So perhaps this would be more appropriately placed in the anglr repo and dealt with there.

If you have the time to update the SO answer/generate an example to use anglr, or reflect modern workflow that would be great, and I think it would be appreciated and used by the remote sensing community that uses R. I used anglr and rgl to generate the figures (which are in fact animated to build the stack in the left panel) in this presentation slide below, and it is commonly requested by my advisor or collaborators for some presentations to stack multiple raster-based datasets like multi-band imagery. image

Won't comment too much on the geospatial package ecosystem but will note a non-insignificant length of my work is going between different raster types... Seconding your point about simply extracting the raster context spatial information, perhaps that would work much better and avoid having to deal with the pitfalls of explicitly handling the different raster types. I am using something like this in my codebase elsewhere, perhaps it would be extended to output consistent spatial information? The code below is not functional as the output types from stars and terra aren't identical. Obviously as you pointed the issue of the crs output is cumbersome

# for an input raster-type x get out res, extent, etc.
  if(methods::is(x, "stars")) {
    geoInfo = stars::st_dimensions(x)
    res = geoInfo$... # insert here necessary information
    x = as.matrix.stars(x) #converts stars to matrix without running into js errors
  } else if(methods::is(watermask, "terra")) { 
    res = res(x[[1]])
    ext = as.vector(ext(x[[1]])))
    x    = terra::as.matrix(x[[1]], wide = T) #assume a single band?
}

Lvulis avatar Jul 22 '22 16:07 Lvulis

excellent thanks for the update! To add a bit, I'm not against packages that support the formats - just I don't want the underlying code to be bound to a bigger package - it just doesn't make sense, when you're building something else that doesn't need sf, terra, geos, gdal, they just get in the way. 🙏😅

mdsumner avatar Jul 22 '22 23:07 mdsumner

ok I've done the minimum for this, for coords and texture you still need raster objects (even if main input is terra)

mdsumner avatar Aug 31 '22 00:08 mdsumner