I am using the arcpullr
package to query GIS data hosted on an ArcGIS server. I am able to download a subset of the data using attributes in my query, but I am not able to get the spatial query get_layer_by_point()
working.
Ultimately what I am hoping to do is extract the coordinates of the nearest point on the line for use in another process. I'm open to using another package or building the query outside of a package.
Here is an example. I am able to extract the line using its Permanent_Identifier
. I manually looked up this value, but in future cases would prefer to query the line using its proximity to a point.
In this example, I know the point and the line both exist and are close to each other.
library(arcpullr)
#> Loading required package: sf
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
pt_url <- "https://geodataservices.wdfw.wa.gov/arcgis/rest/services/ApplicationServices/FP_Sites/MapServer/1"
pt_sf <- get_spatial_layer(pt_url, where = "SiteId = '991057'")
#> Warning in CPL_crs_from_input(x): GDAL Message 1: +init=epsg:XXXX syntax is
#> deprecated. It might return a CRS with a non-EPSG compliant axis order.
# works to extract this reach using its Identifier code
line_url <- "https://fortress.wa.gov/ecy/gisprod/arcgis/rest/services/NHD/NHD_Cache/MapServer/1"
line_sf <- get_spatial_layer(line_url, where = "Permanent_Identifier = '165793370'")
plot(st_geometry(line_sf))
plot(st_geometry(pt_sf), add = TRUE, col = 'red')
Created on 2021-09-24 by the reprex package (v2.0.0)
But I am not able to do so by spatial query relative to the point. The API documentation is here (note the distance
parameter) and code I have tried is below
line_sf2 <- get_layer_by_point(line_url, pt_sf, where = sql_where(distance=500, units="feet"))
#> Warning in get_esri_features(query_url, out_fields, where, token, ...): No
#> records match the search critera