Restricting geographical space for SDM analyses in R
I would approach this as follows:
Get a polygon of the country boundary where your study area is located,
then buffer it inside, (using a negative buffer distance). Now you can
"difference" the full country boundary and the inner buffer to get just
the coastal strip.
Here's an example:
library(sf)
library(maptools)
library(dplyr)
library(ggplot2)
theme_set(theme_bw())
data("wrld_simpl") # From maptools package
# Example for Egypt
egypt = st_as_sf(wrld_simpl[wrld_simpl$NAME == "Egypt",])
# Transform to Spherical Mercator for correct buffering in meters
egypt = st_transform(egypt, 3857)
# Inside buffer size 50 kilometers
d = 50000
# Setup polygon to crop only coast region
coast_corners = matrix(c(26,32,34,32,34,30,26,30,26,32),
????????????????????? ncol=2, byrow=TRUE)
coast_region = st_sf(st_sfc(st_polygon(list(coast_corners))))
st_crs(coast_region) = st_crs(4326)
# But transform this region also to Spherical Mercator
coast_region = st_transform(coast_region, 3857)
# Use negative buffer distance to get inner buffer
egypt_buffer =? st_buffer(egypt, -d)
# Now Difference the full country and buffer polygons,
# then Crop out only coast region
coastal_strip = st_difference(egypt, egypt_buffer) %>%
? st_crop(., coast_region)
# Plot result
ggplot(data = egypt) +
? geom_sf() +
? geom_sf(data = coastal_strip, fill="red")
HTH,
Micha
On 11/16/20 1:44 PM, Francisco Borges wrote:
I am conducting SDM analysis in R, and would like to restrict my predictions in the geographical space. I am aware of how to do it by cropping the world space with latitude and longitude, but my case is a little bit trickier. I want to restrict my analysis to only the coastal area (i.e. from ocean to, let's say a certain distance inland). I have yet to find a solution online to this question, but I am aware that using a shapefile it could work. I have zero knowledge of GIS, unfortunately, as I understand that this could be one of the solutions. I appreciate any info or suggestion you can provide me Best, *Francisco Borges* MARE ? Marine and Environmental Sciences Centre Laborat?rio Mar?timo da Guia - Faculdade de Ci?ncias da Universidade de Lisboa Av. Nossa Senhora do Cabo, 939 2750-374 Cascais, Portugal Tel: +351 214 869 211 publons.com/a/1504585/ orcid.org/0000-0002-3911-0421 http://www.mare-centre.pt/pt/user/8232 [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Micha Silver Ben Gurion Univ. Sde Boker, Remote Sensing Lab cell: +972-523-665918 -------------- next part -------------- A non-text attachment was scrubbed... Name: buffer_example.pdf Type: application/pdf Size: 9320 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20201117/872ec8bd/attachment.pdf>