Skip to content

Commit 683f7b8

Browse files
committed
#215 fix for capturing lat and lon params in inat data
1 parent 9f9d748 commit 683f7b8

File tree

6 files changed

+13
-16
lines changed

6 files changed

+13
-16
lines changed

R/as.inat.R

-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@
2222
#' as.inat(tt[[1]])
2323
#' as.inat(uu[[1]])
2424
#' as.inat(tt[1:2])
25-
#'
26-
#' library("dplyr")
27-
#' bind_rows(lapply(tt, function(x) {
28-
#' data.frame(x$taxon[c('id','name','rank','unique_name')],
29-
#' stringsAsFactors = FALSE)
30-
#' }))
3125
#' }
3226
as.inat <- function(x, ...) UseMethod("as.inat")
3327

R/inat.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ spocc_inat_handle <- function(x){
139139
}
140140

141141
spocc_get_inat_obs_id <- function(id, callopts = list()) {
142-
q_path <- paste("observations/", as.character(id), ".json", sep = "")
143142
cli <- crul::HttpClient$new(url = inat_base_url, opts = callopts)
144-
res <- cli$get(path = q_path)
143+
res <- cli$get(path = file.path(inat_path, as.character(id)))
145144
res$raise_for_status()
146145
jsonlite::fromJSON(res$parse("UTF-8"))
147146
}

R/plugins.r

+8
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,14 @@ foo_inat <- function(sources, query, limit, page, geometry, has_coords,
266266
res <- out$data
267267
res$prov <- rep("inat", nrow(res))
268268
res <- rename(res, c("taxon.name" = "name"))
269+
# pull out lon/lat from geojson field
270+
cds <- res$geojson.coordinates
271+
lons <- sapply(cds, "[[", 1)
272+
lons[vapply(lons, is.null, logical(1))] <- NA_character_
273+
res$longitude <- unlist(lons)
274+
lats <- sapply(cds, "[[", 2)
275+
lats[vapply(lats, is.null, logical(1))] <- NA_character_
276+
res$latitude <- unlist(lats)
269277
res <- stand_latlon(res)
270278
res <- add_latlong_if_missing(res)
271279
res <- stand_dates(res, "inat")

man-roxygen/occ_egs.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#' res$ecoengine
77
#' (res <- occ(query = 'Accipiter striatus', from = 'ebird', limit = 50))
88
#' res$ebird
9-
#' (res <- occ(query = 'Danaus plexippus', from = 'inat', limit = 50))
9+
#' (res <- occ(query = 'Danaus plexippus', from = 'inat', limit = 50,
10+
#' has_coords = TRUE))
1011
#' res$inat
1112
#' res$inat$data
1213
#' data.table::rbindlist(res$inat$data$Danaus_plexippus$photos)

man/as.inat.Rd

-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/occ.Rd

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)