The Open Geospatial Consortium (OGC) has created a number of open specifications for web services including web feature services (WFS), web map services (WMS), Web Map Tile Service (WMTS), web coverage services (WCS), and web processing services (WPS). On this page, we will look at how to start working with these functions.
library(httr)
url <- "https://shiny1.envs.vcu.edu/geoserver/wfs"
q <- list( request = "GetCapabilities" )
res <- GET( url = url,
query = q )
res
## Response [https://shiny1.envs.vcu.edu/geoserver/wfs?request=GetCapabilities]
## Date: 2019-11-21 20:10
## Status: 200
## Content-Type: application/xml
## Size: 102 kB
## <BINARY BODY>
If we need to, we can look at the response as an XML format
## {xml_document}
## <WFS_Capabilities version="2.0.0" schemaLocation="http://www.opengis.net/wfs/2.0 http://shiny1.envs.vcu.edu/geoserver/schemas/wfs/2.0/wfs.xsd" updateSequence="269" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wfs/2.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cite="http://www.opengeospatial.net/cite" xmlns:tiger="http://www.census.gov" xmlns:nurc="http://www.nurc.nato.int" xmlns:sde="http://geoserver.sf.net" xmlns:it.geosolutions="http://www.geo-solutions.it" xmlns:topp="http://www.openplans.org/topp" xmlns:sf="http://www.openplans.org/spearfish" xmlns:envs421="ces.vcu.edu" xmlns:baja="dyerlab.com/baja">
## [1] <ows:ServiceIdentification>\n <ows:Title>GeoServer Web Feature Serv ...
## [2] <ows:ServiceProvider>\n <ows:ProviderName>Center for Environmental ...
## [3] <ows:OperationsMetadata>\n <ows:Operation name="GetCapabilities">\n ...
## [4] <FeatureTypeList>\n <FeatureType xmlns:tiger="http://www.census.gov ...
## [5] <fes:Filter_Capabilities>\n <fes:Conformance>\n <fes:Constraint ...
On this server, there exists a feature called bio7
in the baja
workspace. It is a raster image. We can grab that directly from the server as:
library(sf)
query <- list( request="GetFeature",
typeName = "topp:states" )
file <- tempfile(fileext=".gml")
httr::GET( url=url,
query = query,
httr::write_disk(file) )
## Response [https://shiny1.envs.vcu.edu/geoserver/wfs?request=GetFeature&typeName=topp%3Astates]
## Date: 2019-11-21 20:10
## Status: 200
## Content-Type: application/gml+xml; version=3.2
## Size: 310 kB
## <ON DISK> /var/folders/ty/1tdv5mw56p33qx86hnk5h8l80000gn/T//Rtmp72DZ9d/file33e73d5c9b82.gml
then we can translate it into an sf object with the following attributes.
## [1] "sf" "tbl_df" "tbl" "data.frame"
## [1] "gml_id" "STATE_NAME" "STATE_FIPS" "SUB_REGION" "STATE_ABBR"
## [6] "LAND_KM" "WATER_KM" "PERSONS" "FAMILIES" "HOUSHOLD"
## [11] "MALE" "FEMALE" "WORKERS" "DRVALONE" "CARPOOL"
## [16] "PUBTRANS" "EMPLOYED" "UNEMPLOY" "SERVICE" "MANUAL"
## [21] "P_MALE" "P_FEMALE" "SAMP_POP" "the_geom"
## Simple feature collection with 49 features and 23 fields
## geometry type: MULTISURFACE
## dimension: XY
## bbox: xmin: -124.7314 ymin: 24.95597 xmax: -66.96985 ymax: 49.37174
## epsg (SRID): NA
## proj4string: NA
## # A tibble: 49 x 24
## gml_id STATE_NAME STATE_FIPS SUB_REGION STATE_ABBR LAND_KM WATER_KM
## <chr> <chr> <chr> <chr> <chr> <dbl> <dbl>
## 1 state… Illinois 17 E N Cen IL 143987. 1993.
## 2 state… District … 11 S Atl DC 159. 18.0
## 3 state… Delaware 10 S Atl DE 5062. 1385.
## # … with 46 more rows, and 17 more variables: PERSONS <dbl>,
## # FAMILIES <dbl>, HOUSHOLD <dbl>, MALE <dbl>, FEMALE <dbl>,
## # WORKERS <dbl>, DRVALONE <dbl>, CARPOOL <dbl>, PUBTRANS <dbl>,
## # EMPLOYED <dbl>, UNEMPLOY <dbl>, SERVICE <dbl>, MANUAL <dbl>,
## # P_MALE <dbl>, P_FEMALE <dbl>, SAMP_POP <dbl>, the_geom <MULTISURFACE>
The geom feature scolumn is:
## [1] "the_geom"
And we can plot it as: