Skip to content

Commit

Permalink
Merge branch 'main' into prepare-spatial-filter-revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
elipousson authored Oct 29, 2024
2 parents 2bbc824 + 68b3d45 commit dbb1588
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 124 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
^cran-comments\.md$
^CRAN-SUBMISSION$
^README\.md$
^R/dplyr-features\.R$
2 changes: 1 addition & 1 deletion .github/workflows/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
extra-packages: any::pkgdown, any::quarto, local::.
needs: website

- name: Build site
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CRAN-SUBMISSION
.httr-oauth
.Rprofile
.Rprofile
Expand Down
3 changes: 0 additions & 3 deletions CRAN-SUBMISSION

This file was deleted.

6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: arcgislayers
Type: Package
Title: An Interface to ArcGIS Data Services
Version: 0.3.0.9000
Version: 0.3.1.9000
Authors@R: c(
person("Josiah", "Parry", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-9910-865X")),
Expand All @@ -21,9 +21,9 @@ Encoding: UTF-8
LazyData: true
Imports:
arcgisutils (>= 0.2.0),
arcpbf (>= 0.1.2),
arcpbf (>= 0.1.5),
cli,
httr2 (>= 1.0.0),
httr2 (>= 1.0.5),
jsonify,
lifecycle,
RcppSimdJson,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export(get_layer_estimates)
export(get_layers)
export(list_fields)
export(list_items)
export(list_service_raster_fns)
export(match_spatial_rel)
export(prepare_spatial_filter)
export(publish_item)
Expand Down
13 changes: 12 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# arcgislayers (development version)

## Breaking changes

- `dplyr` methods for `collect()`, `select()`, and `filter()` have been removed. <https://github.com/R-ArcGIS/arcgislayers/issues/111> <https://github.com/R-ArcGIS/arcgislayers/issues/224> <https://github.com/R-ArcGIS/arcgislayers/issues/218>

## New features

- Improve handling of `filter_geom` by `arc_select()` by warning if applying `sf::st_union()` to the filter does not generate a length 1 sfc, or if `filter_geom` is supplied when accessing a Table, or if `filter_geom` is empty (@elipousson, #166)

# arcgislayers 0.3.1

## Bug fixes

- `page_size` resulted in error due to introduction of type-check. Fixed and added test to avoid in the future. [#205](https://github.com/R-ArcGIS/arcgislayers/issues/205)
- Add warning if `arc_select()` results include fewer features than expected from request [#220](https://github.com/R-ArcGIS/arcgislayers/issues/220)

## New features

- `arc_raster()` gains an argument `raster_fn` which takes a character scalar and performs a raster function server side before returning results
- `list_service_raster_fns()` is a new helper function to list available raster functions for an `ImageServer`
- Improve handling of `filter_geom` by `arc_select()` by warning if applying `sf::st_union()` to the filter does not generate a length 1 sfc, or if `filter_geom` is supplied when accessing a Table, or if `filter_geom` is empty (@elipousson, #166)
- `arc_open()` ignores queries included in input URLs and retains any custom queries in the `query` attribute for `Table` and `FeatureLayer`s. ([#215](https://github.com/R-ArcGIS/arcgislayers/issues/215))

## Breaking changes

Expand Down
8 changes: 6 additions & 2 deletions R/arc-open.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
arc_open <- function(url, token = arc_token()) {
check_url(url)

# parse url query and strip from url if query matches default
query <- parse_url_query(url) %||% list()
url <- clear_url_query(url)

# extract layer metadata
meta <- fetch_layer_metadata(url, token)

Expand Down Expand Up @@ -84,12 +88,12 @@ arc_open <- function(url, token = arc_token()) {
"FeatureLayer" = structure(
meta,
class = layer_class,
query = list()
query = query
),
"Table" = structure(
meta,
class = layer_class,
query = list()
query = query
),
"FeatureServer" = structure(
meta,
Expand Down
11 changes: 11 additions & 0 deletions R/arc-select.R
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,17 @@ collect_layer <- function(
sf::st_crs(res) <- sf::st_crs(x)
}

if (nrow(res) < n_feats) {
# See https://github.com/R-ArcGIS/arcgislayers/issues/110
cli::cli_warn(
c(
"Results include fewer than the expected {n_feats} features.",
"*" = "Try setting {.arg page_size} to a smaller value to make
sure results include all available features."
)
)
}

res
}

Expand Down
12 changes: 10 additions & 2 deletions R/raster-fns.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@
#' @inheritParams arcgisutils::infer_esri_type
#' @param x an `ImageServer`.
#' @returns a data.frame of the available raster functions.
#' @export
#' @examples
#' # example code
#'
#' # use paste to avoid cran note
#' furl <- paste0(
#' "https://di-usfsdata.img.arcgis.com/arcgis/rest/services",
#' "/FIA_BIGMAP_2018_Species_Aboveground_Biomass/ImageServer"
#' )
#'
#' service <- arc_open(furl)
#' raster_fns <- list_service_raster_fns(service)
#' head(raster_fns)
list_service_raster_fns <- function(x, arg = rlang::caller_arg(x), call = rlang::caller_call()) {
check_inherits_any(x, "ImageServer")

Expand Down
47 changes: 47 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,50 @@ data_frame <- function(x, call = rlang::caller_env()) {
check_data_frame(x, call = call)
structure(x, class = c("tbl", "data.frame"))
}

#' @noRd
clear_url_query <- function(url, keep_default = FALSE) {
query <- parse_url_query(url, keep_default = keep_default)

if (!is.null(query) && rlang::is_empty(query)) {
return(url)
}

url_elements <- httr2::url_parse(url)

# Rebuild URL without query
paste0(
url_elements[["scheme"]], "://",
url_elements[["hostname"]],
sub("/query$", "", url_elements[["path"]])
)
}

#' @noRd
parse_url_query <- function(url, keep_default = FALSE) {
# Parse url
url_elements <- httr2::url_parse(url)

# Return empty list if no query is included in url
if (is.null(url_elements[["query"]])) {
return(list())
}

# Check for default query values
query_match <- match(
url_elements[["query"]],
c(
list(outFields = "*", where = "1=1", f = "geojson"),
list(outFields = "*", where = "1=1")
)
)

# Return NULL for default query
if (is.numeric(query_match) && !keep_default) {
return(NULL)
}

# Otherwise return query
url_elements[["query"]]
}

12 changes: 6 additions & 6 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ s3_register <- function(pkg, generic, class, fun = NULL) {
.onLoad <- function(...) {
s3_register("sf", "st_crs", "FeatureLayer")
s3_register("sf", "st_crs", "ImageServer")
s3_register("dplyr", "collect", "FeatureLayer")
s3_register("dplyr", "collect", "Table")
s3_register("dplyr", "filter", "Table")
s3_register("dplyr", "filter", "FeatureLayer")
s3_register("dplyr", "select", "FeatureLayer")
s3_register("dplyr", "select", "Table")
# s3_register("dplyr", "collect", "FeatureLayer")
# s3_register("dplyr", "collect", "Table")
# s3_register("dplyr", "filter", "Table")
# s3_register("dplyr", "filter", "FeatureLayer")
# s3_register("dplyr", "select", "FeatureLayer")
# s3_register("dplyr", "select", "Table")
}

41 changes: 41 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,44 @@ template:
navbar:
structure:
right: [search, github]

reference:

- title: Read Services
contents:
- arc_open
- arc_raster
- arc_read
- arc_select
- get_layer
- get_all_layers
- get_layers
- get_layer_estimates
- query_layer_attachments
- download_attachments
- list_service_raster_fns
- title: Publish Services
contents:
- create_feature_server
- xss_defaults
- add_item
- publish_item
- publish_layer
- .publish_params
- title: Edit Services
contents:
- add_features
- update_features
- delete_features
- truncate_layer
- title: Utilities
contents:
- clear_query
- list_fields
- pull_field_aliases
- list_items
- refresh_layer
- prepare_spatial_filter
- match_spatial_rel
- update_params

14 changes: 4 additions & 10 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

0 errors | 0 warnings | 1 note

* This is a new release with small bug fixes and 2 minor new functions.

-----

Previous notes:

* ArcGIS is a brand name and not a software name which is why it is unquoted some places in the DESCRIPTION's. These being the `Title` field and in the `Description` where it says "ArcGIS location services."
* REST is not a software but an architecture so it is not quoted.
* Removed R from the title per request
* Replaced instances of `if (interactive())` with `\dontrun{}`. All of these examples require an authorization token that is generated interactively as well as modifies remote data sources. As such
This is a re-release of the removed `arcgislayers`.
This package depends on `arcpbf` which has a minimum supported rust version
of 1.70.
This package's check **will fail** on CRAN's Fedora machines.
9 changes: 8 additions & 1 deletion man/list_service_raster_fns.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion tests/testthat/test-arc_open.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
test_that("arc_open(): Feature Layer", {
ft_url <- "https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_Counties_Generalized_Boundaries/FeatureServer/0"

expect_no_error(arc_open(ft_url))
lyr <- arc_open(ft_url)

expect_no_error(lyr)

ft_query_url <- "https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_Counties_Generalized_Boundaries/FeatureServer/0/query?outFields=%2A&where=1%3D1"

lyr_q <- arc_open(ft_query_url)

expect_identical(lyr, lyr_q)
})


Expand Down
Loading

0 comments on commit dbb1588

Please sign in to comment.