wdnr.gis is a package for pulling data from the Wisconsin Department of Natural Resources (WDNR) ArcGIS REST API sites, which are located here and here. There are a wide variety of services and layers on these sites, and this package helps to make sense of and use these data.

#> Loading required package: arcpullr
#> Loading required package: sf
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1

Notice that dependency packages arcpullr and sf are loaded along with wdnr.gis. These are essential packages that are used to pull data from an ArcGIS REST API and convert them to an sf object in R. All other functions in wdnr.gis are just wrappers around functions within arcpullr and sf that are specific to WDNR’s ArcGIS REST API.

Pulling specific layers

There are a handful of functions that are written specifically to query certain commonly used layers by using either a spatial or a SQL query. The querying is mostly built in to these functions, but advanced querying functionality is also available.

mke_cty_streams <- get_hydro_layer(county = "milwaukee")

You can also pass an sf object to these get_*_layer functions. This example just shows how to query the watershed that a particular point falls in and the streams within that watershed

pt <- sf_point(c(-90.8, 43.4))
watershed <- get_watershed_layer(sf_object = pt, huc_level = "HUC_8")
streams <- get_hydro_layer(sf_object = watershed)

Current functions that query specific WDNR layers are get_hydro_layer, get_watershed_layer, get_fmdb_site_layer, and get_roads_layer. Others are available upon request. If you have a layer that you use a lot, email us with a request for a layer specific function and we can add it in (especially if it will be useful to many others as well).

Finding Sections, Services, and Layers

ArcGIS REST APIs are hierarchical in nature. There are one or more folders, each of which contain one or more services. Within services are one or more layers and perhaps sub-layers. The layers contain the data of interest, but we’ve built in functions to be able to find any of the folders, services, or layers using the following functions:

#> [1] "FM_Trout"
#> [1] "FM_TROUT_ANNO_WTM_Ext"             "FM_TROUT_COUNTY_REGS_WTM"         
#> [5] "FM_TROUT_REGS_WTM_Ext"
match_layers("trout stream")
#> [1] "Trout Stream Regulations 2018-2019" "PNW-ASNRI Trout Streams"           
#> [3] "Trout Stream Lines"

There are also functions to find specific sections, services, and layers when the name is known. These are most useful when trying to obtain a URL for a specific layer.

#> [1] "FM_TROUT_ANNO_WTM_Ext"             "FM_TROUT_COUNTY_REGS_WTM"         
#> [5] "FM_TROUT_REGS_WTM_Ext"

These functions are most useful when combined for finding specific layers and the associated URLs.

list_layers(services = match_services("trout.*stream"))
#> character(0)
list_urls(layers = match_layers("trout.*stream"))
#> [1] "https://dnrmaps.wi.gov/arcgis/rest/services/FM_Trout/FM_TROUT_REGS_WTM_Ext/MapServer/0"      
#> [2] "https://dnrmaps.wi.gov/arcgis/rest/services/WT_SWDV/WT_Designated_Waters_WTM_Ext/MapServer/5"
#> [3] "https://dnrmaps.wi.gov/arcgis/rest/services/WT_SWDV/WT_Fisheries_Waters_WTM_Ext/MapServer/9"

Notice the use of regular expressions in the list_urls function.