Web Coverage Service (wcs) data
- get a bounding box
- build the query url
- download and read raster data
- GetCapabilities
- download digital orthophotos (dop)
- plot 3d graphic with orthophoto as texture
If you have worked with digital elevation models (dem), you probably downloaded big files and had to cut out your region of interest. Or you stitched together multiple files to get the desired coverage. With Web Coverage Service (WCS) you can download raster files in exactly the extent and resolution you want to work with.
We will show how to use the wcs service of the German state Nordrhein-Westfalen (NRW). If you can read German you can read more in the manual about wcs.
We will be working with a digtial elevation model (dem or dgm in German). We will also be using digital ortho photos (dop).
get a bounding box
In order to download data we need a bounding box. We can use the the osmdata package to search for coordinates of a landmark (or region) with the getbb()
function. We will be searching for the “Drachenfels”, a famous mountaintop near the river Rhine.
What we did here is get the coordinates with getbb()
as a matrix of two points. Then we convert the min point to an st_point
object and further convert it to an sfc
object from the sf package. We then have to give it a crs (since the getbb
function doesn’t add this) with st_set_crs
. The query we will use later requires an UTM coordinate system. So we transform to that crs with st_transform
. We then add a buffer around this central coordinate with st_buffer
and calculate the bounding box of that with st_bbox
.
build the query url
Now that we have a bounding box we can insert its coordinates into the data query url using the str_glue()
function of the stringr package. str_glue()
replaces everything inside curly braces.
The resulting url is the following: https://www.wcs.nrw.de/geobasis/wcs_nw_dgm?VERSION=2.0.1&SERVICE=wcs&REQUEST=GetCoverage&COVERAGEID=nw_dgm&FORMAT=image/tiff&SUBSET=x(372511,374511)&SUBSET=y(5613116,5615116)&SCALEFACTOR=1&SUBSETTINGCRS=EPSG:25832. You can also use it in the browser to download the file.
The wcs url consist of the following parts:
- The base url:
https://www.wcs.nrw.de/geobasis/wcs_nw_dgm
- a
?
followed by all the options (devided by&
) VERSION=2.0.1
defines the version of the protocolSERVICE=wcs
defines that we want to use the wcs serviceREQUEST=GetCoverage
is the request to get data. Other requests are for exampleGetCapabilities
orDescribeCoverage
COVERAGEID=nw_dgm
defines the dataset we want to downloadFORMAT=image/tiff
defines the output formatSUBSET=x(372511,374511)
andSUBSET=y(5613116,5615116)
define the bounding box from which we want to get dataSUBSETTINGCRS=EPSG:25832
defines the coordinate system of the subset bounding box coordinates. Some services support multiple coordinate systems. Others work only with one specific.SCALEFACTOR=1
can be used to scale down data before the download. UseSCALEFACTOR=0.1
for 10x aggregation for example.
Further options not used here are:
OUTPUTCRS=EPSG:25832
defines the output crs. For supported crs see theGetCapabilities
request below.INTERPOLATION=nearest
defines the interpolation method for scaled downloads. This can also bebilinear
oraverage
or other values documentend in GetCapabilities.RANGESUBSET=band1,band2
defines the bands to download (relevant for the orthophotos).
More options are described in the official manual on page 8.
download and read raster data
We can now download the data and read it with the raster package
With names(dem)
we give the layer a sensible name.
GetCapabilities
To get more information about the data service we can use the GetCapabilities
request. This returns a XML file that we can read like this:
We can use the htmltidy package to browse through the xml file:
<?xml version="1.0" encoding="UTF-8"?>
<wcs:Capabilities xmlns:wcs="http://www.opengis.net/wcs/2.0" xmlns:ows="http://www.opengis.net/ows/2.0" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:gmlcov="http://www.opengis.net/gmlcov/1.0" xmlns:swe="http://www.opengis.net/swe/2.0" xmlns:inspire_common="http://inspire.ec.europa.eu/schemas/common/1.0" xmlns:inspire_dls="http://inspire.ec.europa.eu/schemas/inspire_dls/1.0" xmlns:crs="http://www.opengis.net/wcs/crs/1.0" xmlns:int="http://www.opengis.net/wcs/interpolation/1.0" xsi:schemaLocation="http://www.opengis.net/wcs/2.0 http://schemas.opengis.net/wcs/2.0/wcsAll.xsd http://inspire.ec.europa.eu/schemas/inspire_dls/1.0 http://inspire.ec.europa.eu/schemas/inspire_dls/1.0/inspire_dls.xsd" version="2.0.1">
<ows:ServiceIdentification>
<ows:Title>WCS NW DGM</ows:Title>
<ows:Abstract>Höhenmodell des Landes NRW.</ows:Abstract>
<ows:Keywords>
<ows:Keyword>NW</ows:Keyword>
<ows:Keyword>NRW</ows:Keyword>
<ows:Keyword>Nordrhein-Westfalen</ows:Keyword>
<ows:Keyword>Bezirksregierung Köln</ows:Keyword>
<ows:Keyword>Abteilung 7</ows:Keyword>
<ows:Keyword>Geobasis NRW</ows:Keyword>
<ows:Keyword>Geobasisdaten</ows:Keyword>
<ows:Keyword>Landesvermessung</ows:Keyword>
<ows:Keyword>AdV</ows:Keyword>
<ows:Keyword>Arbeitsgemeinschaft der Vermessungsverwaltungen der Länder</ows:Keyword>
<ows:Keyword>AdV-OWS-Basisprofil</ows:Keyword>
<ows:Keyword> AdV-WCS-Profil 2.0.1</ows:Keyword>
<ows:Keyword>WCS</ows:Keyword>
<ows:Keyword>WCS_NW_DGM</ows:Keyword>
<ows:Keyword>DGM</ows:Keyword>
<ows:Keyword>Digitales Geländemodell</ows:Keyword>
<ows:Keyword>Geländemodell</ows:Keyword>
<ows:Keyword>INSPIRE</ows:Keyword>
</ows:Keywords>
<ows:ServiceType codeSpace="OGC">OGC WCS</ows:ServiceType>
<ows:ServiceTypeVersion>2.0.1</ows:ServiceTypeVersion>
<ows:ServiceTypeVersion>1.1.1</ows:ServiceTypeVersion>
<ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
<ows:Profile>http://www.opengis.net/spec/WCS/2.0/conf/core</ows:Profile>
<ows:Profile>http://www.opengis.net/spec/WCS_protocol-binding_get-kvp/1.0/conf/get-kvp</ows:Profile>
<ows:Profile>http://www.opengis.net/spec/WCS_protocol-binding_post-xml/1.0/conf/post-xml</ows:Profile>
<ows:Profile>http://www.opengis.net/spec/GMLCOV/1.0/conf/gml-coverage</ows:Profile>
<ows:Profile>http://www.opengis.net/spec/GMLCOV/1.0/conf/multipart</ows:Profile>
<ows:Profile>http://www.opengis.net/spec/GMLCOV/1.0/conf/special-format</ows:Profile>
<ows:Profile>http://www.opengis.net/spec/GMLCOV_geotiff-coverages/1.0/conf/geotiff-coverage</ows:Profile>
<ows:Profile>http://www.opengis.net/spec/WCS_service-extension_crs/1.0/conf/crs</ows:Profile>
<ows:Profile>http://www.opengis.net/spec/WCS_service-extension_scaling/1.0/conf/scaling</ows:Profile>
<ows:Profile>http://www.opengis.net/spec/WCS_service-extension_range-subsetting/1.0/conf/record-subsetting</ows:Profile>
<ows:Profile>http://www.opengis.net/spec/WCS_service-extension_interpolation/1.0/conf/interpolation</ows:Profile>
<ows:Fees>Nutzungsbedingungen: Die Geobasisdaten des amtlichen Vermessungswesens werden als öffentliche Aufgabe gem. VermKatG NRW und gebührenfrei nach Open Data-Prinzipien über online-Verfahren bereitgestellt. Nutzungsbedingungen: siehe https://www.bezreg-koeln.nrw.de/system/files/media/document/file/lizenzbedingungen_geobasis_nrw.pdf</ows:Fees>
<ows:AccessConstraints>NONE</ows:AccessConstraints>
</ows:ServiceIdentification>
<ows:ServiceProvider>
<ows:ProviderName>Geobasis NRW</ows:ProviderName>
<ows:ProviderSite xlink:type="simple" xlink:href="http://www.geobasis.nrw.de"/>
<ows:ServiceContact>
<ows:IndividualName></ows:IndividualName>
<ows:PositionName></ows:PositionName>
<ows:ContactInfo>
<ows:Phone>
<ows:Voice>+49(0)221-147-4994</ows:Voice>
<ows:Facsimile>+49(0)221-147-4874</ows:Facsimile>
</ows:Phone>
<ows:Address>
<ows:DeliveryPoint>Muffendorfer Str. 19-21</ows:DeliveryPoint>
<ows:City>Bonn</ows:City>
<ows:AdministrativeArea>Nordrhein-Westfalen</ows:AdministrativeArea>
<ows:PostalCode>53177</ows:PostalCode>
<ows:Country>Deutschland</ows:Country>
<ows:ElectronicMailAddress>geobasis@bezreg-koeln.nrw.de</ows:ElectronicMailAddress>
</ows:Address>
<ows:OnlineResource xlink:type="simple" xlink:href="http://www.geobasis.nrw.de"/>
<ows:HoursOfService>Montag bis Donnerstag 8:30 - 15:00</ows:HoursOfService>
<ows:ContactInstructions></ows:ContactInstructions>
</ows:ContactInfo>
<ows:Role>Ansprechpartner</ows:Role>
</ows:ServiceContact>
</ows:ServiceProvider>
<ows:OperationsMetadata>
<ows:Operation name="GetCapabilities">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:type="simple" xlink:href="https://www.wcs.nrw.de/geobasis/wcs_nw_dgm?"/>
<ows:Post xlink:type="simple" xlink:href="https://www.wcs.nrw.de/geobasis/wcs_nw_dgm?">
<ows:Constraint name="PostEncoding">
<ows:AllowedValues>
<ows:Value>XML</ows:Value>
</ows:AllowedValues>
</ows:Constraint>
</ows:Post>
</ows:HTTP>
</ows:DCP>
</ows:Operation>
<ows:Operation name="DescribeCoverage">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:type="simple" xlink:href="https://www.wcs.nrw.de/geobasis/wcs_nw_dgm?"/>
<ows:Post xlink:type="simple" xlink:href="https://www.wcs.nrw.de/geobasis/wcs_nw_dgm?">
<ows:Constraint name="PostEncoding">
<ows:AllowedValues>
<ows:Value>XML</ows:Value>
</ows:AllowedValues>
</ows:Constraint>
</ows:Post>
</ows:HTTP>
</ows:DCP>
</ows:Operation>
<ows:Operation name="GetCoverage">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:type="simple" xlink:href="https://www.wcs.nrw.de/geobasis/wcs_nw_dgm?"/>
<ows:Post xlink:type="simple" xlink:href="https://www.wcs.nrw.de/geobasis/wcs_nw_dgm?">
<ows:Constraint name="PostEncoding">
<ows:AllowedValues>
<ows:Value>XML</ows:Value>
</ows:AllowedValues>
</ows:Constraint>
</ows:Post>
</ows:HTTP>
</ows:DCP>
</ows:Operation>
<ows:ExtendedCapabilities>
<inspire_dls:ExtendedCapabilities>
<inspire_common:MetadataUrl xsi:type="inspire_common:resourceLocatorType">
<inspire_common:URL>https://apps.geoportal.nrw.de/soapServices/CSWStartup?Service=CSW&Request=GetRecordById&Version=2.0.2&outputSchema=http://www.isotc211.org/2005/gmd&elementSetName=full&id=9d9ffbae-3f27-437a-92cd-5550af618690</inspire_common:URL>
<inspire_common:MediaType>application/xml</inspire_common:MediaType>
</inspire_common:MetadataUrl>
<inspire_common:SupportedLanguages>
<inspire_common:DefaultLanguage>
<inspire_common:Language>ger</inspire_common:Language>
</inspire_common:DefaultLanguage>
</inspire_common:SupportedLanguages>
<inspire_common:ResponseLanguage>
<inspire_common:Language>ger</inspire_common:Language>
</inspire_common:ResponseLanguage>
<inspire_dls:SpatialDataSetIdentifier>
<inspire_common:Code>https://registry.gdi-de.org/id/de.nw/DGM1</inspire_common:Code>
</inspire_dls:SpatialDataSetIdentifier>
</inspire_dls:ExtendedCapabilities>
</ows:ExtendedCapabilities>
</ows:OperationsMetadata>
<wcs:ServiceMetadata>
<wcs:formatSupported>image/tiff</wcs:formatSupported>
<wcs:formatSupported>image/png</wcs:formatSupported>
<wcs:formatSupported>image/jpeg</wcs:formatSupported>
<wcs:formatSupported>image/png; mode=8bit</wcs:formatSupported>
<wcs:formatSupported>image/vnd.jpeg-png</wcs:formatSupported>
<wcs:formatSupported>image/vnd.jpeg-png8</wcs:formatSupported>
<wcs:Extension>
<int:InterpolationMetadata>
<int:InterpolationSupported>NEAREST</int:InterpolationSupported>
<int:InterpolationSupported>AVERAGE</int:InterpolationSupported>
<int:InterpolationSupported>BILINEAR</int:InterpolationSupported>
</int:InterpolationMetadata>
<crs:CrsMetadata>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/3034</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/3035</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/3043</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/3044</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/3045</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/3857</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/4258</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/4326</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/4647</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/5649</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/5650</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/5651</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/5652</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/5653</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/28992</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/25831</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/25832</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/25833</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/31466</crs:crsSupported>
<crs:crsSupported>http://www.opengis.net/def/crs/EPSG/0/31467</crs:crsSupported>
</crs:CrsMetadata>
</wcs:Extension>
</wcs:ServiceMetadata>
<wcs:Contents>
<wcs:CoverageSummary>
<wcs:CoverageId>nw_dgm</wcs:CoverageId>
<wcs:CoverageSubtype>RectifiedGridCoverage</wcs:CoverageSubtype>
<ows:Metadata xlink:type="simple" xlink:href="https://apps.geoportal.nrw.de/soapServices/CSWStartup?Service=CSW&Request=GetRecordById&Version=2.0.2&outputSchema=http://www.isotc211.org/2005/gmd&elementSetName=full&id=0c6796e5-9eca-4ae6-8b32-1fcc5ae5c481" about="TC211" xlink:role="application/xml"/>
</wcs:CoverageSummary>
</wcs:Contents>
</wcs:Capabilities>
We can for example extract a list of all the supported crs from the xml file:
Or the supported interpolation methods:
Or the output formats supported:
But note: The documentation states that only tiff files are geo referenced.
Finally we can get the coverage ID that we need to set in the query:
download digital orthophotos (dop)
Since Orthophotos are multichannel files (for red, green, blue and infrared) we have to use the stack()
function instead of raster()
to read them. The query is similar to the dem. We add RANGESUBSET=1,2,3
to the query to omit the infrared band (band 4). This saves some download size.
Since the dop has 10 times the resolution of the dem we set SCALEFACTOR=0.1
. This way we get a raster with the same pixel size as the dem.
Similar to the dem we add names to the layers (red, green and blue).
If we look into GetCapabilities of the dop service we can see that this one only supports one crs:
plot 3d graphic with orthophoto as texture
The rayshader package is a wonderful package to create a 3d plot from a dem. You have to install it from github via devtools::install_github("tylermorganwall/rayshader")
since it is not yet on CRAN.
In order to plot the dem with the orthophotos as texture we have to do some conversion as described in this tutorial:
Now we can create an interactive rotatable 3d-plot with the plot_3d
function:
To better the performance you can set triangulate=T
and max_error
to a higher number. This way the graphic will consist of fewer triangles and hence will be faster to render. But be aware that you loose some details with really high values of max_error
:
We can also render a movie: