read.shp {fastshp}R Documentation

Read ESRI shapefile


read.shp reads ESRI shapefile format (.shp). Currently only polygons and polylines are supported.


read.shp(where, format = c("list", "pairlist", "polygon", "table"),
         close = TRUE)



filename to read the data from or a binary connection or a raw vector with the data content


output format (see below for details), defaults to "list".


if where is a connection then this flag determines whether the connection will be closed automatically after reading the shapefile (TRUE) or not (FALSE).


The result depends on the value of the format argument:


list (generic vector) of shapes exactly as represented in the .shp file format: each shape is represented by a list with the following elements:

  • idshape identifier

  • typeshape type

  • boxbounding box - a vector of xmin, ymin, xmax, ymax

  • parts0-based index of the beginning of each part

  • xx coordinates (typically longitude)

  • yy coordinates (typically latitude)


same as "list" except that the list of shapes is stored in a pairlist and not a list. This is the most memory-efficient way of reading a shapefile, because and all other formats are derived from first reading this format. Pairlists are good for linear scans but inefficient for indexing.


same as "list" except that coordinates are represented in R polygon format (parts are separated by NAs in the coordinates) instead of part indexing. This is typically the preferred format for plotting.


The result is a data frame with the following columns: id, type, part, x, y. Coordinates for each part are therefore identified by common id, part tuple. This is typically the preferred format for performing computations on the coordinates.


Although other packages exist for reading shapefiles, the focus of this implementation is speed, so it works on very large compilations of shapes, such as the Tiger database which is impossible to load using naive R implementations.


Simon Urbanek


  # Census 2010 TIGER/Line(TM) state shapefile
  fn <- system.file("shp", "tl_2010_us_state10.shp.xz", package="fastshp")
  s <- read.shp(xzfile(fn, "rb"))

[Package fastshp version 0.1-0 Index]