GIStoolkitis a collection of handy R functions for accomplishing
common GIS tasks.
You can install the development version of GIStoolkit from GitHub with:
remotes::install_github("QAWalker/GIStoolkit")library(GIStoolkit)get_clicked_point() launches an interactive map in your viewer or
browser and allowing the user to save the clicked point. You must click
the marker icon on the left to add a point.
my_point <- get_clicked_point()click_to_crop(raster_obj, mask = TRUE)allows you to define a study
area visually.
The maskparameter determines the output:
mask = TRUE(Default): Launches a polygon tool. The result is clipped to the exact shape, and pixels outside are set toNA.mask = FALSE: Launches an extent tool. The result is cropped to a rectangular bounding box.
r <- terra::rast("my_raster.tif")
# To get a polygon shape:
polygon_crop <- click_to_crop(r, mask = TRUE)
# To crop to a rectangular defined by the extend of the points:
rectangle_crop <- click_to_crop(r, mask = FALSE)
# Save Cropped Results
terra::writeRaster(polygon_crop, filename = "path/to/save/polygon_cropped_raster.tif")
terra::writeRaster(rectangle_crop, filename = "path/to/save/rectangle_cropped_raster.tif")