12/5/2023 0 Comments Crop years raster in rFirst we create an extent polygon using st_bbox, st_as_sfc coerces to a polygon object, then we clip the data with st_intersection. Note that the input into the st_bbox function are in a different order than raster::extent or terra::ext (sf::st_bbox=xmin, ymin, xmax, ymax verses terra::ext=xmin, xmax, ymin, ymax). Here is an approach staying entirely in sf using st_intersects. fishing_pts_sub <- st_as_sf(crop(vect(fishing_pts), The crop function clips the data to a terra extent object, passed in the function using ext. We wrap it all in st_as_sf to coerce back to an sf object. This can be done easily on-the-fly within crop using vect. However please note that, to work your vector data needs to be a terra vect class object. raster county raster plotparcelbb bbox countyshp county shape 4.Use bounding box to clip the appropriate county imagery tile (raster&vector in QGIS) Check class class (raster) class (plotparcelbb) Check. Not sure if I need to convert the bbox to a polygon to do this. library(sf)įishing_pts = ame(lon=runif(100,-80,-50), lat=runif(100,-60,-40))įishing_pts <- st_as_sf(fishing_pts, coords = c("lon", "lat"), I have attempted to use gIntersection and crop (see below). Honestly, they are much faster with modernized code.įirst, add libraries and create some dummy data that looks like yours. This is all somewhat forcing migration to the new spatial classes in sf and terra. The terra library is the replacement for raster, with much of the processing now occurring in C++. The depreciation schedule for sp and rgdal have been announced, being replaced by sf. See the code below: library (sf) library (raster) library (terrain). To get this working with an sf object, I can call raster::crop (raster, as.vector (stbbox (polygon))) as an ugly workaround. So I could just do raster::crop (raster, polygon). Up to now, this was automatically extracted from a Spatial object. ![]() ![]() However, I think the problem is that when you crop the raster::stack it is converted to a raster::brick. The raster is cropped with no errors but when I try and plot the cropped raster I get the following Stack Exchange Network Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. raster::crop expects an extent object as second argument. ![]() I would recommend modernizing your workflow a bit. First: next time make a reproducible example so it is easier to help you Second: always include your library so it is clear where the functions you use came from.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |