R-ArcGIS / arcgislayers

Access ArcGIS Data and Location Services
http://r.esri.com/arcgislayers/
Apache License 2.0
47 stars 10 forks source link

Does not completely download data #189

Closed ar-puuk closed 4 months ago

ar-puuk commented 6 months ago

I am trying to download GDOT's roadway data from GDOT's ArcGIS MapServer. However, some sections of the data don't get downloaded completely. When I download the same file from the same MapServer in ArcGIS Pro, the data downloads completely.

tmap plot

tmap plot

ArcGIS Pro Screenshot

image

To Reproduce Note: I apologize the reprex somehow was having error, the code itself runs.

# install.packages("magrittr")
# install.packages("arcgis")
# install.packages("sf")
# install.packages("tmap")
# install.packages("reprex")

library(magrittr)
library(arcgis)
library(sf)
library(tmap)
library(reprex)

# reprex({

furl = "https://egisp.dot.ga.gov/arcgis/rest/services/ARCWEBSVCMAP/MapServer/"

server <- arcgislayers::arc_open(furl)

arts_bound_layer <- arcgislayers::get_layer(server, id = 15)

arts_bound_sf <- arcgislayers::arc_select(arts_bound_layer,
                                          where = "MPO = 'Augusta TMA'",
                                          crs = 3857) %>% 
  sf::st_cast(to = "POLYGON")

ga_roads_layer <- arcgislayers::get_layer(server, id = 4)

ga_roads_sf <- arcgislayers::arc_select(ga_roads_layer,
                                        where = "ROUTE_TYPE = '1'",
                                        filter_geom = sf::st_geometry(arts_bound_sf),
                                        crs = 3857)

tmap::tmap_mode("view")

tmap::qtm(arts_bound_sf, col = "gray33", lwd = 4, fill = NA) +
  tmap::qtm(ga_roads_sf, col = "ROUTE_TYPE", lwd = 3)

# })

Expected behavior I expect the data to be downloaded completely as shown in the ArcGIS Pro screenshot.

Additional Context The boundary may not be one-to-one in the two screenshots but that shouldn't cause the issue.

JosiahParry commented 4 months ago

This is actually an issue with how the feature service clips the inputs when using filter geom. In your case, I would recommend using a bounding box then clipping afterwards

furl = "https://egisp.dot.ga.gov/arcgis/rest/services/ARCWEBSVCMAP/MapServer/"

server <- arcgislayers::arc_open(furl)

arts_bound_layer <- arcgislayers::get_layer(server, id = 15)

arts_bound_sf <- arcgislayers::arc_select(
  arts_bound_layer,
  where = "MPO = 'Augusta TMA'",
  crs = 3857
)

arts_bound_sf
#> Simple feature collection with 1 feature and 20 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -9167550 ymin: 3925662 xmax: -9083877 ymax: 3988548
#> Projected CRS: WGS 84 / Pseudo-Mercator
#>   OBJECTID HPMS_CODE         MPO                            STUDY_NAME
#> 1       22       131 Augusta TMA Augusta Regional Transportation Study
#>   ABBREVIATION                            URL PHONE STATUS EFFECTIVE_DATE
#> 1         ARTS www.augustaga.gov/680/ARTS-MPO    NA      A     2012-01-01
#>   SHAPE.AREA SHAPE.LEN FIRST_NAME LAST_NAME TITLE EMAIL LOCATION_NAME
#> 1          0         0         NA        NA    NA    NA            NA
#>   LOCATION_ADDRESS CITY STATE ZIP_CODE                       geometry
#> 1               NA   NA    GA       NA MULTIPOLYGON (((-9167549 39...

ga_roads_layer <- arcgislayers::get_layer(server, id = 4)

ga_roads_sf <- arcgislayers::arc_select(
  ga_roads_layer,
  where = "ROUTE_TYPE = '1'",
  filter_geom = sf::st_as_sfc(sf::st_bbox(arts_bound_sf)),
  crs = 3857
)

tmap::qtm(arts_bound_sf, col = "gray33", lwd = 4, fill = NA) +
  tmap::qtm(ga_roads_sf, col = "ROUTE_TYPE", lwd = 3)

Created on 2024-07-08 with reprex v2.1.0

JosiahParry commented 4 months ago

I'm going to close this issue but I'm happy to help however I can in here still! :)(

ar-puuk commented 4 months ago

Thanks @JosiahParry. This is what I eventually did. I was hoping that this bug could be fixed within the source code/package. Anyway, I really appreciate your response.