我無法從 ArcGIS REST API 獲取 R 中的柵格資料。它位于端點https://maps.vcgi.vermont.gov/arcgis/rest/services/EGC_service/IMG_VCGI_LIDARNDSM_WM_CACHE_v1/ImageServer,我只想獲取我感興趣的區域的資料。我可以使用 URL“https://maps.vcgi.vermont.gov/arcgis/services/EGC_services/IMG_VCGI_LIDARNDSM_WM_CACHE_v1/ImageServer/WCSServer”成功地將 QGIS 中的資料加載為 Web 覆寫服務,但想要一些我可以變成R中的光柵層或光柵磚。
我更喜歡高級方法并嘗試了該arcpullr包,使用sf我感興趣的區域的多邊形物件來定義邊界框(aoi在下面的代碼中,這是一個具有 1 個特征和 1 個欄位的簡單特征集合;邊界框: xmin:499682.2 ymin:208467.7 xmax:503271.3 ymax:212056.7;預計 CRS:NAD83/佛蒙特州,32145)。這會在正確的位置回傳一個空的光柵磚(所有值都是 NA):
endpoint <- "https://maps.vcgi.vermont.gov/arcgis/rest/services/EGC_services/IMG_VCGI_LIDARNDSM_WM_CACHE_v1/ImageServer/"
ndsm <- get_image_layer(url = endpoint, sf_object = aoi)
我還嘗試根據API 參考自己構建請求,使用各種查詢,并且只能撰寫空影像檔案(盡管服務器回傳狀態代碼“200”)。這是一個例子:
url <- "https://maps.vcgi.vermont.gov/arcgis/rest/services/EGC_services/IMG_VCGI_LIDARNDSM_WM_CACHE_v1/ImageServer/exportImage?f=html&bbox=499682.2,208467.7,503271.3,212056.7&imageSR=32145&bboxSR=32145&format=png"
file = tempfile(fileext = ".png")
httr::GET(url = url, httr::write_disk(file))
我會很感激任何關于arcpullr開始作業的想法、對其他相對簡單的方法的建議,或者(作為最后的手段)學習更多關于 API 的資源。
uj5u.com熱心網友回復:
您遇到的問題是您沒有使用正確的crs. 您只需將aoifrom轉換EPSG: 32145為EPSG: 3857(空間投影資訊在服務網頁上提供)。
所以,請在下面找到一個小代表。
代表
- 代碼
library(arcpullr)
# Creating the aoi in `EPSG: 32145` and converting it into the right crs (i.e. `EPSG: 3857`)
aoi <- st_sf(st_as_sfc(st_bbox(c(xmin = 499682.2, xmax = 503271.3, ymin = 208467.7, ymax = 212056.7), crs = st_crs(32145)))) %>%
st_transform(., st_crs(3857))
# Extracting the raster corresponding to the `aoi`
endpoint <- "https://maps.vcgi.vermont.gov/arcgis/rest/services/EGC_services/IMG_VCGI_LIDARNDSM_WM_CACHE_v1/ImageServer/"
ndsm <- get_image_layer(url = endpoint, sf_object = aoi)
- 輸出(光柵磚包含像素值)
ndsm
#> class : RasterBrick
#> dimensions : 400, 400, 160000, 3 (nrow, ncol, ncell, nlayers)
#> resolution : 12.58247, 12.58247 (x, y)
#> extent : -8071116, -8066083, 5523882, 5528915 (xmin, xmax, ymin, ymax)
#> crs : proj=merc a=6378137 b=6378137 lat_ts=0 lon_0=0 x_0=0 y_0=0 k=1 units=m nadgrids=@null wktext no_defs
#> source : memory
#> names : X_ags_6919e084_8cf5_46f6_b95c_1090872a66d0.1, X_ags_6919e084_8cf5_46f6_b95c_1090872a66d0.2, X_ags_6919e084_8cf5_46f6_b95c_1090872a66d0.3
#> min values : 1, 49, 0
#> max values : 254, 254, 149
- 可視化
raster::plotRGB(ndsm)

由reprex 包于 2022-02-21 創建(v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/431780.html
