spatial_read: Wrapper functions for reading spatial objects.

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Read either simple features (package sf) and abstract of class Spatial (package sp) from disk using appropriate functionality (“engine”) of respective packages is used.

Usage

1
spatial_read(dsn, engine = c("native", "sp", "sf"))

Arguments

dsn

Character. File name of spatial object (vector GIS).

engine

Character. Functionality of which package is used for reading data. If value is "sf" then package is sf is used and simple features are returned. If value is "sp", then package rgdal is used and Spatial abstracrs (package sp) are returned. If value is "native" then engine selection depends of which namespace has already loaded or has suggested package sf been installed.

Details

Currently, list of arguments of this funtion is simplified and can be expanded.

Value

Depending of used engine, either simple features (package sf) or Spatial abstracts (sp).

Author(s)

Nikita Platonov platonov@sevin.ru

See Also

read_sf (valid if package sf is installed)

readOGR (package rgdal)

spatial_write

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
session_grid(NULL)
n <- 1e2
x <- runif(n,min=25,max=65)
y <- runif(n,min=55,max=65)
z <- runif(n,min=1,max=10)
da <- data.frame(x=x,y=y,z=z)
if (requireNamespace("sf",quietly=TRUE)) {
   obj1 <- sf::st_as_sf(da,coords=c("x","y"),crs=4326)
   print(series(obj1))
   fname1 <- file.path(tempdir(),"res1.shp")
   print(fname1)
   spatial_write(obj1,fname1)
   res1 <- spatial_read(fname1,engine="sf")
   print(series(res1))
}
if (requireNamespace("sp")) {
   obj2 <- da
   sp::coordinates(obj2) <- c("x","y")
   sp::proj4string(obj2) <- sp::CRS("+init=epsg:4326")
   print(series(obj2))
   print(spatial_crs(obj2))
   fname2 <- file.path(tempdir(),"res2.shp")
   print(fname2)
   spatial_write(obj2,fname2)
   res2 <- spatial_read(fname2,engine="sp")
   print(series(obj2))
}
print(spatial_dir(tempdir()))

ursa documentation built on Feb. 26, 2020, 3:01 p.m.