Convert foreign geometry object to an sfc object

# S3 method for list
st_as_sfc(x, ..., crs = NA_crs_)

# S3 method for blob
st_as_sfc(x, ...)

# S3 method for bbox
st_as_sfc(x, ...)

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

# S3 method for raw
st_as_sfc(x, ...)

# S3 method for character
st_as_sfc(x, crs = NA_integer_, ...,
  GeoJSON = FALSE)

# S3 method for factor
st_as_sfc(x, ...)

st_as_sfc(x, ...)

# S3 method for SpatialPoints
st_as_sfc(x, ..., precision = 0)

# S3 method for SpatialPixels
st_as_sfc(x, ..., precision = 0)

# S3 method for SpatialMultiPoints
st_as_sfc(x, ..., precision = 0)

# S3 method for SpatialLines
st_as_sfc(x, ..., precision = 0,
  forceMulti = FALSE)

# S3 method for SpatialPolygons
st_as_sfc(x, ..., precision = 0,
  forceMulti = FALSE)

# S3 method for map
st_as_sfc(x, ...)

Arguments

x

object to convert

...

further arguments

crs

integer or character; coordinate reference system for the

EWKB

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

spatialite

logical; if TRUE, WKB is assumed to be in the spatialite dialect, see https://www.gaia-gis.it/gaia-sins/BLOB-Geometry.html; this is only supported in native endian-ness (i.e., files written on system with the same endian-ness as that on which it is being read).

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).

GeoJSON

logical; if TRUE, try to read geometries from GeoJSON text strings geometry, see st_crs()

precision

precision value; see st_as_binary

forceMulti

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

Details

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.

If x is a character vector, it should be a vector containing well-known-text, or Postgis EWKT or GeoJSON representations of a single geometry for each vector element.

If x is a factor, it is converted to character.

Examples

wkb = structure(list("01010000204071000000000000801A064100000000AC5C1441"), class = "WKB") st_as_sfc(wkb, EWKB = TRUE)
#> Geometry set for 1 feature #> geometry type: POINT #> dimension: XY #> bbox: xmin: 181072 ymin: 333611 xmax: 181072 ymax: 333611 #> epsg (SRID): 28992 #> proj4string: +proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.2369,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0812 +units=m +no_defs
#> POINT (181072 333611)
wkb = structure(list("0x01010000204071000000000000801A064100000000AC5C1441"), class = "WKB") st_as_sfc(wkb, EWKB = TRUE)
#> Geometry set for 1 feature #> geometry type: POINT #> dimension: XY #> bbox: xmin: 181072 ymin: 333611 xmax: 181072 ymax: 333611 #> epsg (SRID): 28992 #> proj4string: +proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.2369,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0812 +units=m +no_defs
#> POINT (181072 333611)
st_as_sfc(st_as_binary(st_sfc(st_point(0:1)))[[1]], crs = 4326)
#> Geometry set for 1 feature #> geometry type: POINT #> dimension: XY #> bbox: xmin: 0 ymin: 1 xmax: 0 ymax: 1 #> epsg (SRID): 4326 #> proj4string: +proj=longlat +datum=WGS84 +no_defs
#> POINT (0 1)
st_as_sfc("SRID=3978;LINESTRING(1663106 -105415,1664320 -104617)")
#> Geometry set for 1 feature #> geometry type: LINESTRING #> dimension: XY #> bbox: xmin: 1663106 ymin: -105415 xmax: 1664320 ymax: -104617 #> epsg (SRID): 3978 #> proj4string: +proj=lcc +lat_1=49 +lat_2=77 +lat_0=49 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
#> LINESTRING (1663106 -105415, 1664320 -104617)