Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subset stars based on attribute value #178

Closed
florisvdh opened this issue May 22, 2019 · 4 comments
Closed

Subset stars based on attribute value #178

florisvdh opened this issue May 22, 2019 · 4 comments

Comments

@florisvdh
Copy link
Member

I hope this is a sensible question; I'm yet starting with stars, which looks very promising to me. Maybe I still overlooked an available solution for my question.

In the raster package one can produce a raster subset based on the cell values (for x and y dimensions at once), e.g. :

rasterobj[rasterobj > 10, drop = FALSE]

It sets the non-conforming cells to NA.

Further, if rasterobj has pure 'NA' rows and/or columns at the edges, the following effectively crops these and reduces the extent:

rasterobj[!is.na(rasterobj), drop = FALSE]

My case at hand is the last one. I could not find an equivalent 'subsetting' application in stars for this purpose, but maybe you can help.

I've looked into the migration table but saw no specific mention.

@edzer
Copy link
Member

edzer commented May 22, 2019

See section 4.2.3 of http://r-spatial.org/book/ for masking out areas based on attribute(s). There is (currently) no auto-crop based on NA edges; you can use st_crop if you have a geometry of the crop area.

@florisvdh
Copy link
Member Author

Thanks for the quick response and for the pointers, I will study this further! As this is for a workflow on several rasters where the NA edges cannot be easily predicted, I think I'll have to convert forth and back to/from raster.

I'm using stars now because it is successful in storing the rasters as subsets in a geopackage and because of its efficient and versatile polygonization and rasterization - that's so great!

@edzer
Copy link
Member

edzer commented May 22, 2019

See #176 for raster round tripping, but that approach might fail if the size of the returned sub-array changes randomly.

@florisvdh
Copy link
Member Author

florisvdh commented May 22, 2019

OK, thanks for this interesting example. (FYI, a rough prototype of the workflow, i.e. on a subset of the whole RasterBrick, is in here, but for further implementation I'll instead convert back to stars in order to write each layer as a geopackage subset, as prototyped further).

@edzer edzer closed this as completed May 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants