Skip to content

Instantly share code, notes, and snippets.

@jebyrnes jebyrnes/coastline_crop.R
Last active Jan 12, 2018

Embed
What would you like to do?
crop out coasts with R
###########
# 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)
@jebyrnes

This comment has been minimized.

Copy link
Owner Author

commented Jan 12, 2018

Hrm - after more feedback, is raster::erase just the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.