readOGR                package:rgdal                R Documentation

_R_e_a_d _O_G_R _v_e_c_t_o_r _m_a_p_s _i_n_t_o _S_p_a_t_i_a_l _o_b_j_e_c_t_s

_D_e_s_c_r_i_p_t_i_o_n:

     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.

_U_s_a_g_e:

     readOGR(dsn, layer, verbose = TRUE, p4s=NULL, drop_unsupported_fields=FALSE,
      input_field_name_encoding=NULL, pointDropZ=FALSE, dropNULLGeometries=TRUE)
     ogrInfo(dsn, layer, input_field_name_encoding=NULL)
     ogrFIDs(dsn, layer)
     ogrDrivers()
     ## S3 method for class 'ogrinfo':
     print(x, ...)

_A_r_g_u_m_e_n_t_s:

     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

     p4s: PROJ4 string defining CRS, if default NULL, the value is read
          from the OGR data set

drop\_unsupported\_fields: default FALSE, if TRUE skip fields other
          than String, Integer, and Real; Date, Time and DateTime are
          converted to String

input\_field\_name\_encoding: default NULL; if not NULL, should be a
          valid encoding name for the source platform of the data
          source and layer, see 'iconv'

pointDropZ: default FALSE, if TRUE, discard third coordinates for point
          geometries; third coordinates are alway discarded for line
          and polygon geometries

dropNULLGeometries: default TRUE, drop both declared NULL geometries,
          and empty geometries with no coordinates; if FALSE, return a
          data frame with the attribute values of the NULL and empty
          geometries

       x: ogrinfo object

     ...: other arguments to print method

_D_e_t_a_i_l_s:

     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). Note that stray files in data source directories (such
     as *.dbf) may lead to suprious errors that accompanying *.shp are
     missing.

_V_a_l_u_e:

     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.

_N_o_t_e:

     The bases for this implementation are taken from functions in
     Barry Rowlingson's draft Rmap package, and from Radim Blazek's
     v.in.ogr program in GRASS.

     Please note that the OGR drivers used may not handle missing data
     gracefully, and be prepared to have to correct for this manually.
     From rgdal 0.5-27, missing value handling has been improved, and
     OGR unset field values are set to NA in R, but drivers and
     external files may vary in their representations of missing
     values.

     In addition, from 0.6-9 date and time fields are read as strings
     rather than being treated as unsupported; NULL geometries are
     identified and dropped. There are differences in the reporting of
     NULL geometries between 'ogrInfo' and 'readOGR' - in 'ogrInfo',
     only declared NULL geometries are reported, but in 'readOGR', any
     line or polygon geometries with no coordinates are assigned NULL
     geometry status as well. An attempt is made to close unclosed
     rings in polygon geometries. 

     For reading GPX files, refer to the OGR GPX format documentation
     for the use of layer tags: "waypoints", "tracks", "routes",
     "track_points" and "route_points" - reading GPX files requires a
     build of GDAL/OGR with the expat XML library. 

     From 0.6-10, attempts are made to detect deleted features still
     present in the layer, but not read. Apparently features deleted in
     Qgis are only marked as deleted, but are still in the layer. These
     are not NULL geometries, but still need to be handled. An attempt
     is made to check the FID values, and 'ogrFIDs' now returns
     attributes permitting this oddity to be detected. Such deleted
     features were seen as NULL in 0.6-9, but are not such.

_A_u_t_h_o_r(_s):

     Roger Bivand

_R_e_f_e_r_e_n_c_e_s:

     <URL: http://www.gdal.org/ogr/>, <URL:
     http://www.gdal.org/ogr/ogr_formats.html>, <URL:
     http://examples.oreilly.com/webmapping/>

_S_e_e _A_l_s_o:

     'SpatialPointsDataFrame-class', 'SpatialLinesDataFrame-class',
     'SpatialPolygonsDataFrame-class', 'readShapePoly', 'iconv'

_E_x_a_m_p_l_e_s:

     ogrDrivers()
     ogrInfo(system.file("vectors", package = "rgdal")[1], "cities")
     cities <- readOGR(system.file("vectors", package = "rgdal")[1], "cities")
     summary(cities)
     ogrInfo(system.file("vectors", package = "rgdal")[1], "kiritimati_primary_roads")
     kiritimati_primary_roads <- readOGR(system.file("vectors", package = "rgdal")[1], "kiritimati_primary_roads")
     summary(kiritimati_primary_roads)
     ogrInfo(system.file("vectors", package = "rgdal")[1], "scot_BNG")
     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)
     }
     ogrInfo(system.file("vectors/ps_cant_31.MIF", package = "rgdal")[1], "ps_cant_31")
     ps_cant_31 <- readOGR(system.file("vectors/ps_cant_31.MIF", package = "rgdal")[1], "ps_cant_31")
     summary(ps_cant_31)
     ogrInfo(system.file("vectors/Up.tab", package = "rgdal")[1], "Up")
     Up <- readOGR(system.file("vectors/Up.tab", package = "rgdal")[1], "Up")
     summary(Up)
     test_trk2 <- try(readOGR(system.file("vectors/test_trk2.gpx", package = "rgdal")[1], "tracks"))
     if (class(test_trk2) != "try-error") summary(test_trk2)
     test_trk2pts <- try(readOGR(system.file("vectors/test_trk2.gpx", package = "rgdal")[1], "track_points"))
     if (class(test_trk2pts) != "try-error") summary(test_trk2pts)
     ogrInfo(system.file("vectors", package = "rgdal")[1], "trin_inca_pl03")
     birds <- readOGR(system.file("vectors", package = "rgdal")[1], "trin_inca_pl03")
     summary(birds)

