Learn R Programming

raster (version 2.3-40)

shapefile: Read or write a shapefile

Description

Reading and writing of "ESRI shapefile" format spatial data. Only the three vector types (points, lines, and polygons) can be stored in shapefiles. These are simple wrapper functions around readOGR and writeOGR (rgdal package).

Usage

## S3 method for class 'character':
shapefile(x, stringsAsFactors=FALSE, verbose=FALSE, ...)

## S3 method for class 'Spatial':
shapefile(x, filename='', overwrite=FALSE, ...)

Arguments

x
character (a file name, when reading a shapefile) or Spatial* object (when writing a shapefile)
filename
character. Filename to write a shapefile
overwrite
Logical. Overwrite existing shapefile?
verbose
Logical. If TRUE, information about the file is printed
stringsAsFactors
Logical. If TRUE, strings are converted to factors
...
Additional arguments passed to rgdal functions readOGR or writeOGR

Value

  • Spatial*DataFrame (reading). Nothing is returned when writing a shapefile.

Examples

Run this code
if (require(rgdal)) {

filename <- system.file("external/lux.shp", package="raster")
filename
p <- shapefile(filename)

shapefile(p, 'copy.shp')
}

Run the code above in your browser using DataLab