Load and Simplify EEZ
library(tidyverse)
library(sf)
library(rmapshaper) # bash prep: sudo apt-get update; sudo apt-get install libv8-dev
library(RPostgreSQL)
library(geojsonio)
library(DT)
# set working dir relative to this rmarkdown file
if (basename(getwd())=='sdg14') setwd('technical')
# setup ~/mbon_data_big: cd ~; ln -s /mbon/data_big mbon_data_big
eez_shp = '~/mbon_data_big/technical/boundaries/eez/eez.shp'
eez_s005_shp = '~/mbon_data_big/technical/boundaries/eez_derived/eez_s005.shp'
esp_s005_shp = '~/mbon_data_big/technical/boundaries/eez_derived/esp_s005.shp'
esp_ck_csv = '~/mbon_data_big/technical/boundaries/eez_derived/esp_ck.csv'
if (!file.exists(eez_s005_shp)){
eez = st_read(eez_shp)
# simplify eez
eez_s005 = eez %>%
geojson_json() %>% # convert to geojson for faster ms_simplify; 69.6 sec
ms_simplify(keep=0.05, keep_shapes=T, explode=F) %>% # simplify; 11.9 minutes
geojson_sp() %>% st_as_sf() # convert back to simple features
# write to shapefile
st_write(eez_s005, eez_s005_shp)
} else {
eez_s005 = st_read(eez_s005_shp)
}
## Reading layer `eez_s005' from data source `/mbon/data_big/technical/boundaries/eez_derived/eez_s005.shp' using driver `ESRI Shapefile'
## converted into: MULTIPOLYGON
## Simple feature collection with 281 features and 24 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -180 ymin: -85.5625 xmax: 180 ymax: 86.99373
## epsg (SRID): 4326
## proj4string: +proj=longlat +datum=WGS84 +no_defs
# plot of EEZ by area
#plot(eez_s005['Area_km2']) # SLOW!
# show eez table
eez_s005 %>%
select(-geometry) %>%
datatable()