In [1]:
library(sf)
## rocker_geospatial_sf/demo/basic.R
Linking to GEOS 3.6.2, GDAL 2.2.3, proj.4 4.9.3
In [2]:
## ----error=TRUE----------------------------------------------------------
outer = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE)
outer
hole1 = matrix(c(1,1,1,2,2,2,2,1,1,1),ncol=2, byrow=TRUE)
hole2 = matrix(c(5,5,5,6,6,6,6,5,5,5),ncol=2, byrow=TRUE)
pol1 = list(outer, hole1, hole2)
pol2 = list(outer + 12, hole1 + 12)
pol3 = list(outer + 24)
mp = list(pol1,pol2,pol3)
(mp1 = st_multipolygon(mp))
pts3 = lapply(mp, function(x) lapply(x, function(y) cbind(y, 0)))
(mp2 = st_multipolygon(pts3))
(mp3 = st_multipolygon(pts3, "XYM"))
pts4 = lapply(mp2, function(x) lapply(x, function(y) cbind(y, 0)))
(mp4 = st_multipolygon(pts4))
st_bbox(mp1)
0 0
10 0
1010
010
0 0
MULTIPOLYGON (((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1), (5 5, 5 6, 6 6, 6 5, 5 5)), ((12 12, 22 12, 22 22, 12 22, 12 12), (13 13, 13 14, 14 14, 14 13, 13 13)), ((24 24, 34 24, 34 34, 24 34, 24 24)))
MULTIPOLYGON Z (((0 0 0, 10 0 0, 10 10 0, 0 10 0, 0 0 0), (1 1 0, 1 2 0, 2 2 0, 2 1 0, 1 1 0), (5 5 0, 5 6 0, 6 6 0, 6 5 0, 5 5 0)), ((12 12 0, 22 12 0, 22 22 0, 12 22 0, 12 12 0), (13 13 0, 13 14 0, 14 14 0, 14 13 0, 13 13 0)), ((24 24 0, 34 24 0, 34 34 0, 24 34 0, 24 24 0)))
MULTIPOLYGON M (((0 0 0, 10 0 0, 10 10 0, 0 10 0, 0 0 0), (1 1 0, 1 2 0, 2 2 0, 2 1 0, 1 1 0), (5 5 0, 5 6 0, 6 6 0, 6 5 0, 5 5 0)), ((12 12 0, 22 12 0, 22 22 0, 12 22 0, 12 12 0), (13 13 0, 13 14 0, 14 14 0, 14 13 0, 13 13 0)), ((24 24 0, 34 24 0, 34 34 0, 24 34 0, 24 24 0)))
MULTIPOLYGON ZM (((0 0 0 0, 10 0 0 0, 10 10 0 0, 0 10 0 0, 0 0 0 0), (1 1 0 0, 1 2 0 0, 2 2 0 0, 2 1 0 0, 1 1 0 0), (5 5 0 0, 5 6 0 0, 6 6 0 0, 6 5 0 0, 5 5 0 0)), ((12 12 0 0, 22 12 0 0, 22 22 0 0, 12 22 0 0, 12 12 0 0), (13 13 0 0, 13 14 0 0, 14 14 0 0, 14 13 0 0, 13 13 0 0)), ((24 24 0 0, 34 24 0 0, 34 34 0 0, 24 34 0 0, 24 24 0 0)))
xmin ymin xmax ymax 
   0    0   34   34 
In [3]:
## ----error=TRUE----------------------------------------------------------
outer = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE)
outer
hole1 = matrix(c(1,1,1,2,2,2,2,1,1,1),ncol=2, byrow=TRUE)
hole2 = matrix(c(5,5,5,6,6,6,6,5,5,5),ncol=2, byrow=TRUE)
pol1 = list(outer, hole1, hole2)
pol2 = list(outer + 12, hole1 + 12)
pol3 = list(outer + 24)
mp = list(pol1,pol2,pol3)
mp1 = st_multipolygon(mp)
(gc = st_geometrycollection(list(p1, ls1, pl1, mp1)))
st_bbox(gc)
attr(try(st_geometrycollection(list(mp3, pl1))), "condition") # Error:
0 0
10 0
1010
010
0 0
Error in vapply(x, class, rep("", 3)): object 'p1' not found
Traceback:

1. st_geometrycollection(list(p1, ls1, pl1, mp1))
2. vapply(x, class, rep("", 3))
In [4]:
## ----error=TRUE----------------------------------------------------------
outer = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE)
outer
hole1 = matrix(c(1,1,1,2,2,2,2,1,1,1),ncol=2, byrow=TRUE)
hole2 = matrix(c(5,5,5,6,6,6,6,5,5,5),ncol=2, byrow=TRUE)
pts = list(outer, hole1, hole2)
(pl1 = st_polygon(pts))
pts3 = lapply(pts, function(x) cbind(x, 0))
(pl2 = st_polygon(pts3))
(pl3 = st_polygon(pts3, "XYM"))
pts4 = lapply(pts3, function(x) cbind(x, 0))
(pl4 = st_polygon(pts4))
st_bbox(pl1)
0 0
10 0
1010
010
0 0
POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1), (5 5, 5 6, 6 6, 6 5, 5 5))
POLYGON Z ((0 0 0, 10 0 0, 10 10 0, 0 10 0, 0 0 0), (1 1 0, 1 2 0, 2 2 0, 2 1 0, 1 1 0), (5 5 0, 5 6 0, 6 6 0, 6 5 0, 5 5 0))
POLYGON M ((0 0 0, 10 0 0, 10 10 0, 0 10 0, 0 0 0), (1 1 0, 1 2 0, 2 2 0, 2 1 0, 1 1 0), (5 5 0, 5 6 0, 6 6 0, 6 5 0, 5 5 0))
POLYGON ZM ((0 0 0 0, 10 0 0 0, 10 10 0 0, 0 10 0 0, 0 0 0 0), (1 1 0 0, 1 2 0 0, 2 2 0 0, 2 1 0 0, 1 1 0 0), (5 5 0 0, 5 6 0 0, 6 6 0 0, 6 5 0 0, 5 5 0 0))
xmin ymin xmax ymax 
   0    0   10   10 
