R Under development (unstable) (2024-09-06 r87103 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 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: > if (suppressPackageStartupMessages(require(sp, quietly = TRUE))) { + 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'))) > > if (require(sp, quietly = TRUE)) { + # 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.89 0.15 1.04