Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening shapefiles in R using rgdal always better than using maptools?

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!

May I conclude that both ways are equivalent, but using rgdal is always safer way to do open a  shapefile?

like image 729
Tomas Avatar asked Jul 20 '13 09:07

Tomas


2 Answers

The following comparison of maptools, rgdal and PBSMapping from the National Center for Ecological Analysis and Synthesis might interest you:

"Read and write ESRI Shapefiles with R"

like image 57
maj Avatar answered Nov 20 '22 02:11

maj


maptools::readShapeLines() get problem with file name containing spacial character eg. German Umlaut.

rgdal can deal with such case

like image 41
satart Avatar answered Nov 20 '22 02:11

satart