spatial_engine: Wrapper functions for manipulation with non-raster spatial...

Description Usage Arguments Value Acknowledgements Author(s) References Examples

Description

These wrappers return iniform properties or do consimilar manipulations for spatial objects of different types: simple features (package sf) and abstract class Spatial (package sp). Appropriate functionality (“engine”) of respective packages is used.

Usage

 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
spatial_engine(obj, verbose = FALSE)

spatial_crs(obj, verbose = FALSE)
spatial_proj(obj, verbose = FALSE)
spatial_proj4(obj, verbose = FALSE)

spatial_crs(obj, verbose = FALSE) <- value
spatial_proj(obj, verbose = FALSE) <- value
spatial_proj4(obj, verbose = FALSE) <- value

spatial_bbox(obj, verbose = FALSE)
spatial_bbox(obj, verbose = FALSE) <- value

spatial_data(obj, subset= ".+", drop = NA, verbose = FALSE)
spatial_data(obj, verbose = FALSE) <- value

spatial_geometry(obj, verbose = FALSE)
spatial_geometry(obj, verbose = FALSE) <- value

spatial_geotype(obj, each = FALSE, verbose = FALSE)
spatial_shape(obj, each = FALSE, verbose = FALSE)

spatial_transform(obj, crs, verbose = FALSE, ...)

spatial_coordinates(obj, verbose = FALSE)
spatial_centroid(obj, verbose = FALSE)

spatial_fields(obj, verbose = FALSE)
spatial_colnames(obj, verbose = FALSE)

spatial_fields(obj, verbose = FALSE) <- value
spatial_colnames(obj, verbose = FALSE) <- value

spatial_area(obj, verbose = FALSE)

spatial_dim(obj, verbose = FALSE)

spatial_count(obj, verbose = FALSE)

spatial_nrow(obj, verbose = FALSE)
spatial_ncol(obj, verbose = FALSE)

spatial_filelist(path = ".", pattern = NA, full.names = TRUE, recursive = FALSE,
                 ignore.case = TRUE)
spatial_dir(path = ".", pattern = NA, full.names = TRUE, recursive = FALSE,
            ignore.case = TRUE)

spatial_basename(fname)
spatial_pattern(fname)

is_spatial(obj, verbose = FALSE)

is_spatial_points(obj, verbose = FALSE)
is_spatial_lines(obj, verbose = FALSE)
is_spatial_polygons(obj, verbose = FALSE)

spatial_intersection(x, y,
                     geometry=c("default", "polygons", "lines", "points", "all"),
                     verbose = FALSE)
spatial_symdifference(x, y, verbose = FALSE)
spatial_difference(x, y, verbose = FALSE)
spatial_union(x, y, byid=NA, verbose = FALSE)

spatial_buffer(obj, dist = 0, quadsegs = 30L, verbose = FALSE)

spatial_trim(obj)

spatial_valid(obj, each = FALSE, reason = FALSE, verbose = FALSE)

spatial_grid(obj)

spatial_bind(...)

Arguments

obj

Simple feature (package sf) or Spatial abstract class (package sp) for all functions, excepting spatial_geometry<-. Data frame for Replace function spatial_geometry<-.

x, y

Objects of simple feature (package sf) class or Spatial abstract class (package sp).

crs

Projection EPSG code or projection PROJ.4 string.

subset

Pattern to field names (colnames) of attribute table (data frame) for subbsetting using regular expressions. By default, all fields are secected.

drop

Logical. Dropping column of data frame. If TRUE, then vector of data is returned. If FALSE, then structure of data is kept. Default is NA, which is interpreted as TRUE for single column and as FALSE for multiple columns.

value

Value for property assignment in replacement functions. Either numeric EPSG code or character PROJ.4 string for spatial_crs<- and spatial_proj4<-. Spatial object or geometry of spatial object for spatial_geometry<-.

path

See description of argument path in function dir.

pattern

See description of argument pattern in function dir.

full.names

See description of argument full.names in function dir.

recursive

See description of argument recirsive in function dir.

ignore.case

See description of argument ignore.case in function dir.

quadsegs

Integer. Number of segments per quadrant (fourth of a circle), for all or per-feature. See description for quadsegs argument of gBuffer and for nQuadSegs argument of st_buffer.

dist

Numeric. Buffer distance for all, or for each of the elements. See description for width argument of gBuffer and for dist argument of st_buffer.

byid

Logical. For spatial_union function, TRUE does unite of each feature; FALSE returns a single feature that is the geometric union of the set of features; default NA is coerced to FALSE for unary operation (missing y) and to TRUE for binary operation.

fname

Character. Filename (source or packed) of spatial data.

each

Logical. Whether result will be returned for each record (TRUE) or generalized (FALSE). Default is FALSE.

geometry

Character. Desired output geometry for engine="sf". If "default" then output geometry is defined internally (e.g., "polygons" for polygons intersection). If "all" then no output subsetting. Default is "default".

reason

Logical. If TRUE, then the reason for validity ("Valid Geomerty") or invalidity is returned. If FALSE, then logical value of validity is returned. Default is FALSE.

verbose

Logical. Value TRUE provides information on console. Default is FALSE.

...

1) Spatial objects for function spatial_bind; 2) Further arguments in function spatial_transform passed to sf::st_transform or to sp::spTransform.

Value

spatial_engine returns package name (character string "sf" or "sp"), which functionality is used for manipulation with spatial object obj.

spatial_crs and spatial_proj4 are synonyms, The Extract functions return projection string in the PROJ.4 notation; the Replace functions change projection property of the object.

spatial_bbox (Extract function) returns numeric vector of length 4 with names "xmin", "ymin", "xmax" and "ymax".

spatial_bbox<- (Replace function) assigns boundary bbox to the object; it is valid only for objects of Spatial abstract class (package sp).

spatial_data (Extract function) returns attribute table only, without geometry. Subsetting fields can be specified by argument subset using regular expressions. If drop=TRUE and selected single column then vector is returned instead of data frame.

spatial_data<- (Replace function) adds spatial data to the object geomerty. Source data (if presents) are droped.

spatial_geometry (Extract function) returns only geometry, which format is depended on class of obj.

spatial_geometry<- (Replace function) addes geometry to the object.

spatial_transform does a transformation of spatial coordinates to the new CRS and returns object of the same class as class of obj.

spatial_geotype and spatial_shape are synonyms; each returns type of spatial data: "POINT", "LINESTRING", "POLYGON", "MULTIPOLYGON", ....

spatial_coordinates returns simplified matrix or list of coordinates of original object.

Extract functions spatial_fields and spatial_columns return column names of spatial attributive table. spatial_columns is synonym to spatial_fields.

Replace functions spatial_fields<- and spatial_columns<- change column names of spatial attributive table. spatial_columns<- is synonym to spatial_fields<-.

spatial_area is valid for polygonal geometry. It returns area of polygons.

spatial_length is valid for linear geometry. It returns length of lines.

spatial_dim gets dimension of spatial coordinates; it returns either 2L (XY) or 3L (XYZ).

spatial_count returns number of items of object geometry.

spatial_nrow and spatial_ncol return number of rows and number of columns of attributive table.

spatial_filelist and its synonym spatial_dir return list of files with file extensions, which are associated with certain GIS vector formats. The function's basis is dir.

spatial_basename returns basename (without extension) of file fname of spatial object.

spatial_pattern returns pattern of spatial_basename for using in regular expressions.

is_spatial returns logical value does the object belong to the class of spatial data.

is_spatial_points returns logical value does the object have point geometry.

is_spatial_lines returns logical value does the object have (multi)linestring geometry.

is_spatial_polygons returns logical value does the object have (multi)polygonal geometry.

spatial_intersection returns intersection of two spatial objects.

spatial_difference returns difference of two spatial objects.

spatial_symdifference returns symmetric difference of two spatial objects.

spatial_buffer returns buffered spatial object.

spatial_union returns combined geometry without internal boundaries.

spatial_trim returns spatial object without extra attributes added by ursa package.

spatial_grid generates suitable spatial grid from input vector and returns object of class ursaGrid.

spatial_centroid returns spatial centroid.

spatial_bind returns spatial object concatenated from input spatial objects.

Acknowledgements

The great improvement for development of functions for manipulation with spatial objects has been reached during work in series of projects (2015-2018) for design of marine protected areas in the Arctic, which were supported by WWF Russia.

Author(s)

Nikita Platonov platonov@sevin.ru

References

Classes and methods in packages sf and sp help.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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("sp")) {
   da.sp <- da
   sp::coordinates(da.sp) <- ~x+y
   sp::proj4string(da.sp) <- "+init=epsg:4326"
   print(spatial_bbox(da.sp))
   print(spatial_crs(da.sp))
}
if (requireNamespace("sf")) {
   da.sf <- sf::st_as_sf(da,coords=c("x","y"),crs=4326)
   print(spatial_bbox(da.sf))
   print(spatial_crs(da.sf))
}

ursa documentation built on May 23, 2021, 1:06 a.m.