R Under development (unstable) (2024-11-03 r87286 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. > suppressPackageStartupMessages(library(sf)) > > # create full polygon: > (f = st_as_sfc("POLYGON FULL")) Geometry set for 1 feature Geometry type: POLYGON Dimension: XY Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 CRS: NA POLYGON FULL > g = st_sfc(st_polygon(list(matrix(c(0,-90,0,-90), 2, byrow = TRUE)))) > identical(f, g) [1] TRUE > old = sf_use_s2(FALSE) Spherical geometry (s2) switched off > try(st_as_sfc("POLYGON FULL")) # errors OGR: Corrupt data Error : OGR error > sf_use_s2(old) Spherical geometry (s2) switched on > (f = st_as_sfc(c("POLYGON FULL", "POLYGON((0 0,1 0,1 1,0 1,0 0))"))) Geometry set for 2 features Geometry type: POLYGON Dimension: XY Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 CRS: NA POLYGON FULL POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) > st_is_full(f) [1] TRUE FALSE > st_bbox(f[1]) xmin ymin xmax ymax -180 -90 180 90 > st_bbox(f[2]) xmin ymin xmax ymax 0 0 1 1 > st_is_valid(f) # full polygon NA: right, we don't know the CRS [1] NA TRUE > st_crs(f) = 'OGC:CRS84' # geodetic: > st_is_valid(f) [1] TRUE TRUE > st_crs(f) = NA > try(st_make_valid(f)) Error in (function (msg) : IllegalArgumentException: Invalid number of points in LinearRing found 2 - must be 0 or >= 3 > st_crs(f) = 'OGC:CRS84' # geodetic: > st_make_valid(f) Geometry set for 2 features Geometry type: POLYGON Dimension: XY Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 Geodetic CRS: WGS 84 (CRS84) POLYGON FULL POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) > # mixed geometries: > (f = st_as_sfc(c("POLYGON FULL", "POLYGON((0 0,1 0,1 1,0 1,0 0))", "POINT(3 1)"), crs = 'OGC:CRS84')) Geometry set for 3 features Geometry type: GEOMETRY Dimension: XY Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 Geodetic CRS: WGS 84 (CRS84) POLYGON FULL POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) POINT (3 1) > st_bbox(f[1]) xmin ymin xmax ymax -180 -90 180 90 > st_bbox(f[3]) xmin ymin xmax ymax 3 1 3 1 > st_is_valid(f) [1] TRUE TRUE TRUE > st_make_valid(f) Geometry set for 3 features Geometry type: GEOMETRY Dimension: XY Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 Geodetic CRS: WGS 84 (CRS84) POLYGON FULL POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) POINT (3 1) > st_make_valid(f[2:3]) Geometry set for 2 features Geometry type: GEOMETRY Dimension: XY Bounding box: xmin: 0 ymin: 0 xmax: 3 ymax: 1 Geodetic CRS: WGS 84 (CRS84) POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) POINT (3 1) > > # roundtrip: > sf = st_as_sf(data.frame(attr = 1:3, geom = f[1:3])) > write_sf(sf, fn <- tempfile(fileext=".gpkg")) > g = read_sf(fn) > g Simple feature collection with 3 features and 1 field Geometry type: GEOMETRY Dimension: XY Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 Geodetic CRS: WGS 84 (CRS84) # A tibble: 3 × 2 attr geom 1 1 POLYGON FULL 2 2 POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) 3 3 POINT (3 1) > > st_is_empty(g) [1] FALSE FALSE FALSE > st_is_full(g) [1] TRUE FALSE FALSE > st_is_valid(g) [1] TRUE TRUE TRUE > st_is_simple(g) [1] TRUE TRUE TRUE > st_dimension(g) [1] 2 2 0 > st_area(g) Units: [m^2] [1] 5.100661e+14 1.236404e+10 0.000000e+00 > st_length(g) Units: [m] [1] 0 0 0 > st_distance(g) Units: [m] [,1] [,2] [,3] [1,] 0 0.0 0.0 [2,] 0 0.0 222356.3 [3,] 0 222356.3 0.0 > > proc.time() user system elapsed 1.17 0.14 1.25