shapefiles {shapefiles}R Documentation

Read and write ESRI shapefiles

Description

This package includes functions to read and write ESRI shapefiles.

Usage

read.shapefile(shape.name)
read.shp(shp.name)
read.shx(shx.name) 
read.dbf(dbf.name) 
write.shapefile(shapefile, out.name, arcgis=FALSE)
write.shp(shp, out.name)
write.shx(shx, out.name)
write.dbf(dbf, out.name, arcgis=FALSE)
calc.header(shapefile)
add.xy(shapefile)
scaleXY(shapefile, scale.factor)
emme2.shp(nodes, links, file.name="d211.in")

Arguments

shape.name String of the shapefile file name without an extension
shp.name String of the shp file name with an extension
shx.name String of the shx file name with an extension
dbf.name String of the dbf file name with an extension
shapefile The shapefile object of lists created by read.shapefile
out.name Filename to write the data to
shp shp portion (list) of the shapefile object of lists
shx shx portion (list) of the shapefile object of lists
dbf dbf portion (list) of the shapefile object of lists
scale.factor Number to divide the shapefile geography by
nodes Points shapefile object of lists
links Lines shapefile object of lists
file.name String of EMME/2 d211 import file to save to
arcgis Replace "." with "_" in column names for ArcGIS

Details

ESRI shapefiles consist of three files. The first file (*.shp) contains the geography of each shape. The second file (*.shx) is an index file which contains record offsets. The third file (*.dbf) contains feature attributes with one record per feature.

read.shapefile calls read.shp, read.shx, and read.dbf to read in an entire shapefile. The result of read.shapefile is a list of many more lists. The sublists are shp, shx, and dbf. Each sublist contains a header list and some sort of data list. The shp list is a list of $shp$header and $shp$shp. The shx list is a list of $shx$header and $shx$index. The dbf list is a list of $dbf$header and $dbf$dbf.

Currently only the read functions are really that useful. The write functions work fine, but building the necessary data in R to write out all the appropriate data in the shp and dbf files is absent at this point.

For details about the ESRI shapefile structure refer to http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf. A detailed description of DBF files can be found at http://www.e-bachmann.dk/docs/xbase.htm. The arcgis argument to write.dbf replaces "." with "_" in field names since ArcGIS does not allow the former. Note that the RODBC package function odbcConnectDbase is faster than read.dbf.

Value

read.shapefile list shapefile list object
read.shp list shp list object
read.shx list shx list object
read.dbf list DBF list object
write.shapefile NA Nothing returned
write.shp NA Nothing returned
write.shx NA Nothing returned
write.dbf NA Nothing returned
calc.header list shapefile list object
add.xy list shapefile list object
scaleXY list shapefile list object
emme2.shp NA Nothing returned

Author(s)

Ben Stabler <benjamin.stabler@odot.state.or.us>
http://www.odot.state.or.us/tddtpau/R.html

Examples

## Don't run: 
#Read entire shapefile
shapefile <- read.shapefile("links")

#Write entire shapefile
write.shapefile(shapefile, "temp", T)

#Read shp, shx, or dbf file
dbf <- read.dbf("links.dbf")

#Write shp, shx, or dbf file
write.dbf(dbf, "links.dbf", T)

#Calculate header (to clean up GeoMedia shapefile exports)
shapefile <- calc.header(shapefile)

#Add the X and Y coordinates to the dbf list of the shapefile list object
shapefile <- add.xy(shapefile)

#Scale the shapefile by scale.factor
shapefile <- scaleXY(shapefile, scale.factor)

#Create an EMME/2 network batch-in file
emme2.shp(nodes, links, "d211.in")
## End Don't run

[Package Contents]