我发现了两种在R中打开shapefile的基本方法-使用rgdal
和maptools
:
# 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的更安全方法? 最佳答案
国家生态分析和综合中心的maptools
,rgdal
和PBSMapping
的以下比较可能使您感兴趣:
"Read and write ESRI Shapefiles with R"