1 2#' Extract feature-level meta 3#' 4#' These functions return the non-coordinate information of a geometry 5#' and/or vector. They do not parse an entire geometry/vector and are 6#' intended to be very fast even for large vectors. 7#' 8#' @inheritParams wk_handle 9#' @param geometry_type An integer code for the geometry type. These 10#' integers follow the WKB specification (e.g., 1 for point, 11#' 7 for geometrycollection). 12#' @param geometry_type_label A character vector of (lowercase) 13#' geometry type labels as would be found in WKT (e.g., point, 14#' geometrycollection). 15#' 16#' @return A data.frame with columns: 17#' - `geometry_type`: An integer identifying the geometry type. 18#' A value of 0 indicates that the types of geometry in the vector 19#' are not known without parsing the entire vector. 20#' - `size`: For points and linestrings, the number of coordinates; for 21#' polygons, the number of rings; for collections, the number of 22#' child geometries. A value of zero indicates an EMPTY geometry. 23#' A value of `NA` means this value is unknown without parsing the 24#' entire geometry. 25#' - `has_z`: `TRUE` if coordinates contain a Z value. A value of `NA` 26#' means this value is unknown without parsing the entire vector. 27#' - `has_m`: `TRUE` if coordinates contain an M value. A value of `NA` 28#' means this value is unknown without parsing the entire vector. 29#' - `srid`: An integer identifying a CRS or NA if this value was not 30#' provided. 31#' - `precision`: A grid size or 0.0 if a grid size was not provided. 32#' Note that coordinate values may not have been rounded; the grid 33#' size only refers to the level of detail with which they should 34#' be interpreted. 35#' 36#' @export 37#' 38#' @examples 39#' wk_vector_meta(as_wkt("LINESTRING (0 0, 1 1)")) 40#' wk_meta(as_wkt("LINESTRING (0 0, 1 1)")) 41#' wk_meta(as_wkb("LINESTRING (0 0, 1 1)")) 42#' 43#' wk_geometry_type_label(1:7) 44#' wk_geometry_type(c("point", "geometrycollection")) 45#' 46wk_meta <- function(handleable, ...) { 47 UseMethod("wk_meta") 48} 49 50#' @rdname wk_meta 51#' @export 52wk_meta.default <- function(handleable, ...) { 53 new_data_frame(wk_handle(handleable, wk_meta_handler(), ...)) 54} 55 56#' @rdname wk_meta 57#' @export 58wk_vector_meta <- function(handleable, ...) { 59 UseMethod("wk_vector_meta") 60} 61 62#' @rdname wk_meta 63#' @export 64wk_vector_meta.default <- function(handleable, ...) { 65 new_data_frame(wk_handle(handleable, wk_vector_meta_handler(), ...)) 66} 67 68#' @rdname wk_meta 69#' @export 70wk_meta_handler <- function() { 71 new_wk_handler(.Call(wk_c_meta_handler_new), "wk_meta_handler") 72} 73 74#' @rdname wk_meta 75#' @export 76wk_vector_meta_handler <- function() { 77 new_wk_handler(.Call(wk_c_vector_meta_handler_new), "wk_vector_meta_handler") 78} 79 80#' @rdname wk_meta 81#' @export 82wk_geometry_type_label <- function(geometry_type) { 83 c( 84 "point", "linestring", "polygon", 85 "multipoint", "multilinestring", "multipolygon", 86 "geometrycollection" 87 )[as.integer(geometry_type)] 88} 89 90#' @rdname wk_meta 91#' @export 92wk_geometry_type <- function(geometry_type_label) { 93 match( 94 geometry_type_label, 95 c( 96 "point", "linestring", "polygon", 97 "multipoint", "multilinestring", "multipolygon", 98 "geometrycollection" 99 ) 100 ) 101} 102