st_as_sfc: ## Method coordinates ## @name coordinates ## @exportMethod...

Description Usage Arguments Details Examples

Description

#' @name st_as_sf #' @examples #' library(sp) #' x = rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1)) #' x1 = 0.1 * x + 0.1 #' x2 = 0.1 * x + 0.4 #' x3 = 0.1 * x + 0.7 #' y = x + 3 #' y1 = x1 + 3 #' y3 = x3 + 3 #' m = matrix(c(3, 0), 5, 2, byrow = TRUE) #' z = x + m #' z1 = x1 + m #' z2 = x2 + m #' z3 = x3 + m #' p1 = Polygons(list( Polygon(x[5:1,]), Polygon(x2), Polygon(x3), #' Polygon(y[5:1,]), Polygon(y1), Polygon(x1), Polygon(y3)), "ID1") #' p2 = Polygons(list( Polygon(z[5:1,]), Polygon(z2), Polygon(z3), Polygon(z1)), #' "ID2") #' if (require("rgeos")) #' r = createSPComment(SpatialPolygons(list(p1,p2))) #' comment(r) #' comment(r@polygons[[1]]) #' scan(text = comment(r@polygons[[1]]), quiet = TRUE) #' library(sf) #' a = st_as_sf(r) #' summary(a) #' #' demo(meuse, ask = FALSE, echo = FALSE) #' summary(st_as_sf(meuse)) #' summary(st_as_sf(meuse.grid)) #' summary(st_as_sf(meuse.area)) #' summary(st_as_sf(meuse.riv)) #' summary(st_as_sf(as(meuse.riv, "SpatialLines"))) #' pol.grd = as(meuse.grid, "SpatialPolygonsDataFrame") #' summary(st_as_sf(pol.grd)) #' summary(st_as_sf(as(pol.grd, "SpatialLinesDataFrame"))) #' @export st_as_sf.Spatial = function(x, ...) if ("data" df = x@data else df = data.frame(row.names = row.names(x)) # empty if ("geometry" warning("column \"geometry\" will be overwritten by geometry column") if (!requireNamespace("sp", quietly = TRUE)) stop("package sp required, please install it first") df$geometry = st_as_sfc(sp::geometry(x), ...) st_as_sf(df) Convert foreign geometry object to an sfc object

Usage

1
2
3
4
5
st_as_sfc(x, ...)

## S3 method for class 'WKB'
st_as_sfc(x, ..., EWKB = FALSE, pureR = FALSE,
  crs = NA_crs_)

Arguments

x

object to convert

...

further arguments

EWKB

logical; if TRUE, parse as EWKB (PostGIS: ST_AsEWKB), otherwise as ISO WKB (PostGIS: ST_AsBinary)

pureR

logical; if TRUE, use only R code, if FALSE, use compiled (C++) code; use TRUE when the endian-ness of the binary differs from the host machine (.Platform$endian).

forceMulti

logical; if TRUE, force coercion into MULTIPOLYGON or MULTILINE objects, else autodetect

Details

Convert foreign geometry object to an sfc object

when converting from WKB, the object x is either a character vector such as typically obtained from PostGIS (either with leading "0x" or without), or a list with raw vectors representing the features in binary (raw) form.

Examples

1
2
3
4
wkb = structure(list("01010000204071000000000000801A064100000000AC5C1441"), class = "WKB")
st_as_sfc(wkb, EWKB = TRUE)
wkb = structure(list("0x01010000204071000000000000801A064100000000AC5C1441"), class = "WKB")
st_as_sfc(wkb, EWKB = TRUE)

mdsumner/gv documentation built on May 22, 2019, 4:44 p.m.