---
title: "ingest_mregions"
subtitle: "Add `raw.mr_eez` for USA EEZ, including territories"
author: "Ben Best"
format:
html:
code-fold: show
---
## MarineRegions.org
* [Sovereign: United States · MRGID 8456 | Marine Regions](https://www.marineregions.org/eezdetails.php?mrgid=8456&all_territories=1&zone=eez)
![](./images/ingest_mregions/MarineRegions.org - Soveriegn US - MRGID 8456.png)
### Fetching
* [Marine Gazetteer web services | Marine Regions](https://www.marineregions.org/gazetteer.php?p=webservices)
* [REST service | Marine Regions](https://www.marineregions.org/gazetteer.php?p=webservices&type=rest)
```{r}
#| eval: false
librarian::shelf(
here, leaflet, leaflet.extras, # mapview,
marinesensitivity/msens,
sf, tibble,
quiet = T)
source(here("libs/db.R")) # define: con
eez_url <- URLencode(
"https://geo.vliz.be/geoserver/MarineRegions/wfs?service=WFS&version=1.0.0&request=GetFeature&typeNames=eez&cql_filter=sovereign1='United States'&outputFormat=SHAPE-ZIP")
eez_zip <- here("tmp/eez.zip")
eez_dir <- here("tmp/eez")
eez_shp <- here("tmp/eez/eez.shp")
download.file(eez_url, destfile = eez_zip, quiet = T)
unzip(eez_zip, exdir = eez_dir)
eez <- read_sf(eez_shp)
st_geometry(eez) = "geom" # rename
mapview::mapView(eez)
schema <- "raw"
table <- "mr_eez"
field <- "geom"
st_write(
eez,
dsn = con,
layer = Id(schema=schema, table = table),
driver = "PostgreSQL",
layer_options = "OVERWRITE=true")
# enforce SRID so shows up in tile.marinesensivity.org
dbExecute(con, glue("SELECT UpdateGeometrySRID('{schema}','{table}','{field}',4326);"))
```
![View of `raw.mr_eez` at [tile.marinesensitivity.org](https://tile.marinesensitivity.org/raw.mr_eez.html#1.5/43.1/-153.5)](./images/ingest_mregions/tile.msens - raw.mr_eez.png)