read.shp: Read ESRI shapefile

Description Usage Arguments Value Note Author(s) Examples

View source: R/shp.R

Description

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

Usage

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

Arguments

where

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

format

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

close

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

Value

The result depends on the value of the format argument:

"list"

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)

"pairlist"

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.

"polygon"

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.

"table"

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.

Note

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.

Author(s)

Simon Urbanek

Examples

1
2
3
  # 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"))

s-u/fastshp documentation built on May 28, 2019, 10:47 a.m.