匯入形狀檔案(.shp)
rgdal
通過使用 rgdal 軟體包中的函式 readOGR(),可以輕鬆地將 ESRI 形狀檔案匯入到 R 中。
library(rgdal)
shp <- readORG(dsn = "/path/to/your/file", layer = "filename")
重要的是要知道,dsn 不能以/結束,而 layer 不允許檔案結束(例如 .shp)
光柵
另一種匯入 shapefile 的方法是通過 raster 庫和 shapefile 函式:
library(raster)
shp <- shapefile("path/to/your/file.shp")
請注意路徑定義與 rgdal import 語句的不同之處。
TMAP
tmap 包為 rgdal::readORG 功能提供了一個很好的包裝器。
library(tmap)
sph <- read_shape("path/to/your/file.shp")