The code below allows you to create a connection to the server and explore the available data layers.
Code
library(sf) # simple features packages for handling vector GIS datalibrary(httr) # generic webservice packagelibrary(tidyverse) # a suite of packages for data wrangling, transformation, plotting, ...library(ows4R) # interface for OGC webserviceslibrary(rnaturalearth) #World Map data from Natural Earthlibrary(leaflet)library(leafem)library(knitr)#Base Layer for ACA GeoServeraca_geo<-"https://allencoralatlas.org/geoserver/ows"# Establish a connectionaca_client <- WFSClient$new(aca_geo, serviceVersion ="1.0.0")#List of featuresaca_lyrs<-aca_client$getFeatureTypes(pretty =TRUE)aca_lyrs
name title
1 coral-atlas:benthic_data_verbose Allen Coral Atlas benthic data
2 coral-atlas:geomorphic_data_verbose Allen Coral Atlas geomorphic data
Request data for your monitoring region
Let’s assume I have two monitoring sites (i.e., locations) in Palau, and I want to extract the geomorphic habitat classification for these sites. The code below allows you to generate your sites and create a bounding box to delineate the spatial extent of your monitoring and query the GeoServer.
Using this bounding box, we can query the server to extract the geomorphic data within this region. The table below is a simple feature data frame (spatial object) containing all the data stored in the GeoServer for geopmorphic habitat classification within the bounding box.
Code
#convert bounding box into string for the querymy.bbox<- my.bbox %>%as.character()%>%paste(.,collapse =',')#set up your queryurl$query <-list(service ="WFS",version ="1.0.0",request ="GetFeature",typename = aca_lyrs$name[2], # I am selecting this layer:"reefcloud:storm4m_exposure_year_tier",bbox = my.bbox,width=768,height=330,srs="EPSG%3A4326",styles='',format="application/openlayers")request <-build_url(url)#request the data and set up coordinate referencepalau<-read_sf(request)%>%st_set_crs(4326)pal <-colorFactor(palette ="YlOrRd",domain = palau$class_name)leaflet(palau)%>%addPolygons(color ="#444444", stroke=F,weight =1, smoothFactor =0.5,opacity =1.0, fillOpacity =1,fillColor =~pal(as.factor(palau$class_name)),highlightOptions =highlightOptions(color ="white", weight =2,bringToFront =TRUE))%>%addLegend("bottomright", pal = pal, values =~as.factor(palau$class_name),title ="Geomorphic classification </br> Allen Coral Atlas",labFormat =labelFormat(),opacity =1 )%>%addMarkers(data=sites, label =~name)%>%addProviderTiles(providers$Esri.WorldImagery)