我想从服务器提供的GeoTIFF数据创建一个RasterLayer.我将使用httr :: GET调用向服务器查询此数据(数据是按需提供的,因此在应用程序中不会有以.tif结尾的URL,而是查询URL).
将此调用的结果作为GeoTIFF文件写入磁盘后,很容易从磁盘上生成的GeoTIFF文件创建RasterLayer:
library(httr)
library(raster)
url <- 'http://download.osgeo.org/geotiff/samples/gdal_eg/cea.tif'
geotiff_file <- tempfile(fileext='.tif')
httr::GET(url,httr::write_disk(path=geotiff_file))
my_raster <- raster(geotiff_file)
my_raster
Run Code Online (Sandbox Code Playgroud)
但是,我想跳过写入磁盘部分并直接从内存服务器响应创建栅格.
response <- httr::GET(url,httr::write_memory())
response
Run Code Online (Sandbox Code Playgroud)
响应的内容是一个原始字符串,我需要将其解释为geoTIFF数据.
str(httr::content(response))
Run Code Online (Sandbox Code Playgroud)
但是,我只能找到从文件中读取的raster或rgdal函数.有关将此原始字符串转换为栅格的任何建议吗?
谢谢!