Skip to content

Commit f63d713

Browse files
committed
update documentation for validate_coord_list
1 parent 9e2759f commit f63d713

File tree

2 files changed

+38
-24
lines changed

2 files changed

+38
-24
lines changed

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
# QCkit v0.1.6
12
2024-03-07
23
* Update error warning in `check_te()` to not reference VPN since NPS no longer uses VPN.
4+
* add private function `.get_unit_bondaries()`: hits ArcGIS API to pull more precise park unit boundaries than `get_park_polgyon()`
5+
* add `validate_coord_list()` function that takes advantage of improved precision of `.get_unit_boundaries()` and is vectorized, enabling users to input multiple coordinate combinations and park units directly from a data frame.
36

47
# QCkit v0.1.5
58
2024-02-09
69
* This version adds the DRR template, example files, and associated documentation to the QCkit package.
7-
* Bugfix in `get_custom_flag()`: it was counting both A (accepted) and AE (Accepted, estiamted) as Accepted. Fixed the regex such that it Accepted will include all cells that start with A followed by nothing or by any character except AE such that flags can have explanation codes added to them (e.g. A_jenkins if "Jenkins" flagged the data as accepted)
10+
* Bugfix in `get_custom_flag()`: it was counting both A (accepted) and AE (Accepted, estimated) as Accepted. Fixed the regex such that it Accepted will include all cells that start with A followed by nothing or by any character except AE such that flags can have explanation codes added to them (e.g. A_jenkins if "Jenkins" flagged the data as accepted)
811

912
# QCkit v0.1.4
1013
2024-01-23

R/geography.R

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
21
#' Test whether decimal GPS coordinates are inside a park unit
32
#'
4-
#' This function can take a list of coordinates and park units as input. In addition to being vectorized, depending on the park borders, it can be a major improvement on `validate_coord()`. Known issues with this function include problems with overlapping unit boundaries. If two park unit boundaries overlap the function will through an error (e.g. Dry Tortugas National Park and Big Cypress National Preserve).
3+
#' This function can take a list of coordinates and park units as input. In
4+
#' adddition to being vectorized, depending on the park borders, it can be a
5+
#' major improvement on `validate_coord()`.
56
#'
6-
#' @param lat numeric. An individual or vector of numeric values representing the decimal degree latitude of a coordinate
7-
#' @param lon numeric. An individual or vector of numeric values representing the decimal degree longitude of a coordinate
8-
#' @param park_unit String. Or list of strings each containing the four letter park unit designation
7+
#' @param lat numeric. An individual or vector of numeric values representing
8+
#' the decimal degree latitude of a coordinate
9+
#' @param lon numeric. An individual or vector of numeric values representing
10+
#' the decimal degree longitude of a coordinate
11+
#' @param park_unit String. Or list of strings each containing the four letter
12+
#' park unit designation
913
#'
1014
#' @return logical
1115
#' @export
@@ -22,28 +26,35 @@
2226
#' df$test_GPS_coord <- x
2327
#' }
2428
validate_coord_list <- function(lat, lon, park_units) {
25-
# get geography from NPS Rest Services
26-
nps_unit <- .get_unit_boundary(park_units)
29+
# get geography from ArcGIS Rest Services
30+
park <- .get_unit_boundary(park_units)
2731

32+
#create a multipolygon sf object
33+
valid_park <- sf::st_make_valid(park)
2834
# create sf dataframe from coordinates
2935
points_df <- data.frame(lon = lon, lat = lat)
30-
points_sf <- sf::st_as_sf(points_df, coords = c("lon", "lat"), crs = 4326, na.fail = FALSE)
36+
points <- sf::st_as_sf(points_df,
37+
coords = c("lon", "lat"),
38+
crs = 4326,
39+
na.fail = FALSE)
3140
# Test whether the coordinates provided are within the polygon spatial feature
32-
results <- as.data.frame(sf::st_contains(nps_unit,
33-
points_sf,
41+
results <- as.data.frame(sf::st_covers(valid_park,
42+
points,
3443
sparse = FALSE))
44+
# Turn data frame into a list of logicals
45+
colnames(results) <- park_units
46+
rownames(results) <- unique(park_units)
3547
in_park <- NULL
36-
for (i in 1:ncol(results)) {
37-
if (sum(results[,i]) > 0) {
38-
in_park <- append(in_park, TRUE)
39-
} else {
40-
in_park <- append(in_park, FALSE)
48+
for (i in seq(ncol(results))) {
49+
for (j in seq(nrow(results))) {
50+
if (colnames(results)[i] == rownames(results)[j]) {
51+
in_park <- append(in_park, results[j,i])
52+
}
4153
}
4254
}
43-
return(in_park)
55+
return(in_park)
4456
}
4557

46-
4758
#' Gets NPS unit boundaries from Arc GIS
4859
#'
4960
#' @param park_units String. Or list of strings.
@@ -64,14 +75,17 @@ validate_coord_list <- function(lat, lon, park_units) {
6475

6576
for (locality in unique_localities) {
6677
# Request feature in WGS84 spatial reference (outSR=4326)
67-
feature_service_path <- paste0('query?where=UNIT_CODE+%3D+%27', locality, '%27&outFields=*&returnGeometry=true&outSR=4326&f=pjson')
78+
feature_service_path <- paste0(
79+
"query?where=UNIT_CODE+%3D+%27",
80+
locality,
81+
"%27&outFields=*&returnGeometry=true&outSR=4326&f=pjson")
6882
feature_service_request <- paste(feature_service_url,
6983
feature_service_path,
7084
sep = "/")
7185
geo_json_feature <- jsonlite::fromJSON(feature_service_request)
7286

7387
# Have to save to temp file
74-
jsonFeature <- utils::download.file(feature_service_request,
88+
json_feature <- utils::download.file(feature_service_request,
7589
temp_output,
7690
mode = "w",
7791
quiet = TRUE)
@@ -81,13 +95,11 @@ validate_coord_list <- function(lat, lon, park_units) {
8195

8296
all_localities <- rbind(all_localities, feature_polygon)
8397
}
84-
file.remove("temp.geojson")
98+
suppressWarnings(file.remove("temp.geojson"))
8599
#featurePoly <- readOGR(dsn = tempOutput, layer = "OGRGeoJSON")
86100
return(all_localities)
87101
}
88102

89-
90-
91103
#' Retrieve the polygon information for the park unit from NPS REST services
92104
#'
93105
#' @description `get_park_polygon()` retrieves a geoJSON string for a polygon of
@@ -139,7 +151,6 @@ validate_coord <- function(unit_code, lat, lon) {
139151

140152
# Test whether the coordinates provided are within the polygon spatial feature
141153
result <- sf::st_covers(park, point, sparse = FALSE)[, 1]
142-
143154
return(result)
144155
}
145156

0 commit comments

Comments
 (0)