Learn R Programming

rgdal (version 0.5-1)

readOGR: Read OGR vector maps into Spatial objects

Description

The function reads an OGR data source and layer into a suitable Spatial vector object. It can only handle layers with conformable geometry features (not mixtures of points, lines, or polygons in a single layer). It will set the spatial reference system if the layer has such metadata.

Usage

readOGR(dsn, layer, verbose = TRUE)
ogrInfo(dsn, layer)
ogrFIDs(dsn, layer)
ogrDrivers()
## S3 method for class 'ogrinfo':
print(x, ...)

Arguments

dsn
data source name (interpretation varies by driver --- for some drivers, dsn is a file name, but may also be a folder)
layer
layer name (varies by driver, may be a file name without extension)
verbose
report progress
x
ogrinfo object
...
other arguments to print method

Value

  • A Spatial object is returned suiting the vector data source, either a SpatialPointsDataFrame (using an AttributeList for its data slot directly), a SpatialLinesDataFrame, or a SpatialPolygonsDataFrame.

Details

The drivers available will depend on the installation of GDAL/OGR, and can vary; the ogrDrivers() function shows which are available, and which may be written (but all are assumed to be readable, which is not the case - KML is writable but not readable). Note that stray files in data source directories (such as *.dbf) may lead to suprious errors that accompanying *.shp are missing.

References

http://www.remotesensing.org/gdal/ogr/index.html, http://www.remotesensing.org/gdal/ogr/ogr_formats.html, http://examples.oreilly.com/webmapping/

See Also

SpatialPointsDataFrame-class, SpatialLinesDataFrame-class, SpatialPolygonsDataFrame-class, readShapePoly

Examples

Run this code
ogrDrivers()
cities <- readOGR(system.file("vectors", package = "rgdal")[1], "cities")
summary(cities)
ogrInfo(system.file("vectors", package = "rgdal")[1], "cities")
kiritimati_primary_roads <- readOGR(system.file("vectors", package = "rgdal")[1], "kiritimati_primary_roads")
summary(kiritimati_primary_roads)
scot_BNG <- readOGR(system.file("vectors", package = "rgdal")[1], "scot_BNG")
summary(scot_BNG)
if ("GML" %in% ogrDrivers()$name) {
  airports <- try(readOGR(system.file("vectors/airports.gml", package = "rgdal")[1], "airports"))
  if (class(airports) != "try-error") summary(airports)
}
ps_cant_31 <- readOGR(system.file("vectors/ps_cant_31.MIF", package = "rgdal")[1], "ps_cant_31")
summary(ps_cant_31)
Up <- readOGR(system.file("vectors/Up.tab", package = "rgdal")[1], "Up")
summary(Up)

Run the code above in your browser using DataLab