In [5]:
## ----error=TRUE----------------------------------------------------------
outer = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE)
hole1 = matrix(c(1,1,1,2,2,2,2,1,1,1),ncol=2, byrow=TRUE)
hole2 = matrix(c(5,5,5,6,6,6,6,5,5,5),ncol=2, byrow=TRUE)
pts = list(outer, hole1, hole2)
(ml1 = st_multilinestring(pts))
pts3 = lapply(pts, function(x) cbind(x, 0))
(ml2 = st_multilinestring(pts3))
(ml3 = st_multilinestring(pts3, "XYM"))
pts4 = lapply(pts3, function(x) cbind(x, 0))
(ml4 = st_multilinestring(pts4))
st_bbox(ml1)
MULTILINESTRING ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1), (5 5, 5 6, 6 6, 6 5, 5 5))
MULTILINESTRING Z ((0 0 0, 10 0 0, 10 10 0, 0 10 0, 0 0 0), (1 1 0, 1 2 0, 2 2 0, 2 1 0, 1 1 0), (5 5 0, 5 6 0, 6 6 0, 6 5 0, 5 5 0))
MULTILINESTRING M ((0 0 0, 10 0 0, 10 10 0, 0 10 0, 0 0 0), (1 1 0, 1 2 0, 2 2 0, 2 1 0, 1 1 0), (5 5 0, 5 6 0, 6 6 0, 6 5 0, 5 5 0))
MULTILINESTRING ZM ((0 0 0 0, 10 0 0 0, 10 10 0 0, 0 10 0 0, 0 0 0 0), (1 1 0 0, 1 2 0 0, 2 2 0 0, 2 1 0 0, 1 1 0 0), (5 5 0 0, 5 6 0 0, 6 6 0 0, 6 5 0 0, 5 5 0 0))
xmin ymin xmax ymax 
   0    0   10   10 
In [6]:
## ----error=TRUE----------------------------------------------------------
pts = matrix(1:10, , 2)
(ls1 = st_linestring(pts))
pts = matrix(1:15, , 3)
(ls2 = st_linestring(pts))
(ls3 = st_linestring(pts, "XYM"))
pts = matrix(1:20, , 4)
(ls4 = st_linestring(pts))
attr(try(st_linestring(pts[1,])), "condition") # Error:
attr(try(st_linestring(matrix(1:10, 2))), "condition")# Error:
st_bbox(ls1)
LINESTRING (1 6, 2 7, 3 8, 4 9, 5 10)
LINESTRING Z (1 6 11, 2 7 12, 3 8 13, 4 9 14, 5 10 15)
LINESTRING M (1 6 11, 2 7 12, 3 8 13, 4 9 14, 5 10 15)
LINESTRING ZM (1 6 11 16, 2 7 12 17, 3 8 13 18, 4 9 14 19, 5 10 15 20)
<simpleError: is.numeric(x) && is.matrix(x) is not TRUE>
<simpleError in getClassDim(x, ncol(x), dim, type): 5 is an illegal number of columns for a LINESTRING>
xmin ymin xmax ymax 
   1    6    5   10 
In [7]:
## ----error=TRUE----------------------------------------------------------
pts = matrix(1:10, , 2)
(mp1 = st_multipoint(pts))
pts = matrix(1:15, , 3)
(mp2 = st_multipoint(pts))
(mp3 = st_multipoint(pts, "XYM"))
pts = matrix(1:20, , 4)
(mp4 = st_multipoint(pts))
attr(try(st_multipoint(1)), "condition") # Error:
attr(try(st_multipoint(1:5)), "condition") # Error:
st_bbox(mp1)
MULTIPOINT (1 6, 2 7, 3 8, 4 9, 5 10)
MULTIPOINT Z (1 6 11, 2 7 12, 3 8 13, 4 9 14, 5 10 15)
MULTIPOINT M (1 6 11, 2 7 12, 3 8 13, 4 9 14, 5 10 15)
MULTIPOINT ZM (1 6 11 16, 2 7 12 17, 3 8 13 18, 4 9 14 19, 5 10 15 20)
<simpleError: is.numeric(x) && is.matrix(x) is not TRUE>
<simpleError: is.numeric(x) && is.matrix(x) is not TRUE>
xmin ymin xmax ymax 
   1    6    5   10 
In [8]:
## ----error=TRUE----------------------------------------------------------
(p1 = st_point(c(1,2)))
class(p1)
st_bbox(p1)
(p2 = st_point(c(1,2,3)))
class(p2)
(p3 = st_point(c(1,2,3), "XYM"))
(p4 = st_point(c(1,2,3,4)))
attr(try(st_point(1)), "condition") # Error:
attr(try(st_point(1:5)), "condition") # Error:
POINT (1 2)
  1. 'XY'
  2. 'POINT'
  3. 'sfg'
xmin ymin xmax ymax 
   1    2    1    2 
POINT Z (1 2 3)
  1. 'XYZ'
  2. 'POINT'
  3. 'sfg'
POINT M (1 2 3)
POINT ZM (1 2 3 4)
<simpleError in getClassDim(x, length(x), dim, "POINT"): 1 is an illegal number of columns for a POINT>
<simpleError in getClassDim(x, length(x), dim, "POINT"): 5 is an illegal number of columns for a POINT>