I found two basic ways to open shapefiles in R - using rgdal
and maptools
:
# 1
require(maptools)
shape_maptools <- readShapeLines("file.shp")
# 2
require(rgdal)
shape_rgdal <- readOGR(".", "file")
The data structures seem exactly the same in both cases (class SpatialLinesDataFrame, package sp). However, while rgdal
reads the projection properly, maptools
does not (you possibly have to assign the CRS manually):
> proj4string(shape_maptools)
[1] NA
> proj4string(shape_rgdal)
[1] "+proj=utm +zone=31 +ellps=intl +units=m +no_defs"
So, why would I ever use maptools
to open shape files? I may only make a mistake of assigning
the CRS manually!