Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

readShapeLines

Read arc shape files into SpatialLinesDataFrame 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. For writing, use rgdal::writeOGR() or sf::st_write() instead.

The readShapeLines function reads data from an arc/line shapefile into a SpatialLinesDataFrame object; the shapefile may be of type polygon, but for just plotting for example coastlines, a SpatialLines object is sufficient. The writeLinesShape function writes data from a SpatialLinesDataFrame object to a shapefile. Note DBF file restrictions in write.dbf.

Usage

readShapeLines(fn, proj4string=CRS(as.character(NA)), verbose=FALSE,
 repair=FALSE, delete_null_obj=FALSE)
writeLinesShape(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.

delete_null_obj

if TRUE, null geometries will be removed together with their data.frame rows

x

a SpatialLinesDataFrame 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

The shpID values of the shapefile will be used as Lines ID values; when writing shapefiles, the object data slot row.names are added to the DBF file as column SL\_ID.

Value

a SpatialLinesDataFrame object

Author(s)

Roger Bivand

See Also

Examples

xx <- readShapeLines(system.file("shapes/fylk-val.shp", package="maptools")[1],
 proj4string=CRS("+proj=utm +zone=33 +datum=WGS84"))
plot(xx, col="blue")
summary(xx)
xxx <- xx[xx$LENGTH > 30000,]
plot(xxx, col="red", add=TRUE)
tmpfl <- paste(tempdir(), "xxline", sep="/")
writeLinesShape(xxx, tmpfl)
getinfo.shape(paste(tmpfl, ".shp", sep=""))
axx <- readShapeLines(tmpfl, proj4string=CRS("+proj=utm +zone=33 +datum=WGS84"))
plot(xxx, col="black", lwd=4)
plot(axx, col="yellow", lwd=1, add=TRUE)
unlink(paste(tmpfl, ".*", sep=""))
xx <- readShapeLines(system.file("shapes/sids.shp", package="maptools")[1],
 proj4string=CRS("+proj=longlat +datum=NAD27"))
plot(xx, col="blue")

maptools

Tools for Handling Spatial Objects

v1.1-1
GPL (>= 2)
Authors
Roger Bivand [cre, aut] (<https://orcid.org/0000-0003-2392-6140>), Nicholas Lewin-Koh [aut], Edzer Pebesma [ctb], Eric Archer [ctb], Adrian Baddeley [ctb], Nick Bearman [ctb], Hans-Jörg Bibiko [ctb], Steven Brey [ctb], Jonathan Callahan [ctb], German Carrillo [ctb], Stéphane Dray [ctb], David Forrest [ctb], Michael Friendly [ctb], Patrick Giraudoux [ctb], Duncan Golicher [ctb], Virgilio Gómez Rubio [ctb], Patrick Hausmann [ctb], Karl Ove Hufthammer [ctb], Thomas Jagger [ctb], Kent Johnson [ctb], Matthew Lewis [ctb] (<https://orcid.org/0000-0003-2244-4078>), Sebastian Luque [ctb], Don MacQueen [ctb], Andrew Niccolai [ctb], Edzer Pebesma [ctb], Oscar Perpiñán Lamigueiro [ctb], Ethan Plunkett [ctb], Ege Rubak [ctb] (<https://orcid.org/0000-0002-6675-533X>), Tom Short [ctb], Greg Snow [ctb], Ben Stabler [ctb], Murray Stokely [ctb], Rolf Turner [ctb]
Initial release
2021-03-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.