MyNixOS website logo
Description

Converts Between R Objects and Simple Feature Objects.

Converts between R and Simple Feature 'sf' objects, without depending on the Simple Feature library. Conversion functions are available at both the R level, and through 'Rcpp'.

R buildstatus Coveragestatus downloads CRAN RStudio mirrordownloads

Another spatial library?

Yep. In a few of my other libraries I’ve made use of sf objects, but without importing the sf library itself. This is by design because sf is quite a ‘heavy’ library.

Therefore I’ve written / copied these methods for constructing the sf objects across a few different libraries.

So I thought it would be useful to have these in one place. And here they are.

Does it really make sf objects?

Yes and No.

These functions do not perform any validity checks on the geometries. Nor do they set Coordinate Reference Systems, EPSG, PROJ4 or precision attributes.

What they do is convert R and Rcpp objects (vectors, matrices and data.frames) into the correct sf class structure, so you can then assign these values yourself.

Are there any catches?

Yes. Your data has to be ordered before coverting to sf.

Where are the examples?

They’re on the website. GO NOW!

(however, here’s a taster)


df <- data.frame(
  id = c(1,1,1,1,1,2,2,2,2,2)
  , x = c(1,2,2,1,1,3,4,4,3,3)
  , y = c(1,1,2,2,1,3,3,4,4,3)
)

df$val <- letters[df$id]

sfheaders::sf_linestring( df, x = "x", y = "y", linestring_id = "id", keep = TRUE )

# Simple feature collection with 2 features and 2 fields
# geometry type:  LINESTRING
# dimension:      XY
# bbox:           xmin: 1 ymin: 1 xmax: 4 ymax: 4
# epsg (SRID):    NA
# proj4string:    NA
#   id val                       geometry
# 1  1   a LINESTRING (1 1, 2 1, 2 2, ...
# 2  2   b LINESTRING (3 3, 4 3, 4 4, ...

sfheaders::sf_polygon( df, x = "x", y = "y", polygon_id = "id" , keep = TRUE )

# Simple feature collection with 2 features and 2 fields
# geometry type:  POLYGON
# dimension:      XY
# bbox:           xmin: 1 ymin: 1 xmax: 4 ymax: 4
# epsg (SRID):    NA
# proj4string:    NA
#   id val                       geometry
# 1  1   a POLYGON ((1 1, 2 1, 2 2, 1 ...
# 2  2   b POLYGON ((3 3, 4 3, 4 4, 3 ...
Metadata

Version

0.4.4

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows