Created
April 7, 2020 12:12
-
-
Save z3tt/84d06b3d66adca38b2795ebed449f2bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` r | |
library(tidyverse) | |
library(raster) | |
library(sf) | |
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3 | |
oceans <- | |
rnaturalearth::ne_download(scale = 10, | |
category = "physical", | |
type = "ocean", | |
returnclass = "sf") | |
#> OGR data source with driver: ESRI Shapefile | |
#> Source: "C:\Users\Cedric\AppData\Local\Temp\RtmpKQR6db", layer: "ne_10m_ocean" | |
#> with 1 features | |
#> It has 3 fields | |
ggplot(oceans) + geom_sf(fill = "dodgerblue") | |
``` | |
 | |
``` r | |
bbox <- as(extent(4, 16, 39, 51), 'SpatialPolygons') | |
crs(bbox) <- crs(oceans) | |
oceans_med <- oceans %>% | |
st_crop(., bbox) | |
#> although coordinates are longitude/latitude, st_intersection assumes that they are planar | |
#> Warning: attribute variables are assumed to be spatially constant throughout all | |
#> geometries | |
ggplot(oceans_med) + geom_sf(fill = "dodgerblue") | |
``` | |
 | |
``` r | |
oceans_fix <- st_difference(oceans_med, st_as_sfc(st_bbox(oceans_med))) | |
#> although coordinates are longitude/latitude, st_difference assumes that they are planar | |
#> Warning: attribute variables are assumed to be spatially constant throughout all | |
#> geometries | |
ggplot(oceans_fix) + geom_sf(fill = "dodgerblue") | |
``` | |
 | |
<sup>Created on 2020-04-07 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment