How can I read ESRI polygon/polyline shapefile in R environment using rgdal or other library? can I get a syntax for it?

  • 1
    This link might help as it mentions how to do it using rgdal: nceas.ucsb.edu/scicomp/usecases/ReadWriteESRIShapeFiles – Joseph Oct 13 '14 at 13:00
  • 2
    In the future, please make some effort to search the site. This is addressed in many posts. That said, look at "readOGR" for vector and "readGDAL" for rasters using the rgdal package. The help documents are very clear with specific examples for shapefiles. The preferred alternative for rasters are "raster", "stack" or "brick" in the raster packages. There are also options using the maptools package but they do not retain projection information. One advantage of rgdal is that you have access to several additional functions associated with GDAL. – Jeffrey Evans Oct 13 '14 at 15:48

Possible duplicate with How to open a Shapefile in R?

There are many packages to read shapefiles:

  • I cannot find any "shapefile" command in dismo package, not even the words "shapefile" or "shp" in the description pdf of the package. A look at the functions does not help, either. Were there any changes in the last versions (I'm reading the help for version 1.3-3, published in nov 17th 2020)? Or is there any obscure way to do it? – Asier May 29 at 19:54
  • from Dismo: 0.7/shapefile: Read a shapefile it is a simple wrapper around readOGR (rgdal package) – gene May 30 at 8:03

readShapeSpatial in the maptools package is my go-to function:


Nice tutorial here: http://www.kevjohnson.org/making-maps-in-r/


As previously stated, a really useful function is readOGR from the package rgdal, but also fortify from ggplot2, which transforms the object SpatialPolygonsDataFrame (difficult to work with!) into an R-friendly one.

A good tutorial can be found here.

  • This is not correct! The readOGR is what creates the sp SpatialPolygonsDataFrame object, not fortify. The fortify function, which is now depreciated in leu of broom and tidy, is just a method for converting an sp object to something that ggplot2 can handle. I have no idea what R friendly is supposed to mean. An S4 class is quite R like and objects resulting from fortify are not suitable for subsequent spatial analysis using the array of supporting spatial R packages. – Jeffrey Evans Dec 30 '17 at 2:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.