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.
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.
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.
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
Current functions that query specific WDNR layers are
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).
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:
match_sections("trout") #>  "FM_Trout" match_services("trout") #>  "FM_TROUT_ANNO_WTM_Ext" "FM_TROUT_COUNTY_REGS_WTM" #>  "FM_TROUT_HAB_SITES_WTM_Ext" "FM_TROUT_NONDNR_EASEMENTS_WTM_Ext" #>  "FM_TROUT_REGS_WTM_Ext" match_layers("trout stream") #>  "Trout Stream Regulations 2018-2019" "PNW-ASNRI Trout Streams" #>  "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.
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")) #>  "https://dnrmaps.wi.gov/arcgis/rest/services/FM_Trout/FM_TROUT_REGS_WTM_Ext/MapServer/0" #>  "https://dnrmaps.wi.gov/arcgis/rest/services/WT_SWDV/WT_Designated_Waters_WTM_Ext/MapServer/5" #>  "https://dnrmaps.wi.gov/arcgis/rest/services/WT_SWDV/WT_Fisheries_Waters_WTM_Ext/MapServer/9"
Notice the use of regular expressions in the