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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> # MULTIPOLYGONS
> suppressPackageStartupMessages(library(sf))
> library(grid)
> nc = st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
> grid.newpage()
> # pushViewport(viewport(width = 0.8, height = 0.8))
> pushViewport(st_viewport(nc))
> invisible(lapply(st_geometry(nc), function(x) grid.draw(st_as_grob(x, gp = gpar(fill = 'red')))))
>
> # POLYGONS
> # nc = st_read(system.file("gpkg/nc.gpkg", package="sf"), "nc.gpkg", type = 3)
> nc = st_read(system.file("shape/nc.shp", package="sf"), type = 3, quiet = TRUE)
> grid.newpage()
> pushViewport(st_viewport(nc))
> invisible(lapply(st_geometry(nc), function(x) grid.draw(st_as_grob(x, gp = gpar(fill = 'red')))))
>
> # POINTS:
> data(meuse, package = "sp")
> meuse_sf = st_as_sf(meuse, coords = c("x", "y"), crs = 28992, agr = "constant")
> grid.newpage()
> pushViewport(st_viewport(meuse_sf))
> invisible(lapply(st_geometry(meuse_sf),
+ function(x) grid.draw(st_as_grob(x, gp = gpar(fill = 'red')))))
>
> # MULTIPOINTS
> mp = st_multipoint(cbind(runif(100), runif(100)))
> grid.newpage()
> pushViewport(st_viewport(mp))
> grid.draw(st_as_grob(mp, gp = gpar(fill = 'red')))
>
> # LINESTRING
> ls = st_linestring(cbind(1:10, rnorm(10)))
> grid.newpage()
> pushViewport(st_viewport(ls))
> grid.draw(st_as_grob(ls, gp = gpar(fill = 'red')))
>
> # MULTILINESTRING
> ls = st_multilinestring(list(cbind(1:10, 5+rnorm(10)), cbind(1:10, rnorm(10)), cbind(1:10, -5+rnorm(10))))
> grid.newpage()
> pushViewport(st_viewport(ls))
> grid.draw(st_as_grob(ls, gp = gpar(fill = 'red')))
>
> # POINTS, right aspect in Long/Lat:
> meuse_ll = st_transform(meuse_sf, 4326)
> grid.newpage()
> pushViewport(st_viewport(meuse_ll))
> invisible(lapply(st_geometry(meuse_ll),
+ function(x) grid.draw(st_as_grob(x, gp = gpar(fill = 'red')))))
>
> # WRONG aspect:
> st_crs(meuse_ll) = NA
> grid.newpage()
> pushViewport(st_viewport(meuse_ll))
> invisible(lapply(st_geometry(meuse_ll),
+ function(x) grid.draw(st_as_grob(x, gp = gpar(fill = 'red')))))
>
> gc = st_geometrycollection(list(st_point(0:1), st_linestring(matrix(1:4,2))))
> grb = st_as_grob(gc)
>
> proc.time()
user system elapsed
0.620 0.035 0.647
|