我发现了两种在R中打开shapefile的基本方法-使用rgdalmaptools:

# 1
require(maptools)
shape_maptools <- readShapeLines("file.shp")

# 2
require(rgdal)
shape_rgdal <- readOGR(".", "file")
在这两种情况下,数据结构似乎完全相同(类SpatialLinesDataFrame,程序包sp)。但是,在 rgdal reads the projection properly, maptools does not时(您可能必须手动分配CRS):
> proj4string(shape_maptools)
[1] NA
> proj4string(shape_rgdal)
[1] "+proj=utm +zone=31 +ellps=intl +units=m +no_defs"
那么,为什么我要使用maptools打开形状文件?我可能只会犯一个错误的分配
手动CRS!
我是否可以得出结论,两种方法是等效的,但是使用rgdal始终是打开shapefile的更安全方法?

最佳答案

国家生态分析和综合中心的maptoolsrgdalPBSMapping的以下比较可能使您感兴趣:

"Read and write ESRI Shapefiles with R"

10-07 12:52