readShapePoly {maptools}R Documentation

Read polygon shape files into SpatialPolygonsDataFrame objects

Description

The readShapePoly reads data from a polygon shapefile into a SpatialPolygonsDataFrame object. The writePolyShape function writes data from a SpatialPolygonsDataFrame object to a shapefile.

Usage

readShapePoly(fn, IDvar=NULL, proj4string=CRS(as.character(NA)), verbose=FALSE)
writePolyShape(x, fn, factor2char = TRUE)

Arguments

fn shapefile layer name, without extension
IDvar a character string: the name of a column in the shapefile DBF containing the ID values of the shapes - the values will be converted to a character vector
proj4string Object of class CRS; holding a valid proj4 string
verbose default TRUE - report type of shapefile and number of shapes
x a SpatialPolygonsDataFrame object
factor2char logical, default TRUE, convert factor columns to character

Details

If no IDvar argument is given, the shpID values of the shapefile will be used as Polygons ID values; when writing shapefiles, the object data slot rownames are added to the DBF file as column SP_ID.

Value

a SpatialPolygonsDataFrame object

Author(s)

Roger Bivand

Examples

library(maptools)
xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
plot(xx, border="blue", axes=TRUE, las=1)
text(getSpPPolygonsLabptSlots(xx), labels=getSpPPolygonsIDSlots(xx), cex=0.6)
as(xx, "data.frame")[1:5, 1:6]
xxx <- xx[xx$SID74 < 2,]
plot(xxx, border="red", add=TRUE)
tmpfl <- paste(tempdir(), "xxline", sep="/")
writePolyShape(xxx, tmpfl)
getinfo.shape(paste(tmpfl, ".shp", sep=""))
axx <- readShapePoly(tmpfl, proj4string=CRS("+proj=longlat +ellps=clrk66"))
plot(xxx, border="black", lwd=4)
plot(axx, border="yellow", lwd=1, add=TRUE)
unlink(paste(tmpfl, ".*", sep=""))

[Package maptools version 0.5-11 Index]