Last active
January 12, 2018 20:16
-
-
Save jebyrnes/c2e8d2b6c82849dad3a813d952ab8bb0 to your computer and use it in GitHub Desktop.
crop out coasts with R
This file contains 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
########### | |
# Libraries | |
########### | |
library(sp) | |
library(rgdal) | |
library(rgeos) | |
library(raster) | |
library(tidyverse) | |
library(spdplyr) | |
#### Load polygons | |
#data from https://www.nceas.ucsb.edu/~byrnes/floating_forests/ff_polys_proj.rds | |
classifications <- readRDS("../../data/output/consensus_shapefiles/ff_polys_proj.rds") | |
rownames(classifications@data) <- row.names(classifications) #this was throwing some oddness | |
#### Load coastline | |
#data from https://github.com/Irosenthal/Floating_Forests with this path | |
ca_coastline <- readOGR("../../data/coastlines/California", layer="California") | |
#Clip out anything on land in California | |
clip <- gDifference(classifications, ca_coastline, byid=TRUE) | |
row.names(clip) <- gsub(" .*", "", row.names(clip)) | |
all_spdfs_together_cropped <- SpatialPolygonsDataFrame(clip, | |
data=classifications@data) | |
#check to make sure it worked | |
plot(all_spdfs_together_cropped %>% filter(threshold==1), border="red") | |
plot(ca_coastline, add=TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hrm - after more feedback, is raster::erase just the solution?