readShapeSpatial {maptools} | R Documentation

## Read shape files into Spatial*DataFrame objects

### Description

The use of this function is deprecated and it is not being maintained. Use `rgdal::readOGR()` or `sf::st_read()` instead - both of these read the coordinate reference system from the input file, while this deprecated function does not. The `readShapeSpatial` reads data from a shapefile into a `Spatial*DataFrame` object. The `writeSpatialShape` function writes data from a `Spatial*DataFrame` object to a shapefile. Note DBF file restrictions in `write.dbf`.

### Usage

    readShapeSpatial(fn, proj4string=CRS(as.character(NA)),
    	verbose=FALSE, repair=FALSE, IDvar=NULL, force_ring=FALSE,
    	delete_null_obj=FALSE, retrieve_ABS_null=FALSE)
    writeSpatialShape(x, fn, factor2char = TRUE, max_nchar=254)

### Arguments

`fn` | shapefile layer name, when writing omitting the extensions *.shp, *.shx and *.dbf, which are added in the function
`proj4string` | Object of class `CRS`; holding a valid proj4 string
`verbose` | default FALSE - report type of shapefile and number of shapes
`repair` | default FALSE: some shapefiles provided by Geolytics Inc. have values of object sizes stored in the *.shx index file that are eight bytes too large, leading the function to try to read past the end of file. If repair=TRUE, an attempt is made to repair the internal values, permitting such files to be read.
`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 (Polygons only)
`force_ring` | if TRUE, close unclosed input rings (Polygons only)
`delete_null_obj` | if TRUE, null geometries inserted by ABS will be removed together with their data.frame rows (Polygons and Lines)
`retrieve_ABS_null` | default FALSE, if TRUE and delete\_null\_obj also TRUE, the function will return a data frame containing the data from any null geometries inserted by ABS (Polygons only)
`x` | a vector data `Spatial*DataFrame` object
`factor2char` | logical, default TRUE, convert factor columns to character
`max_nchar` | default 254, may be set to a higher limit and passed through to the DBF writer, please see Details in `write.dbf`

### 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 row.names are added to the DBF file as column SP\_ID.

### Value

a Spatial*DataFrame object of a class corresponding to the input shapefile

### Author(s)

Roger Bivand

### See Also

`write.dbf`

### Examples

    library(maptools)
    xx <- readShapeSpatial(system.file("shapes/sids.shp", package="maptools")[1],
     IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
    summary(xx)
    xxx <- xx[xx$SID74 < 2,]
    tmpfl <- paste(tempdir(), "xxpoly", sep="/")
    writeSpatialShape(xxx, tmpfl)
    getinfo.shape(paste(tmpfl, ".shp", sep=""))
    unlink(paste(tmpfl, ".*", sep=""))
    xx <- readShapeSpatial(system.file("shapes/fylk-val.shp",
     package="maptools")[1], proj4string=CRS("+proj=utm +zone=33 +datum=WGS84"))
    summary(xx)
    xxx <- xx[xx$LENGTH > 30000,]
    plot(xxx, col="red", add=TRUE)
    tmpfl <- paste(tempdir(), "xxline", sep="/")
    writeSpatialShape(xxx, tmpfl)
    getinfo.shape(paste(tmpfl, ".shp", sep=""))
    unlink(paste(tmpfl, ".*", sep=""))
    xx <- readShapeSpatial(system.file("shapes/baltim.shp", package="maptools")[1])
    summary(xx)
    xxx <- xx[xx$PRICE < 40,]
    tmpfl <- paste(tempdir(), "xxpts", sep="/")
    writeSpatialShape(xxx, tmpfl)
    getinfo.shape(paste(tmpfl, ".shp", sep=""))
    unlink(paste(tmpfl, ".*", sep=""))

[Package maptools version 0.9-2 Index]