1 2R version 4.1.1 (2021-08-10) -- "Kick Things" 3Copyright (C) 2021 The R Foundation for Statistical Computing 4Platform: x86_64-pc-linux-gnu (64-bit) 5 6R is free software and comes with ABSOLUTELY NO WARRANTY. 7You are welcome to redistribute it under certain conditions. 8Type 'license()' or 'licence()' for distribution details. 9 10R is a collaborative project with many contributors. 11Type 'contributors()' for more information and 12'citation()' on how to cite R or R packages in publications. 13 14Type 'demo()' for some demos, 'help()' for on-line help, or 15'help.start()' for an HTML browser interface to help. 16Type 'q()' to quit R. 17 18> suppressPackageStartupMessages(library(sf)) 19> 20> # create empty geometries: 21> st_point(rep(NA_real_,2)) 22POINT EMPTY 23> st_point(rep(NA_real_,3), dim = "XYZ") 24POINT Z EMPTY 25> st_point(rep(NA_real_,3), dim = "XYM") 26POINT M EMPTY 27> st_point(rep(NA_real_,4), dim = "XYZM") 28POINT ZM EMPTY 29> 30> st_multipoint() 31MULTIPOINT EMPTY 32> st_multipoint(matrix(numeric(0), 0, 3), dim = "XYZ") 33MULTIPOINT Z EMPTY 34> st_multipoint(matrix(numeric(0), 0, 3), dim = "XYM") 35MULTIPOINT M EMPTY 36> st_multipoint(matrix(numeric(0), 0, 4), dim = "XYZM") 37MULTIPOINT ZM EMPTY 38> 39> st_linestring(matrix(numeric(0), 0, 2), "XY") 40LINESTRING EMPTY 41> st_linestring(matrix(numeric(0), 0, 3), "XYZ") 42LINESTRING Z EMPTY 43> st_linestring(matrix(numeric(0), 0, 3), "XYM") 44LINESTRING M EMPTY 45> st_linestring(matrix(numeric(0), 0, 4), "XYZM") 46LINESTRING ZM EMPTY 47> 48> st_multilinestring(list(), "XY") 49MULTILINESTRING EMPTY 50> st_multilinestring(list(), "XYZ") 51MULTILINESTRING Z EMPTY 52> st_multilinestring(list(), "XYM") 53MULTILINESTRING M EMPTY 54> st_multilinestring(list(), "XYZM") 55MULTILINESTRING ZM EMPTY 56> 57> st_polygon(list(), "XY") 58POLYGON EMPTY 59> st_polygon(list(), "XYZ") 60POLYGON Z EMPTY 61> st_polygon(list(), "XYM") 62POLYGON M EMPTY 63> st_polygon(list(), "XYZM") 64POLYGON ZM EMPTY 65> 66> st_multipolygon(list(), "XY") 67MULTIPOLYGON EMPTY 68> st_multipolygon(list(), "XYZ") 69MULTIPOLYGON Z EMPTY 70> st_multipolygon(list(), "XYM") 71MULTIPOLYGON M EMPTY 72> st_multipolygon(list(), "XYZM") 73MULTIPOLYGON ZM EMPTY 74> 75> st_geometrycollection() 76GEOMETRYCOLLECTION EMPTY 77> st_geometrycollection(dim = "XYZ") 78GEOMETRYCOLLECTION Z EMPTY 79> st_geometrycollection(dim = "XYM") 80GEOMETRYCOLLECTION M EMPTY 81> st_geometrycollection(dim = "XYZM") 82GEOMETRYCOLLECTION ZM EMPTY 83> 84> st_point(rep(NA_real_,2)) 85POINT EMPTY 86> st_multipoint() 87MULTIPOINT EMPTY 88> st_linestring(matrix(numeric(0), 0, 2)) 89LINESTRING EMPTY 90> st_multilinestring(list(), "XY") 91MULTILINESTRING EMPTY 92> st_polygon(list(), "XY") 93POLYGON EMPTY 94> st_multipolygon(list(), "XY") 95MULTIPOLYGON EMPTY 96> st_geometrycollection(, "XY") 97GEOMETRYCOLLECTION EMPTY 98> 99> (e1 = st_sfc( 100+ st_point(rep(NA_real_,2)), 101+ st_multipoint(), 102+ st_linestring(matrix(numeric(0), 0, 2)), 103+ st_multilinestring(list(), "XY"), 104+ st_polygon(list(), "XY"), 105+ st_multipolygon(list(), "XY"), 106+ st_geometrycollection(, "XY"))) 107Geometry set for 7 features (with 7 geometries empty) 108Geometry type: GEOMETRY 109Dimension: XY 110Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA 111CRS: NA 112First 5 geometries: 113POINT EMPTY 114MULTIPOINT EMPTY 115LINESTRING EMPTY 116MULTILINESTRING EMPTY 117POLYGON EMPTY 118> 119> (e2 = st_sfc(st_point(rep(NA_real_,3), "XYZ"), 120+ st_multipoint(matrix(numeric(0),0,3), dim = "XYZ"), 121+ st_linestring(matrix(numeric(0), 0, 3)), 122+ st_multilinestring(list(), "XYZ"), 123+ st_polygon(list(), "XYZ"), 124+ st_multipolygon(list(), "XYZ"), 125+ st_geometrycollection(dim = "XYZ"))) 126Geometry set for 7 features (with 7 geometries empty) 127Geometry type: GEOMETRY 128Dimension: XYZ 129Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA 130z_range: zmin: NA zmax: NA 131CRS: NA 132First 5 geometries: 133POINT Z EMPTY 134MULTIPOINT Z EMPTY 135LINESTRING Z EMPTY 136MULTILINESTRING Z EMPTY 137POLYGON Z EMPTY 138> 139> (e3 = st_sfc(st_point(rep(NA_real_,3), "XYM"), 140+ st_multipoint(matrix(numeric(0),0,3), dim = "XYM"), 141+ st_linestring(matrix(numeric(0), 0, 3), "XYM"), 142+ st_multilinestring(list(), "XYM"), 143+ st_polygon(list(), "XYM"), 144+ st_multipolygon(list(), "XYM"), 145+ st_geometrycollection(dim = "XYM"))) 146Geometry set for 7 features (with 7 geometries empty) 147Geometry type: GEOMETRY 148Dimension: XYM 149Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA 150m_range: mmin: NA mmax: NA 151CRS: NA 152First 5 geometries: 153POINT M EMPTY 154MULTIPOINT M EMPTY 155LINESTRING M EMPTY 156MULTILINESTRING M EMPTY 157POLYGON M EMPTY 158> 159> (e4 = st_sfc(st_point(rep(NA_real_,4)), 160+ st_multipoint(matrix(numeric(0),0,4), dim = "XYZM"), 161+ st_linestring(matrix(numeric(0), 0, 4)), 162+ st_multilinestring(list(), "XYZM"), 163+ st_polygon(list(), "XYZM"), 164+ st_multipolygon(list(), "XYZM"), 165+ st_geometrycollection(dim = "XYZM"))) 166Geometry set for 7 features (with 7 geometries empty) 167Geometry type: GEOMETRY 168Dimension: XYZM 169Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA 170z_range: zmin: NA zmax: NA 171m_range: mmin: NA mmax: NA 172CRS: NA 173First 5 geometries: 174POINT ZM EMPTY 175MULTIPOINT ZM EMPTY 176LINESTRING ZM EMPTY 177MULTILINESTRING ZM EMPTY 178POLYGON ZM EMPTY 179> 180> st_as_sfc(st_as_binary(e1, pureR = TRUE)) 181Geometry set for 7 features (with 7 geometries empty) 182Geometry type: GEOMETRY 183Dimension: XY 184Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA 185CRS: NA 186First 5 geometries: 187POINT EMPTY 188MULTIPOINT EMPTY 189LINESTRING EMPTY 190MULTILINESTRING EMPTY 191POLYGON EMPTY 192> st_as_sfc(st_as_binary(e1, pureR = FALSE)) 193Geometry set for 7 features (with 7 geometries empty) 194Geometry type: GEOMETRY 195Dimension: XY 196Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA 197CRS: NA 198First 5 geometries: 199POINT EMPTY 200MULTIPOINT EMPTY 201LINESTRING EMPTY 202MULTILINESTRING EMPTY 203POLYGON EMPTY 204> st_as_sfc(st_as_binary(e2, pureR = FALSE)) 205Geometry set for 7 features (with 7 geometries empty) 206Geometry type: GEOMETRY 207Dimension: XYZ 208Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA 209z_range: zmin: NA zmax: NA 210CRS: NA 211First 5 geometries: 212POINT Z EMPTY 213MULTIPOINT Z EMPTY 214LINESTRING Z EMPTY 215MULTILINESTRING Z EMPTY 216POLYGON Z EMPTY 217> st_as_sfc(st_as_binary(e3, pureR = FALSE)) 218Geometry set for 7 features (with 7 geometries empty) 219Geometry type: GEOMETRY 220Dimension: XYM 221Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA 222m_range: mmin: NA mmax: NA 223CRS: NA 224First 5 geometries: 225POINT M EMPTY 226MULTIPOINT M EMPTY 227LINESTRING M EMPTY 228MULTILINESTRING M EMPTY 229POLYGON M EMPTY 230> st_as_sfc(st_as_binary(e4, pureR = FALSE)) 231Geometry set for 7 features (with 7 geometries empty) 232Geometry type: GEOMETRY 233Dimension: XYZM 234Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA 235z_range: zmin: NA zmax: NA 236m_range: mmin: NA mmax: NA 237CRS: NA 238First 5 geometries: 239POINT ZM EMPTY 240MULTIPOINT ZM EMPTY 241LINESTRING ZM EMPTY 242MULTILINESTRING ZM EMPTY 243POLYGON ZM EMPTY 244> st_as_sfc(st_as_binary(e1, pureR = FALSE)) 245Geometry set for 7 features (with 7 geometries empty) 246Geometry type: GEOMETRY 247Dimension: XY 248Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA 249CRS: NA 250First 5 geometries: 251POINT EMPTY 252MULTIPOINT EMPTY 253LINESTRING EMPTY 254MULTILINESTRING EMPTY 255POLYGON EMPTY 256> 257> # sfc_GEOMETRY: 258> x = st_sfc(st_point(0:1), st_linestring(matrix(1:4,2,2))) 259> st_intersects(x, x, sparse = FALSE) 260 [,1] [,2] 261[1,] TRUE FALSE 262[2,] FALSE TRUE 263> 264> # two empty geoms: 265> x = st_sfc(st_multipoint(), st_linestring()) 266> st_intersects(x, x, sparse = FALSE) 267 [,1] [,2] 268[1,] FALSE FALSE 269[2,] FALSE FALSE 270> 271> # write & read: 272> x = st_sf(a = 2:1, geom = structure(st_sfc(st_linestring(), st_linestring(matrix(1:4,2))))) 273> write_sf(x, "empty.gpkg") 274writing GPKG: substituting LOCAL_CS["Undefined Cartesian SRS"] for missing CRS 275> y = st_read("empty.gpkg", quiet = TRUE) 276> all.equal(x, y) 277[1] "Component \"geom\": Attributes: < Component \"crs\": Component \"input\": 'is.NA' value mismatch: 0 in current 1 in target >" 278[2] "Component \"geom\": Attributes: < Component \"crs\": Component \"wkt\": 'is.NA' value mismatch: 0 in current 1 in target >" 279> 280> # https://github.com/edzer/sfr/issues/398 : 281> pt = st_sfc(st_point(c(0,92)), crs = 4267) 282> robin_crs <- "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs" 283> # india_crs <- "+init=epsg:24383" # India-centered Lambert conformal conic projection 284> india_crs <- "+proj=lcc +lat_1=12 +lat_0=12 +lon_0=80 +k_0=0.99878641 +x_0=2743195.5 +y_0=914398.5 +a=6377299.151 +b=6356098.145120132 +towgs84=295,736,257,0,0,0,0 +units=m +no_defs" 285> st_transform(st_transform(pt, robin_crs), india_crs)[[1]] 286POINT EMPTY 287> 288> proc.time() 289 user system elapsed 290 0.656 0.039 0.697 291