ropensci / mregions2

Access the Marine Regions Gazetteer and the Marine Regions Data Products in R. Maintained by @salvafern.
https://docs.ropensci.org/mregions2/
MIT License
4 stars 2 forks source link

Marine region not fully recovered with gaz_geometry #26

Open lawleyjw opened 1 month ago

lawleyjw commented 1 month ago

I am trying to calculate the area for several marine regions and noticed that the area I was getting was smaller than expected. So I tried mapping the regions to look for inconsistencies. When I run the code below I get the image below it, but what it seems to be missing a large portion of the area that marine region should cover (see latest image). Am I missing any options with gaz_geometry or is there an issue here? I appreciate any assistance/advice.

test <- gaz_geometry(26584, multipart=FALSE) #same things happens if multipart=TRUE
test_sf <- st_as_sf(test)
ggplot() +
  geom_sf(data = test_sf, fill = 'blue', color = 'black') +
  ggtitle("Pacific Part of Canada's EEZ") +
  theme_minimal()

Screen Shot 2024-05-29 at 21 49 57

Screen Shot 2024-05-29 at 21 50 12
bart-v commented 1 month ago

Clearly the R code does not take into account the multiple polygons returned by the API @salvafern This works fine: https://marineregions.org/rest/getGazetteerGeometries.jsonld/26584/

salvafern commented 1 month ago

The code was not considering a case when the geometry has one single source but two attributeValue(s) as here:

http://marineregions.org/mrgid/26584/geometries?source=80&attributeValue=25505 http://marineregions.org/mrgid/26584/geometries?source=80&attributeValue=25585

And only the first was being picked up. Should be fixed now.

library(mregions2)
library(ggplot2)
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE

test <- gaz_geometry(26584, multipart=FALSE) #same things happens if multipart=TRUE
test_sf <- st_as_sf(test)
ggplot() +
  geom_sf(data = test_sf, fill = 'blue', color = 'black') +
  ggtitle("Pacific Part of Canada's EEZ") +
  theme_minimal()

Created on 2024-06-03 with reprex v2.1.0

@lawleyjw Thanks a lot for spotting, please don't hesitate to raise more issues if you encountered any.

lawleyjw commented 1 week ago

Thanks @salvafern !

I am still getting the same issue though with other regions. See example below:

> library(mregions2)
> library(ggplot2)
> library(sf)
Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
> test <- gaz_geometry(8940, multipart=FALSE) #same things happens if multipart=TRUE
> test_sf <- st_as_sf(test)
> ggplot() +
+   geom_sf(data = test_sf, fill = 'blue', color = 'black') +
+   theme_minimal()
Screen Shot 2024-06-24 at 14 10 32 Screen Shot 2024-06-24 at 14 10 17
salvafern commented 1 week ago

I will have a look