EncodeSF: Encode Simple Feature

Description Usage Arguments Examples

Description

Converts coordinates from simple-feature objects (sf) into encoded polylines

Usage

1
EncodeSF(sf, id = NULL)

Arguments

sf

simple-feature object (from library(sf))

id

column of sf to be used as the id. If NULL, a value from 1 to .N will be assigned to a column called .id

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
## Not run: 
library(sf)

## sf_LINESTRING
sf_line <- st_as_sfc(c("LINESTRING(-80.190 25.774, -66.118 18.466, -64.757 32.321)",
                       "LINESTRING(-70.579 28.745, -67.514 29.570, -66.668 27.339)"))

sf <- st_sf(id = paste0("line", 1:2), sf_line)

EncodeSF(sf)
EncodeSF(sf, id = "id")


## sf_POLYGON
sf_poly <- st_as_sfc(c("POLYGON((-80.190 25.774, -66.118 18.466, -64.757 32.321))",
                       "POLYGON((-70.579 28.745, -67.514 29.570, -66.668 27.339), (0 0, 1 0, 3 2))"))

EncodeSF(sf_poly)

sf <- st_sf(id = paste0("poly", 1:2), sf_poly)

EncodeSF(sf)

EncodeSF(sf, id = "id")

p1 <- rbind(c(0,0), c(1,0), c(3,2), c(2,4), c(1,4), c(0,0))
p2 <- rbind(c(1,1), c(1,2), c(2,2), c(1,1))
pol <- st_polygon(list(p1,p2))

EncodeSF(pol)

sf_poly <- st_as_sfc("POLYGON((0 0, 1 0, 3 2, 2 4, 1 4, 0 0), (1 1, 1 2, 2 2, 1 1))")
EncodeSF(sf_poly)

sf <- st_sf(id = "poly", sf_poly)
EncodeSF(sf)

EncodeSF(sf, id = "id")

## sf_MULTIPOLYGON
sf_poly <- st_as_sfc(c("MULTIPOLYGON(((-80.190 25.774, -66.118 18.466, -64.757 32.321)))",
                       "MULTIPOLYGON(((-70.579 28.745, -67.514 29.570, -66.668 27.339), (1 1, 2 2, 1.5 1.5)), ((0 0, 1 0, 3 2)))"))
sf <- st_sf(id = paste0("poly", 1:2), sf_poly)
EncodeSF(sf)



filename <- system.file("shape/nc.shp", package="sf")
nc <- st_read(filename)

sdt <- EncodeSF(nc)

nc$id <- 1:nrow(nc)
sdt <- EncodeSF(nc, id = "id")



## End(Not run)

SymbolixAU/spatialdatatable documentation built on May 6, 2019, 11:20 a.m.