writeOGR                package:rgdal                R Documentation

_W_r_i_t_e _s_p_a_t_i_a_l _v_e_c_t_o_r _d_a_t_a _u_s_i_n_g _O_G_R

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

     The function is an interface with the OGR abstraction library for
     spatial vector data, allowing data to be written out using
     supported drivers. The drivers supported will depend on the local
     installation, and the capabilities of those drivers (many are
     read-only). The objects exported are SpatialPointsDataFrame,
     SpatialLinesDataFrame, or SpatialPolygonsDataFrame objects as
     defined in the sp package.

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

     writeOGR(obj, dsn, layer, driver, dataset_options = NULL, layer_options=NULL, verbose = FALSE)

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

     obj: a SpatialPointsDataFrame, SpatialLinesDataFrame, or a
          SpatialPolygonsDataFrame object.

     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)

  driver: a character string equal to one of the driver names returned
          by 'ogrDrivers'

dataset_options: a character vector of options, which vary by driver,
          and should be treated as experimental

layer_options: a character vector of options, which vary by driver, and
          should be treated as experimental

 verbose: if TRUE, returns a list of information about the attempted
          write operation

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

     Working out which combination of dsn, layer, and driver (and
     option) values give the desired output takes time and care, and is
     constrained by the ability of drivers to write output; many are
     read-only. Use of the references given is highly advisable, with
     searches in the archives of other software using GDAL/OGR.

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

     if verbose=TRUE, a list of information about the attempted write
     operation

_N_o_t_e:

     Only a subset of possible data slot column classes may be written
     out; if the function returns an error that the data type is
     unknown, examine the classes and check that they are one of
     'c("numeric", "character", "factor", "POSIXt", "integer")', and if
     not convert to such classes.

     For writing with the KML driver, note that the geometries should
     be in geographical coordinates with datum WGS84.

_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:

     'readOGR'

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

     cities <- readOGR(system.file("vectors", package = "rgdal")[1], "cities")
     is.na(cities$POPULATION) <- cities$POPULATION == -99
     summary(cities$POPULATION)
     td <- tempdir()
     if(nchar(Sys.getenv("OSGEO4W_ROOT") > 0)) {
         OLDPWD <- getwd()
         setwd(td)
         td <- "."
     }
     writeOGR(cities, td, "cities", driver="ESRI Shapefile")
     cities2 <- readOGR(td, "cities")
     summary(cities2$POPULATION)
     all.equal(cities, cities2)
     ## Not run: 
     if ("GML" %in% ogrDrivers()$name) {
       airports <- try(readOGR(system.file("vectors/airports.gml", package = "rgdal")[1], "airports"))
       if (class(airports) != "try-error") {
         writeOGR(cities, paste(td, "cities.gml", sep="/"), "cities", driver="GML")
         cities3 <- readOGR(paste(td, "cities.gml", sep="/"), "cities")
         all.equal(cities, cities3)
       }
     }
     ## End(Not run)
     # The GML driver does not support coordinate reference systems
     if ("KML" %in% ogrDrivers()$name) {
       data(meuse)
       coordinates(meuse) <- c("x", "y")
       proj4string(meuse) <- CRS("+init=epsg:28992")
       meuse_ll <- spTransform(meuse, CRS("+proj=longlat +datum=WGS84"))
       writeOGR(meuse_ll["zinc"], paste(td, "meuse.kml", sep="/"), "zinc", "KML")
     }
     list.files(td)
     roads <- readOGR(system.file("vectors", package = "rgdal")[1], "kiritimati_primary_roads")
     summary(roads)
     writeOGR(roads, td, "roads", driver="MapInfo File")
     roads2 <- readOGR(paste(td, "roads.tab", sep="/"), "roads")
     summary(roads2)
     scot_BNG <- readOGR(system.file("vectors", package = "rgdal")[1], "scot_BNG")
     summary(scot_BNG)
     writeOGR(scot_BNG, td, "scot_BNG", driver="MapInfo File")
     list.files(td)
     scot_BNG2 <- readOGR(paste(td, "scot_BNG.tab", sep="/"), "scot_BNG")
     summary(scot_BNG2)
     writeOGR(scot_BNG, td, "scot_BNG", driver="MapInfo File", dataset_options="FORMAT=MIF")
     list.files(td)
     scot_BNG3 <- readOGR(paste(td, "scot_BNG.mif", sep="/"), "scot_BNG")
     summary(scot_BNG3)
     if(nchar(Sys.getenv("OSGEO4W_ROOT") > 0)) {
         setwd(OLDPWD)
     }

