Skip to content

Restricting geographical space for SDM analyses in R

3 messages · Francisco Borges, Ben Tupper, Micha Silver

#
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
#
Hi,

You can limit the domain of your modeling to irregular polygons such
as a coastline buffered to some +/- distance inshore/offshore, but the
ease of doing so depends upon your data and covariates. You haven't
provided much detail (well, none actually) so it's a challenge to
suggest anything.  For the vector/point data take a look at the sf
package (https://CRAN.R-project.org/package=sf) or sp
(https://CRAN.R-project.org/package=sp) packages, and for rasterized
data you could try raster (https://CRAN.R-project.org/package=raster),
terra (https://CRAN.R-project.org/package=terra) or stars
(https://CRAN.R-project.org/package=stars) packages.

Cheers,
Ben

On Mon, Nov 16, 2020 at 6:44 AM Francisco Borges
<franciscoomcborges at gmail.com> wrote:

  
    
#
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: