-
Notifications
You must be signed in to change notification settings - Fork 1
/
imap.R
185 lines (170 loc) 路 5.28 KB
/
imap.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#' Get data from Maryland iMap
#'
#' Get data from Maryland iMap including Computer Assisted Mass Appraisal
#' (CAMA), parcel data, Maryland Inventory of Historic Properties data, and a
#' variety of water data.
#'
#' @details Options for type parameter:
#'
#' - [get_cama_data()]: Default: "core"; options: "bldg" (detailed building
#' characteristics), "core", "land", "subarea" (building subarea).
#' - [get_water_data()]: Default: "streams", options: "streams" (Rivers and
#' streams generalized), "streams detailed" (Rivers and streams generalized),
#' "federal watersheds", "8 digit watersheds", "12 digit watersheds", "navigable
#' waterways", "ponds" (Lakes and ponds)
#' - [get_parcel_data()]: Default "boundaries", options: "boundaries" (Parcel
#' boundaries), "points" (Parcel points)
#' - [get_mht_data()]: Default: "mihp"; options: "mihp" (Maryland Inventory of
#' Historic Properties), "nr" (National Register of Historic Places),
#' "easements" (Preservation Easements held by the Maryland Historical Trust)
#'
#' @details Helper functions:
#'
#' - [format_parcel_data()] is a wrapper for [getdata::bind_block_col()] used by
#' [get_parcel_data()]
#' - [get_imap_url()] is a look-up function for the `md_imap_index` using the
#' short "nm" column as a index.
#'
#' @param location A `sf`, `sfc`, or `bbox` object (or other object convertible
#' with [sfext::as_bbox()]. Required.
#' @param nm Layer name identifier used to retrieve url from `md_imap_index`
#' based on the snakecase "nm" column; Default: `NULL`.
#' @param type Default and supported options vary by function. See details.
#' @param crs Coordinate reference system to return. Defaults to
#' `getOption("mapmaryland.crs", default = 3857)`.
#' @param ... Additional parameters passed to [getdata::get_esri_data()]
#' @name get_imap_data
#' @export
#' @importFrom getdata get_esri_data
#' @importFrom sfext rename_sf_col
get_imap_data <- function(location = NULL,
nm = NULL,
crs = getOption("mapmaryland.crs", default = 3857),
...) {
url <- get_imap_url(nm)
data <-
getdata::get_esri_data(
location = location,
url = url,
crs = crs,
...
)
if (!inherits(data, "sf")) {
return(data)
}
sfext::rename_sf_col(data)
}
#' @name get_cama_data
#' @rdname get_imap_data
#' @export
get_cama_data <- function(location,
type = "core",
crs = getOption("mapmaryland.crs", default = 3857),
...) {
nm <-
type2nm(
type = type,
index = "imap_cama"
)
get_imap_data(
location = location,
nm = nm,
crs = crs,
...
)
}
#' @name get_parcel_data
#' @rdname get_imap_data
#' @param block If block is `TRUE`, pass parcel data to
#' [getdata::bind_block_col()]. Defaults to `FALSE`.
#' @export
#' @importFrom getdata bind_block_col
get_parcel_data <- function(location,
type = "boundaries",
crs = getOption("mapmaryland.crs", default = 3857),
block = FALSE,
...) {
nm <-
type2nm(
type = type,
index = "imap_parcel"
)
data <-
get_imap_data(
location = location,
nm = nm,
crs = crs,
...
)
if (!block || !all(rlang::has_name(data, c("strtnum", "strtdir", "strtnam", "strttyp")))) {
return(data)
}
format_parcel_data(data)
}
#' @name format_parcel_data
#' @rdname get_imap_data
#' @param data Data to pass to [getdata::bind_block_col()].
#' [format_parcel_data()] only.
#' @param imap_addr_cols Named list with address column names for input data.
#' Passed to corresponding parameters in [getdata::bind_block_col()]
#' @export
format_parcel_data <- function(data,
imap_addr_cols = list(
bldg_num = "strtnum",
street_dir_prefix = "strtdir",
street_name = "strtnam",
street_suffix = "strttyp"
)) {
getdata::bind_block_col(
data,
bldg_num = imap_addr_cols$bldg_num,
street_dir_prefix = imap_addr_cols$street_dir_prefix,
street_name = imap_addr_cols$street_name,
street_suffix = imap_addr_cols$street_suffix,
case = "upper"
)
}
#' @name get_mht_data
#' @rdname get_imap_data
#' @export
get_mht_data <- function(location,
type = "mihp",
crs = getOption("mapmaryland.crs", default = 3857),
...) {
nm <-
type2nm(
type = type,
index = "imap_mht"
)
get_imap_data(
location = location,
nm = nm,
crs = crs,
...
)
}
#' @name get_water_data
#' @rdname get_imap_data
#' @export
get_water_data <- function(location,
type = "streams",
crs = getOption("mapmaryland.crs", default = 3857),
...) {
nm <-
type2nm(
type = type,
index = "imap_water"
)
get_imap_data(
location = location,
nm = nm,
crs = crs,
...
)
}
#' @name get_imap_url
#' @rdname get_imap_data
#' @export
get_imap_url <- function(nm = NULL) {
get_index_var(nm = nm, index = md_imap_index, var = "url")
}