arc.write: Write dataset, raster, feature, table or layer

View source: R/arc.write.R

arc.writeR Documentation

Write dataset, raster, feature, table or layer

Description

Export a data object to an ArcGIS dataset. If the data frame includes a spatial attribute, this function writes a feature dataset. If no spatial attribute is found, a table is instead written. If data is raster-like object, this function writes a raster dataset. See ‘Details’ section for more information.

Usage

  arc.write(path, data, ..., overwrite = FALSE)

Arguments

path

full output path

data

Accepts input source objects (see ‘Details’ for the types of objects allowed).

...

Additional arguments:

  • coords list containing geometry. Accepts Spatial objects. If data is data.frame coords can be list of field names (see Example #2).

  • shape_info list. Required argument if data has no spatial attribute (see Example #2).

  • validate logical. Default FALSE. If TRUE makes the geometries topologically correct.

overwrite

overwrite existing dataset. default = FALSE.

Details

Export to a new table dataset when data type is:

  • named list of vectors (see Example #4)

  • data.frame

Export to a new feature dataset when data type is:

  • arc.data result of arc.select

  • named list of vectors, parameters coords and shape_info are required (see Example #5)

  • data.frame, parameters coords and shape_info are required (see Example #2)

  • SpatialPointsDataFrame in package sp

  • SpatialLinesDataFrame in package sp

  • SpatialPolygonsDataFrame in package sp

  • sf, sfc in package sf

Export to a new raster dataset when data type is:

  • arc.raster result of arc.raster

  • SpatialPixels, SpatialPixelsDataFrame in package sp (see Example #6)

  • SpatialGrid in package sp

  • RasterLayer in package raster (see Example #7)

  • RasterBrick in package raster

Below are pairs of example paths and the resulting data types:

  • C:/place.gdb/fc: File Geodatabase Feature Class

  • C:/place.gdb/fdataset/fc: File Geodatabase Feature Dataset

  • in_memory\logreg: In-memory workspace (must be run in ArcGIS Session)

  • C:/place.shp: Esri Shapefile

  • C:/place.dbf: Table

  • C:/place.gdb/raster: File Geodatabase Raster when data parameter is arc.raster or Raster* object

  • C:/image.img: ERDAS Imaging

  • C:/image.tif: Geo TIFF

References

Note

To write Date column type corresponding data column must have POSIXct type (see Example #4).

See Also

arc.open, arc.select, arc.raster

Examples


## Example #1. write a shapefile
fc <- arc.open(system.file("extdata", "ca_ozone_pts.shp", package="arcgisbinding"))
d <- arc.select(fc, 'ozone')
d[1,] <- 0.6
arc.write(tempfile("ca_new", fileext=".shp"), d)

## create and write to a new file geodatabase
fgdb_path <- file.path(tempdir(), "data.gdb")


data(meuse, package="sp")
## Example #2. create feature dataset 'meuse'
arc.write(file.path(fgdb_path, "meuse\\pts"), data=meuse, coords=c("x", "y", "elev"), shape_info=list(type='Point',hasZ=TRUE,WKID=28992))
data(meuse.riv, package="sp")
riv <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(meuse.riv)),"meuse.riv")))

## Example #3. write only geometry
arc.write(file.path(fgdb_path, "meuse\\riv"), coords=riv)


## Example #4. write a table
t <- Sys.time() # now
arc.write(file.path(fgdb_path, "tlb"), data=list(
  'f_double'=c(23,45),
  'f_string'=c('hello', 'bob'),
  'f_datetime'=as.POSIXct(c(t, t - 3600)) # now and an hour ago
  ))

## Example #5. from scratch as feature class
arc.write(file.path(fgdb_path, "fc_pts"), data=list('data'=rnorm(100)),
          coords=list(x=runif(100,min=0,max=10),y=runif(100,min=0,max=10)),
          shape_info=list(type='Point'))


## Example #6. write Raster
# make SpatialPixelsDataFrame
data(meuse.grid, package="sp")
sp::coordinates(meuse.grid) = c("x", "y")
sp::gridded(meuse.grid) <- TRUE
meuse.grid@proj4string=sp::CRS(arc.fromWktToP4(28992))

arc.write(file.path(fgdb_path, "meuse_grid"), meuse.grid)



## Example #7. write using a RasterLayer object
r <- raster::raster(ncol=10, nrow=10)
raster::values(r) <- runif(raster::ncell(r))

arc.write(file.path(fgdb_path, "raster"), r)




R-ArcGIS/r-bridge documentation built on May 3, 2024, 9:47 a.m.