Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helpers for building SQL queries #34

Open
elipousson opened this issue Mar 6, 2024 · 1 comment
Open

Helpers for building SQL queries #34

elipousson opened this issue Mar 6, 2024 · 1 comment

Comments

@elipousson
Copy link

I'm not sure whether these would belong here or in arcgislayers or wouldn't be of interest at all but I've been using a couple of helper functions that make creating queries for FeatureLayers much easier. These are the two I'm currently using most often:

ansi_in <- function(needle, haystack, ..., .envir = rlang::current_env(), .con = DBI::ANSI()) {
  glue::glue_sql(needle, " ", "IN", " ({haystack*})", ..., .envir = .envir, .con = .con)
}

sql_collapse <- function(x, sep = " AND ") {
  glue::glue_sql_collapse(x, sep = sep)
}

I think the same syntax rules described here also apply to the REST API: https://doc.arcgis.com/en/drone2map/latest/help/sql-reference-for-elements-used-in-query-expressions.htm

@JosiahParry
Copy link
Collaborator

I'm wondering if the dplyr integration is sufficient for this?

library(arcgis)
#> Attaching core arcgis packages:
#> → arcgisutils v0.2.0
#> → arcgislayers v0.2.0

furl <- paste0(
  "https://services3.arcgis.com/ZvidGQkLaDJxRSJ2/arcgis/rest/services/",
  "PLACES_LocalData_for_BetterHealth/FeatureServer/0"
)

x <- arc_open(furl)
dplyr::filter(x, StateAbbr %in% c("CA", "GA"))
#> <FeatureLayer>
#> Name: PlacePoints
#> Geometry Type: esriGeometryPoint
#> CRS: 3785
#> Capabilities: Query,Extract
#> Query:
#>   where: StateAbbr IN ('CA', 'GA')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants