spatial_engine {ursa} | R Documentation |
Wrapper functions for manipulation with non-raster spatial objects
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
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 |
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 |
drop |
Logical. Dropping column of data frame. If |
value |
Value for property assignment in replacement functions. Either numeric EPSG code or character PROJ.4 string for |
path |
See description of argument |
pattern |
See description of argument |
full.names |
See description of argument |
recursive |
See description of argument |
ignore.case |
See description of argument |
quadsegs |
Integer. Number of segments per quadrant (fourth of a circle), for all or per-feature. See description
for |
dist |
Numeric. Buffer distance for all, or for each of the elements. See description
for |
byid |
Logical. For |
fname |
Character. Filename (source or packed) of spatial data. |
each |
Logical. Whether result will be returned for each record ( |
geometry |
Character. Desired output geometry for |
reason |
Logical. If |
verbose |
Logical. Value |
... |
1) Spatial objects for function |
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.
Author(s)
Nikita Platonov platonov@sevin.ru
References
Classes and methods in packages sf and sp help.
Examples
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))
}