diff --git a/articles/sf7.html b/articles/sf7.html index 1849caeed..96a10360c 100644 --- a/articles/sf7.html +++ b/articles/sf7.html @@ -489,14 +489,14 @@

Buffers uk_buffer_sf = st_buffer(uk_projected, dist = 20000) }) ## user system elapsed -## 0.022 0.000 0.022 +## 0.023 0.000 0.022 # sf way with few than the 30 segments in the buffer system.time({ uk_projected = st_transform(uk_sfc, 27700) uk_buffer_sf2 = st_buffer(uk_projected, dist = 20000, nQuadSegs = 4) }) ## user system elapsed -## 0.008 0.000 0.008 +## 0.009 0.000 0.008 # s2 with default cell size system.time({ uk_buffer = s2_buffer_cells(uk, distance = 20000) @@ -514,7 +514,7 @@

Buffers uk_buffer2 = s2_buffer_cells(uk, distance = 20000, max_cells = 100) }) ## user system elapsed -## 0.004 0.000 0.004 +## 0.003 0.000 0.003

The result of the previous benchmarks emphasizes the point that there are trade-offs between geographic resolution and computational resources, something that web developers working on geographic services diff --git a/pkgdown.yml b/pkgdown.yml index 9a4d082b6..965ccb7c0 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -9,7 +9,7 @@ articles: sf5: sf5.html sf6: sf6.html sf7: sf7.html -last_built: 2024-11-03T19:49Z +last_built: 2024-11-03T19:54Z urls: reference: https://r-spatial.github.io/sf/reference article: https://r-spatial.github.io/sf/articles diff --git a/reference/gdal_utils.html b/reference/gdal_utils.html index 843052068..a11379a8d 100644 --- a/reference/gdal_utils.html +++ b/reference/gdal_utils.html @@ -219,7 +219,7 @@

Examples#> Band 1 Block=20x20 Type=Byte, ColorInterp=Gray #> Computed Min/Max=74.000,255.000 #> Reading layer `storms_xyz' from data source -#> `/tmp/RtmpPF9T6H/file1d5f5075b0a8.gpkg' using driver `GPKG' +#> `/tmp/RtmpokzaW8/file1d2f48fe6ba9.gpkg' using driver `GPKG' #> Simple feature collection with 71 features and 0 fields #> Geometry type: LINESTRING #> Dimension: XYZ diff --git a/reference/st_write.html b/reference/st_write.html index 0bee4d8ea..2b12f9ff9 100644 --- a/reference/st_write.html +++ b/reference/st_write.html @@ -201,12 +201,12 @@

Examples#> Geodetic CRS: NAD27 st_write(nc, paste0(tempdir(), "/", "nc.shp")) #> Writing layer `nc' to data source -#> `/tmp/RtmpPF9T6H/nc.shp' using driver `ESRI Shapefile' +#> `/tmp/RtmpokzaW8/nc.shp' using driver `ESRI Shapefile' #> Writing 100 features with 14 fields and geometry type Multi Polygon. st_write(nc, paste0(tempdir(), "/", "nc.shp"), delete_layer = TRUE) # overwrites #> Deleting layer `nc' using driver `ESRI Shapefile' #> Writing layer `nc' to data source -#> `/tmp/RtmpPF9T6H/nc.shp' using driver `ESRI Shapefile' +#> `/tmp/RtmpokzaW8/nc.shp' using driver `ESRI Shapefile' #> Writing 100 features with 14 fields and geometry type Multi Polygon. if (require(sp, quietly = TRUE)) { data(meuse, package = "sp") # loads data.frame from sp @@ -224,11 +224,11 @@

Examples try(st_write(nc, "PG:dbname=postgis", "sids", layer_options = "OVERWRITE=true")) } # } } -#> Writing layer `meuse' to data source `/tmp/RtmpPF9T6H/meuse.csv' using driver `CSV' +#> Writing layer `meuse' to data source `/tmp/RtmpokzaW8/meuse.csv' using driver `CSV' #> options: GEOMETRY=AS_XY #> Writing 155 features with 12 fields and geometry type Point. -#> Deleting source `/tmp/RtmpPF9T6H/meuse.csv' using driver `CSV' -#> Writing layer `meuse' to data source `/tmp/RtmpPF9T6H/meuse.csv' using driver `CSV' +#> Deleting source `/tmp/RtmpokzaW8/meuse.csv' using driver `CSV' +#> Writing layer `meuse' to data source `/tmp/RtmpokzaW8/meuse.csv' using driver `CSV' #> options: GEOMETRY=AS_WKT #> Writing 155 features with 12 fields and geometry type Point. diff --git a/search.json b/search.json index 92ace3a06..359c95d8d 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"path":"https://r-spatial.github.io/sf/CONDUCT.html","id":null,"dir":"","previous_headings":"","what":"Contributor Code of Conduct","title":"Contributor Code of Conduct","text":"contributors maintainers project, pledge respect people contribute reporting issues, posting feature requests, updating documentation, submitting pull requests patches, activities. committed making participation project harassment-free experience everyone, regardless level experience, gender, gender identity expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion. Examples unacceptable behavior participants include use sexual language imagery, derogatory comments personal attacks, trolling, public private harassment, insults, unprofessional conduct. Project maintainers right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct. Project maintainers follow Code Conduct may removed project team. Instances abusive, harassing, otherwise unacceptable behavior may reported opening issue contacting one project maintainers. Code Conduct adapted Contributor Covenant (http:contributor-covenant.org), version 1.0.0, available http://contributor-covenant.org/version/1/0/0/","code":""},{"path":"https://r-spatial.github.io/sf/PROPOSAL.html","id":null,"dir":"","previous_headings":"","what":"Simple Features for R","title":"Simple Features for R","text":"Applicant: Edzer Pebesma, Institute Geoinformatics, University Muenster, Germany; edzer.pebesma@uni-muenster.de Supporting authors: Edzer Pebesma, Roger Bivand, Michael Sumner, Robert Hijmans, Virgilio Gómez-Rubio Simple features open (OGC ISO) interface standard access manipulation spatial vector data (points, lines, polygons). includes standard SQL schema supports storage, retrieval, query update feature collections via SQL interface. commonly used databases provide interface. GeoJSON standard encoding simple features JSON, used JavaScript MongoDB. Well-known-text (WKT) text representation simple features used often linked data; well-known-binary ([WKB] (https://en.wikipedia.org/wiki/Well-known_text)) standard binary representation used databases. Simple Feature Access defines coordinate reference systems, makes easy move data longitude-latitude projections back forth standardized way. GDAL open source C++ library reading writing raster vector data 225 drivers (supported file formats, data base connectors, web service interfaces). GDAL used practically open source geospatial projects many industry products (including ESRI’s ArcGIS, ERDAS, FME). provides coordinate transformations (built top PROJ.4) geometric operations (e.g. polygon intersections, unions, buffers distance). Standards coordinate transformations change time; changes typically adopted directly GDAL/PROJ.4 easily find way R-packages mapproj. Since 2005, CRAN package sp provides classes methods spatial (point, line, polygon raster) data. approach sp takes similar xts zoo handle time index time series data: objects store spatial geometries separately associated attribute data, matching order. Package spacetime, CRAN since 2010, extends sp xts handle data varies space time. Today, 221 CRAN packages depend , import link sp, 259 including Suggests; including recursive dependencies numbers 376 5040. implementation sp follow simple features, rather practice used time release, following ESRI shapefiles implemented. cluster packages around sp shown Andrie de Vries’ blog CRAN’s network structure green. -CRAN package rgdal2 interface GDAL 2.0, uses raw pointers interface features, import data R, using GDAL handle everything. CRAN Package wkb, contributed Tibco Software, converts WKB representations several simple feature classes corresponding classes sp, seems needed Tibco software purposes.","code":""},{"path":"https://r-spatial.github.io/sf/PROPOSAL.html","id":"the-problem","dir":"","previous_headings":"","what":"The problem","title":"Simple Features for R","text":"problems solve : R can currently represent simple features directly. can read simple feature classes sp classes, uses representation , can write data back without loss information furnished ancilliary metadata encoded comment attribute Polygons object. instance internally distinguish POLYGON MULTIPOLYGON deal several simple feature classes, including TIN GEOMETRYCOLLECTION, handle CURVE geometries. current implementation lines vector data package sp partly ambiguous (slot ringDir slot hole indicate whether Polygon hole superceded comment attribute), complicated (exterior polygon hole belong - handled comment attribute), considered difficult work (S4). current implementation hard maintain contains incremental changes baseline predated industry-standard OGC/ISO (Simple Feature Interface Specification). lack support simple features makes current interfaces open source libraries (GDAL/OGR PROJ.4: rgdal, GEOS: rgeos) difficult understand maintain, even though work specification. current implementation scale model coordinates. desirable R packages offered opportunity migrate --date libraries coordinate transformations (providing proper support datum transformation), avoid make simplifying assumptions (e.g., spatial data come longitude/latitude using datum WGS84; web maps use web Mercator). users benefit solving problems? mainly affect use data bases modern javascript-based web APIs largely converged adopting simple features (CartoDB), well need simpler light-weight handling spatial data R. also reduce effort users developers understand way spatial information represented R, making easier build upon reuse R code , lead good, sustainable shared R code base. longer run affect users packages currently reusing sp classes, manage migrate sp exclusively use simple feature classes representing vector data. Since recent 2.0 release GDAL integrates raster vector data, R package mirrors classes makes possible implement operations -database (similar DBI, RPostgreSQL dplyr ), making possible R manipulate spatial data fit memory. Big Data analysis R often proceeds connecting R database holds data. commonly used commercial open source databases store spatial point, line polygon data form simple features. Representing simple features R simplify big data analysis spatial data.","code":""},{"path":"https://r-spatial.github.io/sf/PROPOSAL.html","id":"the-plan","dir":"","previous_headings":"","what":"The plan","title":"Simple Features for R","text":"want solve problem carrying following steps (M1 refers month 1): develop R package implements simple features R, simple yet gives users access complete data, includes S3 representation extends data.frame (M1-3) add package C++ interface GDAL 2.0, read write simple feature data, interface functionality (coordinate transformation, geometry operations) (M3-8) develop prototypically implement migration path sp become compliant simple features (M7-12) write user-oriented tutorial vignettes showing use files, data base connections, web API’s, leaflet, ggmap, dplyr (M7-10) write tutorial vignette R package writers reusing package (M10) Collect process community feed back (M6-12). Failure modes recovery plan: Failure mode: S3 classes simple represent simple features class hierarchy. Recovery plan: try () using list column geometry, nested lists represent nested structures; (ii) use WKT character column; (iii) using WKB blob column Migrating sp breaks downstream packages. Recovery plan: involve Roger Bivand, Barry Rowlingson, Robert Hijmans (raster) Tim Keitt (rgdal/rgdal2) proceed; patient smooth problems together package maintainers.","code":""},{"path":"https://r-spatial.github.io/sf/PROPOSAL.html","id":"how-can-the-isc-help","dir":"","previous_headings":"","what":"How can the ISC help","title":"Simple Features for R","text":"following table contains cost items. visit Roger anticipated halfway project; communications use skype. project planned duration 12 months.","code":""},{"path":"https://r-spatial.github.io/sf/PROPOSAL.html","id":"dissemination","dir":"","previous_headings":"","what":"Dissemination","title":"Simple Features for R","text":"Development take place github, information shared reactions contributions invited r-sig-geo, well StackOverflow GIS StackExchange. project use Apache 2.0 license maximum dissemination (similar GDAL, uses X/MIT). work published 4 blogs (quarterly), announced r-sig-geo (3300 subscribers), intermediary results presented UseR! 2016. final result published paper either submitted R Journal Journal Statistical Software; paper available publication package vignette.","code":""},{"path":"https://r-spatial.github.io/sf/PROPOSAL.html","id":"user-slides","dir":"","previous_headings":"","what":"UseR! slides","title":"Simple Features for R","text":"UseR! 2016 slides found .","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"what-is-a-feature","dir":"Articles","previous_headings":"","what":"What is a feature?","title":"1. Simple Features for R","text":"feature thought thing, object real world, building tree. case objects, often consist objects. case features : set features can form single feature. forest stand can feature, forest can feature, city can feature. satellite image pixel can feature, complete image can feature . Features geometry describing Earth feature located, attributes, describe properties. geometry tree can delineation crown, stem, point indicating centre. properties may include height, color, diameter breast height particular date, . standard says: “simple feature defined OpenGIS Abstract specification spatial non-spatial attributes. Spatial attributes geometry valued, simple features based 2D geometry linear interpolation vertices.” see soon standard extend coverage beyond 2D beyond linear interpolation. , take simple features data structures operations described standard.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"dimensions","dir":"Articles","previous_headings":"What is a feature?","what":"Dimensions","title":"1. Simple Features for R","text":"geometries composed points. Points coordinates 2-, 3- 4-dimensional space. points geometry dimensionality. addition X Y coordinates, two optional additional dimensions: Z coordinate, denoting altitude M coordinate (rarely used), denoting measure associated point, rather feature whole (case feature attribute); examples time measurement, measurement error coordinates four possible cases : two-dimensional points refer x y, easting northing, longitude latitude, refer XY three-dimensional points XYZ three-dimensional points XYM four-dimensional points XYZM (third axis Z, fourth M)","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"simple-feature-geometry-types","dir":"Articles","previous_headings":"What is a feature?","what":"Simple feature geometry types","title":"1. Simple Features for R","text":"following seven simple feature types common, instance ones used GeoJSON: geometry types can also (typed) empty set, containing zero coordinates (POINT standard clear represent empty geometry). Empty geometries can thought analogue missing (NA) attributes, NULL values empty lists. remaining geometries 10 rarer, increasingly find implementations: Note CIRCULASTRING, COMPOUNDCURVE CURVEPOLYGON described SFA standard, SQL-MM part 3 standard. descriptions copied PostGIS manual.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"coordinate-reference-system","dir":"Articles","previous_headings":"What is a feature?","what":"Coordinate reference system","title":"1. Simple Features for R","text":"Coordinates can placed Earth’s surface coordinate reference system (CRS) known; may spheroid CRS WGS84, projected, two-dimensional (Cartesian) CRS UTM zone Web Mercator, CRS three-dimensions, including time. Similarly, M-coordinates need attribute reference system, e.g. measurement unit.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"how-simple-features-in-r-are-organized","dir":"Articles","previous_headings":"","what":"How simple features in R are organized","title":"1. Simple Features for R","text":"Package sf represents simple features native R objects. Similar PostGIS, functions methods sf operate spatial data prefixed st_, refers spatial type; makes easily findable command-line completion. Simple features implemented R native data, using simple data structures (S3 classes, lists, matrix, vector). Typical use involves reading, manipulating writing sets features, attributes geometries. attributes typically stored data.frame objects (similar tbl_df), also store feature geometries data.frame column. Since geometries single-valued, put list-column, list length equal number records data.frame, list element holding simple feature geometry feature. three classes used represent simple features : sf, table (data.frame) feature attributes feature geometries, contains sfc, list-column geometries feature (record), composed sfg, feature geometry individual simple feature. now discuss three classes.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"sf-objects-with-simple-features","dir":"Articles","previous_headings":"How simple features in R are organized","what":"sf: objects with simple features","title":"1. Simple Features for R","text":"usually work geometries single simple features, datasets consisting sets features attributes, two put together sf (simple feature) objects. following command reads nc dataset file contained sf package: (Note users use system.file() give filename directly, shapefiles consist one file, identical basename, reside directory.) short report printed gives file name, driver (ESRI Shapefile), mentions 100 features (records, represented rows) 14 fields (attributes, represented columns). object class meaning extends (“” ) data.frame, single list-column geometries, held column name print first three features, see attribute values abridged version geometry give following output: output see: green simple feature: single record, data.frame row, consisting attributes geometry blue single simple feature geometry (object class sfg) red simple feature list-column (object class sfc, column data.frame) although geometries native R objects, printed well-known text Methods sf objects : also possible create data.frame objects geometry list-columns class sf, e.g. : However, objects: longer register column geometry list-column longer plot method, lack dedicated methods listed class sf","code":"library(sf) ## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE nc <- st_read(system.file(\"shape/nc.shp\", package=\"sf\")) ## Reading layer `nc' from data source ## `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' ## Simple feature collection with 100 features and 14 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 ## Geodetic CRS: NAD27 class(nc) ## [1] \"sf\" \"data.frame\" attr(nc, \"sf_column\") ## [1] \"geometry\" print(nc[9:15], n = 3) methods(class = \"sf\") ## [1] [ [[<- ## [3] [<- $<- ## [5] aggregate as.data.frame ## [7] cbind coerce ## [9] dbDataType dbWriteTable ## [11] duplicated identify ## [13] initialize merge ## [15] plot points ## [17] print rbind ## [19] show slotsFromS3 ## [21] st_agr st_agr<- ## [23] st_area st_as_s2 ## [25] st_as_sf st_as_sfc ## [27] st_bbox st_boundary ## [29] st_break_antimeridian st_buffer ## [31] st_cast st_centroid ## [33] st_collection_extract st_concave_hull ## [35] st_convex_hull st_coordinates ## [37] st_crop st_crs ## [39] st_crs<- st_difference ## [41] st_drop_geometry st_exterior_ring ## [43] st_filter st_geometry ## [45] st_geometry<- st_inscribed_circle ## [47] st_interpolate_aw st_intersection ## [49] st_intersects st_is_full ## [51] st_is_valid st_is ## [53] st_join st_line_merge ## [55] st_m_range st_make_valid ## [57] st_minimum_rotated_rectangle st_nearest_points ## [59] st_node st_normalize ## [61] st_point_on_surface st_polygonize ## [63] st_precision st_reverse ## [65] st_sample st_segmentize ## [67] st_set_precision st_shift_longitude ## [69] st_simplify st_snap ## [71] st_sym_difference st_transform ## [73] st_triangulate_constrained st_triangulate ## [75] st_union st_voronoi ## [77] st_wrap_dateline st_write ## [79] st_z_range st_zm ## [81] text transform ## see '?methods' for accessing help and source code nc.no_sf <- as.data.frame(nc) class(nc.no_sf) ## [1] \"data.frame\""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"sfc-simple-feature-geometry-list-column","dir":"Articles","previous_headings":"How simple features in R are organized","what":"sfc: simple feature geometry list-column","title":"1. Simple Features for R","text":"column sf data.frame contains geometries list, class sfc. can retrieve geometry list-column case nc$geom nc[[15]], general way uses st_geometry(): Geometries printed abbreviated form, can view complete geometry selecting , e.g. first one : way printed called well-known text, part standards. word MULTIPOLYGON followed three parentheses, can consist multiple polygons, form MULTIPOLYGON(POL1,POL2), POL1 might consist exterior ring zero interior rings, (EXT1,HOLE1,HOLE2). Sets coordinates belonging single polygon held together parentheses, get ((crds_ext)(crds_hole1)(crds_hole2)) crds_ comma-separated set coordinates ring. leads case , MULTIPOLYGON(((crds_ext))) refers exterior ring (1), without holes (2), first polygon (3) - hence three parentheses. can see single polygon rings: polygons dataset multiple exterior rings; can identified : Following MULTIPOLYGON datastructure, R list lists lists matrices. instance, get first 3 coordinate pairs second exterior ring (first ring always exterior) geometry feature 4 : Geometry columns class, Methods geometry list-columns include: Coordinate reference systems (st_crs() st_transform()) discussed section coordinate reference systems. st_as_wkb() st_as_text() convert geometry list-columns well-known-binary well-known-text, explained . st_bbox() retrieves coordinate bounding box. Attributes include:","code":"(nc_geom <- st_geometry(nc)) ## Geometry set for 100 features ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 ## Geodetic CRS: NAD27 ## First 5 geometries: ## MULTIPOLYGON (((-81.47276 36.23436, -81.54084 3... ## MULTIPOLYGON (((-81.23989 36.36536, -81.24069 3... ## MULTIPOLYGON (((-80.45634 36.24256, -80.47639 3... ## MULTIPOLYGON (((-76.00897 36.3196, -76.01735 36... ## MULTIPOLYGON (((-77.21767 36.24098, -77.23461 3... nc_geom[[1]] ## MULTIPOLYGON (((-81.47276 36.23436, -81.54084 36.27251, -81.56198 36.27359, -81.63306 36.34069, -81.74107 36.39178, -81.69828 36.47178, -81.7028 36.51934, -81.67 36.58965, -81.3453 36.57286, -81.34754 36.53791, -81.32478 36.51368, -81.31332 36.4807, -81.26624 36.43721, -81.26284 36.40504, -81.24069 36.37942, -81.23989 36.36536, -81.26424 36.35241, -81.32899 36.3635, -81.36137 36.35316, -81.36569 36.33905, -81.35413 36.29972, -81.36745 36.2787, -81.40639 36.28505, -81.41233 36.26729, -81.43104 36.26072, -81.45289 36.23959, -81.47276 36.23436))) par(mar = c(0,0,1,0)) plot(nc[1], reset = FALSE) # reset = FALSE: we want to add to a plot with a legend plot(nc[1,1], col = 'grey', add = TRUE) par(mar = c(0,0,1,0)) (w <- which(sapply(nc_geom, length) > 1)) ## [1] 4 56 57 87 91 95 plot(nc[w,1], col = 2:7) nc_geom[[4]][[2]][[1]][1:3,] ## [,1] [,2] ## [1,] -76.02717 36.55672 ## [2,] -75.99866 36.55665 ## [3,] -75.91192 36.54253 class(nc_geom) ## [1] \"sfc_MULTIPOLYGON\" \"sfc\" methods(class = 'sfc') ## [1] [ [<- ## [3] as.data.frame c ## [5] coerce format ## [7] identify initialize ## [9] Ops points ## [11] print rep ## [13] show slotsFromS3 ## [15] st_area st_as_binary ## [17] st_as_grob st_as_s2 ## [19] st_as_sf st_as_text ## [21] st_bbox st_boundary ## [23] st_break_antimeridian st_buffer ## [25] st_cast st_centroid ## [27] st_collection_extract st_concave_hull ## [29] st_convex_hull st_coordinates ## [31] st_crop st_crs ## [33] st_crs<- st_difference ## [35] st_exterior_ring st_geometry ## [37] st_inscribed_circle st_intersection ## [39] st_intersects st_is_full ## [41] st_is_valid st_is ## [43] st_line_merge st_m_range ## [45] st_make_valid st_minimum_rotated_rectangle ## [47] st_nearest_points st_node ## [49] st_normalize st_point_on_surface ## [51] st_polygonize st_precision ## [53] st_reverse st_sample ## [55] st_segmentize st_set_precision ## [57] st_shift_longitude st_simplify ## [59] st_snap st_sym_difference ## [61] st_transform st_triangulate_constrained ## [63] st_triangulate st_union ## [65] st_voronoi st_wrap_dateline ## [67] st_write st_z_range ## [69] st_zm str ## [71] summary text ## [73] vec_cast.sfc vec_ptype2.sfc ## see '?methods' for accessing help and source code attributes(nc_geom) ## $n_empty ## [1] 0 ## ## $crs ## Coordinate Reference System: ## User input: NAD27 ## wkt: ## GEOGCRS[\"NAD27\", ## DATUM[\"North American Datum 1927\", ## ELLIPSOID[\"Clarke 1866\",6378206.4,294.978698213898, ## LENGTHUNIT[\"metre\",1]]], ## PRIMEM[\"Greenwich\",0, ## ANGLEUNIT[\"degree\",0.0174532925199433]], ## CS[ellipsoidal,2], ## AXIS[\"latitude\",north, ## ORDER[1], ## ANGLEUNIT[\"degree\",0.0174532925199433]], ## AXIS[\"longitude\",east, ## ORDER[2], ## ANGLEUNIT[\"degree\",0.0174532925199433]], ## ID[\"EPSG\",4267]] ## ## $class ## [1] \"sfc_MULTIPOLYGON\" \"sfc\" ## ## $precision ## [1] 0 ## ## $bbox ## xmin ymin xmax ymax ## -84.32385 33.88199 -75.45698 36.58965"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"mixed-geometry-types","dir":"Articles","previous_headings":"How simple features in R are organized","what":"Mixed geometry types","title":"1. Simple Features for R","text":"class nc_geom c(\"sfc_MULTIPOLYGON\", \"sfc\"): sfc shared geometry types, sfc_TYPE TYPE indicating type particular geometry hand. two “special” types: GEOMETRYCOLLECTION, GEOMETRY. GEOMETRYCOLLECTION indicates geometries may contain mix geometry types, Still, geometries single type. second GEOMETRY, indicates geometries geometry list-column varying type: two fundamentally different: GEOMETRY superclass without instances, GEOMETRYCOLLECTION geometry instance. GEOMETRY list-columns occur read data source mix geometry types. GEOMETRYCOLLECTION single feature’s geometry: intersection two feature polygons may consist points, lines polygons, see example .","code":"(mix <- st_sfc(st_geometrycollection(list(st_point(1:2))), st_geometrycollection(list(st_linestring(matrix(1:4,2)))))) ## Geometry set for 2 features ## Geometry type: GEOMETRYCOLLECTION ## Dimension: XY ## Bounding box: xmin: 1 ymin: 2 xmax: 2 ymax: 4 ## CRS: NA ## GEOMETRYCOLLECTION (POINT (1 2)) ## GEOMETRYCOLLECTION (LINESTRING (1 3, 2 4)) class(mix) ## [1] \"sfc_GEOMETRYCOLLECTION\" \"sfc\" (mix <- st_sfc(st_point(1:2), st_linestring(matrix(1:4,2)))) ## Geometry set for 2 features ## Geometry type: GEOMETRY ## Dimension: XY ## Bounding box: xmin: 1 ymin: 2 xmax: 2 ymax: 4 ## CRS: NA ## POINT (1 2) ## LINESTRING (1 3, 2 4) class(mix) ## [1] \"sfc_GEOMETRY\" \"sfc\""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"sfg-simple-feature-geometry","dir":"Articles","previous_headings":"How simple features in R are organized","what":"sfg: simple feature geometry","title":"1. Simple Features for R","text":"Simple feature geometry (sfg) objects carry geometry single feature, e.g. point, linestring polygon. Simple feature geometries implemented R native data, using following rules single POINT numeric vector set points, e.g. LINESTRING ring POLYGON matrix, row containing point set list Creator functions rarely used practice, since typically bulk read write spatial data. useful illustration: means can represent 2-, 3- 4-dimensional coordinates. geometry objects inherit sfg (simple feature geometry), also type (e.g. POINT), dimension (e.g. XYM) class name. figure illustrates six seven common types. exception POINT single point geometry, remaining six common single simple feature geometry types correspond single features (single records, rows data.frame) created like objects created shown : Geometries can also empty, ","code":"(x <- st_point(c(1,2))) ## POINT (1 2) str(x) ## 'XY' num [1:2] 1 2 (x <- st_point(c(1,2,3))) ## POINT Z (1 2 3) str(x) ## 'XYZ' num [1:3] 1 2 3 (x <- st_point(c(1,2,3), \"XYM\")) ## POINT M (1 2 3) str(x) ## 'XYM' num [1:3] 1 2 3 (x <- st_point(c(1,2,3,4))) ## POINT ZM (1 2 3 4) str(x) ## 'XYZM' num [1:4] 1 2 3 4 st_zm(x, drop = TRUE, what = \"ZM\") ## POINT (1 2) p <- rbind(c(3.2,4), c(3,4.6), c(3.8,4.4), c(3.5,3.8), c(3.4,3.6), c(3.9,4.5)) (mp <- st_multipoint(p)) ## MULTIPOINT ((3.2 4), (3 4.6), (3.8 4.4), (3.5 3.8), (3.4 3.6), (3.9 4.5)) s1 <- rbind(c(0,3),c(0,4),c(1,5),c(2,5)) (ls <- st_linestring(s1)) ## LINESTRING (0 3, 0 4, 1 5, 2 5) s2 <- rbind(c(0.2,3), c(0.2,4), c(1,4.8), c(2,4.8)) s3 <- rbind(c(0,4.4), c(0.6,5)) (mls <- st_multilinestring(list(s1,s2,s3))) ## MULTILINESTRING ((0 3, 0 4, 1 5, 2 5), (0.2 3, 0.2 4, 1 4.8, 2 4.8), (0 4.4, 0.6 5)) p1 <- rbind(c(0,0), c(1,0), c(3,2), c(2,4), c(1,4), c(0,0)) p2 <- rbind(c(1,1), c(1,2), c(2,2), c(1,1)) pol <-st_polygon(list(p1,p2)) p3 <- rbind(c(3,0), c(4,0), c(4,1), c(3,1), c(3,0)) p4 <- rbind(c(3.3,0.3), c(3.8,0.3), c(3.8,0.8), c(3.3,0.8), c(3.3,0.3))[5:1,] p5 <- rbind(c(3,3), c(4,2), c(4,3), c(3,3)) (mpol <- st_multipolygon(list(list(p1,p2), list(p3,p4), list(p5)))) ## MULTIPOLYGON (((0 0, 1 0, 3 2, 2 4, 1 4, 0 0), (1 1, 1 2, 2 2, 1 1)), ((3 0, 4 0, 4 1, 3 1, 3 0), (3.3 0.3, 3.3 0.8, 3.8 0.8, 3.8 0.3, 3.3 0.3)), ((3 3, 4 2, 4 3, 3 3))) (gc <- st_geometrycollection(list(mp, mpol, ls))) ## GEOMETRYCOLLECTION (MULTIPOINT ((3.2 4), (3 4.6), (3.8 4.4), (3.5 3.8), (3.4 3.6), (3.9 4.5)), MULTIPOLYGON (((0 0, 1 0, 3 2, 2 4, 1 4, 0 0), (1 1, 1 2, 2 2, 1 1)), ((3 0, 4 0, 4 1, 3 1, 3 0), (3.3 0.3, 3.3 0.8, 3.8 0.8, 3.8 0.3, 3.3 0.3)), ((3 3, 4 2, 4 3, 3 3))), LINESTRING (0 3, 0 4, 1 5, 2 5)) (x <- st_geometrycollection()) ## GEOMETRYCOLLECTION EMPTY length(x) ## [1] 0"},{"path":[]},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"wkt-and-wkb","dir":"Articles","previous_headings":"How simple features in R are organized > Well-known text, well-known binary, precision","what":"WKT and WKB","title":"1. Simple Features for R","text":"Well-known text (WKT) well-known binary (WKB) two encodings simple feature geometries. Well-known text, e.g. seen (without leading ## [1] quotes), human-readable. Coordinates usually floating point numbers, moving large amounts information text slow imprecise. reason, use well-known binary (WKB) encoding WKT WKB can transformed back R native objects GDAL, GEOS, spatial databases GIS read write WKB fast precise. Conversion R native objects WKB done package sf compiled (C++/Rcpp) code, making reusable fast route /O simple feature geometries R.","code":"x <- st_linestring(matrix(10:1,5)) st_as_text(x) ## [1] \"LINESTRING (10 5, 9 4, 8 3, 7 2, 6 1)\" st_as_binary(x) ## [1] 01 02 00 00 00 05 00 00 00 00 00 00 00 00 00 24 40 00 00 00 00 00 00 14 40 ## [26] 00 00 00 00 00 00 22 40 00 00 00 00 00 00 10 40 00 00 00 00 00 00 20 40 00 ## [51] 00 00 00 00 00 08 40 00 00 00 00 00 00 1c 40 00 00 00 00 00 00 00 40 00 00 ## [76] 00 00 00 00 18 40 00 00 00 00 00 00 f0 3f st_as_sfc(\"LINESTRING(10 5, 9 4, 8 3, 7 2, 6 1)\")[[1]] ## LINESTRING (10 5, 9 4, 8 3, 7 2, 6 1) st_as_sfc(structure(list(st_as_binary(x)), class = \"WKB\"))[[1]] ## LINESTRING (10 5, 9 4, 8 3, 7 2, 6 1)"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"precision","dir":"Articles","previous_headings":"How simple features in R are organized > Well-known text, well-known binary, precision","what":"Precision","title":"1. Simple Features for R","text":"One attributes geometry list-column (sfc) precision: double number , non-zero, causes rounding conversion WKB, might help certain geometrical operations succeed otherwise fail due floating point representation. model GEOS, copies Java Topology Suite (JTS), works like : precision zero (default, unspecified), nothing modified negative values convert float (4-byte real) precision positive values convert round(x*precision)/precision. precision model, see also , written : “… specify 3 decimal places precision, use scale factor 1000. specify -3 decimal places precision (.e. rounding nearest 1000), use scale factor 0.001.” Note coordinates, also Z M values (present) affected. Choosing values precision may require experimenting.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"reading-and-writing","dir":"Articles","previous_headings":"How simple features in R are organized","what":"Reading and writing","title":"1. Simple Features for R","text":"’ve seen , reading spatial data external file can done : can suppress output adding argument quiet=TRUE using otherwise nearly identical quiet Writing takes place fashion, using st_write(): repeat , get error message file already exists, can overwrite : quiet alternative default,","code":"filename <- system.file(\"shape/nc.shp\", package=\"sf\") nc <- st_read(filename) ## Reading layer `nc' from data source ## `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' ## Simple feature collection with 100 features and 14 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 ## Geodetic CRS: NAD27 nc <- read_sf(filename) st_write(nc, \"nc.shp\") ## Writing layer `nc' to data source `nc.shp' using driver `ESRI Shapefile' ## Writing 100 features with 14 fields and geometry type Multi Polygon. st_write(nc, \"nc.shp\", delete_layer = TRUE) ## Deleting layer `nc' using driver `ESRI Shapefile' ## Writing layer `nc' to data source `nc.shp' using driver `ESRI Shapefile' ## Writing 100 features with 14 fields and geometry type Multi Polygon. write_sf(nc, \"nc.shp\") # silently overwrites"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"driver-specific-options","dir":"Articles","previous_headings":"How simple features in R are organized > Reading and writing","what":"Driver-specific options","title":"1. Simple Features for R","text":"dsn layer arguments st_read() st_write() denote data source name optionally layer name. exact interpretation well options support vary per driver, GDAL driver documentation best consulted . instance, PostGIS table database postgis might read : PG: string indicates concerns PostGIS driver, followed database name, possibly port user credentials. layer driver arguments specified, st_read() tries guess datasource, else simply reads first layer, giving warning case . st_read() typically reads coordinate reference system proj4string, EPSG (SRID). GDAL retrieve SRID (EPSG code) proj4string strings, , needed, set user. See also section coordinate reference systems. st_drivers() returns data.frame listing available drivers, metadata: names, whether driver can write, whether raster /vector driver. drivers can read. Reading common data formats illustrated : st_layers(dsn) lists layers present data source dsn, gives number fields, features geometry type layer: see case, number features NA xml file whole file needs read, may costly large files. can force counting : Another example reading kml kmz files :","code":"meuse <- st_read(\"PG:dbname=postgis\", \"meuse\") st_layers(system.file(\"osm/overpass.osm\", package=\"sf\")) Sys.setenv(OSM_USE_CUSTOM_INDEXING=\"NO\") st_layers(system.file(\"osm/overpass.osm\", package=\"sf\"), do_count = TRUE) # Download .shp data u_shp <- \"http://coagisweb.cabq.gov/datadownload/biketrails.zip\" download.file(u_shp, \"biketrails.zip\") unzip(\"biketrails.zip\") u_kmz <- \"http://coagisweb.cabq.gov/datadownload/BikePaths.kmz\" download.file(u_kmz, \"BikePaths.kmz\") # Read file formats biketrails_shp <- st_read(\"biketrails.shp\") if(Sys.info()[1] == \"Linux\") # may not work if not Linux biketrails_kmz <- st_read(\"BikePaths.kmz\") u_kml = \"http://www.northeastraces.com/oxonraces.com/nearme/safe/6.kml\" download.file(u_kml, \"bikeraces.kml\") bikraces <- st_read(\"bikeraces.kml\")"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"crud","dir":"Articles","previous_headings":"How simple features in R are organized > Reading and writing","what":"Create, read, update and delete","title":"1. Simple Features for R","text":"GDAL provides crud (create, read, update, delete) functions persistent storage. st_read() (read_sf()) used reading. st_write() (write_sf()) creates, following arguments control update delete: update=TRUE causes existing data source updated, exists; option default TRUE database drivers, database updated adding table. delete_layer=TRUE causes st_write try open data source delete layer; errors given data source present, layer exist data source. delete_dsn=TRUE causes st_write delete data source present, writing layer newly created data source. error given data source exist. option handled care, may wipe complete directories databases.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"connection-to-spatial-databases","dir":"Articles","previous_headings":"How simple features in R are organized > Reading and writing","what":"Connection to spatial databases","title":"1. Simple Features for R","text":"Read write functions, st_read() st_write(), can handle connections spatial databases read WKB WKT directly without using GDAL. Although intended use DBI interface, current use testing functions limited PostGIS.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"crs","dir":"Articles","previous_headings":"How simple features in R are organized","what":"Coordinate reference systems and transformations","title":"1. Simple Features for R","text":"Coordinate reference systems (CRS) like measurement units coordinates: specify location Earth particular coordinate pair refers . saw sfc objects (geometry list-columns) two attributes store CRS: epsg proj4string. implies geometries geometry list-column must CRS. may NA, e.g. case CRS unknown, work local coordinate systems (e.g. inside building, body, abstract space). proj4string generic, string-based description CRS, understood PROJ library. defines projection types (often) defines parameter values particular projections, hence can cover infinite amount different projections. library (also used GDAL) provides functions convert transform different CRS. epsg integer ID particular, known CRS can resolved proj4string. proj4string values can resolved back corresponding epsg ID, always work. importance epsg values stored data besides proj4string values epsg refers particular, well-known CRS, whose parameters may change (improve) time; fixing proj4string may remove possibility benefit improvements, limit provenance datasets, may help reproducibility. Coordinate reference system transformations can carried using st_transform(), e.g. converting longitudes/latitudes NAD27 web mercator (EPSG:3857) can done :","code":"nc.web_mercator <- st_transform(nc, 3857) st_geometry(nc.web_mercator)[[4]][[2]][[1]][1:3,] ## [,1] [,2] ## [1,] -8463267 4377519 ## [2,] -8460094 4377510 ## [3,] -8450437 4375553"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"conversion-including-to-and-from-sp","dir":"Articles","previous_headings":"How simple features in R are organized","what":"Conversion, including to and from sp","title":"1. Simple Features for R","text":"sf objects objects deriving Spatial (package sp) can coerced ways: Spatial* objects support MULTILINESTRING MULTIPOLYGON, LINESTRING POLYGON geometries automatically coerced MULTI form. converting Spatial* sf, geometries consist single POLYGON (possibly holes), POLYGON otherwise geometries returned MULTIPOLYGON: mix POLYGON MULTIPOLYGON (common shapefiles) created. Argument forceMulti=TRUE override , create MULTIPOLYGONs cases. LINES situation identical.","code":"showMethods(\"coerce\", classes = \"sf\") ## Function: coerce (package methods) ## from=\"sf\", to=\"Spatial\" ## from=\"Spatial\", to=\"sf\" methods(st_as_sf) ## [1] st_as_sf.data.frame* st_as_sf.lpp* st_as_sf.map* ## [4] st_as_sf.owin* st_as_sf.ppp* st_as_sf.ppplist* ## [7] st_as_sf.psp* st_as_sf.s2_geography* st_as_sf.sf* ## [10] st_as_sf.sfc* st_as_sf.Spatial* st_as_sf.SpatVector* ## see '?methods' for accessing help and source code methods(st_as_sfc) ## [1] st_as_sfc.bbox* st_as_sfc.blob* ## [3] st_as_sfc.character* st_as_sfc.dimensions* ## [5] st_as_sfc.factor* st_as_sfc.list* ## [7] st_as_sfc.map* st_as_sfc.owin* ## [9] st_as_sfc.pq_geometry* st_as_sfc.psp* ## [11] st_as_sfc.raw* st_as_sfc.s2_geography* ## [13] st_as_sfc.sf* st_as_sfc.SpatialLines* ## [15] st_as_sfc.SpatialMultiPoints* st_as_sfc.SpatialPixels* ## [17] st_as_sfc.SpatialPoints* st_as_sfc.SpatialPolygons* ## [19] st_as_sfc.tess* st_as_sfc.WKB* ## see '?methods' for accessing help and source code # anticipate that sp::CRS will expand proj4strings: p4s <- \"+proj=longlat +datum=NAD27 +no_defs +ellps=clrk66 +nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat\" st_crs(nc) <- p4s # anticipate geometry column name changes: names(nc)[15] = \"geometry\" attr(nc, \"sf_column\") = \"geometry\" nc.sp <- as(nc, \"Spatial\") class(nc.sp) ## [1] \"SpatialPolygonsDataFrame\" ## attr(,\"package\") ## [1] \"sp\" nc2 <- st_as_sf(nc.sp) all.equal(nc, nc2) ## [1] \"Attributes: < Component \\\"class\\\": Lengths (4, 2) differ (string compare on first 2) >\" ## [2] \"Attributes: < Component \\\"class\\\": 1 string mismatch >\" ## [3] \"Component \\\"geometry\\\": Attributes: < Component \\\"crs\\\": Component \\\"input\\\": 1 string mismatch >\" ## [4] \"Component \\\"geometry\\\": Attributes: < Component \\\"crs\\\": Component \\\"wkt\\\": 1 string mismatch >\""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"geometrycollection","dir":"Articles","previous_headings":"How simple features in R are organized","what":"Geometrical operations","title":"1. Simple Features for R","text":"standard simple feature access defines number geometrical operations. st_is_valid() st_is_simple() return Boolean indicating whether geometry valid simple. st_distance() returns dense numeric matrix distances geometries. st_relate() returns character matrix DE9-IM values pair geometries: st_intersects(), st_disjoint(), st_touches(), st_crosses(), st_within(), st_contains(), st_overlaps(), st_equals(), st_covers(), st_covered_by(), st_equals_exact() st_is_within_distance() return sparse matrix (sgbp object) matching (TRUE) indexes, full logical matrix: st_buffer(), st_boundary(), st_convexhull(), st_union_cascaded, st_simplify, st_triangulate(), st_polygonize(), st_centroid(), st_segmentize(), st_union() return new geometries, e.g.: st_intersection(), st_union(), st_difference(), st_sym_difference() return new geometries function pairs geometries: following code shows computing intersection two polygons may yield GEOMETRYCOLLECTION point, line polygon:","code":"st_is_valid(nc[1:2,]) ## [1] TRUE TRUE x = st_transform(nc, 32119) st_distance(x[c(1,4,22),], x[c(1, 33,55,56),]) ## Units: [m] ## [,1] [,2] [,3] [,4] ## [1,] 0.00 312184.9 128341.85 475623.3 ## [2,] 440561.15 114939.7 590434.80 0.0 ## [3,] 18944.03 352719.1 78756.89 517527.8 st_relate(nc[1:5,], nc[1:4,]) ## although coordinates are longitude/latitude, st_relate assumes that they are ## planar ## [,1] [,2] [,3] [,4] ## [1,] \"2FFF1FFF2\" \"FF2F11212\" \"FF2FF1212\" \"FF2FF1212\" ## [2,] \"FF2F11212\" \"2FFF1FFF2\" \"FF2F11212\" \"FF2FF1212\" ## [3,] \"FF2FF1212\" \"FF2F11212\" \"2FFF1FFF2\" \"FF2FF1212\" ## [4,] \"FF2FF1212\" \"FF2FF1212\" \"FF2FF1212\" \"2FFF1FFF2\" ## [5,] \"FF2FF1212\" \"FF2FF1212\" \"FF2FF1212\" \"FF2FF1212\" st_intersects(nc[1:5,], nc[1:4,]) ## Sparse geometry binary predicate list of length 5, where the predicate ## was `intersects' ## 1: 1, 2 ## 2: 1, 2, 3 ## 3: 2, 3 ## 4: 4 ## 5: (empty) st_intersects(nc[1:5,], nc[1:4,], sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] TRUE TRUE FALSE FALSE ## [2,] TRUE TRUE TRUE FALSE ## [3,] FALSE TRUE TRUE FALSE ## [4,] FALSE FALSE FALSE TRUE ## [5,] FALSE FALSE FALSE FALSE sel <- c(1,5,14) geom = st_geometry(nc.web_mercator[sel,]) buf <- st_buffer(geom, dist = 30000) plot(buf, border = 'red') plot(geom, add = TRUE) plot(st_buffer(geom, -5000), add = TRUE, border = 'blue') par(mar = rep(0,4)) u <- st_union(nc) plot(u) opar <- par(mfrow = c(1, 2)) a <- st_polygon(list(cbind(c(0,0,7.5,7.5,0),c(0,-1,-1,0,0)))) b <- st_polygon(list(cbind(c(0,1,2,3,4,5,6,7,7,0),c(1,0,.5,0,0,0.5,-0.5,-0.5,1,1)))) plot(a, ylim = c(-1,1)) title(\"intersecting two polygons:\") plot(b, add = TRUE, border = 'red') (i <- st_intersection(a,b)) ## GEOMETRYCOLLECTION (POLYGON ((7 0, 7 -0.5, 6 -0.5, 5.5 0, 7 0)), LINESTRING (4 0, 3 0), POINT (1 0)) plot(a, ylim = c(-1,1)) title(\"GEOMETRYCOLLECTION\") plot(b, add = TRUE, border = 'red') plot(i, add = TRUE, col = 'green', lwd = 2) par(opar)"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"non-simple-and-non-valid-geometries","dir":"Articles","previous_headings":"How simple features in R are organized","what":"Non-simple and non-valid geometries","title":"1. Simple Features for R","text":"Non-simple geometries instance self-intersecting lines (left); non-valid geometries instance polygons slivers (middle) self-intersections (right).","code":"library(sf) x1 <- st_linestring(cbind(c(0,1,0,1),c(0,1,1,0))) x2 <- st_polygon(list(cbind(c(0,1,1,1,0,0),c(0,0,1,0.6,1,0)))) x3 <- st_polygon(list(cbind(c(0,1,0,1,0),c(0,1,1,0,0)))) st_is_simple(st_sfc(x1)) ## [1] FALSE st_is_valid(st_sfc(x2,x3)) ## [1] FALSE FALSE"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"units","dir":"Articles","previous_headings":"","what":"Units","title":"1. Simple Features for R","text":"possible geometric operations st_distance(), st_length() st_area() report results units attribute appropriate CRS: units package can used convert units: result can stripped attributes needs :","code":"a <- st_area(nc[1,]) attributes(a) ## $units ## $numerator ## [1] \"m\" \"m\" ## ## $denominator ## character(0) ## ## attr(,\"class\") ## [1] \"symbolic_units\" ## ## $class ## [1] \"units\" units::set_units(a, km^2) # result in square kilometers ## 1137.108 [km^2] units::set_units(a, ha) # result in hectares ## 113710.8 [ha] as.numeric(a) ## [1] 1137107793"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"how-attributes-relate-to-geometries","dir":"Articles","previous_headings":"","what":"How attributes relate to geometries","title":"1. Simple Features for R","text":"(eventually topic new vignette; now explain last attribute sf objects) standard documents simple features detailed geometric aspects features, say nearly nothing attributes, except values understood another reference system (units measurement, e.g. implemented package units). . variables like air temperature, interpolation usually makes sense, others like human body temperature doesn’t. difference air temperature field, continues sensors, body temperature object property doesn’t extend beyond body – spatial statistics bodies called point pattern, temperature point marks. geometries non-zero size (positive length area), attribute values may refer every sub-geometry (every point), may summarize geometry. example, state’s population density summarizes whole state, meaningful estimate population density give point inside state without context state. hand, land use geological maps give polygons constant land use geology, every point inside polygon class. properties spatially extensive, meaning attributes summed two geometries merged: population example. properties spatially intensive, averaged, population density example. Simple feature objects class sf agr attribute points attribute-geometry-relationship, attributes relate geometry. can defined creation time: specified, field filled NA values, non-NA, one three possibilities: information (still done) can instance either return missing values generate warnings aggregate value point location inside polygon retrieved, list implicit assumptions made retrieving attribute values points inside polygon relation_to_geometry missing. decide attributes geometry split: nothing case attribute constant, give error warning case aggregate, change relation_to_geometry constant case identity. reading: S. Scheider, B. Gräler, E. Pebesma, C. Stasch, 2016. Modelling spatio-temporal information generation. Int J Geographic Information Science, 30 (10), 1980-2008. (open access) Stasch, C., S. Scheider, E. Pebesma, W. Kuhn, 2014. Meaningful Spatial Prediction Aggregation. Environmental Modelling & Software, 51, (149–165, open access).","code":"nc <- st_read(system.file(\"shape/nc.shp\", package=\"sf\"), agr = c(AREA = \"aggregate\", PERIMETER = \"aggregate\", CNTY_ = \"identity\", CNTY_ID = \"identity\", NAME = \"identity\", FIPS = \"identity\", FIPSNO = \"identity\", CRESS_ID = \"identity\", BIR74 = \"aggregate\", SID74 = \"aggregate\", NWBIR74 = \"aggregate\", BIR79 = \"aggregate\", SID79 = \"aggregate\", NWBIR79 = \"aggregate\")) ## Reading layer `nc' from data source ## `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' ## Simple feature collection with 100 features and 14 fields ## Attribute-geometry relationships: aggregate (8), identity (6) ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 ## Geodetic CRS: NAD27 st_agr(nc) ## AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID ## aggregate aggregate identity identity identity identity identity identity ## BIR74 SID74 NWBIR74 BIR79 SID79 NWBIR79 ## aggregate aggregate aggregate aggregate aggregate aggregate ## Levels: constant aggregate identity data(meuse, package = \"sp\") meuse_sf <- st_as_sf(meuse, coords = c(\"x\", \"y\"), crs = 28992, agr = \"constant\") st_agr(meuse_sf) ## cadmium copper lead zinc elev dist om ffreq ## constant constant constant constant constant constant constant constant ## soil lime landuse dist.m ## constant constant constant constant ## Levels: constant aggregate identity"},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"reading-and-writing-through-gdal","dir":"Articles","previous_headings":"","what":"Reading and writing through GDAL","title":"2. Reading, Writing and Converting Simple Features","text":"Geospatial Data Abstraction Library (GDAL) Swiss Army Knife spatial data: reads writes vector raster data practically every file format, database, significance. Package sf reads writes using GDAL using st_read() st_write(). data model GDAL uses needs data source, may file, directory, database layer, single geospatial dataset inside file directory e.g. table database. specification driver (.e., format) driver-specific reading writing data sources, layers may sound complex, needed map 200 data formats! Package sf tries hard simplify possible (e.g. file contains single layer), vignette try point options.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"using-st_read","dir":"Articles","previous_headings":"Reading and writing through GDAL","what":"Using st_read","title":"2. Reading, Writing and Converting Simple Features","text":"example, read North Carolina counties SIDS dataset, comes shipped sf package : Typical users use file name path fname, first set R’s working directory setwd() use file name without path. see single argument used find datasource layer. works datasource contains single layer. case number layers zero (e.g. database tables), error message given. case layers one, first layer returned, message warning given: message points st_layers() command, lists driver layers datasource, e.g. particular layer can now read e.g. st_layers() option count number features case missing: datasources (e.g. OSM xml files) report number features, need completely read . GDAL allows one geometry column feature layer; reported st_layers(). case layer contains geometries attributes (fields), st_read() still returns sf object, geometry column . see GDAL automatically detects driver (file format) datasource, trying turn. st_read() follows conventions base R, similar reads tabular data data.frames. means character data read, default factors. insist retrieving character data character vectors, argument stringsAsFactors can set FALSE: Alternatively, user can set global option stringsAsFactors, effect:","code":"library(sf) ## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE fname <- system.file(\"shape/nc.shp\", package=\"sf\") fname ## [1] \"/home/runner/work/_temp/Library/sf/shape/nc.shp\" nc <- st_read(fname) ## Reading layer `nc' from data source ## `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' ## Simple feature collection with 100 features and 14 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 ## Geodetic CRS: NAD27 > st_read(\"PG:dbname=postgis\") Multiple layers are present in data source PG:dbname=postgis, reading layer `meuse'. Use `st_layers' to list all layer names and their type in a data source. Set the `layer' argument in `st_read' to read a particular layer. Reading layer `meuse' from data source `PG:dbname=postgis' using driver `PostgreSQL' Simple feature collection with 155 features and 12 fields geometry type: POINT dimension: XY bbox: xmin: 178605 ymin: 329714 xmax: 181390 ymax: 333611 epsg (SRID): 28992 proj4string: +proj=sterea +lat_0=52.15616055555555 ... Warning message: In eval(substitute(expr), envir, enclos) : automatically selected the first layer in a data source containing more than one. > st_layers(\"PG:dbname=postgis\") Driver: PostgreSQL Available layers: layer_name geometry_type features fields 1 meuse Point 155 12 2 meuse_sf Point 155 12 3 sids Multi Polygon 100 14 4 meuse_tbl Point 155 13 5 meuse_tbl2 Point 155 13 > st_read(\"PG:dbname=postgis\", \"sids\") st_read(fname, stringsAsFactors = FALSE) options(stringsAsFactors = FALSE) st_read(fname) ## Reading layer `nc' from data source ## `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' ## Simple feature collection with 100 features and 14 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 ## Geodetic CRS: NAD27"},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"using-st_write","dir":"Articles","previous_headings":"Reading and writing through GDAL","what":"Using st_write","title":"2. Reading, Writing and Converting Simple Features","text":"write simple features object file, need least two arguments, object filename: file name taken data source name. default layer name basename (filename without path) data source name. , st_write() needs guess driver. command , instance, equivalent : guessing drivers works explained next section.","code":"st_write(nc, \"nc1.shp\") st_write(nc, dsn = \"nc1.shp\", layer = \"nc.shp\", driver = \"ESRI Shapefile\") ## Writing layer `nc' to data source `nc1.shp' using driver `ESRI Shapefile' ## Writing 100 features with 14 fields and geometry type Multi Polygon."},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"guessing-a-driver-for-output","dir":"Articles","previous_headings":"Reading and writing through GDAL","what":"Guessing a driver for output","title":"2. Reading, Writing and Converting Simple Features","text":"output driver guessed datasource name, either extension (.shp: ESRI Shapefile), prefix (PG:: PostgreSQL). list extensions corresponding driver (short driver name) : list prefixes :","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"dataset-and-layer-reading-or-creation-options","dir":"Articles","previous_headings":"Reading and writing through GDAL","what":"Dataset and layer reading or creation options","title":"2. Reading, Writing and Converting Simple Features","text":"Various GDAL drivers options influences reading writing process, example driver table already exists database: append records table overwrite : case table exists option specified, driver give error. Driver-specific options documented driver manual gdal. Multiple options can given multiple strings options. st_read(), options; st_write(), one needs distinguish dataset_options layer_options, first related opening dataset, second creating layers dataset.","code":"st_write(st_as_sf(meuse), \"PG:dbname=postgis\", \"meuse\", layer_options = \"OVERWRITE=true\")"},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"reading-and-writing-directly-to-and-from-spatial-databases","dir":"Articles","previous_headings":"","what":"Reading and writing directly to and from spatial databases","title":"2. Reading, Writing and Converting Simple Features","text":"Package sf supports reading writing spatial databases using DBI interface. far, testing mainly done PostGIS, databases might work may also need work. example reading : see second example query given. query may contain spatial predicates, way work massive spatial datasets R without read completely memory. Similarly, tables can written: , default table (layer) name taken object name (meuse). Argument drop informs drop (remove) table writing; logical argument binary determines whether use well-known binary well-known text writing geometry (well-known binary faster lossless).","code":"library(RPostgreSQL) conn = dbConnect(PostgreSQL(), dbname = \"postgis\") meuse = st_read(conn, \"meuse\") meuse_1_3 = st_read(conn, query = \"select * from meuse limit 3;\") dbDisconnect(conn) conn = dbConnect(PostgreSQL(), dbname = \"postgis\") st_write(conn, meuse, drop = TRUE) dbDisconnect(conn)"},{"path":[]},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"conversion-to-and-from-well-known-text","dir":"Articles","previous_headings":"Conversion to other formats: WKT, WKB, sp","what":"Conversion to and from well-known text","title":"2. Reading, Writing and Converting Simple Features","text":"usual form see simple features printed well-known text: can create well-known text strings explicitly using st_as_text: can convert back WKT using st_as_sfc():","code":"st_point(c(0,1)) ## POINT (0 1) st_linestring(matrix(0:9,ncol=2,byrow=TRUE)) ## LINESTRING (0 1, 2 3, 4 5, 6 7, 8 9) x = st_linestring(matrix(0:9,ncol=2,byrow=TRUE)) str = st_as_text(x) x ## LINESTRING (0 1, 2 3, 4 5, 6 7, 8 9) st_as_sfc(str) ## Geometry set for 1 feature ## Geometry type: LINESTRING ## Dimension: XY ## Bounding box: xmin: 0 ymin: 1 xmax: 8 ymax: 9 ## CRS: NA ## LINESTRING (0 1, 2 3, 4 5, 6 7, 8 9)"},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"conversion-to-and-from-well-known-binary","dir":"Articles","previous_headings":"Conversion to other formats: WKT, WKB, sp","what":"Conversion to and from well-known binary","title":"2. Reading, Writing and Converting Simple Features","text":"Well-known binary created simple features st_as_binary(): object returned st_as_binary() class WKB either list raw vectors, single raw vector. can converted hexadecimal character vector using rawToHex(): Converting back sf uses st_as_sfc():","code":"x = st_linestring(matrix(0:9,ncol=2,byrow=TRUE)) (x = st_as_binary(x)) ## [1] 01 02 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f0 3f ## [26] 00 00 00 00 00 00 00 40 00 00 00 00 00 00 08 40 00 00 00 00 00 00 10 40 00 ## [51] 00 00 00 00 00 14 40 00 00 00 00 00 00 18 40 00 00 00 00 00 00 1c 40 00 00 ## [76] 00 00 00 00 20 40 00 00 00 00 00 00 22 40 class(x) ## [1] \"raw\" rawToHex(x) ## [1] \"0102000000050000000000000000000000000000000000f03f000000000000004000000000000008400000000000001040000000000000144000000000000018400000000000001c4000000000000020400000000000002240\" x = st_as_binary(st_sfc(st_point(0:1), st_point(5:6))) st_as_sfc(x) ## Geometry set for 2 features ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 0 ymin: 1 xmax: 5 ymax: 6 ## CRS: NA ## POINT (0 1) ## POINT (5 6)"},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"conversion-to-and-from-sp","dir":"Articles","previous_headings":"Conversion to other formats: WKT, WKB, sp","what":"Conversion to and from sp","title":"2. Reading, Writing and Converting Simple Features","text":"Spatial objects maintained package sp can converted simple feature objects geometries st_as_sf() st_as_sfc(), respectively: example : Conversion simple feature objects class sf sfc corresponding Spatial* objects done using method, coercing Spatial:","code":"methods(st_as_sf) ## [1] st_as_sf.data.frame* st_as_sf.lpp* st_as_sf.map* ## [4] st_as_sf.owin* st_as_sf.ppp* st_as_sf.ppplist* ## [7] st_as_sf.psp* st_as_sf.s2_geography* st_as_sf.sf* ## [10] st_as_sf.sfc* st_as_sf.Spatial* st_as_sf.SpatVector* ## see '?methods' for accessing help and source code methods(st_as_sfc) ## [1] st_as_sfc.bbox* st_as_sfc.blob* ## [3] st_as_sfc.character* st_as_sfc.dimensions* ## [5] st_as_sfc.factor* st_as_sfc.list* ## [7] st_as_sfc.map* st_as_sfc.owin* ## [9] st_as_sfc.pq_geometry* st_as_sfc.psp* ## [11] st_as_sfc.raw* st_as_sfc.s2_geography* ## [13] st_as_sfc.sf* st_as_sfc.SpatialLines* ## [15] st_as_sfc.SpatialMultiPoints* st_as_sfc.SpatialPixels* ## [17] st_as_sfc.SpatialPoints* st_as_sfc.SpatialPolygons* ## [19] st_as_sfc.tess* st_as_sfc.WKB* ## see '?methods' for accessing help and source code library(sp) data(meuse) coordinates(meuse) = ~x+y m.sf = st_as_sf(meuse) opar = par(mar=rep(0,4)) plot(m.sf) ## Warning: plotting the first 10 out of 12 attributes; use max.plot = 12 to plot ## all x = st_sfc(st_point(c(5,5)), st_point(c(6,9)), crs = 4326) as(x, \"Spatial\") ## SpatialPoints: ## coords.x1 coords.x2 ## [1,] 5 5 ## [2,] 6 9 ## Coordinate Reference System (CRS) arguments: +proj=longlat +datum=WGS84 ## +no_defs"},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"type-transformations","dir":"Articles","previous_headings":"","what":"Type transformations","title":"3. Manipulating Simple Feature Geometries","text":"sections discusses simple feature geometries one type can converted another. converting lines polygons, see also st_polygonize() .","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"for-single-geometries","dir":"Articles","previous_headings":"Type transformations","what":"For single geometries","title":"3. Manipulating Simple Feature Geometries","text":"single geometries, st_cast() convert XX MULTIXX, e.g. LINESTRING MULTILINESTRING convert MULTIXX XX MULTIXX length one (else, still convert warn loss information) convert MULTIXX XX MULTIXX length one, warn loss information convert GEOMETRYCOLLECTION length one component Examples first three types : Examples fourth type :","code":"library(sf) ## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE suppressPackageStartupMessages(library(dplyr)) st_point(c(1,1)) %>% st_cast(\"MULTIPOINT\") ## MULTIPOINT ((1 1)) st_multipoint(rbind(c(1,1))) %>% st_cast(\"POINT\") ## Warning in st_cast.MULTIPOINT(., \"POINT\"): point from first coordinate only ## POINT (1 1) st_multipoint(rbind(c(1,1),c(2,2))) %>% st_cast(\"POINT\") ## Warning in st_cast.MULTIPOINT(., \"POINT\"): point from first coordinate only ## POINT (1 1) st_geometrycollection(list(st_point(c(1,1)))) %>% st_cast(\"POINT\") ## POINT (1 1)"},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"for-collections-of-geometry-sfc-and-simple-feature-collections-sf","dir":"Articles","previous_headings":"Type transformations","what":"For collections of geometry (sfc) and simple feature collections (sf)","title":"3. Manipulating Simple Feature Geometries","text":"noted reading geometries using st_read(), type argument can used control class returned geometry: option handled GDAL library; case failure convert target type, original types returned, case mix POLYGON MULTIPOLYGON geometries, leading GEOMETRY superclass. try read multipolygons polygons, secondary rings multipolygons get lost. functions return objects mixed geometry type (GEOMETRY), downstream functions st_write() may difficulty handling . cases, st_cast() may help modify type. sets geometry objects (sfc) simple feature sets (sf),st_cast` can used specifying target type, without specifying . target type given, st_cast() tries smart two cases: class object GEOMETRY, elements identical type, elements length-one GEOMETRYCOLLECTION objects, case GEOMETRYCOLLECTION objects replaced content (may GEOMETRY mix ) Examples :","code":"shp = system.file(\"shape/nc.shp\", package=\"sf\") class(st_geometry(st_read(shp, quiet = TRUE))) ## [1] \"sfc_MULTIPOLYGON\" \"sfc\" class(st_geometry(st_read(shp, quiet = TRUE, type = 3))) ## [1] \"sfc_POLYGON\" \"sfc\" class(st_geometry(st_read(shp, quiet = TRUE, type = 1))) ## [1] \"sfc_GEOMETRY\" \"sfc\" ls <- st_linestring(rbind(c(0,0),c(1,1),c(2,1))) mls <- st_multilinestring(list(rbind(c(2,2),c(1,3)), rbind(c(0,0),c(1,1),c(2,1)))) (sfc <- st_sfc(ls,mls)) ## Geometry set for 2 features ## Geometry type: GEOMETRY ## Dimension: XY ## Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 3 ## CRS: NA ## LINESTRING (0 0, 1 1, 2 1) ## MULTILINESTRING ((2 2, 1 3), (0 0, 1 1, 2 1)) st_cast(sfc, \"MULTILINESTRING\") ## Geometry set for 2 features ## Geometry type: MULTILINESTRING ## Dimension: XY ## Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 3 ## CRS: NA ## MULTILINESTRING ((0 0, 1 1, 2 1)) ## MULTILINESTRING ((2 2, 1 3), (0 0, 1 1, 2 1)) sf <- st_sf(a = 5:4, geom = sfc) st_cast(sf, \"MULTILINESTRING\") ## Simple feature collection with 2 features and 1 field ## Geometry type: MULTILINESTRING ## Dimension: XY ## Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 3 ## CRS: NA ## a geom ## 1 5 MULTILINESTRING ((0 0, 1 1,... ## 2 4 MULTILINESTRING ((2 2, 1 3)... ls <- st_linestring(rbind(c(0,0),c(1,1),c(2,1))) mls1 <- st_multilinestring(list(rbind(c(2,2),c(1,3)), rbind(c(0,0),c(1,1),c(2,1)))) mls2 <- st_multilinestring(list(rbind(c(4,4),c(4,3)), rbind(c(2,2),c(2,1),c(3,1)))) (sfc <- st_sfc(ls,mls1,mls2)) ## Geometry set for 3 features ## Geometry type: GEOMETRY ## Dimension: XY ## Bounding box: xmin: 0 ymin: 0 xmax: 4 ymax: 4 ## CRS: NA ## LINESTRING (0 0, 1 1, 2 1) ## MULTILINESTRING ((2 2, 1 3), (0 0, 1 1, 2 1)) ## MULTILINESTRING ((4 4, 4 3), (2 2, 2 1, 3 1)) class(sfc[2:3]) ## [1] \"sfc_MULTILINESTRING\" \"sfc\" class(st_cast(sfc[2:3])) ## [1] \"sfc_MULTILINESTRING\" \"sfc\" gc1 <- st_geometrycollection(list(st_linestring(rbind(c(0,0),c(1,1),c(2,1))))) gc2 <- st_geometrycollection(list(st_multilinestring(list(rbind(c(2,2),c(1,3)), rbind(c(0,0),c(1,1),c(2,1)))))) gc3 <- st_geometrycollection(list(st_multilinestring(list(rbind(c(4,4),c(4,3)), rbind(c(2,2),c(2,1),c(3,1)))))) (sfc <- st_sfc(gc1,gc2,gc3)) ## Geometry set for 3 features ## Geometry type: GEOMETRYCOLLECTION ## Dimension: XY ## Bounding box: xmin: 0 ymin: 0 xmax: 4 ymax: 4 ## CRS: NA ## GEOMETRYCOLLECTION (LINESTRING (0 0, 1 1, 2 1)) ## GEOMETRYCOLLECTION (MULTILINESTRING ((2 2, 1 3)... ## GEOMETRYCOLLECTION (MULTILINESTRING ((4 4, 4 3)... class(st_cast(sfc)) ## [1] \"sfc_GEOMETRY\" \"sfc\" class(st_cast(st_cast(sfc), \"MULTILINESTRING\")) ## [1] \"sfc_MULTILINESTRING\" \"sfc\""},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"affine-transformations","dir":"Articles","previous_headings":"","what":"Affine transformations","title":"3. Manipulating Simple Feature Geometries","text":"Affine transformations transformations type f(x)=xA+bf(x) = xA + b, matrix AA used flatten, scale /rotate, bb translate xx. Low-level examples : Just make point, can instance rotate counties North Carolina 90 degrees clockwise around centroid, shrink 75% original size:","code":"(p = st_point(c(0,2))) ## POINT (0 2) p + 1 ## POINT (1 3) p + c(1,2) ## POINT (1 4) p + p ## POINT (0 4) p * p ## POINT (0 4) rot = function(a) matrix(c(cos(a), sin(a), -sin(a), cos(a)), 2, 2) p * rot(pi/4) ## POINT (1.414214 1.414214) p * rot(pi/2) ## POINT (2 1.224647e-16) p * rot(pi) ## POINT (2.449294e-16 -2) nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\"), quiet = TRUE) ncg = st_geometry(nc) plot(ncg, border = 'grey') cntrd = st_centroid(ncg) ncg2 = (ncg - cntrd) * rot(pi/2) * .75 + cntrd plot(ncg2, add = TRUE) plot(cntrd, col = 'red', add = TRUE, cex = .5)"},{"path":[]},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"getting-and-setting-coordinate-reference-systems-of-sf-objects","dir":"Articles","previous_headings":"Coordinate reference systems conversion and transformation","what":"Getting and setting coordinate reference systems of sf objects","title":"3. Manipulating Simple Feature Geometries","text":"coordinate reference system objects class sf sfc obtained st_crs(), replaced st_crs<-: alternative, pipe-friendly version st_crs<- ","code":"library(sf) geom = st_sfc(st_point(c(0,1)), st_point(c(11,12))) s = st_sf(a = 15:16, geometry = geom) st_crs(s) ## Coordinate Reference System: NA s1 = s st_crs(s1) <- 4326 st_crs(s1) ## Coordinate Reference System: ## User input: EPSG:4326 ## wkt: ## GEOGCRS[\"WGS 84\", ## ENSEMBLE[\"World Geodetic System 1984 ensemble\", ## MEMBER[\"World Geodetic System 1984 (Transit)\"], ## MEMBER[\"World Geodetic System 1984 (G730)\"], ## MEMBER[\"World Geodetic System 1984 (G873)\"], ## MEMBER[\"World Geodetic System 1984 (G1150)\"], ## MEMBER[\"World Geodetic System 1984 (G1674)\"], ## MEMBER[\"World Geodetic System 1984 (G1762)\"], ## MEMBER[\"World Geodetic System 1984 (G2139)\"], ## ELLIPSOID[\"WGS 84\",6378137,298.257223563, ## LENGTHUNIT[\"metre\",1]], ## ENSEMBLEACCURACY[2.0]], ## PRIMEM[\"Greenwich\",0, ## ANGLEUNIT[\"degree\",0.0174532925199433]], ## CS[ellipsoidal,2], ## AXIS[\"geodetic latitude (Lat)\",north, ## ORDER[1], ## ANGLEUNIT[\"degree\",0.0174532925199433]], ## AXIS[\"geodetic longitude (Lon)\",east, ## ORDER[2], ## ANGLEUNIT[\"degree\",0.0174532925199433]], ## USAGE[ ## SCOPE[\"Horizontal component of 3D system.\"], ## AREA[\"World.\"], ## BBOX[-90,-180,90,180]], ## ID[\"EPSG\",4326]] s2 = s st_crs(s2) <- \"+proj=longlat +datum=WGS84\" all.equal(s1, s2) ## [1] \"Component \\\"geometry\\\": Attributes: < Component \\\"crs\\\": Component \\\"input\\\": 1 string mismatch >\" ## [2] \"Component \\\"geometry\\\": Attributes: < Component \\\"crs\\\": Component \\\"wkt\\\": 1 string mismatch >\" s1 %>% st_set_crs(4326) ## Simple feature collection with 2 features and 1 field ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 0 ymin: 1 xmax: 11 ymax: 12 ## Geodetic CRS: WGS 84 ## a geometry ## 1 15 POINT (0 1) ## 2 16 POINT (11 12)"},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"coordinate-reference-system-transformations","dir":"Articles","previous_headings":"Coordinate reference systems conversion and transformation","what":"Coordinate reference system transformations","title":"3. Manipulating Simple Feature Geometries","text":"change coordinate reference system one non-missing value another non-missing value, CRS changed without modifying coordinates, warning issued reproject values: cleaner way better expresses intention generate warning first wipe CRS assigning missing value, set intended value. carry coordinate conversion transformation, use st_transform() see coordinates actually modified (projected).","code":"s3 <- s1 %>% st_set_crs(4326) %>% st_set_crs(3857) ## Warning: st_crs<- : replacing crs does not reproject data; use st_transform for ## that s3 <- s1 %>% st_set_crs(NA) %>% st_set_crs(3857) s3 <- s1 %>% st_transform(3857) s3 ## Simple feature collection with 2 features and 1 field ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 0 ymin: 111325.1 xmax: 1224514 ymax: 1345708 ## Projected CRS: WGS 84 / Pseudo-Mercator ## a geometry ## 1 15 POINT (0 111325.1) ## 2 16 POINT (1224514 1345708)"},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"geometrical-operations","dir":"Articles","previous_headings":"","what":"Geometrical operations","title":"3. Manipulating Simple Feature Geometries","text":"geometrical operations st_op(x) st_op2(x,y) work sf objects sfc objects x y; since operations work geometries, non-geometry parts sf object simply discarded. Also, binary operations st_op2(x,y) called single argument, st_op2(x), handled st_op2(x,x). illustrate geometrical operations simple dataset:","code":"b0 = st_polygon(list(rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1)))) b1 = b0 + 2 b2 = b0 + c(-0.2, 2) x = st_sfc(b0, b1, b2) a0 = b0 * 0.8 a1 = a0 * 0.5 + c(2, 0.7) a2 = a0 + 1 a3 = b0 * 0.5 + c(2, -0.5) y = st_sfc(a0,a1,a2,a3) plot(x, border = 'red') plot(y, border = 'green', add = TRUE)"},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"unary-operations","dir":"Articles","previous_headings":"Geometrical operations","what":"Unary operations","title":"3. Manipulating Simple Feature Geometries","text":"st_is_valid() returns whether polygon geometries topologically valid: st_is_simple() whether line geometries simple: st_area() returns area polygon geometries, st_length() length line geometries:","code":"b0 = st_polygon(list(rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1)))) b1 = st_polygon(list(rbind(c(-1,-1), c(1,-1), c(1,1), c(0,-1), c(-1,-1)))) st_is_valid(st_sfc(b0,b1)) ## [1] TRUE FALSE s = st_sfc(st_linestring(rbind(c(0,0), c(1,1))), st_linestring(rbind(c(0,0), c(1,1),c(0,1),c(1,0)))) st_is_simple(s) ## [1] TRUE FALSE st_area(x) ## [1] 4 4 4 st_area(st_sfc(st_point(c(0,0)))) ## [1] 0 st_length(st_sfc(st_linestring(rbind(c(0,0),c(1,1),c(1,2))), st_linestring(rbind(c(0,0),c(1,0))))) ## [1] 2.414214 1.000000 st_length(st_sfc(st_multilinestring(list(rbind(c(0,0),c(1,1),c(1,2))),rbind(c(0,0),c(1,0))))) # ignores 2nd part! ## [1] 2.414214"},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"binary-operations-distance-and-relate","dir":"Articles","previous_headings":"Geometrical operations","what":"Binary operations: distance and relate","title":"3. Manipulating Simple Feature Geometries","text":"st_distance() computes shortest distance matrix geometries; dense matrix: st_relate() returns dense character matrix DE9-IM relationships pair geometries: element [,j] matrix nine characters, referring relationship x[] y[j], encoded IxIy,IxBy,IxEy,BxIy,BxBy,BxEy,ExIy,ExBy,ExEyI_xI_y,I_xB_y,I_xE_y,B_xI_y,B_xB_y,B_xE_y,E_xI_y,E_xB_y,E_xE_y II refers interior, BB boundary, EE exterior, e.g. BxIyB_xI_y dimensionality intersection boundary BxB_x x[] interior IyI_y y[j], one {0,1,2,F}, indicating zero-, one-, two-dimension intersection, (F) intersection, respectively.","code":"st_distance(x,y) ## [,1] [,2] [,3] [,4] ## [1,] 0.0000000 0.6 0 0.500000 ## [2,] 0.2828427 0.0 0 1.000000 ## [3,] 0.2000000 0.8 0 1.220656 st_relate(x,y) ## [,1] [,2] [,3] [,4] ## [1,] \"212FF1FF2\" \"FF2FF1212\" \"212101212\" \"FF2FF1212\" ## [2,] \"FF2FF1212\" \"212101212\" \"212101212\" \"FF2FF1212\" ## [3,] \"FF2FF1212\" \"FF2FF1212\" \"212101212\" \"FF2FF1212\""},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"binary-logical-operations","dir":"Articles","previous_headings":"Geometrical operations","what":"Binary logical operations:","title":"3. Manipulating Simple Feature Geometries","text":"Binary logical operations return either sparse matrix dense matrix list element sparse matrix contains indices TRUE elements row dense matrix. large geometry sets, dense matrices take lot memory mostly filled FALSE values, hence default return sparse matrix. st_intersects() returns every geometry pair whether intersect (dense matrix), elements intersect (sparse). Note st_intersection() package returns geometry intersection instead logicals st_intersects() (see next section vignette). binary predicates include (using sparse readability):","code":"st_intersects(x,y) ## Sparse geometry binary predicate list of length 3, where the predicate ## was `intersects' ## 1: 1, 3 ## 2: 2, 3 ## 3: 3 st_intersects(x, x, sparse = FALSE) ## [,1] [,2] [,3] ## [1,] TRUE TRUE TRUE ## [2,] TRUE TRUE FALSE ## [3,] TRUE FALSE TRUE st_intersects(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] TRUE FALSE TRUE FALSE ## [2,] FALSE TRUE TRUE FALSE ## [3,] FALSE FALSE TRUE FALSE st_disjoint(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] FALSE TRUE FALSE TRUE ## [2,] TRUE FALSE FALSE TRUE ## [3,] TRUE TRUE FALSE TRUE st_touches(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] FALSE FALSE FALSE FALSE ## [2,] FALSE FALSE FALSE FALSE ## [3,] FALSE FALSE FALSE FALSE st_crosses(s, s, sparse = FALSE) ## [,1] [,2] ## [1,] FALSE FALSE ## [2,] FALSE FALSE st_within(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] FALSE FALSE FALSE FALSE ## [2,] FALSE FALSE FALSE FALSE ## [3,] FALSE FALSE FALSE FALSE st_contains(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] TRUE FALSE FALSE FALSE ## [2,] FALSE FALSE FALSE FALSE ## [3,] FALSE FALSE FALSE FALSE st_overlaps(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] FALSE FALSE TRUE FALSE ## [2,] FALSE TRUE TRUE FALSE ## [3,] FALSE FALSE TRUE FALSE st_equals(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] FALSE FALSE FALSE FALSE ## [2,] FALSE FALSE FALSE FALSE ## [3,] FALSE FALSE FALSE FALSE st_covers(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] TRUE FALSE FALSE FALSE ## [2,] FALSE FALSE FALSE FALSE ## [3,] FALSE FALSE FALSE FALSE st_covered_by(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] FALSE FALSE FALSE FALSE ## [2,] FALSE FALSE FALSE FALSE ## [3,] FALSE FALSE FALSE FALSE st_covered_by(y, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] TRUE FALSE FALSE FALSE ## [2,] FALSE TRUE FALSE FALSE ## [3,] FALSE FALSE TRUE FALSE ## [4,] FALSE FALSE FALSE TRUE st_equals_exact(x, y,0.001, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] FALSE FALSE FALSE FALSE ## [2,] FALSE FALSE FALSE FALSE ## [3,] FALSE FALSE FALSE FALSE"},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"operations-returning-a-geometry","dir":"Articles","previous_headings":"Geometrical operations","what":"Operations returning a geometry","title":"3. Manipulating Simple Feature Geometries","text":"intersection two geometries geometry covered ; obtained st_intersection(): Note st_intersects() returns logical matrix indicating whether geometry pair intersects (see previous section vignette). get everything intersection, use st_difference() st_sym_difference(): st_segmentize() adds points straight line sections lines polygon object: st_polygonize() polygonizes multilinestring, long points form closed polygon:","code":"u = st_union(x) plot(u) par(mfrow=c(1,2), mar = rep(0,4)) plot(st_buffer(u, 0.2)) plot(u, border = 'red', add = TRUE) plot(st_buffer(u, 0.2), border = 'grey') plot(u, border = 'red', add = TRUE) plot(st_buffer(u, -0.2), add = TRUE) plot(st_boundary(x)) par(mfrow = c(1:2)) plot(st_convex_hull(x)) plot(st_convex_hull(u)) par(mfrow = c(1,1)) par(mfrow=c(1,2)) plot(x) plot(st_centroid(x), add = TRUE, col = 'red') plot(x) plot(st_centroid(u), add = TRUE, col = 'red') plot(x) plot(y, add = TRUE) plot(st_intersection(st_union(x),st_union(y)), add = TRUE, col = 'red') par(mfrow=c(2,2), mar = c(0,0,1,0)) plot(x, col = '#ff333388'); plot(y, add=TRUE, col='#33ff3388') title(\"x: red, y: green\") plot(x, border = 'grey') plot(st_difference(st_union(x),st_union(y)), col = 'lightblue', add = TRUE) title(\"difference(x,y)\") plot(x, border = 'grey') plot(st_difference(st_union(y),st_union(x)), col = 'lightblue', add = TRUE) title(\"difference(y,x)\") plot(x, border = 'grey') plot(st_sym_difference(st_union(y),st_union(x)), col = 'lightblue', add = TRUE) title(\"sym_difference(x,y)\") par(mfrow=c(1,3),mar=c(1,1,0,0)) pts = rbind(c(0,0),c(1,0),c(2,1),c(3,1)) ls = st_linestring(pts) plot(ls) points(pts) ls.seg = st_segmentize(ls, 0.3) plot(ls.seg) pts = ls.seg points(pts) pol = st_polygon(list(rbind(c(0,0),c(1,0),c(1,1),c(0,1),c(0,0)))) pol.seg = st_segmentize(pol, 0.3) plot(pol.seg, col = 'grey') points(pol.seg[[1]]) par(mfrow=c(1,2),mar=c(0,0,1,0)) mls = st_multilinestring(list(matrix(c(0,0,0,1,1,1,0,0),,2,byrow=TRUE))) x = st_polygonize(mls) plot(mls, col = 'grey') title(\"multilinestring\") plot(x, col = 'grey') title(\"polygon\")"},{"path":"https://r-spatial.github.io/sf/articles/sf4.html","id":"subsetting-feature-sets","dir":"Articles","previous_headings":"","what":"Subsetting feature sets","title":"4. Manipulating Simple Features","text":"can subset feature sets using square bracket notation use drop argument drop geometries: can also use spatial object row selector, select features intersect another spatial feature: see result set Ashe included, default value argument op [.sf st_intersects(), Ashe intersects . exclude self-intersection using predicate st_touches() (overlapping features don’t touch): Using dplyr, can calling predicate directly:","code":"nc[1, \"NWBIR74\"] ## Simple feature collection with 1 feature and 1 field ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: 1193283 ymin: 913341.9 xmax: 1340555 ymax: 1044158 ## Projected CRS: NAD83 / North Carolina (ftUS) ## NWBIR74 geometry ## 1 10 MULTIPOLYGON (((1270814 913... nc[1, \"NWBIR74\", drop = TRUE] ## [1] 10 ## attr(,\"class\") ## [1] \"numeric\" Ashe = nc[nc$NAME == \"Ashe\",] class(Ashe) ## [1] \"sf\" \"data.frame\" nc[Ashe,] ## Simple feature collection with 4 features and 14 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: 1142157 ymin: 823092 xmax: 1448920 ymax: 1044158 ## Projected CRS: NAD83 / North Carolina (ftUS) ## AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 ## 1 0.114 1.442 1825 1825 Ashe 37009 37009 5 1091 1 ## 2 0.061 1.231 1827 1827 Alleghany 37005 37005 3 487 0 ## 18 0.199 1.984 1874 1874 Wilkes 37193 37193 97 3146 4 ## 19 0.081 1.288 1880 1880 Watauga 37189 37189 95 1323 1 ## NWBIR74 BIR79 SID79 NWBIR79 geometry ## 1 10 1364 0 19 MULTIPOLYGON (((1270814 913... ## 2 10 542 3 12 MULTIPOLYGON (((1340555 959... ## 18 200 3725 7 222 MULTIPOLYGON (((1402677 837... ## 19 17 1775 1 33 MULTIPOLYGON (((1171158 868... Ashe = nc[nc$NAME == \"Ashe\",] nc[Ashe, op = st_touches] ## Simple feature collection with 3 features and 14 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: 1142157 ymin: 823092 xmax: 1448920 ymax: 1035641 ## Projected CRS: NAD83 / North Carolina (ftUS) ## AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 ## 2 0.061 1.231 1827 1827 Alleghany 37005 37005 3 487 0 ## 18 0.199 1.984 1874 1874 Wilkes 37193 37193 97 3146 4 ## 19 0.081 1.288 1880 1880 Watauga 37189 37189 95 1323 1 ## NWBIR74 BIR79 SID79 NWBIR79 geometry ## 2 10 542 3 12 MULTIPOLYGON (((1340555 959... ## 18 200 3725 7 222 MULTIPOLYGON (((1402677 837... ## 19 17 1775 1 33 MULTIPOLYGON (((1171158 868... nc %>% filter(lengths(st_touches(., Ashe)) > 0) ## Simple feature collection with 3 features and 14 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: 1142157 ymin: 823092 xmax: 1448920 ymax: 1035641 ## Projected CRS: NAD83 / North Carolina (ftUS) ## AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 ## 1 0.061 1.231 1827 1827 Alleghany 37005 37005 3 487 0 ## 2 0.199 1.984 1874 1874 Wilkes 37193 37193 97 3146 4 ## 3 0.081 1.288 1880 1880 Watauga 37189 37189 95 1323 1 ## NWBIR74 BIR79 SID79 NWBIR79 geometry ## 1 10 542 3 12 MULTIPOLYGON (((1340555 959... ## 2 200 3725 7 222 MULTIPOLYGON (((1402677 837... ## 3 17 1775 1 33 MULTIPOLYGON (((1171158 868..."},{"path":"https://r-spatial.github.io/sf/articles/sf4.html","id":"aggregating-or-summarizing-feature-sets","dir":"Articles","previous_headings":"","what":"Aggregating or summarizing feature sets","title":"4. Manipulating Simple Features","text":"Suppose want compare 1974 fraction SID (sudden infant death) counties intersect Ashe remaining ones. can :","code":"a <- aggregate(nc[, c(\"SID74\", \"BIR74\")], list(Ashe_nb = lengths(st_intersects(nc, Ashe)) > 0), sum) (a <- a %>% mutate(frac74 = SID74 / BIR74) %>% select(frac74)) ## Simple feature collection with 2 features and 1 field ## Geometry type: GEOMETRY ## Dimension: XY ## Bounding box: xmin: 406262.2 ymin: 48374.87 xmax: 3052887 ymax: 1044158 ## Projected CRS: NAD83 / North Carolina (ftUS) ## frac74 geometry ## 1 0.0020406588 MULTIPOLYGON (((454152.6 58... ## 2 0.0009922276 POLYGON ((1372054 837052.3,... plot(a[2], col = c(grey(.8), grey(.5))) plot(st_geometry(Ashe), border = '#ff8888', add = TRUE, lwd = 2)"},{"path":"https://r-spatial.github.io/sf/articles/sf4.html","id":"joining-two-feature-sets-based-on-attributes","dir":"Articles","previous_headings":"","what":"Joining two feature sets based on attributes","title":"4. Manipulating Simple Features","text":"usual join verbs base R (merge) dplyr (left_join(), etc) work sf objects well; joining takes place attributes (ignoring geometries). case matching geometry, empty geometry substituted. second argument data.frame (similar), sf object:","code":"x = st_sf(a = 1:2, geom = st_sfc(st_point(c(0,0)), st_point(c(1,1)))) y = data.frame(a = 2:3) merge(x, y) ## Simple feature collection with 1 feature and 1 field ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 1 ymin: 1 xmax: 1 ymax: 1 ## CRS: NA ## a geom ## 1 2 POINT (1 1) merge(x, y, all = TRUE) ## Simple feature collection with 3 features and 1 field (with 1 geometry empty) ## Geometry type: GEOMETRY ## Dimension: XY ## Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 ## CRS: NA ## a geom ## 1 1 POINT (0 0) ## 2 2 POINT (1 1) ## 3 3 GEOMETRYCOLLECTION EMPTY right_join(x, y) ## Joining with `by = join_by(a)` ## Simple feature collection with 2 features and 1 field (with 1 geometry empty) ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 1 ymin: 1 xmax: 1 ymax: 1 ## CRS: NA ## a geom ## 1 2 POINT (1 1) ## 2 3 POINT EMPTY"},{"path":"https://r-spatial.github.io/sf/articles/sf4.html","id":"joining-two-feature-sets-based-on-geometries","dir":"Articles","previous_headings":"","what":"Joining two feature sets based on geometries","title":"4. Manipulating Simple Features","text":"joining based spatial intersections (kind), st_join() used: join method left join, retaining records first attribute: geometry retained first argument. spatial join predicate can controlled function compatible st_intersects() (default), e.g.","code":"x = st_sf(a = 1:3, geom = st_sfc(st_point(c(1,1)), st_point(c(2,2)), st_point(c(3,3)))) y = st_buffer(x, 0.1) x = x[1:2,] y = y[2:3,] plot(st_geometry(x), xlim = c(.5, 3.5)) plot(st_geometry(y), add = TRUE) st_join(x, y) ## Simple feature collection with 2 features and 2 fields ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 1 ymin: 1 xmax: 2 ymax: 2 ## CRS: NA ## a.x a.y geom ## 1 1 NA POINT (1 1) ## 2 2 2 POINT (2 2) st_join(y, x) ## Simple feature collection with 2 features and 2 fields ## Geometry type: POLYGON ## Dimension: XY ## Bounding box: xmin: 1.9 ymin: 1.9 xmax: 3.1 ymax: 3.1 ## CRS: NA ## a.x a.y geom ## 2 2 2 POLYGON ((2.1 2, 2.099863 1... ## 3 3 NA POLYGON ((3.1 3, 3.099863 2... st_join(x, y, join = st_covers) # no matching y records: points don't cover circles ## Simple feature collection with 2 features and 2 fields ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 1 ymin: 1 xmax: 2 ymax: 2 ## CRS: NA ## a.x a.y geom ## 1 1 NA POINT (1 1) ## 2 2 NA POINT (2 2) st_join(y, x, join = st_covers) # matches for those circles covering a point ## Simple feature collection with 2 features and 2 fields ## Geometry type: POLYGON ## Dimension: XY ## Bounding box: xmin: 1.9 ymin: 1.9 xmax: 3.1 ymax: 3.1 ## CRS: NA ## a.x a.y geom ## 2 2 2 POLYGON ((2.1 2, 2.099863 1... ## 3 3 NA POLYGON ((3.1 3, 3.099863 2..."},{"path":[]},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"geometry-only-sfc","dir":"Articles","previous_headings":"Plot methods for sf and sfc objects","what":"Geometry only: sfc","title":"5. Plotting Simple Features","text":"Geometry list-columns (objects class sfc, obtained st_geometry method) show geometry: can annotated colors, symbols, etc., usual base plots, e.g. points added polygon plot : legends, titles can added afterwards. border = NA removes polygon borders. can seen, axes plotted sensitive CRS, case longitude/latitude coordinates, degree symbols orientation added axes = TRUE.","code":"library(sf) ## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE demo(nc, ask = FALSE, echo = FALSE) plot(st_geometry(nc)) plot(st_geometry(nc), col = sf.colors(12, categorical = TRUE), border = 'grey', axes = TRUE) plot(st_geometry(st_centroid(nc)), pch = 3, col = 'red', add = TRUE) ## Warning: st_centroid assumes attributes are constant over geometries"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"geometry-with-attributes-sf","dir":"Articles","previous_headings":"Plot methods for sf and sfc objects","what":"Geometry with attributes: sf","title":"5. Plotting Simple Features","text":"default plot sf object multi-plot attributes, reasonable maximum: warning attributes can reasonably plotted. One can increase maximum number maps plotted row/column layout chosen plotting area maximally filled. default value max.plot can controlled, e.g. setting global option sf_max.plot:","code":"plot(nc) ## Warning: plotting the first 9 out of 14 attributes; use max.plot = 14 to plot ## all plot(nc, max.plot = 14) options(sf_max.plot=1) plot(nc)"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"color-key-place-and-size","dir":"Articles","previous_headings":"","what":"Color key place and size","title":"5. Plotting Simple Features","text":"case single attribute selected, default color key given side plot leaves much possible room plotted map; nc : can controlled, set particular side (1=, 2=left, 3=4=right): size color key can controlled, using either relative units (number 0 1) absolute units (like lcm(2) 2 cm): Keys factor variables bit different, typically don’t want rotate text :","code":"plot(nc[\"AREA\"]) plot(nc[\"AREA\"], key.pos = 4) plot(nc[\"AREA\"], key.pos = 1, axes = TRUE, key.width = lcm(1.3), key.length = 1.0) nc$f = cut(nc$AREA, 10) plot(nc[\"f\"], axes = TRUE, key.pos = 4, pal = sf.colors(10), key.width = lcm(5))"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"class-intervals","dir":"Articles","previous_headings":"","what":"Class intervals","title":"5. Plotting Simple Features","text":"Color breaks (class intervals) can controlled plot arguments breaks nbreaks. nbreaks specifies number breaks; breaks either vector break values: breaks used indicate breaks-finding method passed style argument classInt::classIntervals(). default value, pretty, results rounded class breaks, side effect nbreaks may honoured approximately. methods include \"equal\" break data range \"nbreaks\" equal classes, \"quantile\" use quantiles class breaks, \"jenks\", used software.","code":"plot(nc[\"AREA\"], breaks = c(0,.05,.1,.15,.2,.25)) plot(nc[\"AREA\"], breaks = \"jenks\")"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"how-does-sf-project-geographic-coordinates","dir":"Articles","previous_headings":"","what":"How does sf project geographic coordinates?","title":"5. Plotting Simple Features","text":"Package sf plots projected maps native projection, meaning easting northing mapped linearly x y axis, keeping aspect ratio 1 (one unit east equals one unit north). geographic data, coordinates constitute degrees longitude latitude, chooses equirectangular projection (also called equidistant circular), center plot (bounding box) one unit north equals one unit east. Proj.4 also lets project data projection, plot , apart values along axes, otherwise identical ","code":"plot(st_geometry(nc), axes = TRUE) lat_ts = mean(st_bbox(nc)[c(2,4)]) # latitude of true scale eqc = st_transform(nc, paste0(\"+proj=eqc +lat_ts=\", lat_ts)) plot(st_geometry(eqc), axes = TRUE)"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"graticules","dir":"Articles","previous_headings":"","what":"Graticules","title":"5. Plotting Simple Features","text":"Graticules grid lines along equal longitude (meridians) latitude (parallels) , depending projection used, often plot curved lines map, giving reference terms longitude latitude. sf::st_graticule() tries create graticule grid arbitrary maps. infinitely many projections, likely many cases succeed well, examples welcomed sf issues. following plot shows graticule geometry , see graticule reach plot boundaries (cut bounding box usa), axes show projected coordinates. compute graticule within plotting function, know plotting region can compute plot margins, add axes graticule units: can also pass crs object graticule obtain graticule datum different default (WGS84). st_graticule() takes parameters, can pass object returned graticule parameter plot, get finer control: still doesn’t look great – completely controlling plotting region base plots easy.","code":"library(maps) usa = st_as_sf(map('usa', plot = FALSE, fill = TRUE)) laea = st_crs(\"+proj=laea +lat_0=30 +lon_0=-95\") # Lambert equal area usa <- st_transform(usa, laea) g = st_graticule(usa) plot(st_geometry(g), axes = TRUE) plot(usa, graticule = TRUE, key.pos = NULL, axes = TRUE) g = st_graticule(usa, lon = seq(-130,-65,5)) plot(usa, graticule = g, key.pos = NULL, axes = TRUE, xlim = st_bbox(usa)[c(1,3)], ylim = st_bbox(usa)[c(2,4)], xaxs = \"i\", yaxs = \"i\")"},{"path":[]},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"grid-st_as_grob","dir":"Articles","previous_headings":"Plotting sf objects with other packages","what":"grid: st_as_grob","title":"5. Plotting Simple Features","text":"Package sf provides number methods st_as_grob(): convert simple simple feature objects grob (“graphics objects”) objects; grobs graphic primitives grid plotting package. methods can used plotting packages build grid, ggplot2 (uses geom_sf()) tmap. addition, st_viewport() can used set grid viewport sf object, aspect ratio similar plot.sf().","code":"methods(st_as_grob) ## [1] st_as_grob.CIRCULARSTRING* st_as_grob.COMPOUNDCURVE* ## [3] st_as_grob.CURVEPOLYGON* st_as_grob.GEOMETRYCOLLECTION* ## [5] st_as_grob.LINESTRING* st_as_grob.MULTILINESTRING* ## [7] st_as_grob.MULTIPOINT* st_as_grob.MULTIPOLYGON* ## [9] st_as_grob.MULTISURFACE* st_as_grob.POINT* ## [11] st_as_grob.POLYGON* st_as_grob.sfc* ## [13] st_as_grob.sfc_CIRCULARSTRING* st_as_grob.sfc_LINESTRING* ## [15] st_as_grob.sfc_MULTILINESTRING* st_as_grob.sfc_MULTIPOINT* ## [17] st_as_grob.sfc_MULTIPOLYGON* st_as_grob.sfc_POINT* ## [19] st_as_grob.sfc_POLYGON* ## see '?methods' for accessing help and source code"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"ggplot2","dir":"Articles","previous_headings":"Plotting sf objects with other packages","what":"ggplot2","title":"5. Plotting Simple Features","text":"contains geom specially simple feature objects, support graticule white lines background using sf::st_graticule(). Support currently good polygons; lines points, mileage may vary. Polygons can colored using aes: sets maps can plotted facet plots rearranging sf object, e.g. ","code":"library(ggplot2) ggplot() + geom_sf(data = usa) ggplot() + geom_sf(data = nc, aes(fill = BIR74)) + scale_y_continuous(breaks = 34:36) library(dplyr) ## ## Attaching package: 'dplyr' ## The following objects are masked from 'package:stats': ## ## filter, lag ## The following objects are masked from 'package:base': ## ## intersect, setdiff, setequal, union library(tidyr) nc2 <- nc %>% select(SID74, SID79, geom) %>% gather(VAR, SID, -geom) ggplot() + geom_sf(data = nc2, aes(fill = SID)) + facet_wrap(~VAR, ncol = 1) + scale_y_continuous(breaks = 34:36)"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"mapview","dir":"Articles","previous_headings":"Plotting sf objects with other packages","what":"mapview","title":"5. Plotting Simple Features","text":"Package mapview creates interactive maps html pages, using package leaflet workhorse. Extensive examples found . example obtained gives map interactive: can zoom pan, query features clicking .","code":"library(mapview) mapviewOptions(fgb = FALSE) # needed when creating web pages mapview(nc[\"BIR74\"], col.regions = sf.colors(10), fgb = FALSE)"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"tmap","dir":"Articles","previous_headings":"Plotting sf objects with other packages","what":"tmap","title":"5. Plotting Simple Features","text":"Package tmap another package plotting maps, emphasis production-ready maps. tmap also interactive leaflet maps: Replotting last map non-interactive mode simple : draft version book Elegant informative maps tmap Martijn Tennekes Jakub Nowosad found https://r-tmap.github.io/","code":"library(tmap) qtm(nc) tmap_mode(\"view\") tm_shape(nc) + tm_fill(\"BIR74\", palette = sf.colors(5)) ttm() tmap_last()"},{"path":"https://r-spatial.github.io/sf/articles/sf6.html","id":"what-is-this-epsg-code-all-about","dir":"Articles","previous_headings":"","what":"What is this EPSG code all about?","title":"6. Miscellaneous","text":"EPSG stands maintained, well-understood registry spatial reference systems, maintained International Association Oil & Gas Producers (IOGP). EPSG stands authority, e.g. EPSG:4326 stands spatial reference system ID 4326 maintained EPSG authority. website EPSG registry found epsg.org domain. Using 4326 instead EPSG:4326 allowed (EPSG default authority) latter form, EPSG:4326 better (less ambiguous).","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf6.html","id":"why-should-we-use-ogccrs84-instead-of-epsg4326","dir":"Articles","previous_headings":"","what":"Why should we use OGC:CRS84 instead of EPSG:4326?","title":"6. Miscellaneous","text":"EPSG:4326 formally defines coordinate axes order latitude-longitude, practically data sources software environments use longitude-latitude axis order. OGC:CRS84 equivalent EPSG:4326 except defines coordinate axis order longitude-latitude, removing ambiguity speak. See also st_axis_order()","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf6.html","id":"how-does-sf-deal-with-secondary-geometry-columns","dir":"Articles","previous_headings":"","what":"How does sf deal with secondary geometry columns?","title":"6. Miscellaneous","text":"sf objects can one geometry list-column, always one geometry column considered active, returned st_geometry(). multiple geometry columns, default print methods reports one active: can switch active geometry using st_geometry<- st_set_geometry(), ","code":"library(sf) ## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE demo(nc, ask = FALSE, echo = FALSE) nc$geom2 = st_centroid(st_geometry(nc)) print(nc, n = 2) ## Simple feature collection with 100 features and 14 fields ## Attribute-geometry relationships: aggregate (8), identity (6), NA's (1) ## Active geometry column: geom ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 ## Geodetic CRS: NAD27 ## First 2 features: ## AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 ## 1 0.114 1.442 1825 1825 Ashe 37009 37009 5 1091 1 ## 2 0.061 1.231 1827 1827 Alleghany 37005 37005 3 487 0 ## NWBIR74 BIR79 SID79 NWBIR79 geom ## 1 10 1364 0 19 MULTIPOLYGON (((-81.47276 3... ## 2 10 542 3 12 MULTIPOLYGON (((-81.23989 3... ## geom2 ## 1 POINT (-81.49823 36.4314) ## 2 POINT (-81.12513 36.49111) plot(st_geometry(nc)) st_geometry(nc) <- \"geom2\" plot(st_geometry(nc))"},{"path":"https://r-spatial.github.io/sf/articles/sf6.html","id":"does-st_simplify-preserve-topology","dir":"Articles","previous_headings":"","what":"Does st_simplify preserve topology?","title":"6. Miscellaneous","text":"st_simplify() topology-preserving function, level individual feature geometries. means, simply said, applying , polygon still polygon. However two features longer shared boundary, applying st_simplify object guarantee resulting object two polygons still boundary common, since simplification done independently, feature geometry.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf6.html","id":"why-do-my-dplyr-verbs-not-work-for-sf-objects","dir":"Articles","previous_headings":"","what":"Why do my dplyr verbs not work for sf objects?","title":"6. Miscellaneous","text":"! However, many developers like write scripts never load packages address functions sf:: prefix, works moment dplyr generic like select sf object needed: one call dplyr::select (won’t know search package sf) sf::select (doesn’t exist)? Neither works. One case simply load sf, e.g. ","code":"i = sf::st_intersects(sf1, sf2) library(sf)"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"7. Spherical geometry in sf using s2geometry","text":"vignette describes spherical geometry implies, package sf uses s2geometry library (http://s2geometry.io) geometrical measures, predicates transformations. sf loaded, report whether s2 used; can switched (resorting flat space geometry) sf_use_s2(FALSE). package’s functions start s2_ way sf function names start st_. sf functions automatically use s2 functions working ellipsoidal coordinates; case, e.g. st_voronoi(), warning like emitted.","code":"library(sf) ## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE ## ## Attaching package: 'sf' ## The following object is masked from 'package:lwgeom': ## ## st_perimeter library(s2) Warning message: In st_voronoi.sfc(st_geometry(x), st_sfc(envelope), dTolerance, : st_voronoi does not correctly triangulate longitude/latitude data"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"projected-and-geographic-coordinates","dir":"Articles","previous_headings":"","what":"Projected and geographic coordinates","title":"7. Spherical geometry in sf using s2geometry","text":"Spatial coordinates either refer projected (Cartesian) coordinates, meaning associated points flat space, unprojected geographic coordinates, refer angles (latitude, longitude) pointing locations sphere (ellipsoid). flat space also referred R2R^2, sphere S2S^2 Package sf implements simple features, standard point, line, polygon geometries geometries built points (nodes) connected straight lines (edges). simple feature standard say much suitability dealing geographic coordinates, topological relational system builds upon (DE9-IM) refer R2R^2, two-dimensional flat space. Yet, data routinely served exchanged using geographic coordinates. Using software assumes R2R^2, flat space may work problems, although sf version 0.9-x functions place spherical/ellipsoidal computations (package lwgeom, computing area, length, distance, segmentizing), also happily warned user R2R^2, flat computations coordinates messages like hinting responsibility user take care potential problems. however leaves ambiguities, e.g. whether LINESTRING(-179 0,179 0) passes POINT(0 0), passes POINT(180 0) whether straight line, cutting Earth’s surface, curved line following Earth’s surface Starting sf version 1.0, provide spatial object geographical coordinate reference system, sf uses new package s2 (Dunnington, Pebesma, Rubak 2020) spherical geometry, functions computing pretty much measures, predicates transformations sphere. means: hodge-podge functions working R2R^2, annoying messages, ellipsoid considerable speed increase functions computations ellipsoid (considered accurate, also slower) s2 package really wrapper around C++ s2geometry library written Google, used many products (e.g. Google Maps, Google Earth Engine, Bigquery GIS) translated several programming languages. projected coordinates sf continues work R2R^2 .","code":"although coordinates are longitude/latitude, st_intersects assumes that they are planar"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"fundamental-differences","dir":"Articles","previous_headings":"","what":"Fundamental differences","title":"7. Spherical geometry in sf using s2geometry","text":"Compared geometry R2R^2, DE9-IM, s2 package brings fundamentally new concepts, discussed first.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"polygons-on-s2-divide-the-sphere-in-two-parts","dir":"Articles","previous_headings":"Fundamental differences","what":"Polygons on S2S^2 divide the sphere in two parts","title":"7. Spherical geometry in sf using s2geometry","text":"sphere (S2S^2), polygon defines two areas; following exterior ring, need define inside, definition left side enclosing edges. also means can flip polygon (inverting edge order) obtain part globe, addition empty polygon (empty set) can full polygon (entire globe). Simple feature geometries obey ring direction : exterior rings counter clockwise, interior (hole) rings clockwise, sense obsolete difference exterior ring interior rings defined position (exterior, followed zero interior). sf::read_sf() argument check_ring_dir checks, corrects, ring directions many (legacy) datasets wrong ring directions. wrong ring directions, many things still work. S2S^2, ring direction essential. reason, st_as_s2 argument oriented = FALSE, check correct ring directions, assuming exterior rings occupy area smaller half globe: default conversion sf s2 uses oriented = FALSE, get example oceans computed difference full polygon representing entire globe, countries, shown orthographic projection: (Note printing POLYGON FULL valid WKT according simple feature standard, include .) can now calculate proportion Earth’s surface covered oceans:","code":"nc = read_sf(system.file(\"gpkg/nc.gpkg\", package=\"sf\")) # wrong ring directions s2_area(st_as_s2(nc, oriented = FALSE)[1:3]) # corrects ring direction, correct area: ## [1] 1137107793 610916077 1423145355 s2_area(st_as_s2(nc, oriented = TRUE)[1:3]) # wrong direction: Earth's surface minus area ## [1] 5.100649e+14 5.100655e+14 5.100646e+14 nc = read_sf(system.file(\"gpkg/nc.gpkg\", package=\"sf\"), check_ring_dir = TRUE) s2_area(st_as_s2(nc, oriented = TRUE)[1:3]) # no second correction needed here: ## [1] 1137107793 610916077 1423145355 all(units::drop_units(st_area(nc)) == s2_area(st_as_s2(nc, oriented = FALSE))) ## [1] TRUE g = st_as_sfc(\"POLYGON FULL\", crs = 'EPSG:4326') g ## Geometry set for 1 feature ## Geometry type: POLYGON ## Dimension: XY ## Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 ## Geodetic CRS: WGS 84 ## POLYGON FULL options(s2_oriented = TRUE) # don't change orientation from here on co = st_as_sf(s2_data_countries()) oc = st_difference(g, st_union(co)) # oceans b = st_buffer(st_as_sfc(\"POINT(-30 52)\", crs = 'EPSG:4326'), 9800000) # visible half i = st_intersection(b, oc) # visible ocean plot(st_transform(i, \"+proj=ortho +lat_0=52 +lon_0=-30\"), col = 'blue') st_area(oc) / st_area(g) ## 0.711301 [1]"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"semi-open-polygon-boundaries","dir":"Articles","previous_headings":"Fundamental differences","what":"Semi-open polygon boundaries","title":"7. Spherical geometry in sf using s2geometry","text":"Polygons s2geometry can CLOSED: contain boundaries, point boundary intersects polygon OPEN: contain boundaries, points boundary intersect polygon SEMI-OPEN: contain part boundaries, boundary non-overlapping polygons contained one polygon. principle DE9-IM model deals interior, boundary exterior, intersection predicates sensitive (difference contains covers boundaries). DE9-IM however uniquely assign points polygons polygons form polygon coverage (overlaps, shared boundaries). means count points polygon, points fall shared polygon boundaries, either miss (contains) count double (covers, intersects); might lead bias require post-processing. Using SEMI-OPEN non-overlapping polygons guarantees every point assigned maximally one polygon intersection. corresponds e.g. handled grid (raster) coverage, every grid cell (typically) contains upper-left corner upper left sides.","code":"a = st_as_sfc(\"POINT(0 0)\", crs = 'EPSG:4326') b = st_as_sfc(\"POLYGON((0 0,1 0,1 1,0 1,0 0))\", crs = 'EPSG:4326') st_intersects(a, b, model = \"open\") ## Sparse geometry binary predicate list of length 1, where the predicate ## was `intersects' ## 1: (empty) st_intersects(a, b, model = \"closed\") ## Sparse geometry binary predicate list of length 1, where the predicate ## was `intersects' ## 1: 1 st_intersects(a, b, model = \"semi-open\") # a toss ## Sparse geometry binary predicate list of length 1, where the predicate ## was `intersects' ## 1: (empty) st_intersects(a, b) # default: closed ## Sparse geometry binary predicate list of length 1, where the predicate ## was `intersects' ## 1: 1"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"bounding-cap-bounding-rectangle","dir":"Articles","previous_headings":"Fundamental differences","what":"Bounding cap, bounding rectangle","title":"7. Spherical geometry in sf using s2geometry","text":"Computing minimum maximum values coordinate ranges, sf st_bbox(), limited value spherical coordinates due spherical space, area covered necessarily covered coordinate range. Two examples: small regions covering antimeridian (longitude +/- 180) end huge longitude range, doesn’t make clear antimeridian spanned regions including pole end latitude range extending +/- 90 S2 two alternatives: bounding cap bounding rectangle: cap reports bounding cap (circle) mid point (lat, lng) angle around point. bounding rectangle reports _lo _hi bounds lat lng coordinates. Note Fiji, lng_lo higher lng_hi indicates region covers (crosses) antimeridian.","code":"fiji = s2_data_countries(\"Fiji\") aa = s2_data_countries(\"Antarctica\") s2_bounds_cap(fiji) ## lng lat angle ## 1 178.7459 -17.15444 1.801369 s2_bounds_rect(c(fiji,aa)) ## lng_lo lat_lo lng_hi lat_hi ## 1 177.285 -18.28799 -179.7933 -16.02088 ## 2 -180.000 -90.00000 180.0000 -63.27066"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"switching-between-s2-and-geos","dir":"Articles","previous_headings":"","what":"Switching between S2 and GEOS","title":"7. Spherical geometry in sf using s2geometry","text":"two-dimensional R2R^2 library formerly used sf GEOS, sf can instrumented use GEOS s2. First ask s2 used default: can switch (use GEOS) switch (use s2) ","code":"sf_use_s2() ## [1] TRUE sf_use_s2(FALSE) ## Spherical geometry (s2) switched off sf_use_s2(TRUE) ## Spherical geometry (s2) switched on"},{"path":[]},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"area","dir":"Articles","previous_headings":"Measures","what":"Area","title":"7. Spherical geometry in sf using s2geometry","text":"","code":"options(s2_oriented = FALSE) # correct orientation from here on library(sf) library(units) ## udunits database from /usr/share/xml/udunits/udunits2.xml nc = read_sf(system.file(\"gpkg/nc.gpkg\", package=\"sf\")) sf_use_s2(TRUE) a1 = st_area(nc) sf_use_s2(FALSE) ## Spherical geometry (s2) switched off a2 = st_area(nc) plot(a1, a2) abline(0, 1) summary((a1 - a2)/a1) ## Min. 1st Qu. Median Mean 3rd Qu. Max. ## -2.638e-04 -1.650e-04 -7.133e-05 -6.448e-05 1.598e-05 2.817e-04"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"length","dir":"Articles","previous_headings":"Measures","what":"Length","title":"7. Spherical geometry in sf using s2geometry","text":"","code":"nc_ls = st_cast(nc, \"MULTILINESTRING\") sf_use_s2(TRUE) ## Spherical geometry (s2) switched on l1 = st_length(nc_ls) sf_use_s2(FALSE) ## Spherical geometry (s2) switched off l2 = st_length(nc_ls) plot(l1 , l2) abline(0, 1) summary((l1-l2)/l1) ## Min. 1st Qu. Median Mean 3rd Qu. Max. ## -0.0012301 -0.0004396 -0.0001258 -0.0001123 0.0001742 0.0009660"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"distances","dir":"Articles","previous_headings":"Measures","what":"Distances","title":"7. Spherical geometry in sf using s2geometry","text":"","code":"sf_use_s2(TRUE) ## Spherical geometry (s2) switched on d1 = st_distance(nc, nc[1:10,]) sf_use_s2(FALSE) ## Spherical geometry (s2) switched off d2 = st_distance(nc, nc[1:10,]) plot(as.vector(d1), as.vector(d2)) abline(0, 1) summary(as.vector(d1)-as.vector(d2)) ## Min. 1st Qu. Median Mean 3rd Qu. Max. ## -1424.5 -613.2 -236.5 -319.5 0.0 460.1"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"predicates","dir":"Articles","previous_headings":"","what":"Predicates","title":"7. Spherical geometry in sf using s2geometry","text":"unary binary predicates available s2, except st_relate() pattern. addition, using s2 predicates, depending model, intersections neighbours reported model closed (default):","code":"sf_use_s2(TRUE) ## Spherical geometry (s2) switched on st_intersects(nc[1:3,], nc[1:3,]) # self-intersections + neighbours ## Sparse geometry binary predicate list of length 3, where the predicate ## was `intersects' ## 1: 1, 2 ## 2: 1, 2, 3 ## 3: 2, 3 sf_use_s2(TRUE) st_intersects(nc[1:3,], nc[1:3,], model = \"semi-open\") # only self-intersections ## Sparse geometry binary predicate list of length 3, where the predicate ## was `intersects' ## 1: 1 ## 2: 2 ## 3: 3"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"transformations","dir":"Articles","previous_headings":"","what":"Transformations","title":"7. Spherical geometry in sf using s2geometry","text":"st_intersection(), st_union(), st_difference(), st_sym_difference() available s2 equivalents. N-ary intersection difference (yet) present; cascaded union present; unioning feature work s2.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"buffers","dir":"Articles","previous_headings":"Transformations","what":"Buffers","title":"7. Spherical geometry in sf using s2geometry","text":"Buffers can calculated features geographic coordinates follows, using unprojected object representing UK example: plots show can adjust level spatial precision results s2 buffer operations max_cells argument, set 1000 default. Deciding appropriate value balance excessive detail increasing computational resources (represented uk_buffer2, bottom left) excessive simplification (bottom right). Note buffers created s2 always follow s2 cell boundaries, never smooth. Hence, choosing large number max_cells leads seemingly smooth , zoomed , complex buffers. achieve similar result first transform result use sf::st_buffer(). simple benchmark shows computational efficiency s2 geometry engine comparison transforming creating buffers: result previous benchmarks emphasizes point trade-offs geographic resolution computational resources, something web developers working geographic services Google Maps understand well. case default setting 1000 cells, runs slightly faster default transform -> buffer workflow, probably appropriate given low resolution input geometry representing UK.","code":"uk = s2_data_countries(\"United Kingdom\") class(uk) ## [1] \"s2_geography\" \"wk_vctr\" uk_sfc = st_as_sfc(uk) uk_buffer = st_buffer(uk_sfc, dist = 20000) uk_buffer2 = st_buffer(uk_sfc, dist = 20000, max_cells = 10000) uk_buffer3 = st_buffer(uk_sfc, dist = 20000, max_cells = 100) class(uk_buffer) ## [1] \"sfc_MULTIPOLYGON\" \"sfc\" plot(uk_sfc) plot(uk_buffer) plot(uk_buffer2) plot(uk_buffer3) uk_sf = st_as_sf(uk) # the sf way system.time({ uk_projected = st_transform(uk_sfc, 27700) uk_buffer_sf = st_buffer(uk_projected, dist = 20000) }) ## user system elapsed ## 0.022 0.000 0.022 # sf way with few than the 30 segments in the buffer system.time({ uk_projected = st_transform(uk_sfc, 27700) uk_buffer_sf2 = st_buffer(uk_projected, dist = 20000, nQuadSegs = 4) }) ## user system elapsed ## 0.008 0.000 0.008 # s2 with default cell size system.time({ uk_buffer = s2_buffer_cells(uk, distance = 20000) }) ## user system elapsed ## 0.03 0.00 0.03 # s2 with 10000 cells system.time({ uk_buffer2 = s2_buffer_cells(uk, distance = 20000, max_cells = 10000) }) ## user system elapsed ## 0.282 0.000 0.282 # s2 with 100 cells system.time({ uk_buffer2 = s2_buffer_cells(uk, distance = 20000, max_cells = 100) }) ## user system elapsed ## 0.004 0.000 0.004"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"st_buffer-or-st_is_within_distance","dir":"Articles","previous_headings":"Transformations","what":"st_buffer or st_is_within_distance?","title":"7. Spherical geometry in sf using s2geometry","text":"discussed sf issue tracker, deciding workflows selecting appropriate levels level geographic resolution can iterative process. st_buffer() powered GEOS, R2R^2 data, smooth (nearly) exact. st_buffer() powered S2S^2 rougher, complex, non-smooth, may need tuning. common pattern st_buffer() used : compute buffers around set features x (points, lines, polygons) within buffers, find occurrences spatial variable y aggregate (e.g. count points, average raster variable like precipitation population density) work aggregated values (discard buffer) case, working geographic coordinates, may pay compute buffers, instead directly work st_is_within_distance() select, feature x, features y within certain distance d x. S2S^2 version function uses spatial indexes, fast large datasets.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"references","dir":"Articles","previous_headings":"Transformations","what":"References","title":"7. Spherical geometry in sf using s2geometry","text":"Dewey Dunnington, Edzer Pebesma Ege Rubak, 2020. s2: Spherical Geometry Operators Using S2S^2 Geometry Library. https://r-spatial.github.io/s2/, https://github.com/r-spatial/s2","code":""},{"path":"https://r-spatial.github.io/sf/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Edzer Pebesma. Author, maintainer. Roger Bivand. Contributor. Etienne Racine. Contributor. Michael Sumner. Contributor. Ian Cook. Contributor. Tim Keitt. Contributor. Robin Lovelace. Contributor. Hadley Wickham. Contributor. Jeroen Ooms. Contributor. Kirill Müller. Contributor. Thomas Lin Pedersen. Contributor. Dan Baston. Contributor. Dewey Dunnington. Contributor.","code":""},{"path":"https://r-spatial.github.io/sf/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Pebesma, E., & Bivand, R. (2023). Spatial Data Science: Applications R. Chapman Hall/CRC. https://doi.org/10.1201/9780429459016 Pebesma, E., 2018. Simple Features R: Standardized Support Spatial Vector Data. R Journal 10 (1), 439-446, https://doi.org/10.32614/RJ-2018-009","code":"@Book{, author = {Edzer Pebesma and Roger Bivand}, title = {{Spatial Data Science: With applications in R}}, year = {2023}, publisher = {{Chapman and Hall/CRC}}, url = {https://r-spatial.org/book/}, doi = {10.1201/9780429459016}, } @Article{, author = {Edzer Pebesma}, title = {{Simple Features for R: Standardized Support for Spatial Vector Data}}, year = {2018}, journal = {{The R Journal}}, doi = {10.32614/RJ-2018-009}, url = {https://doi.org/10.32614/RJ-2018-009}, pages = {439--446}, volume = {10}, number = {1}, }"},{"path":"https://r-spatial.github.io/sf/index.html","id":"simple-features-for-r","dir":"","previous_headings":"","what":"Simple Features for R","title":"Simple Features for R","text":"package provides simple features access R. Blogs, links • Cheatsheet • Installing • Contributing • Acknowledgment • cite Package sf: represents simple features records data.frame tibble geometry list-column represents natively R 17 simple feature types dimensions (XY, XYZ, XYM, XYZM) interfaces GEOS geometrical operations projected coordinates, (R package s2) s2geometry geometrical operations ellipsoidal coordinates interfaces GDAL, supporting driver options, Date POSIXct list-columns interfaces PRØJ coordinate reference system conversion transformation uses well-known-binary serialisations written C++/Rcpp fast /O GDAL GEOS reads writes spatial databases PostGIS using DBI lwgeom selected liblwgeom/PostGIS functions stars raster data, raster vector data cubes (spatial time series) sfnetworks geospatial network data (Illustration (c) 2018 Allison Horst)","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"books-journal-articles-blogs-presentations-vignettes-sp-sf-wiki","dir":"","previous_headings":"","what":"Books, journal articles, blogs, presentations, vignettes, sp-sf wiki","title":"Simple Features for R","text":"open access R Journal article summarizes package two books: Spatial Data Science: applications R, Geocomputation R package vignettes: first, second, third, fourth, fifth, sixth, seventh blog posts: first, second, third, fourth original R Consortium ISC proposal, R Consortium blog post presentations: rstudio::conf 2018 (video), UseR! 2016 wiki page describing sp-sf migration","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"cheatsheet","dir":"","previous_headings":"","what":"Cheatsheet","title":"Simple Features for R","text":"CC 4.0 Ryan Garnett","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"installing","dir":"","previous_headings":"","what":"Installing","title":"Simple Features for R","text":"Install either CRAN : install binary packages Windows MacOS, unless configured R tries install source packages; case, see . Install development versions GitHub :","code":"install.packages(\"sf\") library(remotes) install_github(\"r-spatial/sf\")"},{"path":"https://r-spatial.github.io/sf/index.html","id":"windows","dir":"","previous_headings":"Installing","what":"Windows","title":"Simple Features for R","text":"Installing sf source works Windows Rtools installed.","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"macos","dir":"","previous_headings":"Installing","what":"MacOS","title":"Simple Features for R","text":"MacOS users strongly encouraged install sf binary packages CRAN, unless familiar compilers, linking, C++ source code, homebrew. easiest way install gdal using Homebrew. Recent versions Homebrew include full-featured --date gdal formula, installs proj gdal time: gdal installed, able install sf package source R. current version proj homebrew, installation requires additional configuration: development version: using sf rgdal together, necessary install rgdal source using configuration: Alternatively, instructions explain install gdal using kyngchaos frameworks. Mac OS 11 Big Sur source install instruction, see ","code":"brew install pkg-config brew install gdal install.packages(\"sf\", type = \"source\", configure.args = \"--with-proj-lib=$(brew --prefix)/lib/\") library(remotes) install_github(\"r-spatial/sf\", configure.args = \"--with-proj-lib=$(brew --prefix)/lib/\") install.packages(\"rgdal\", type = \"source\", configure.args = c(\"--with-proj-lib=$(brew --prefix)/lib/\", \"--with-proj-include=$(brew --prefix)/include/\"))"},{"path":"https://r-spatial.github.io/sf/index.html","id":"linux","dir":"","previous_headings":"Installing","what":"Linux","title":"Simple Features for R","text":"Unix-alikes, GDAL (>= 2.0.1), GEOS (>= 3.4.0) Proj.4 (>= 4.8.0) required.","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"ubuntu","dir":"","previous_headings":"Installing > Linux","what":"Ubuntu","title":"Simple Features for R","text":"Dependencies recent versions Ubuntu (18.04 later) available official repositories; can install : However, get --date versions dependencies GDAL, recommend adding ubuntugis-unstable PPA package repositories installing follows: Adding PPA required installing sf older versions Ubuntu (e.g. Xenial). Another option, advanced users, install dependencies source; see e.g. older Travis config file hints.","code":"apt-get -y update && apt-get install -y libudunits2-dev libgdal-dev libgeos-dev libproj-dev sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable sudo apt-get update sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev libsqlite0-dev"},{"path":"https://r-spatial.github.io/sf/index.html","id":"fedora","dir":"","previous_headings":"Installing > Linux","what":"Fedora","title":"Simple Features for R","text":"following command installs required dependencies:","code":"sudo dnf install gdal-devel proj-devel geos-devel sqlite-devel udunits2-devel"},{"path":"https://r-spatial.github.io/sf/index.html","id":"arch","dir":"","previous_headings":"Installing > Linux","what":"Arch","title":"Simple Features for R","text":"Get gdal, proj, geos podofo main repos, udunits AUR:","code":"pacman -S gdal proj geos arrow podofo yay/pacaur/yaourt/whatever -S udunits"},{"path":"https://r-spatial.github.io/sf/index.html","id":"renv-or-conda","dir":"","previous_headings":"Installing > Linux","what":"renv or conda","title":"Simple Features for R","text":"several reports sf fails install source package R used renv, R installed conda environment. experience , please raise issue , try sort renv developers conda maintainers, try use binary installs sf package, e.g. r2u, Posit package manager","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"other","dir":"","previous_headings":"Installing > Linux","what":"Other","title":"Simple Features for R","text":"install Debian, rocker geospatial Dockerfiles may helpful. Ubuntu Dockerfiles found .","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"multiple-gdal-geos-andor-proj-versions-on-your-system","dir":"","previous_headings":"Installing","what":"Multiple GDAL, GEOS and/or PROJ versions on your system","title":"Simple Features for R","text":"use dynamic linking (installation source) multiple versions libraries installed (e.g. one ubuntugis-unstable, another installed source /usr/local/lib) general work, even setting LD_LIBRARY_PATH manually. See reason .","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"lwgeom","dir":"","previous_headings":"Installing","what":"lwgeom","title":"Simple Features for R","text":"Functions methods require liblwgeom, including ellipsoidal (spherical Euclidean) metrics (area, distances), provide used lwgeom, also CRAN.","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"contributing","dir":"","previous_headings":"","what":"Contributing","title":"Simple Features for R","text":"Contributions sorts welcome, issues pull requests preferred ways sharing . contributing pull requests, please adhere package style (package code use = rather <-; don’t change indentation; tab stops 4 spaces preferred). project released Contributor Code Conduct. participating project, agree abide terms.","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"how-to-cite","dir":"","previous_headings":"","what":"How to cite","title":"Simple Features for R","text":"Package sf can cited : Edzer Pebesma, 2018. Simple Features R: Standardized Support Spatial Vector Data. R Journal 10:1, 439-446. Pebesma, E.; Bivand, R. (2023). Spatial Data Science: Applications R (1st ed.). 314 pages. Chapman Hall/CRC.","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"acknowledgment","dir":"","previous_headings":"","what":"Acknowledgment","title":"Simple Features for R","text":"project gratefully acknowledges financial support ","code":""},{"path":"https://r-spatial.github.io/sf/reference/Ops.html","id":null,"dir":"Reference","previous_headings":"","what":"Arithmetic operators for simple feature geometries — Ops","title":"Arithmetic operators for simple feature geometries — Ops","text":"Arithmetic operators simple feature geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/Ops.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Arithmetic operators for simple feature geometries — Ops","text":"","code":"# S3 method for class 'sfg' Ops(e1, e2) # S3 method for class 'sfc' Ops(e1, e2)"},{"path":"https://r-spatial.github.io/sf/reference/Ops.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Arithmetic operators for simple feature geometries — Ops","text":"e1 object class sfg sfc e2 numeric, object class sfg; case e1 class sfc also object class sfc allowed","code":""},{"path":"https://r-spatial.github.io/sf/reference/Ops.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Arithmetic operators for simple feature geometries — Ops","text":"object class sfg","code":""},{"path":"https://r-spatial.github.io/sf/reference/Ops.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Arithmetic operators for simple feature geometries — Ops","text":"case e2 numeric, +, -, *, /, %% %/% add, subtract, multiply, divide, modulo, integer-divide e2. case e2 n x n matrix, * matrix-multiplies / multiplies inverse. e2 sfg object, |, /, & %/% result geometric union, difference, intersection symmetric difference respectively, == != return geometric ()equality, using st_equals. e2 sfg sfc object, operations + - POINT geometries. e1 class sfc, e2 length 2 numeric, considered two-dimensional point (needed repeated ) operations + -, cases individual numbers repeated; see commented examples. reported (https://github.com/r-spatial/sf/issues/2067) certain ATLAS versions result invalid polygons, final point ring longer equal first point. case, setting precisions st_set_precision may help.","code":""},{"path":"https://r-spatial.github.io/sf/reference/Ops.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Arithmetic operators for simple feature geometries — Ops","text":"","code":"st_point(c(1,2,3)) + 4 #> POINT Z (5 6 7) st_point(c(1,2,3)) * 3 + 4 #> POINT Z (7 10 13) m = matrix(0, 2, 2) diag(m) = c(1, 3) # affine: st_point(c(1,2)) * m + c(2,5) #> POINT (3 11) # world in 0-360 range: if (require(maps, quietly = TRUE)) { w = st_as_sf(map('world', plot = FALSE, fill = TRUE)) w2 = (st_geometry(w) + c(360,90)) %% c(360) - c(0,90) w3 = st_wrap_dateline(st_set_crs(w2 - c(180,0), 4326)) + c(180,0) plot(st_set_crs(w3, 4326), axes = TRUE) } #> Warning: GDAL Error 1: TopologyException: Input geom 0 is invalid: Self-intersection at 16.123485685639235 -84.347832314219417 #> Warning: GDAL Error 1: TopologyException: Input geom 0 is invalid: Self-intersection at 16.123485685639235 -84.347832314219417 (mp <- st_point(c(1,2)) + st_point(c(3,4))) # MULTIPOINT (1 2, 3 4) #> POINT (4 6) mp - st_point(c(3,4)) # POINT (1 2) #> POINT (1 2) opar = par(mfrow = c(2,2), mar = c(0, 0, 1, 0)) a = st_buffer(st_point(c(0,0)), 2) b = a + c(2, 0) p = function(m) { plot(c(a,b)); plot(eval(parse(text=m)), col=grey(.9), add = TRUE); title(m) } o = lapply(c('a | b', 'a / b', 'a & b', 'a %/% b'), p) par(opar) sfc = st_sfc(st_point(0:1), st_point(2:3)) sfc + c(2,3) # added to EACH geometry #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 2 ymin: 4 xmax: 4 ymax: 6 #> CRS: NA #> POINT (2 4) #> POINT (4 6) sfc * c(2,3) # first geometry multiplied by 2, second by 3 #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 2 xmax: 6 ymax: 9 #> CRS: NA #> POINT (0 2) #> POINT (6 9) nc = st_transform(st_read(system.file(\"gpkg/nc.gpkg\", package=\"sf\")), 32119) # nc state plane, m #> Reading layer `nc.gpkg' from data source #> `/home/runner/work/_temp/Library/sf/gpkg/nc.gpkg' using driver `GPKG' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 b = st_buffer(st_centroid(st_union(nc)), units::set_units(50, km)) # shoot a hole in nc: plot(st_geometry(nc) / b, col = grey(.9))"},{"path":"https://r-spatial.github.io/sf/reference/aggregate.sf.html","id":null,"dir":"Reference","previous_headings":"","what":"aggregate an sf object — aggregate.sf","title":"aggregate an sf object — aggregate.sf","text":"aggregate sf object, possibly union-ing geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/aggregate.sf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"aggregate an sf object — aggregate.sf","text":"","code":"# S3 method for class 'sf' aggregate( x, by, FUN, ..., do_union = TRUE, simplify = TRUE, join = st_intersects )"},{"path":"https://r-spatial.github.io/sf/reference/aggregate.sf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"aggregate an sf object — aggregate.sf","text":"x object class sf either list grouping vectors length equal nrow(x) (see aggregate), object class sf sfc geometries used generate groupings, using binary predicate specified argument join FUN function passed aggregate, case ids specified attributes need grouped ... arguments passed FUN do_union logical; grouped geometries unioned using st_union? See details. simplify logical; see aggregate join logical spatial predicate function use simple features object geometry; see st_join","code":""},{"path":"https://r-spatial.github.io/sf/reference/aggregate.sf.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"aggregate an sf object — aggregate.sf","text":"sf object aggregated attributes geometries; additional grouping variables names names(ids) named Group.ids[[]]; see aggregate.","code":""},{"path":"https://r-spatial.github.io/sf/reference/aggregate.sf.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"aggregate an sf object — aggregate.sf","text":"case do_union FALSE, aggregate simply combine geometries using c.sfg. polygons sharing boundary combined, leads geometries invalid; see https://github.com/r-spatial/sf/issues/681.","code":""},{"path":"https://r-spatial.github.io/sf/reference/aggregate.sf.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"aggregate an sf object — aggregate.sf","text":"work using formula notation involving ~ defined aggregate.","code":""},{"path":"https://r-spatial.github.io/sf/reference/aggregate.sf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"aggregate an sf object — aggregate.sf","text":"","code":"m1 = cbind(c(0, 0, 1, 0), c(0, 1, 1, 0)) m2 = cbind(c(0, 1, 1, 0), c(0, 0, 1, 0)) pol = st_sfc(st_polygon(list(m1)), st_polygon(list(m2))) set.seed(1985) d = data.frame(matrix(runif(15), ncol = 3)) p = st_as_sf(x = d, coords = 1:2) plot(pol) plot(p, add = TRUE) (p_ag1 = aggregate(p, pol, mean)) #> Simple feature collection with 2 features and 1 field #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> X3 geometry #> 1 0.5951766 POLYGON ((0 0, 0 1, 1 1, 0 0)) #> 2 0.2997908 POLYGON ((0 0, 1 0, 1 1, 0 0)) plot(p_ag1) # geometry same as pol # works when x overlaps multiple objects in 'by': p_buff = st_buffer(p, 0.2) plot(p_buff, add = TRUE) (p_ag2 = aggregate(p_buff, pol, mean)) # increased mean of second #> Simple feature collection with 2 features and 1 field #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> X3 geometry #> 1 0.5951766 POLYGON ((0 0, 0 1, 1 1, 0 0)) #> 2 0.5958297 POLYGON ((0 0, 1 0, 1 1, 0 0)) # with non-matching features m3 = cbind(c(0, 0, -0.1, 0), c(0, 0.1, 0.1, 0)) pol = st_sfc(st_polygon(list(m3)), st_polygon(list(m1)), st_polygon(list(m2))) (p_ag3 = aggregate(p, pol, mean)) #> Simple feature collection with 3 features and 1 field #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: -0.1 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> X3 geometry #> 1 NA POLYGON ((0 0, 0 0.1, -0.1 ... #> 2 0.5951766 POLYGON ((0 0, 0 1, 1 1, 0 0)) #> 3 0.2997908 POLYGON ((0 0, 1 0, 1 1, 0 0)) plot(p_ag3) # In case we need to pass an argument to the join function: (p_ag4 = aggregate(p, pol, mean, join = function(x, y) st_is_within_distance(x, y, dist = 0.3))) #> Simple feature collection with 3 features and 1 field #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: -0.1 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> X3 geometry #> 1 NA POLYGON ((0 0, 0 0.1, -0.1 ... #> 2 0.5951766 POLYGON ((0 0, 0 1, 1 1, 0 0)) #> 3 0.5999887 POLYGON ((0 0, 1 0, 1 1, 0 0))"},{"path":"https://r-spatial.github.io/sf/reference/bind.html","id":null,"dir":"Reference","previous_headings":"","what":"Bind rows (features) of sf objects — bind","title":"Bind rows (features) of sf objects — bind","text":"Bind rows (features) sf objects Bind columns (variables) sf objects","code":""},{"path":"https://r-spatial.github.io/sf/reference/bind.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Bind rows (features) of sf objects — bind","text":"","code":"# S3 method for class 'sf' rbind(..., deparse.level = 1) # S3 method for class 'sf' cbind(..., deparse.level = 1, sf_column_name = NULL) st_bind_cols(...)"},{"path":"https://r-spatial.github.io/sf/reference/bind.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Bind rows (features) of sf objects — bind","text":"... objects bind; note rbind cbind methods, objects class sf; see dotsMethods deparse.level integer; see rbind sf_column_name character; specifies active geometry; passed st_sf","code":""},{"path":"https://r-spatial.github.io/sf/reference/bind.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Bind rows (features) of sf objects — bind","text":"cbind called multiple sf objects warns multiple geometry columns present geometry column use specified using argument sf_column_name; see also st_sf.","code":""},{"path":"https://r-spatial.github.io/sf/reference/bind.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Bind rows (features) of sf objects — bind","text":"rbind cbind non-standard method dispatch (see cbind): rbind cbind method sf objects called arguments binded class sf. need cbind e.g. data.frame sf, use data.frame directly use st_sf result, use bind_cols; see examples. st_bind_cols deprecated; use cbind instead.","code":""},{"path":"https://r-spatial.github.io/sf/reference/bind.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Bind rows (features) of sf objects — bind","text":"","code":"crs = st_crs(3857) a = st_sf(a=1, geom = st_sfc(st_point(0:1)), crs = crs) b = st_sf(a=1, geom = st_sfc(st_linestring(matrix(1:4,2))), crs = crs) c = st_sf(a=4, geom = st_sfc(st_multilinestring(list(matrix(1:4,2)))), crs = crs) rbind(a,b,c) #> Simple feature collection with 3 features and 1 field #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 2 ymax: 4 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a geom #> 1 1 POINT (0 1) #> 2 1 LINESTRING (1 3, 2 4) #> 3 4 MULTILINESTRING ((1 3, 2 4)) rbind(a,b) #> Simple feature collection with 2 features and 1 field #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 2 ymax: 4 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a geom #> 1 1 POINT (0 1) #> 2 1 LINESTRING (1 3, 2 4) rbind(a,b) #> Simple feature collection with 2 features and 1 field #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 2 ymax: 4 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a geom #> 1 1 POINT (0 1) #> 2 1 LINESTRING (1 3, 2 4) rbind(b,c) #> Simple feature collection with 2 features and 1 field #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: 1 ymin: 3 xmax: 2 ymax: 4 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a geom #> 1 1 LINESTRING (1 3, 2 4) #> 2 4 MULTILINESTRING ((1 3, 2 4)) cbind(a,b,c) # warns #> Simple feature collection with 1 feature and 3 fields #> Active geometry column: geom #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 0 ymax: 1 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a a.1 a.2 geom geom.1 geom.2 #> 1 1 1 4 POINT (0 1) LINESTRING (1 3, 2 4) MULTILINESTRING ((1 3, 2 4)) if (require(dplyr, quietly = TRUE)) dplyr::bind_cols(a,b) #> #> Attaching package: ‘dplyr’ #> The following objects are masked from ‘package:stats’: #> #> filter, lag #> The following objects are masked from ‘package:base’: #> #> intersect, setdiff, setequal, union #> New names: #> • `a` -> `a...1` #> • `geom` -> `geom...2` #> • `a` -> `a...3` #> • `geom` -> `geom...4` #> a...1 geom...2 a...3 geom...4 #> 1 1 POINT (0 1) 1 LINESTRING (1 3, 2 4) c = st_sf(a=4, geomc = st_sfc(st_multilinestring(list(matrix(1:4,2)))), crs = crs) cbind(a,b,c, sf_column_name = \"geomc\") #> Simple feature collection with 1 feature and 3 fields #> Active geometry column: geomc #> Geometry type: MULTILINESTRING #> Dimension: XY #> Bounding box: xmin: 1 ymin: 3 xmax: 2 ymax: 4 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a a.1 a.2 geom geom.1 geomc #> 1 1 1 4 POINT (0 1) LINESTRING (1 3, 2 4) MULTILINESTRING ((1 3, 2 4)) df = data.frame(x=3) st_sf(data.frame(c, df)) #> Simple feature collection with 1 feature and 2 fields #> Geometry type: MULTILINESTRING #> Dimension: XY #> Bounding box: xmin: 1 ymin: 3 xmax: 2 ymax: 4 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a x geomc #> 1 4 3 MULTILINESTRING ((1 3, 2 4)) if (require(dplyr, quietly = TRUE)) dplyr::bind_cols(c, df) #> Simple feature collection with 1 feature and 2 fields #> Geometry type: MULTILINESTRING #> Dimension: XY #> Bounding box: xmin: 1 ymin: 3 xmax: 2 ymax: 4 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a x geomc #> 1 4 3 MULTILINESTRING ((1 3, 2 4))"},{"path":"https://r-spatial.github.io/sf/reference/coerce-methods.html","id":null,"dir":"Reference","previous_headings":"","what":"Methods to coerce simple features to Spatial* and Spatial*DataFrame objects — as","title":"Methods to coerce simple features to Spatial* and Spatial*DataFrame objects — as","text":"as_Spatial() allows convert sf sfc Spatial*DataFrame Spatial* sp compatibility. can also use (x, \"Spatial\") transform sp objects sf sfc (x, \"sf\").","code":""},{"path":"https://r-spatial.github.io/sf/reference/coerce-methods.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Methods to coerce simple features to Spatial* and Spatial*DataFrame objects — as","text":"","code":"as_Spatial(from, cast = TRUE, IDs = paste0(\"ID\", seq_along(from)))"},{"path":"https://r-spatial.github.io/sf/reference/coerce-methods.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Methods to coerce simple features to Spatial* and Spatial*DataFrame objects — as","text":"object class sf, sfc_POINT, sfc_MULTIPOINT, sfc_LINESTRING, sfc_MULTILINESTRING, sfc_POLYGON, sfc_MULTIPOLYGON. cast logical; TRUE, st_cast() converting, e.g. GEOMETRY objects mix POLYGON MULTIPOLYGON cast MULTIPOLYGON. IDs character vector IDs Spatial* geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/coerce-methods.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Methods to coerce simple features to Spatial* and Spatial*DataFrame objects — as","text":"geometry-object deriving Spatial, appropriate class","code":""},{"path":"https://r-spatial.github.io/sf/reference/coerce-methods.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Methods to coerce simple features to Spatial* and Spatial*DataFrame objects — as","text":"Package sp supports three dimensions POINT MULTIPOINT (SpatialPoint*). geometries must two-dimensional (XY). Dimensions can dropped using st_zm() = \"M\" = \"ZM\". converting simple features (.e., sf objects) Spatial counterpart, use (obj, \"Spatial\")","code":""},{"path":"https://r-spatial.github.io/sf/reference/coerce-methods.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Methods to coerce simple features to Spatial* and Spatial*DataFrame objects — as","text":"","code":"nc <- st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 if (require(sp, quietly = TRUE)) { # convert to SpatialPolygonsDataFrame spdf <- as_Spatial(nc) # identical to spdf <- as(nc, \"Spatial\") # convert to SpatialPolygons as(st_geometry(nc), \"Spatial\") # back to sf as(spdf, \"sf\") } #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 #> First 10 features: #> AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 #> 1 0.114 1.442 1825 1825 Ashe 37009 37009 5 1091 1 #> 2 0.061 1.231 1827 1827 Alleghany 37005 37005 3 487 0 #> 3 0.143 1.630 1828 1828 Surry 37171 37171 86 3188 5 #> 4 0.070 2.968 1831 1831 Currituck 37053 37053 27 508 1 #> 5 0.153 2.206 1832 1832 Northampton 37131 37131 66 1421 9 #> 6 0.097 1.670 1833 1833 Hertford 37091 37091 46 1452 7 #> 7 0.062 1.547 1834 1834 Camden 37029 37029 15 286 0 #> 8 0.091 1.284 1835 1835 Gates 37073 37073 37 420 0 #> 9 0.118 1.421 1836 1836 Warren 37185 37185 93 968 4 #> 10 0.124 1.428 1837 1837 Stokes 37169 37169 85 1612 1 #> NWBIR74 BIR79 SID79 NWBIR79 geometry #> 1 10 1364 0 19 MULTIPOLYGON (((-81.47276 3... #> 2 10 542 3 12 MULTIPOLYGON (((-81.23989 3... #> 3 208 3616 6 260 MULTIPOLYGON (((-80.45634 3... #> 4 123 830 2 145 MULTIPOLYGON (((-76.00897 3... #> 5 1066 1606 3 1197 MULTIPOLYGON (((-77.21767 3... #> 6 954 1838 5 1237 MULTIPOLYGON (((-76.74506 3... #> 7 115 350 2 139 MULTIPOLYGON (((-76.00897 3... #> 8 254 594 2 371 MULTIPOLYGON (((-76.56251 3... #> 9 748 1190 2 844 MULTIPOLYGON (((-78.30876 3... #> 10 160 2038 5 176 MULTIPOLYGON (((-80.02567 3..."},{"path":"https://r-spatial.github.io/sf/reference/dbDataType.html","id":null,"dir":"Reference","previous_headings":"","what":"Determine database type for R vector — dbDataType,PostgreSQLConnection,sf-method","title":"Determine database type for R vector — dbDataType,PostgreSQLConnection,sf-method","text":"Determine database type R vector Determine database type R vector","code":""},{"path":"https://r-spatial.github.io/sf/reference/dbDataType.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Determine database type for R vector — dbDataType,PostgreSQLConnection,sf-method","text":"","code":"# S4 method for class 'PostgreSQLConnection,sf' dbDataType(dbObj, obj) # S4 method for class 'DBIObject,sf' dbDataType(dbObj, obj)"},{"path":"https://r-spatial.github.io/sf/reference/dbDataType.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Determine database type for R vector — dbDataType,PostgreSQLConnection,sf-method","text":"dbObj DBIObject driver connection. obj Object convert","code":""},{"path":"https://r-spatial.github.io/sf/reference/dbWriteTable.html","id":null,"dir":"Reference","previous_headings":"","what":"Write sf object to Database — dbWriteTable,PostgreSQLConnection,character,sf-method","title":"Write sf object to Database — dbWriteTable,PostgreSQLConnection,character,sf-method","text":"Write sf object Database Write sf object Database","code":""},{"path":"https://r-spatial.github.io/sf/reference/dbWriteTable.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Write sf object to Database — dbWriteTable,PostgreSQLConnection,character,sf-method","text":"","code":"# S4 method for class 'PostgreSQLConnection,character,sf' dbWriteTable( conn, name, value, ..., row.names = FALSE, overwrite = FALSE, append = FALSE, field.types = NULL, binary = TRUE ) # S4 method for class 'DBIObject,character,sf' dbWriteTable( conn, name, value, ..., row.names = FALSE, overwrite = FALSE, append = FALSE, field.types = NULL, binary = TRUE )"},{"path":"https://r-spatial.github.io/sf/reference/dbWriteTable.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Write sf object to Database — dbWriteTable,PostgreSQLConnection,character,sf-method","text":"conn DBIObject name character vector names (table names, fields, keywords). value data.frame. ... placeholder future use. row.names Add row.name column, vector length nrow(obj) containing row.names; default FALSE. overwrite try drop table writing; default FALSE. append Append rows existing table; default FALSE. field.types default NULL. Allows override type conversion R PostgreSQL. See dbDataType() details. binary Send geometries serialized Well-Known Binary (WKB); FALSE, uses Well-Known Text (WKT). Defaults TRUE (WKB).","code":""},{"path":"https://r-spatial.github.io/sf/reference/db_drivers.html","id":null,"dir":"Reference","previous_headings":"","what":"Drivers for which update should be TRUE by default — db_drivers","title":"Drivers for which update should be TRUE by default — db_drivers","text":"Drivers update TRUE default","code":""},{"path":"https://r-spatial.github.io/sf/reference/db_drivers.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Drivers for which update should be TRUE by default — db_drivers","text":"","code":"db_drivers"},{"path":"https://r-spatial.github.io/sf/reference/db_drivers.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Drivers for which update should be TRUE by default — db_drivers","text":"object class character length 12.","code":""},{"path":"https://r-spatial.github.io/sf/reference/dot-stop_geos.html","id":null,"dir":"Reference","previous_headings":"","what":"Internal functions — .stop_geos","title":"Internal functions — .stop_geos","text":"Internal functions","code":""},{"path":"https://r-spatial.github.io/sf/reference/dot-stop_geos.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Internal functions — .stop_geos","text":"","code":".stop_geos(msg)"},{"path":"https://r-spatial.github.io/sf/reference/dot-stop_geos.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Internal functions — .stop_geos","text":"msg error message","code":""},{"path":"https://r-spatial.github.io/sf/reference/extension_map.html","id":null,"dir":"Reference","previous_headings":"","what":"Map extension to driver — extension_map","title":"Map extension to driver — extension_map","text":"Map extension driver","code":""},{"path":"https://r-spatial.github.io/sf/reference/extension_map.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Map extension to driver — extension_map","text":"","code":"extension_map"},{"path":"https://r-spatial.github.io/sf/reference/extension_map.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Map extension to driver — extension_map","text":"object class list length 26.","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal.html","id":null,"dir":"Reference","previous_headings":"","what":"functions to interact with gdal not meant to be called directly by users (but e.g. by stars::read_stars) — gdal","title":"functions to interact with gdal not meant to be called directly by users (but e.g. by stars::read_stars) — gdal","text":"functions interact gdal meant called directly users (e.g. stars::read_stars)","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"functions to interact with gdal not meant to be called directly by users (but e.g. by stars::read_stars) — gdal","text":"","code":"gdal_read( x, ..., options = character(0), driver = character(0), read_data = TRUE, NA_value = NA_real_, RasterIO_parameters = list() ) gdal_write( x, ..., file, driver = \"GTiff\", options = character(0), type = \"Float32\", NA_value = NA_real_, geotransform, update = FALSE, scale_offset = c(1, 0) ) gdal_inv_geotransform(gt) gdal_crs(file, options = character(0)) gdal_metadata( file, domain_item = character(0), options = character(0), parse = TRUE ) gdal_subdatasets(file, options = character(0), name = TRUE) gdal_polygonize( x, mask = NULL, file = tempfile(), driver = \"GTiff\", use_integer = TRUE, geotransform, breaks = classInt::classIntervals(na.omit(as.vector(x[[1]])))$brks, use_contours = FALSE, contour_lines = FALSE, connect8 = FALSE, ... ) gdal_rasterize(sf, x, gt, file, driver = \"GTiff\", options = character()) gdal_extract( f, pts, resampling = c(\"nearest\", \"bilinear\", \"cubic\", \"cubicspline\") ) gdal_read_mdim( file, array_name = character(0), options = character(0), offset = integer(0), count = integer(0), step = integer(0), proxy = FALSE, debug = FALSE ) gdal_write_mdim( file, driver, dimx, cdl, wkt, xy, ..., root_group_options = character(0), options = character(0), as_float = TRUE ) gdal_create(f, nxy, values, crs, xlim, ylim)"},{"path":"https://r-spatial.github.io/sf/reference/gdal.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"functions to interact with gdal not meant to be called directly by users (but e.g. by stars::read_stars) — gdal","text":"x character vector, possibly length larger 1 one raster read ... ignored options character; driver specific options regarding reading creating dataset driver character; driver short name; empty vector, driver auto-detected. read_data logical; FALSE, imagery metadata returned NA_value (double) non-NA value use missing values; NA, writing missing values specially flagged output dataset, reading default (dataset) missing values used (present / set). RasterIO_parameters list named parameters GDAL's RasterIO; see stars::read_stars documentation. file file name type gdal write type geotransform length 6 numeric vector GDAL geotransform parameters. update logical; TRUE existing raster file pixel values shall updated. scale_offset length 2 numeric; contains scale offset values gt double vector length 6 domain_item character vector length 0, 1 (domain), 2 (domain item); use \"\" default domain, use NA_character_ query domain names. parse logical; metadata parsed named list (TRUE) returned character data? name logical; retrieve name subdataset? FALSE, retrieve description mask stars object NA mask (0 NA), NULL use_integer boolean; TRUE, raster values read (rounded ) unsigned 32-bit integers values; FALSE read 32-bit floating points numbers. former supposedly faster. breaks numeric vector break values contour polygons (lines) use_contours logical; contour_lines logical; connect8 logical; TRUE use 8 connection algorithm, rather 4 sf object class sf f character; file name pts points matrix resampling character; resampling method; method cubic cubicspline, stars_proxy objects used GDAL version >= 3.10.0 array_name array name offset offset (pixels) count number pixels read step step size (pixels) proxy logical; return proxy object? debug logical; print debug messages? dimx integer named vector dimensions object cdl list variables, named dim attribute wkt character; WKT crs xy character; names spatial x y dimension root_group_options character; driver specific options regarding creation root group as_float logical; TRUE write 4-byte floating point numbers, FALSE write 8-byte doubles. nxy integer vector length 2 values fill value crs object class crs xlim numeric ylim numeric","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"functions to interact with gdal not meant to be called directly by users (but e.g. by stars::read_stars) — gdal","text":"object class crs, see st_crs. named list metadata items gdal_subdatasets returns zero-length list file subdatasets, else named list subdatasets.","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"functions to interact with gdal not meant to be called directly by users (but e.g. by stars::read_stars) — gdal","text":"functions exported single purpose used package stars, meant used directly may change disappear without prior notice deprecation warnings. gdal_inv_geotransform returns inverse geotransform gdal_crs reads coordinate reference system GDAL data set get_metadata gets metadata raster layer gdal_subdatasets returns subdatasets gdal dataset","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"functions to interact with gdal not meant to be called directly by users (but e.g. by stars::read_stars) — gdal","text":"","code":"if (FALSE) { # \\dontrun{ f = system.file(\"tif/L7_ETMs.tif\", package=\"stars\") f = system.file(\"nc/avhrr-only-v2.19810901.nc\", package = \"stars\") gdal_metadata(f) gdal_metadata(f, NA_character_) try(gdal_metadata(f, \"wrongDomain\")) gdal_metadata(f, c(\"\", \"AREA_OR_POINT\")) } # }"},{"path":"https://r-spatial.github.io/sf/reference/gdal_addo.html","id":null,"dir":"Reference","previous_headings":"","what":"Add or remove overviews to/from a raster image — gdal_addo","title":"Add or remove overviews to/from a raster image — gdal_addo","text":"add remove overviews /raster image","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal_addo.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add or remove overviews to/from a raster image — gdal_addo","text":"","code":"gdal_addo( file, overviews = c(2, 4, 8, 16), method = \"NEAREST\", layers = integer(0), options = character(0), config_options = character(0), clean = FALSE, read_only = FALSE )"},{"path":"https://r-spatial.github.io/sf/reference/gdal_addo.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add or remove overviews to/from a raster image — gdal_addo","text":"file character; file name overviews integer; overview levels method character; method create overview; one : nearest, average, rms, gauss, cubic, cubicspline, lanczos, average_mp, average_magphase, mode layers integer; layers create overviews (default: ) options character; dataset opening options config_options named character vector GDAL config options, like c(option1=value1, option2=value2) clean logical; TRUE remove overviews, add read_only logical; TRUE, add overviews another file extension .ovr added file","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal_addo.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add or remove overviews to/from a raster image — gdal_addo","text":"TRUE, invisibly, success","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/gdal_utils.html","id":null,"dir":"Reference","previous_headings":"","what":"Native interface to gdal utils — gdal_utils","title":"Native interface to gdal utils — gdal_utils","text":"Native interface gdal utils","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal_utils.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Native interface to gdal utils — gdal_utils","text":"","code":"gdal_utils( util = \"info\", source, destination, options = character(0), quiet = !(util %in% c(\"info\", \"gdalinfo\", \"ogrinfo\", \"vectorinfo\", \"mdiminfo\")) || (\"-multi\" %in% options), processing = character(0), colorfilename = character(0), config_options = character(0), read_only = FALSE )"},{"path":"https://r-spatial.github.io/sf/reference/gdal_utils.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Native interface to gdal utils — gdal_utils","text":"util character; one info, warp, rasterize, translate, vectortranslate (ogr2ogr), buildvrt, demprocessing, nearblack, grid, mdiminfo mdimtranslate (last two requiring GDAL 3.1), ogrinfo (requiring GDAL 3.7), footprint (requiring GDAL 3.8) source character; name input layer(s); warp, buidvrt mdimtranslate can one destination character; name output layer options character; options utility quiet logical; TRUE, suppress printing output info mdiminfo, suppress printing progress processing character; processing options demprocessing colorfilename character; name color file demprocessing (mandatory processing=\"color-relief\") config_options named character vector GDAL config options, like c(option1=value1, option2=value2) read_only logical; ogrinfo: TRUE, source opened read-mode","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal_utils.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Native interface to gdal utils — gdal_utils","text":"info returns character vector raster metadata; utils return (invisibly) logical indicating success (.e., TRUE); case failure, error raised.","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/gdal_utils.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Native interface to gdal utils — gdal_utils","text":"","code":"if (sf_extSoftVersion()[\"GDAL\"] > \"2.1.0\") { # info utils can be used to list information about a raster # dataset. More info: https://gdal.org/programs/gdalinfo.html in_file <- system.file(\"tif/geomatrix.tif\", package = \"sf\") gdal_utils(\"info\", in_file, options = c(\"-mm\", \"-proj4\")) # vectortranslate utils can be used to convert simple features data between # file formats. More info: https://gdal.org/programs/ogr2ogr.html in_file <- system.file(\"shape/storms_xyz.shp\", package=\"sf\") out_file <- paste0(tempfile(), \".gpkg\") gdal_utils( util = \"vectortranslate\", source = in_file, destination = out_file, # output format must be specified for GDAL < 2.3 options = c(\"-f\", \"GPKG\") ) # The parameters can be specified as c(\"name\") or c(\"name\", \"value\"). The # vectortranslate utils can perform also various operations during the # conversion process. For example, we can reproject the features during the # translation. gdal_utils( util = \"vectortranslate\", source = in_file, destination = out_file, options = c( \"-f\", \"GPKG\", # output file format for GDAL < 2.3 \"-s_srs\", \"EPSG:4326\", # input file SRS \"-t_srs\", \"EPSG:2264\", # output file SRS \"-overwrite\" ) ) st_read(out_file) # The parameter s_srs had to be specified because, in this case, the in_file # has no associated SRS. st_read(in_file) } #> Driver: GTiff/GeoTIFF #> Files: /home/runner/work/_temp/Library/sf/tif/geomatrix.tif #> Size is 20, 20 #> Coordinate System is: #> PROJCRS[\"WGS 84 / UTM zone 11N\", #> BASEGEOGCRS[\"WGS 84\", #> ENSEMBLE[\"World Geodetic System 1984 ensemble\", #> MEMBER[\"World Geodetic System 1984 (Transit)\"], #> MEMBER[\"World Geodetic System 1984 (G730)\"], #> MEMBER[\"World Geodetic System 1984 (G873)\"], #> MEMBER[\"World Geodetic System 1984 (G1150)\"], #> MEMBER[\"World Geodetic System 1984 (G1674)\"], #> MEMBER[\"World Geodetic System 1984 (G1762)\"], #> MEMBER[\"World Geodetic System 1984 (G2139)\"], #> ELLIPSOID[\"WGS 84\",6378137,298.257223563, #> LENGTHUNIT[\"metre\",1]], #> ENSEMBLEACCURACY[2.0]], #> PRIMEM[\"Greenwich\",0, #> ANGLEUNIT[\"degree\",0.0174532925199433]], #> ID[\"EPSG\",4326]], #> CONVERSION[\"UTM zone 11N\", #> METHOD[\"Transverse Mercator\", #> ID[\"EPSG\",9807]], #> PARAMETER[\"Latitude of natural origin\",0, #> ANGLEUNIT[\"degree\",0.0174532925199433], #> ID[\"EPSG\",8801]], #> PARAMETER[\"Longitude of natural origin\",-117, #> ANGLEUNIT[\"degree\",0.0174532925199433], #> ID[\"EPSG\",8802]], #> PARAMETER[\"Scale factor at natural origin\",0.9996, #> SCALEUNIT[\"unity\",1], #> ID[\"EPSG\",8805]], #> PARAMETER[\"False easting\",500000, #> LENGTHUNIT[\"metre\",1], #> ID[\"EPSG\",8806]], #> PARAMETER[\"False northing\",0, #> LENGTHUNIT[\"metre\",1], #> ID[\"EPSG\",8807]]], #> CS[Cartesian,2], #> AXIS[\"(E)\",east, #> ORDER[1], #> LENGTHUNIT[\"metre\",1]], #> AXIS[\"(N)\",north, #> ORDER[2], #> LENGTHUNIT[\"metre\",1]], #> USAGE[ #> SCOPE[\"Engineering survey, topographic mapping.\"], #> AREA[\"Between 120°W and 114°W, northern hemisphere between equator and 84°N, onshore and offshore. Canada - Alberta; British Columbia (BC); Northwest Territories (NWT); Nunavut. Mexico. United States (USA).\"], #> BBOX[0,-120,84,-114]], #> ID[\"EPSG\",32611]] #> Data axis to CRS axis mapping: 1,2 #> PROJ.4 string is: #> '+proj=utm +zone=11 +datum=WGS84 +units=m +no_defs' #> GeoTransform = #> 1841001.75, 1.5, -5 #> 1144003.25, -5, -1.5 #> Metadata: #> AREA_OR_POINT=Point #> Image Structure Metadata: #> INTERLEAVE=BAND #> Corner Coordinates: #> Upper Left ( 1841001.750, 1144003.250) (104d50'47.45\"W, 10d 7'13.55\"N) #> Lower Left ( 1840901.750, 1143973.250) (104d50'50.69\"W, 10d 7'12.72\"N) #> Upper Right ( 1841031.750, 1143903.250) (104d50'46.60\"W, 10d 7'10.33\"N) #> Lower Right ( 1840931.750, 1143873.250) (104d50'49.85\"W, 10d 7' 9.50\"N) #> Center ( 1840966.750, 1143938.250) (104d50'48.65\"W, 10d 7'11.53\"N) #> Band 1 Block=20x20 Type=Byte, ColorInterp=Gray #> Computed Min/Max=74.000,255.000 #> Reading layer `storms_xyz' from data source #> `/tmp/RtmpPF9T6H/file1d5f5075b0a8.gpkg' using driver `GPKG' #> Simple feature collection with 71 features and 0 fields #> Geometry type: LINESTRING #> Dimension: XYZ #> Bounding box: xmin: -5785269 ymin: -8509454 xmax: 25097160 ymax: 15846560 #> z_range: zmin: 924 zmax: 1017 #> Projected CRS: NAD83 / North Carolina (ftUS) #> Reading layer `storms_xyz' from data source #> `/home/runner/work/_temp/Library/sf/shape/storms_xyz.shp' using driver `ESRI Shapefile' #> Simple feature collection with 71 features and 0 fields #> Geometry type: LINESTRING #> Dimension: XYZ #> Bounding box: xmin: -102.2 ymin: 8.3 xmax: 0 ymax: 59.5 #> z_range: zmin: 924 zmax: 1017 #> CRS: NA"},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_ops.html","id":null,"dir":"Reference","previous_headings":"","what":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","title":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","text":"Perform geometric set operations simple feature geometry collections","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_ops.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","text":"","code":"st_intersection(x, y, ...) # S3 method for class 'sfc' st_intersection(x, y, ...) # S3 method for class 'sf' st_intersection(x, y, ...) st_difference(x, y, ...) # S3 method for class 'sfc' st_difference(x, y, ...) st_sym_difference(x, y, ...) st_snap(x, y, tolerance)"},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_ops.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","text":"x object class sf, sfc sfg y object class sf, sfc sfg ... arguments passed s2_options tolerance tolerance values used st_snap; numeric value object class units; may tolerance values feature x","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_ops.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","text":"intersection, difference symmetric difference two sets geometries. returned object class first argument (x) non-empty geometries resulting applying operation geometry pairs x y. case x class sf, matching attributes original object(s) added. sfc geometry list-column returned carries attribute idx, n--2 matrix every row index corresponding entries x y, respectively.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_ops.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","text":"using GEOS using s2, spatial index built argument x; see https://r-spatial.org/r/2017/06/22/spatial-index.html. reference STR tree algorithm : Leutenegger, Scott T., Mario . Lopez, Jeffrey Edgington. \"STR: simple efficient algorithm R-tree packing.\" Data Engineering, 1997. Proceedings. 13th international conference . IEEE, 1997. pdf, search Google Scholar. called missing y, sfc method st_intersection returns non-empty intersections geometries x; attribute idx contains list-column indexes contributing geometries. called missing y, sf method st_intersection returns sf object attributes taken contributing feature lowest index; two fields added: n.overlaps number overlapping features x, list-column origins indexes overlapping features. st_difference called single argument, overlapping areas erased geometries indexed greater numbers argument x; geometries empty contained fully inside geometries higher priority removed entirely. st_difference.sfc method single argument returns object \"idx\" attribute original index returned geometries. st_snap snaps vertices segments geometry another geometry's vertices. y contains one geometry, geometries merged collection snapping collection. (GEOS docs:) \"snap distance tolerance used control snapping performed. Snapping one geometry another can improve robustness overlay operations eliminating nearly-coincident edges (cause problems noding intersection calculation). much snapping can result invalid topology created, number location snapped vertices decided using heuristics determine safe snap. can result potential snaps omitted, however.\"","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_ops.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","text":"find whether pairs simple feature geometries intersect, use function st_intersects instead st_intersection. using GEOS using s2 polygons contain boundary. using s2 determined model defaults s2_options, can overridden via ... argument, e.g. model = \"closed\" force DE-9IM compliant behaviour polygons (reproduce GEOS results).","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_ops.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","text":"","code":"set.seed(131) library(sf) m = rbind(c(0,0), c(1,0), c(1,1), c(0,1), c(0,0)) p = st_polygon(list(m)) n = 100 l = vector(\"list\", n) for (i in 1:n) l[[i]] = p + 10 * runif(2) s = st_sfc(l) plot(s, col = sf.colors(categorical = TRUE, alpha = .5)) title(\"overlapping squares\") d = st_difference(s) # sequential differences: s1, s2-s1, s3-s2-s1, ... plot(d, col = sf.colors(categorical = TRUE, alpha = .5)) title(\"non-overlapping differences\") i = st_intersection(s) # all intersections plot(i, col = sf.colors(categorical = TRUE, alpha = .5)) title(\"non-overlapping intersections\") summary(lengths(st_overlaps(s, s))) # includes self-counts! #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0.00 2.00 3.50 3.66 5.00 8.00 summary(lengths(st_overlaps(d, d))) #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0 0 0 0 0 0 summary(lengths(st_overlaps(i, i))) #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0 0 0 0 0 0 sf = st_sf(s) i = st_intersection(sf) # all intersections plot(i[\"n.overlaps\"]) summary(i$n.overlaps - lengths(i$origins)) #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0 0 0 0 0 0 # A helper function that erases all of y from x: st_erase = function(x, y) st_difference(x, st_union(st_combine(y))) poly = st_polygon(list(cbind(c(0, 0, 1, 1, 0), c(0, 1, 1, 0, 0)))) lines = st_multilinestring(list( cbind(c(0, 1), c(1, 1.05)), cbind(c(0, 1), c(0, -.05)), cbind(c(1, .95, 1), c(1.05, .5, -.05)) )) snapped = st_snap(poly, lines, tolerance=.1) plot(snapped, col='red') plot(poly, border='green', add=TRUE) plot(lines, lwd=2, col='blue', add=TRUE)"},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_pred.html","id":null,"dir":"Reference","previous_headings":"","what":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","title":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","text":"Geometric binary predicates pairs simple feature geometry sets","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_pred.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","text":"","code":"st_intersects(x, y, sparse = TRUE, ...) st_disjoint(x, y = x, sparse = TRUE, prepared = TRUE, ...) st_touches(x, y, sparse = TRUE, prepared = TRUE, ...) st_crosses(x, y, sparse = TRUE, prepared = TRUE, ...) st_within(x, y, sparse = TRUE, prepared = TRUE, ...) st_contains(x, y, sparse = TRUE, prepared = TRUE, ..., model = \"open\") st_contains_properly(x, y, sparse = TRUE, prepared = TRUE, ...) st_overlaps(x, y, sparse = TRUE, prepared = TRUE, ...) st_equals( x, y, sparse = TRUE, prepared = FALSE, ..., retain_unique = FALSE, remove_self = FALSE ) st_covers(x, y, sparse = TRUE, prepared = TRUE, ..., model = \"closed\") st_covered_by(x, y = x, sparse = TRUE, prepared = TRUE, ..., model = \"closed\") st_equals_exact(x, y, par, sparse = TRUE, prepared = FALSE, ...) st_is_within_distance(x, y = x, dist, sparse = TRUE, ..., remove_self = FALSE)"},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_pred.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","text":"x object class sf, sfc sfg y object class sf, sfc sfg; missing, x used sparse logical; sparse index list returned (TRUE) dense logical matrix? See . ... Arguments passed s2::s2_options snap Use s2_snap_identity(), s2_snap_distance(), s2_snap_level(), s2_snap_precision() specify coordinate rounding occur. snap_radius opposed snap function, specifies maximum distance vertex move, snap radius (radians) sets minimum distance vertices output cause vertices move distance specified snap function. can used simplify result boolean operation. Use -1 specify minimum distance acceptable. duplicate_edges Use TRUE keep duplicate edges (e.g., duplicate points). edge_type One 'directed' (default) 'undirected'. validate Use TRUE validate result builder. polyline_type One 'path' (default) 'walk'. 'walk', polylines backtrack preserved. polyline_sibling_pairs One 'discard' (default) 'keep'. simplify_edge_chains Use TRUE remove vertices within snap_radius original vertex. split_crossing_edges Use TRUE split crossing polyline edges creating geometries. idempotent Use FALSE apply snap even snapping necessary satisfy vertex constraints. dimensions combination 'point', 'polyline', /'polygon' can used constrain output s2_rebuild() boolean operation. prepared logical; prepare geometry x, looping y? See Details. model character; polygon/polyline model; one \"open\", \"semi-open\" \"closed\"; see Details. retain_unique logical; TRUE (y missing) return indexes points larger current index; can used select unique geometries, see examples. argument can used geometry predicates; see also distinct.sf find records geometries attributes distinct. remove_self logical; TRUE (y missing) return indexes geometries different current index; can used omit self-intersections; see examples. argument can used geometry predicates par numeric; parameter used \"equals_exact\" (margin); dist distance threshold; geometry indexes distances smaller equal value returned; numeric value units value distance units.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_pred.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","text":"sparse=FALSE, st_predicate (predicate e.g. \"intersects\") returns dense logical matrix element ,j equal TRUE predicate(x[], y[j]) (e.g., geometry feature j intersect); sparse=TRUE, object class sgbp returned, sparse list representation matrix, list element integer vector indices j predicate(x[],y[j]) TRUE (hence zero-length integer vector none TRUE). dense matrix, one can find one elements intersect apply(mat, 1, ), sparse list lengths(lst) > 0, see examples .","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_pred.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","text":"prepared TRUE, x contains POINT geometries y contains polygons, polygon geometries prepared, rather points. predicates, spatial index built argument x; see https://r-spatial.org/r/2017/06/22/spatial-index.html. Specifically, st_intersects, st_disjoint, st_touches st_crosses, st_within, st_contains, st_contains_properly, st_overlaps, st_equals, st_covers st_covered_by build spatial indexes efficient geometry calculations. st_relate, st_equals_exact, ; st_is_within_distance uses spatial index geographic coordinates sf_use_s2() true. y missing, st_predicate(x, x) effectively called, square matrix returned diagonal elements st_predicate(x[], x[]). Sparse geometry binary predicate (sgbp) lists following attributes: region.id row.names x (, else 1:n), ncol number features y, predicate name predicate used. model, see https://github.com/r-spatial/s2/issues/32 st_contains_properly(,B) true intersects B's interior, edges exterior; contains , properly contain . See also st_relate https://en.wikipedia.org/wiki/DE-9IM detailed description underlying algorithms. st_equals_exact returns true two geometries type vertices corresponding index equal specified tolerance.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_pred.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","text":"intersection pairs simple feature geometries, use function st_intersection instead st_intersects.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_pred.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","text":"","code":"pts = st_sfc(st_point(c(.5,.5)), st_point(c(1.5, 1.5)), st_point(c(2.5, 2.5))) pol = st_polygon(list(rbind(c(0,0), c(2,0), c(2,2), c(0,2), c(0,0)))) (lst = st_intersects(pts, pol)) #> Sparse geometry binary predicate list of length 3, where the predicate #> was `intersects' #> 1: 1 #> 2: 1 #> 3: (empty) (mat = st_intersects(pts, pol, sparse = FALSE)) #> [,1] #> [1,] TRUE #> [2,] TRUE #> [3,] FALSE # which points fall inside a polygon? apply(mat, 1, any) #> [1] TRUE TRUE FALSE lengths(lst) > 0 #> [1] TRUE TRUE FALSE # which points fall inside the first polygon? st_intersects(pol, pts)[[1]] #> [1] 1 2 # remove duplicate geometries: p1 = st_point(0:1) p2 = st_point(2:1) p = st_sf(a = letters[1:8], geom = st_sfc(p1, p1, p2, p1, p1, p2, p2, p1)) st_equals(p) #> Sparse geometry binary predicate list of length 8, where the predicate #> was `equals' #> 1: 1, 2, 4, 5, 8 #> 2: 1, 2, 4, 5, 8 #> 3: 3, 6, 7 #> 4: 1, 2, 4, 5, 8 #> 5: 1, 2, 4, 5, 8 #> 6: 3, 6, 7 #> 7: 3, 6, 7 #> 8: 1, 2, 4, 5, 8 st_equals(p, remove_self = TRUE) #> Sparse geometry binary predicate list of length 8, where the predicate #> was `equals', with remove_self = TRUE #> 1: 2, 4, 5, 8 #> 2: 1, 4, 5, 8 #> 3: 6, 7 #> 4: 1, 2, 5, 8 #> 5: 1, 2, 4, 8 #> 6: 3, 7 #> 7: 3, 6 #> 8: 1, 2, 4, 5 (u = st_equals(p, retain_unique = TRUE)) #> Sparse geometry binary predicate list of length 8, where the predicate #> was `equals', with retain_unique = TRUE #> 1: 2, 4, 5, 8 #> 2: 4, 5, 8 #> 3: 6, 7 #> 4: 5, 8 #> 5: 8 #> 6: 7 #> 7: (empty) #> 8: (empty) # retain the records with unique geometries: p[-unlist(u),] #> Simple feature collection with 2 features and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 2 ymax: 1 #> CRS: NA #> a geom #> 1 a POINT (0 1) #> 3 c POINT (2 1)"},{"path":"https://r-spatial.github.io/sf/reference/geos_combine.html","id":null,"dir":"Reference","previous_headings":"","what":"Combine or union feature geometries — geos_combine","title":"Combine or union feature geometries — geos_combine","text":"Combine several feature geometries one, without unioning resolving internal boundaries","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_combine.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Combine or union feature geometries — geos_combine","text":"","code":"st_combine(x) st_union(x, y, ..., by_feature = FALSE, is_coverage = FALSE)"},{"path":"https://r-spatial.github.io/sf/reference/geos_combine.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Combine or union feature geometries — geos_combine","text":"x object class sf, sfc sfg y object class sf, sfc sfg (optional) ... ignored by_feature logical; TRUE, union feature y missing else pair features; FALSE return single feature geometric union set features x y missing, else unions elements Cartesian product sets is_coverage logical; TRUE, use optimized algorithm features form polygonal coverage (overlaps)","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_combine.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Combine or union feature geometries — geos_combine","text":"st_combine returns single, combined geometry, resolved boundaries; returned geometries may well invalid. y missing, st_union(x) returns single geometry resolved boundaries, else geometries unioned pairs x[] y[j].","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_combine.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Combine or union feature geometries — geos_combine","text":"st_combine combines geometries without resolving borders, using c.sfg (analogous c ordinary vectors). st_union called single argument, x, (y missing) by_feature FALSE geometries unioned together sfg single-geometry sfc object returned. by_feature TRUE feature geometry unioned individually. can instance used resolve internal boundaries polygons combined using st_combine. y provided, elements x y unioned, pairwise by_feature TRUE, else Cartesian product sets. Unioning set overlapping polygons effect merging areas (.e. effect iteratively unioning individual polygons together). Unioning set LineStrings effect fully noding dissolving input linework. context \"fully noded\" means node endpoint output every endpoint line segment crossing input. \"Dissolved\" means duplicate (e.g. coincident) line segments portions line segments reduced single line segment output.\tUnioning set Points effect merging identical points (producing set duplicates).","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/geos_combine.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Combine or union feature geometries — geos_combine","text":"","code":"nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 st_combine(nc) #> Geometry set for 1 feature #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 #> MULTIPOLYGON (((-81.47276 36.23436, -81.54084 3... plot(st_union(nc))"},{"path":"https://r-spatial.github.io/sf/reference/geos_measures.html","id":null,"dir":"Reference","previous_headings":"","what":"Compute geometric measurements — geos_measures","title":"Compute geometric measurements — geos_measures","text":"Compute Euclidean great circle distance pairs geometries; compute, area length set geometries.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_measures.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compute geometric measurements — geos_measures","text":"","code":"st_area(x, ...) # S3 method for class 'sfc' st_area(x, ...) st_length(x, ...) st_perimeter(x, ...) st_distance( x, y, ..., dist_fun, by_element = FALSE, which = ifelse(isTRUE(st_is_longlat(x)), \"Great Circle\", \"Euclidean\"), par = 0, tolerance = 0 )"},{"path":"https://r-spatial.github.io/sf/reference/geos_measures.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compute geometric measurements — geos_measures","text":"x object class sf, sfc sfg ... passed s2_distance, s2_distance_matrix, s2_perimeter y object class sf, sfc sfg, defaults x dist_fun deprecated by_element logical; TRUE, return vector distance first elements x y, second, etc; error raised x y length. FALSE, return dense matrix pairwise distances. character; Cartesian coordinates : one Euclidean, Hausdorff Frechet; geodetic coordinates, great circle distances computed; see details par equal Hausdorff Frechet, optionally use value 0 1 densify geometry tolerance ignored st_is_longlat(x) FALSE; otherwise, set positive value, first distance smaller tolerance returned, true distance may smaller; may speed computation. meters, units object convertible meters.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_measures.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compute geometric measurements — geos_measures","text":"coordinate reference system x set, functions return values unit measurement; see set_units. st_area returns area geometry, coordinate reference system used; case x degrees longitude/latitude, st_geod_area used area calculation. st_length returns length LINESTRING MULTILINESTRING geometry, using coordinate reference system. POINT, MULTIPOINT, POLYGON MULTIPOLYGON geometries return zero. by_element FALSE st_distance returns dense numeric matrix dimension length(x) length(y); otherwise returns numeric vector length x y error raised lengths x y unequal. Distances involving empty geometries NA.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_measures.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Compute geometric measurements — geos_measures","text":"great circle distance calculations use default spherical distances (s2_distance s2_distance_matrix); sf_use_s2() FALSE, ellipsoidal distances computed using st_geod_distance uses function geod_inverse GeographicLib (part PROJ); see Karney, Charles FF, 2013, Algorithms geodesics, Journal Geodesy 87(1), 43–55","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/geos_measures.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Compute geometric measurements — geos_measures","text":"","code":"b0 = st_polygon(list(rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1)))) b1 = b0 + 2 b2 = b0 + c(-0.2, 2) x = st_sfc(b0, b1, b2) st_area(x) #> [1] 4 4 4 line = st_sfc(st_linestring(rbind(c(30,30), c(40,40))), crs = 4326) st_length(line) #> 1435335 [m] 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) poly = st_polygon(list(outer, hole1, hole2)) mpoly = st_multipolygon(list( list(outer, hole1, hole2), list(outer + 12, hole1 + 12) )) st_length(st_sfc(poly, mpoly)) #> [1] 0 0 st_perimeter(poly) #> [1] 48 st_perimeter(mpoly) #> [1] 92 p = st_sfc(st_point(c(0,0)), st_point(c(0,1)), st_point(c(0,2))) st_distance(p, p) #> [,1] [,2] [,3] #> [1,] 0 1 2 #> [2,] 1 0 1 #> [3,] 2 1 0 st_distance(p, p, by_element = TRUE) #> [1] 0 0 0"},{"path":"https://r-spatial.github.io/sf/reference/geos_query.html","id":null,"dir":"Reference","previous_headings":"","what":"Dimension, simplicity, validity or is_empty queries on simple feature geometries — geos_query","title":"Dimension, simplicity, validity or is_empty queries on simple feature geometries — geos_query","text":"Dimension, simplicity, validity is_empty queries simple feature geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_query.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Dimension, simplicity, validity or is_empty queries on simple feature geometries — geos_query","text":"","code":"st_dimension(x, NA_if_empty = TRUE) st_is_simple(x) st_is_empty(x)"},{"path":"https://r-spatial.github.io/sf/reference/geos_query.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Dimension, simplicity, validity or is_empty queries on simple feature geometries — geos_query","text":"x object class sf, sfc sfg NA_if_empty logical; TRUE, return NA empty geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_query.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Dimension, simplicity, validity or is_empty queries on simple feature geometries — geos_query","text":"st_dimension returns numeric vector 0 points, 1 lines, 2 surfaces, , NA_if_empty TRUE, NA empty geometries. st_is_simple returns logical vector, indicating geometry whether simple (e.g., self-intersecting) st_is_empty returns geometry whether empty","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_query.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Dimension, simplicity, validity or is_empty queries on simple feature geometries — geos_query","text":"","code":"x = st_sfc( st_point(0:1), st_linestring(rbind(c(0,0),c(1,1))), st_polygon(list(rbind(c(0,0),c(1,0),c(0,1),c(0,0)))), st_multipoint(), st_linestring(), st_geometrycollection()) st_dimension(x) #> [1] 0 1 2 NA NA NA st_dimension(x, FALSE) #> [1] 0 1 2 0 1 0 ls = st_linestring(rbind(c(0,0), c(1,1), c(1,0), c(0,1))) st_is_simple(st_sfc(ls, st_point(c(0,0)))) #> [1] FALSE TRUE ls = st_linestring(rbind(c(0,0), c(1,1), c(1,0), c(0,1))) st_is_empty(st_sfc(ls, st_point(), st_linestring())) #> [1] FALSE TRUE TRUE"},{"path":"https://r-spatial.github.io/sf/reference/geos_unary.html","id":null,"dir":"Reference","previous_headings":"","what":"Geometric unary operations on simple feature geometry sets — geos_unary","title":"Geometric unary operations on simple feature geometry sets — geos_unary","text":"Geometric unary operations simple feature geometries. generics, methods sfg, sfc sf objects, returning object class. operations work per-feature basis, ignoring features.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_unary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Geometric unary operations on simple feature geometry sets — geos_unary","text":"","code":"st_buffer( x, dist, nQuadSegs = 30, endCapStyle = \"ROUND\", joinStyle = \"ROUND\", mitreLimit = 1, singleSide = FALSE, ... ) st_boundary(x) st_convex_hull(x) st_concave_hull(x, ratio, ..., allow_holes) st_simplify(x, preserveTopology, dTolerance = 0) st_triangulate(x, dTolerance = 0, bOnlyEdges = FALSE) st_triangulate_constrained(x) st_inscribed_circle(x, dTolerance, ...) st_minimum_rotated_rectangle(x, ...) st_voronoi(x, envelope, dTolerance = 0, bOnlyEdges = FALSE) st_polygonize(x) st_line_merge(x, ..., directed = FALSE) st_centroid(x, ..., of_largest_polygon = FALSE) st_point_on_surface(x) st_reverse(x) st_node(x) st_segmentize(x, dfMaxLength, ...) st_exterior_ring(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/geos_unary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Geometric unary operations on simple feature geometry sets — geos_unary","text":"x object class sfg, sfc sf dist numeric object class units; buffer distance , elements x. case x geodetic coordinates (lon/lat) sf_use_s2() TRUE, numeric dist taken distance meters units object dist converted meters. case x geodetic coordinates (lon/lat) sf_use_s2() FALSE, numeric dist taken degrees, units object dist converted arc_degree (warnings issued). case x geodetic coordinates (projected) numeric dist assumed units coordinates, units dist converted st_crs(x) NA. nQuadSegs integer; number segments per quadrant (fourth circle), per-feature; see details endCapStyle character; style line ends, one 'ROUND', 'FLAT', 'SQUARE'; see details joinStyle character; style line joins, one 'ROUND', 'MITRE', 'BEVEL'; see details mitreLimit numeric; limit extension join joinStyle 'MITRE' used (default 1.0, minimum 0.0); see details singleSide logical; TRUE, single-sided buffers returned linear geometries, case negative dist values give buffers right-hand side, positive left; see details ... st_buffer passed s2::s2_buffer_cells(), otherwise ignored ratio numeric; fraction convex: 1 returns convex hulls, 0 maximally concave hulls allow_holes logical; TRUE, resulting concave hull may holes preserveTopology logical; carry topology preserving simplification? May specified , feature geometries. Note topology preserved single feature geometries, sets . specified (.e. default), internally set equal FALSE input data specified projected coordinates sf_use_s2() returns FALSE. Ignored cases (warning set equal FALSE) since function implicitly calls s2::s2_simplify always preserve topological relationships (per single feature). dTolerance numeric; tolerance parameter, specified feature geometry. run st_simplify, input data specified long-lat coordinates sf_use_s2() returns TRUE, value dTolerance must specified meters. bOnlyEdges logical; TRUE, return lines, else return polygons envelope object class sfc sfg containing POLYGON envelope voronoi diagram; takes effect larger default envelope, chosen envelope empty polygon directed logical; TRUE, lines opposite directions merged of_largest_polygon logical; st_centroid: TRUE, return centroid largest (sub)polygon MULTIPOLYGON rather whole MULTIPOLYGON dfMaxLength maximum length line segment. x geographical coordinates (long/lat), dfMaxLength either numeric expressed meter, object class units length units rad degree; segmentation long/lat case takes place along great circle, using st_geod_segmentize.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_unary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Geometric unary operations on simple feature geometry sets — geos_unary","text":"object class x, manipulated geometry.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_unary.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Geometric unary operations on simple feature geometry sets — geos_unary","text":"st_buffer computes buffer around geometry/geometry. Depending spatial coordinate system, different engine (GEOS S2) can used, different function arguments. nQuadSegs, endCapsStyle, joinStyle, mitreLimit singleSide parameters work GEOS engine used (.e. projected coordinates sf_use_s2() set FALSE). See postgis.net/docs/ST_Buffer.html details. max_cells min_level parameters (s2::s2_buffer_cells()) work S2 engine (.e. geographic coordinates) can used change buffer shape (e.g. smoothing). negative buffer returns empty polygons instead shrinking, set sf_use_s2() FALSE. st_boundary returns boundary geometry st_convex_hull creates convex hull set points st_concave_hull creates concave hull geometry st_simplify simplifies lines removing vertices. st_triangulate triangulates set points (constrained). st_triangulate requires GEOS version 3.4 st_triangulate_constrained returns constrained delaunay triangulation polygons; requires GEOS version 3.10 st_inscribed_circle returns maximum inscribed circle polygon geometries. st_inscribed_circle, nQuadSegs 0 2-point LINESTRING returned center point boundary point every circle, otherwise circle (buffer) returned nQuadSegs controls number points per quadrant approximate circle. st_inscribed_circle requires GEOS version 3.9 st_minimum_rotated_rectangle returns minimum rotated rectangular POLYGON encloses input geometry. rectangle width equal minimum diameter, longer length. convex hill input degenerate (line point) linestring point returned. st_voronoi creates voronoi tessellation. st_voronoi requires GEOS version 3.5 st_polygonize creates polygon lines form closed ring. case st_polygonize, x must object class LINESTRING MULTILINESTRING, sfc geometry list-column object containing st_line_merge merges lines. case st_line_merge, x must object class MULTILINESTRING, sfc geometry list-column object containing st_centroid gives centroid geometry st_point_on_surface returns point guaranteed (multi)surface. st_reverse reverses nodes line st_node adds nodes linear geometries intersections without node, works individual linear geometries st_segmentize adds points straight lines","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/geos_unary.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Geometric unary operations on simple feature geometry sets — geos_unary","text":"","code":"## st_buffer, style options (taken from rgeos gBuffer) l1 = st_as_sfc(\"LINESTRING(0 0,1 5,4 5,5 2,8 2,9 4,4 6.5)\") op = par(mfrow=c(2,3)) plot(st_buffer(l1, dist = 1, endCapStyle=\"ROUND\"), reset = FALSE, main = \"endCapStyle: ROUND\") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, endCapStyle=\"FLAT\"), reset = FALSE, main = \"endCapStyle: FLAT\") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, endCapStyle=\"SQUARE\"), reset = FALSE, main = \"endCapStyle: SQUARE\") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, nQuadSegs=1), reset = FALSE, main = \"nQuadSegs: 1\") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, nQuadSegs=2), reset = FALSE, main = \"nQuadSegs: 2\") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, nQuadSegs= 5), reset = FALSE, main = \"nQuadSegs: 5\") plot(l1,col='blue',add=TRUE) par(op) l2 = st_as_sfc(\"LINESTRING(0 0,1 5,3 2)\") op = par(mfrow = c(2, 3)) plot(st_buffer(l2, dist = 1, joinStyle=\"ROUND\"), reset = FALSE, main = \"joinStyle: ROUND\") plot(l2, col = 'blue', add = TRUE) plot(st_buffer(l2, dist = 1, joinStyle=\"MITRE\"), reset = FALSE, main = \"joinStyle: MITRE\") plot(l2, col= 'blue', add = TRUE) plot(st_buffer(l2, dist = 1, joinStyle=\"BEVEL\"), reset = FALSE, main = \"joinStyle: BEVEL\") plot(l2, col= 'blue', add=TRUE) plot(st_buffer(l2, dist = 1, joinStyle=\"MITRE\" , mitreLimit=0.5), reset = FALSE, main = \"mitreLimit: 0.5\") plot(l2, col = 'blue', add = TRUE) plot(st_buffer(l2, dist = 1, joinStyle=\"MITRE\",mitreLimit=1), reset = FALSE, main = \"mitreLimit: 1\") plot(l2, col = 'blue', add = TRUE) plot(st_buffer(l2, dist = 1, joinStyle=\"MITRE\",mitreLimit=3), reset = FALSE, main = \"mitreLimit: 3\") plot(l2, col = 'blue', add = TRUE) par(op) nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 nc_g = st_geometry(nc) plot(st_convex_hull(nc_g)) plot(nc_g, border = grey(.5), add = TRUE) pt = st_combine(st_sfc(st_point(c(0,80)), st_point(c(120,80)), st_point(c(240,80)))) st_convex_hull(pt) # R2 #> Geometry set for 1 feature #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 0 ymin: 80 xmax: 240 ymax: 80 #> CRS: NA #> LINESTRING (0 80, 240 80) st_convex_hull(st_set_crs(pt, 'OGC:CRS84')) # S2 #> Geometry set for 1 feature #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: -120 ymin: 80 xmax: 120 ymax: 80 #> Geodetic CRS: WGS 84 #> POLYGON ((-120 80, 0 80, 120 80, -120 80)) set.seed(131) if (compareVersion(sf_extSoftVersion()[[\"GEOS\"]], \"3.11.0\") > -1) { pts = cbind(runif(100), runif(100)) m = st_multipoint(pts) co = sf:::st_concave_hull(m, 0.3) coh = sf:::st_concave_hull(m, 0.3, allow_holes = TRUE) plot(co, col = 'grey') plot(coh, add = TRUE, border = 'red') plot(m, add = TRUE) } # st_simplify examples: op = par(mfrow = c(2, 3), mar = rep(0, 4)) plot(nc_g[1]) plot(st_simplify(nc_g[1], dTolerance = 1e3)) # 1000m plot(st_simplify(nc_g[1], dTolerance = 5e3)) # 5000m nc_g_planar = st_transform(nc_g, 2264) # planar coordinates, US foot plot(nc_g_planar[1]) plot(st_simplify(nc_g_planar[1], dTolerance = 1e3)) # 1000 foot plot(st_simplify(nc_g_planar[1], dTolerance = 5e3)) # 5000 foot par(op) if (compareVersion(sf_extSoftVersion()[[\"GEOS\"]], \"3.10.0\") > -1) { pts = rbind(c(0,0), c(1,0), c(1,1), c(.5,.5), c(0,1), c(0,0)) po = st_polygon(list(pts)) co = st_triangulate_constrained(po) tr = st_triangulate(po) plot(po, col = NA, border = 'grey', lwd = 15) plot(tr, border = 'green', col = NA, lwd = 5, add = TRUE) plot(co, border = 'red', col = 'NA', add = TRUE) } if (compareVersion(sf_extSoftVersion()[[\"GEOS\"]], \"3.9.0\") > -1) { nc_t = st_transform(nc, 'EPSG:2264') x = st_inscribed_circle(st_geometry(nc_t)) plot(st_geometry(nc_t), asp = 1, col = grey(.9)) plot(x, add = TRUE, col = '#ff9999') } set.seed(1) x = st_multipoint(matrix(runif(10),,2)) box = st_polygon(list(rbind(c(0,0),c(1,0),c(1,1),c(0,1),c(0,0)))) if (compareVersion(sf_extSoftVersion()[[\"GEOS\"]], \"3.5.0\") > -1) { v = st_sfc(st_voronoi(x, st_sfc(box))) plot(v, col = 0, border = 1, axes = TRUE) plot(box, add = TRUE, col = 0, border = 1) # a larger box is returned, as documented plot(x, add = TRUE, col = 'red', cex=2, pch=16) plot(st_intersection(st_cast(v), box)) # clip to smaller box plot(x, add = TRUE, col = 'red', cex=2, pch=16) # matching Voronoi polygons to data points: # https://github.com/r-spatial/sf/issues/1030 # generate 50 random unif points: n = 100 pts = st_as_sf(data.frame(matrix(runif(n), , 2), id = 1:(n/2)), coords = c(\"X1\", \"X2\")) # compute Voronoi polygons: pols = st_collection_extract(st_voronoi(do.call(c, st_geometry(pts)))) # match them to points: pts$pols = pols[unlist(st_intersects(pts, pols))] plot(pts[\"id\"], pch = 16) # ID is color plot(st_set_geometry(pts, \"pols\")[\"id\"], xlim = c(0,1), ylim = c(0,1), reset = FALSE) plot(st_geometry(pts), add = TRUE) layout(matrix(1)) # reset plot layout } mls = st_multilinestring(list(matrix(c(0,0,0,1,1,1,0,0),,2,byrow=TRUE))) st_polygonize(st_sfc(mls)) #> Geometry set for 1 feature #> Geometry type: GEOMETRYCOLLECTION #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> GEOMETRYCOLLECTION (POLYGON ((0 0, 0 1, 1 1, 0 ... mls = st_multilinestring(list(rbind(c(0,0), c(1,1)), rbind(c(2,0), c(1,1)))) st_line_merge(st_sfc(mls)) #> Geometry set for 1 feature #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 1 #> CRS: NA #> LINESTRING (0 0, 1 1, 2 0) plot(nc_g, axes = TRUE) plot(st_centroid(nc_g), add = TRUE, pch = 3, col = 'red') mp = st_combine(st_buffer(st_sfc(lapply(1:3, function(x) st_point(c(x,x)))), 0.2 * 1:3)) plot(mp) plot(st_centroid(mp), add = TRUE, col = 'red') # centroid of combined geometry plot(st_centroid(mp, of_largest_polygon = TRUE), add = TRUE, col = 'blue', pch = 3) plot(nc_g, axes = TRUE) plot(st_point_on_surface(nc_g), add = TRUE, pch = 3, col = 'red') #> Warning: st_point_on_surface may not give correct results for longitude/latitude data if (compareVersion(sf_extSoftVersion()[[\"GEOS\"]], \"3.7.0\") > -1) { st_reverse(st_linestring(rbind(c(1,1), c(2,2), c(3,3)))) } #> LINESTRING (3 3, 2 2, 1 1) (l = st_linestring(rbind(c(0,0), c(1,1), c(0,1), c(1,0), c(0,0)))) #> LINESTRING (0 0, 1 1, 0 1, 1 0, 0 0) st_polygonize(st_node(l)) #> GEOMETRYCOLLECTION (POLYGON ((0 0, 0.5 0.5, 1 0, 0 0)), POLYGON ((0.5 0.5, 0 1, 1 1, 0.5 0.5))) st_node(st_multilinestring(list(rbind(c(0,0), c(1,1), c(0,1), c(1,0), c(0,0))))) #> MULTILINESTRING ((0 0, 0.5 0.5), (0.5 0.5, 1 1, 0 1, 0.5 0.5), (0.5 0.5, 1 0, 0 0)) sf = st_sf(a=1, geom=st_sfc(st_linestring(rbind(c(0,0),c(1,1)))), crs = 4326) if (require(lwgeom, quietly = TRUE)) { seg = st_segmentize(sf, units::set_units(100, km)) seg = st_segmentize(sf, units::set_units(0.01, rad)) nrow(seg$geom[[1]]) } #> Linking to liblwgeom 3.0.0beta1 r16016, GEOS 3.10.2, PROJ 8.2.1 #> #> Attaching package: ‘lwgeom’ #> The following object is masked from ‘package:sf’: #> #> st_perimeter #> [1] 5"},{"path":"https://r-spatial.github.io/sf/reference/interpolate_aw.html","id":null,"dir":"Reference","previous_headings":"","what":"Areal-weighted interpolation of polygon data — interpolate_aw","title":"Areal-weighted interpolation of polygon data — interpolate_aw","text":"Areal-weighted interpolation polygon data","code":""},{"path":"https://r-spatial.github.io/sf/reference/interpolate_aw.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Areal-weighted interpolation of polygon data — interpolate_aw","text":"","code":"st_interpolate_aw(x, to, extensive, ...) # S3 method for class 'sf' st_interpolate_aw(x, to, extensive, ..., keep_NA = FALSE, na.rm = FALSE)"},{"path":"https://r-spatial.github.io/sf/reference/interpolate_aw.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Areal-weighted interpolation of polygon data — interpolate_aw","text":"x object class sf, want aggregate attributes object class sf sfc, target geometries extensive logical; TRUE, attribute variables assumed spatially extensive (like population) sum preserved, otherwise, spatially intensive (like population density) mean preserved. ... ignored keep_NA logical; TRUE, return features , FALSE return non-NA values (row.names index corresponding feature ) na.rm logical; TRUE remove features NA attributes x interpolating","code":""},{"path":"https://r-spatial.github.io/sf/reference/interpolate_aw.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Areal-weighted interpolation of polygon data — interpolate_aw","text":"extensive TRUE na.rm set TRUE, geometries NA effectively treated zero attribute values.","code":""},{"path":"https://r-spatial.github.io/sf/reference/interpolate_aw.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Areal-weighted interpolation of polygon data — interpolate_aw","text":"","code":"nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 g = st_make_grid(nc, n = c(10, 5)) a1 = st_interpolate_aw(nc[\"BIR74\"], g, extensive = FALSE) #> Warning: st_interpolate_aw assumes attributes are constant or uniform over areas of x sum(a1$BIR74) / sum(nc$BIR74) # not close to one: property is assumed spatially intensive #> [1] 0.4026287 a2 = st_interpolate_aw(nc[\"BIR74\"], g, extensive = TRUE) #> Warning: st_interpolate_aw assumes attributes are constant or uniform over areas of x # verify mass preservation (pycnophylactic) property: sum(a2$BIR74) / sum(nc$BIR74) #> [1] 0.9999998 a1$intensive = a1$BIR74 a1$extensive = a2$BIR74 plot(a1[c(\"intensive\", \"extensive\")], key.pos = 4)"},{"path":"https://r-spatial.github.io/sf/reference/is_driver_available.html","id":null,"dir":"Reference","previous_headings":"","what":"Check if driver is available — is_driver_available","title":"Check if driver is available — is_driver_available","text":"Search driver table driver listed","code":""},{"path":"https://r-spatial.github.io/sf/reference/is_driver_available.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check if driver is available — is_driver_available","text":"","code":"is_driver_available(drv, drivers = st_drivers())"},{"path":"https://r-spatial.github.io/sf/reference/is_driver_available.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check if driver is available — is_driver_available","text":"drv character. Name driver drivers data.frame. Table containing driver names support. Default st_drivers","code":""},{"path":"https://r-spatial.github.io/sf/reference/is_driver_can.html","id":null,"dir":"Reference","previous_headings":"","what":"Check if a driver can perform an action — is_driver_can","title":"Check if a driver can perform an action — is_driver_can","text":"Search driver table match driver name action (e.g. \"write\") check action supported.","code":""},{"path":"https://r-spatial.github.io/sf/reference/is_driver_can.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check if a driver can perform an action — is_driver_can","text":"","code":"is_driver_can(drv, drivers = st_drivers(), operation = \"write\")"},{"path":"https://r-spatial.github.io/sf/reference/is_driver_can.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check if a driver can perform an action — is_driver_can","text":"drv character. Name driver drivers data.frame. Table containing driver names support. Default st_drivers operation character. action check","code":""},{"path":"https://r-spatial.github.io/sf/reference/is_geometry_column.html","id":null,"dir":"Reference","previous_headings":"","what":"Check if the columns could be of a coercable type for sf — is_geometry_column","title":"Check if the columns could be of a coercable type for sf — is_geometry_column","text":"Check columns coercable type sf","code":""},{"path":"https://r-spatial.github.io/sf/reference/is_geometry_column.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check if the columns could be of a coercable type for sf — is_geometry_column","text":"","code":"is_geometry_column(con, x, classes = \"\")"},{"path":"https://r-spatial.github.io/sf/reference/is_geometry_column.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check if the columns could be of a coercable type for sf — is_geometry_column","text":"con database connection x inherits data.frame classes classes inherited","code":""},{"path":"https://r-spatial.github.io/sf/reference/merge.sf.html","id":null,"dir":"Reference","previous_headings":"","what":"merge method for sf and data.frame object — merge.sf","title":"merge method for sf and data.frame object — merge.sf","text":"merge method sf data.frame object","code":""},{"path":"https://r-spatial.github.io/sf/reference/merge.sf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"merge method for sf and data.frame object — merge.sf","text":"","code":"# S3 method for class 'sf' merge(x, y, ...)"},{"path":"https://r-spatial.github.io/sf/reference/merge.sf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"merge method for sf and data.frame object — merge.sf","text":"x object class sf y object class data.frame ... arguments passed merge.data.frame","code":""},{"path":"https://r-spatial.github.io/sf/reference/merge.sf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"merge method for sf and data.frame object — merge.sf","text":"","code":"a = data.frame(a = 1:3, b = 5:7) st_geometry(a) = st_sfc(st_point(c(0,0)), st_point(c(1,1)), st_point(c(2,2))) b = data.frame(x = c(\"a\", \"b\", \"c\"), b = c(2,5,6)) merge(a, b) #> Simple feature collection with 2 features and 3 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> b a x geometry #> 1 5 1 b POINT (0 0) #> 2 6 2 c POINT (1 1) merge(a, b, all = TRUE) #> Simple feature collection with 4 features and 3 fields (with 1 geometry empty) #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 2 #> CRS: NA #> b a x geometry #> 1 2 NA a GEOMETRYCOLLECTION EMPTY #> 2 5 1 b POINT (0 0) #> 3 6 2 c POINT (1 1) #> 4 7 3 POINT (2 2)"},{"path":"https://r-spatial.github.io/sf/reference/nc.html","id":null,"dir":"Reference","previous_headings":"","what":"North Carolina SIDS data — nc","title":"North Carolina SIDS data — nc","text":"Sudden Infant Death Syndrome (SIDS) sample data North Carolina counties, two time periods (1974-78 1979-84). details columns can found spdep package vignette. Please note , though basically nc.sids dataset spData package, nc contains subset variables. differences also discussed vignette.","code":""},{"path":"https://r-spatial.github.io/sf/reference/nc.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"North Carolina SIDS data — nc","text":"sf object","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/nc.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"North Carolina SIDS data — nc","text":"","code":"# \\donttest{ nc <- st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 # }"},{"path":"https://r-spatial.github.io/sf/reference/plot.html","id":null,"dir":"Reference","previous_headings":"","what":"plot sf object — plot","title":"plot sf object — plot","text":"plot one attributes sf object map Plot sf object","code":""},{"path":"https://r-spatial.github.io/sf/reference/plot.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"plot sf object — plot","text":"","code":"# S3 method for class 'sf' plot( x, y, ..., main, pal = NULL, nbreaks = 10, breaks = \"pretty\", max.plot = getOption(\"sf_max.plot\", default = 9), key.pos = get_key_pos(x, ...), key.length = 0.618, key.width = kw_dflt(x, key.pos), reset = TRUE, logz = FALSE, extent = x, xlim = st_bbox(extent)[c(1, 3)], ylim = st_bbox(extent)[c(2, 4)], compact = FALSE ) get_key_pos(x, ...) # S3 method for class 'sfc_POINT' plot( x, y, ..., pch = 1, cex = 1, col = 1, bg = 0, lwd = 1, lty = 1, type = \"p\", add = FALSE ) # S3 method for class 'sfc_MULTIPOINT' plot( x, y, ..., pch = 1, cex = 1, col = 1, bg = 0, lwd = 1, lty = 1, type = \"p\", add = FALSE ) # S3 method for class 'sfc_LINESTRING' plot(x, y, ..., lty = 1, lwd = 1, col = 1, pch = 1, type = \"l\", add = FALSE) # S3 method for class 'sfc_CIRCULARSTRING' plot(x, y, ...) # S3 method for class 'sfc_MULTILINESTRING' plot(x, y, ..., lty = 1, lwd = 1, col = 1, pch = 1, type = \"l\", add = FALSE) # S3 method for class 'sfc_POLYGON' plot( x, y, ..., lty = 1, lwd = 1, col = NA, cex = 1, pch = NA, border = 1, add = FALSE, rule = \"evenodd\", xpd = par(\"xpd\") ) # S3 method for class 'sfc_MULTIPOLYGON' plot( x, y, ..., lty = 1, lwd = 1, col = NA, border = 1, add = FALSE, rule = \"evenodd\", xpd = par(\"xpd\") ) # S3 method for class 'sfc_GEOMETRYCOLLECTION' plot( x, y, ..., pch = 1, cex = 1, bg = 0, lty = 1, lwd = 1, col = 1, border = 1, add = FALSE ) # S3 method for class 'sfc_GEOMETRY' plot( x, y, ..., pch = 1, cex = 1, bg = 0, lty = 1, lwd = 1, col = ifelse(st_dimension(x) == 2, NA, 1), border = 1, add = FALSE ) # S3 method for class 'sfg' plot(x, ...) plot_sf( x, xlim = NULL, ylim = NULL, asp = NA, axes = FALSE, bgc = par(\"bg\"), ..., xaxs, yaxs, lab, setParUsrBB = FALSE, bgMap = NULL, expandBB = c(0, 0, 0, 0), graticule = NA_crs_, col_graticule = \"grey\", border, extent = x ) sf.colors(n = 10, cutoff.tails = c(0.35, 0.2), alpha = 1, categorical = FALSE) # S3 method for class 'sf' text(x, labels = row.names(x), ...) # S3 method for class 'sfc' text(x, labels = seq_along(x), ..., of_largest_polygon = FALSE) # S3 method for class 'sf' points(x, ...) # S3 method for class 'sfc' points(x, ..., of_largest_polygon = FALSE)"},{"path":"https://r-spatial.github.io/sf/reference/plot.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"plot sf object — plot","text":"x object class sf y ignored ... specifications, see plot_sf plot details. main title plot (NULL remove) pal palette function, similar rainbow, palette values; omitted, sf.colors used nbreaks number colors breaks (ignored factor character variables) breaks either numeric vector actual breaks, name method accepted style argument classIntervals max.plot integer; lower boundary maximum number attributes plot; default value (9) can overridden setting global option sf_max.plot, e.g. options(sf_max.plot=2) key.pos numeric; side plot color key: 1 bottom, 2 left, 3 top, 4 right; set NULL omit key completely, 0 plot key, -1 select automatically. multiple columns plotted single function call default key plotted every submap stretched individually; key requested (col missing) maps colored according single key. Auto select depends plot size, map aspect, , set, parameter asp. lenght 2, second value, ranging 0 1, determines key placed available space (default: 0.5, center). key.length amount space reserved key along axis, length scale bar key.width amount space reserved key (incl. labels), thickness/width scale bar reset logical; FALSE, keep plot mode allows adding map elements; TRUE restore original mode plotting sf objects attributes; see details. logz logical; TRUE, use log10-scale attribute variable. case, breaks need given log10-values; see examples. extent object st_bbox method define plot extent; defaults x xlim see plot.window ylim see plot.window compact logical; compact sub-plots plotting space? pch plotting symbol cex symbol size col color plotting features; length(col) equal 1 nrow(x), warning emitted colors recycled. Specifying col suppresses plotting legend key. bg symbol background color lwd line width lty line type type plot type: 'p' points, 'l' lines, 'b' add logical; add current plot? Note using add=TRUE, may set reset=FALSE first plot command. border color polygon border(s); using NA hides rule see polypath; winding, exterior ring direction opposite holes; evenodd, plotting robust misspecified ring directions xpd see par; sets polygon clipping strategy; implemented POLYGON MULTIPOLYGON asp see , see par axes logical; axes plotted? (default FALSE) bgc background color xaxs see par yaxs see par lab see par setParUsrBB default FALSE; set par “usr” bounding box; see bgMap object class ggmap, returned function RgoogleMaps::GetMap expandBB numeric; fractional values expand bounding box , direction (bottom, left, top, right) graticule logical, object class crs (e.g., st_crs(4326) WGS84 graticule), object created st_graticule; TRUE give WGS84 graticule object returned st_graticule col_graticule color used graticule (present) n integer; number colors cutoff.tails numeric, [0,0.5] start end values alpha numeric, [0,1], transparency categorical logical; want colors categorical variable? (see details) labels character, text draw (one per row input) of_largest_polygon logical, passed st_centroid","code":""},{"path":"https://r-spatial.github.io/sf/reference/plot.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"plot sf object — plot","text":"plot.sf maximally plots max.plot maps colors following attribute columns, one map per attribute. uses sf.colors default colors. control placement individual maps, set parameter mfrow par prior plotting, plot single maps one one; note works combination setting parameters key.pos=NULL (legend) reset=FALSE. plot.sfc plots geometry, additional parameters can passed control color, lines symbols. setting reset FALSE, original device parameters lost, device must reset using dev.() order reset . parameter can set specify labels placed along key; see examples. features plotted order apppear sf object. See examples different plotting order wanted. plot_sf sets plotting area, axes, graticule, webmap background; called plot methods anything drawn. argument setParUsrBB may used pass logical value TRUE functions within plot.Spatial. set TRUE, par(“usr”) overwritten c(xlim, ylim), defaults bounding box spatial object. needed particular context graphic output specified device given width height, matched spatial object, using par(“xaxs”) par(“yaxs”) addition par(mar=c(0,0,0,0)). default aspect map plots 1; however data projected (coordinates long/lat), aspect default set 1/cos(* pi/180) y coordinate middle map (mean ylim, defaults y range bounding box). implies Equirectangular projection. non-categorical colors sf.colors taken bpy.colors, modified cutoff.tails defaults categorical TRUE, default colors https://colorbrewer2.org/ (n < 9, Set2, else Set3). text.sf adds text existing base graphic. Text placed centroid feature x. Provide POINT features control placement. points.sf adds point symbols existing base graphic. points text shown correctly, try setting argument reset FALSE plot() call.","code":""},{"path":"https://r-spatial.github.io/sf/reference/plot.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"plot sf object — plot","text":"","code":"nc = st_read(system.file(\"gpkg/nc.gpkg\", package=\"sf\"), quiet = TRUE) # plot single attribute, auto-legend: plot(nc[\"SID74\"]) # plot multiple: plot(nc[c(\"SID74\", \"SID79\")]) # better use ggplot2::geom_sf to facet and get a single legend! # adding to a plot of an sf object only works when using reset=FALSE in the first plot: plot(nc[\"SID74\"], reset = FALSE) plot(st_centroid(st_geometry(nc)), add = TRUE) # log10 z-scale: plot(nc[\"SID74\"], logz = TRUE, breaks = c(0,.5,1,1.5,2), at = c(0,.5,1,1.5,2)) # and we need to reset the plotting device after that, e.g. by layout(1) # when plotting only geometries, the reset=FALSE is not needed: plot(st_geometry(nc)) plot(st_geometry(nc)[1], col = 'red', add = TRUE) # add a custom legend to an arbitray plot: layout(matrix(1:2, ncol = 2), widths = c(1, lcm(2))) plot(1) .image_scale(1:10, col = sf.colors(9), key.length = lcm(8), key.pos = 4, at = 1:10) # manipulate plotting order, plot largest polygons first: p = st_polygon(list(rbind(c(0,0), c(1,0), c(1,1), c(0,1), c(0,0)))) x = st_sf(a=1:4, st_sfc(p, p * 2, p * 3, p * 4)) # plot(x, col=2:5) only shows the largest polygon! plot(x[order(st_area(x), decreasing = TRUE),], col = 2:5) # plot largest polygons first sf.colors(10) #> [1] \"#0000B3FF\" \"#0400FFFF\" \"#4500FFFF\" \"#8500FFFF\" \"#C527D8FF\" \"#FF50AFFF\" #> [7] \"#FF7A85FF\" \"#FFA35CFF\" \"#FFCC33FF\" \"#FFF50AFF\" text(nc, labels = substring(nc$NAME,1,1))"},{"path":"https://r-spatial.github.io/sf/reference/prefix_map.html","id":null,"dir":"Reference","previous_headings":"","what":"Map prefix to driver — prefix_map","title":"Map prefix to driver — prefix_map","text":"Map prefix driver","code":""},{"path":"https://r-spatial.github.io/sf/reference/prefix_map.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Map prefix to driver — prefix_map","text":"","code":"prefix_map"},{"path":"https://r-spatial.github.io/sf/reference/prefix_map.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Map prefix to driver — prefix_map","text":"object class list length 10.","code":""},{"path":"https://r-spatial.github.io/sf/reference/proj_tools.html","id":null,"dir":"Reference","previous_headings":"","what":"Manage PROJ settings — proj_tools","title":"Manage PROJ settings — proj_tools","text":"Query manage PROJ search path network settings","code":""},{"path":"https://r-spatial.github.io/sf/reference/proj_tools.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Manage PROJ settings — proj_tools","text":"","code":"sf_proj_search_paths(paths = character(0), with_proj = NA) sf_proj_network(enable = FALSE, url = character(0)) sf_proj_pipelines( source_crs, target_crs, authority = character(0), AOI = numeric(0), Use = \"NONE\", grid_availability = \"USED\", desired_accuracy = -1, strict_containment = FALSE, axis_order_authority_compliant = st_axis_order() )"},{"path":"https://r-spatial.github.io/sf/reference/proj_tools.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Manage PROJ settings — proj_tools","text":"paths search path set; omit paths need queried with_proj logical; NA set GDAL PROJ, otherwise set either PROJ (TRUE) GDAL (FALSE) enable logical; set enable (TRUE) disable (FALSE) proj network search facility url character; use specify override default proj network CDN source_crs, target_crs object class crs character authority character; constrain output pipelines authority AOI length four numeric; desired area interest resulting coordinate transformations (west, south, east, north, degrees). area interest crossing anti-meridian, west greater east. Use one \"NONE\", \"\", \"INTERSECTION\", \"SMALLEST\", indicating AOI's source_crs target_crs used grid_availability character; one \"USED\" (Grid availability used sorting results. Operations grids missing sorted last), \"DISCARD\" (Completely discard operation required grid missing) , \"IGNORED\" (Ignore grid availability . Results presented grids available.), \"AVAILABLE\" (Results presented grids known PROJ (registered grid_alternatives table database) available. Used typically networking enabled.) desired_accuracy numeric; return pipelines least accuracy strict_containment logical; default FALSE; permit partial matching area interest; TRUE strictly contain area interest. area interest either given AOI, implied source/target coordinate reference systems axis_order_authority_compliant logical; FALSE always choose ‘x’ longitude first axis; TRUE, follow axis orders given coordinate reference systems constructing first axis; FALSE, follow axis orders given ","code":""},{"path":"https://r-spatial.github.io/sf/reference/proj_tools.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Manage PROJ settings — proj_tools","text":"sf_proj_search_paths() returns search path (possibly setting ) sf_proj_network called without arguments returns logical indicating whether network search datum grids enabled, called arguments returns character vector URL CDN used (specified url). sf_proj_pipelines() returns table candidate coordinate transformation pipelines along accuracy; NA accuracy indicates ballpark accuracy.","code":""},{"path":"https://r-spatial.github.io/sf/reference/rawToHex.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert raw vector(s) into hexadecimal character string(s) — rawToHex","title":"Convert raw vector(s) into hexadecimal character string(s) — rawToHex","text":"Convert raw vector(s) hexadecimal character string(s)","code":""},{"path":"https://r-spatial.github.io/sf/reference/rawToHex.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert raw vector(s) into hexadecimal character string(s) — rawToHex","text":"","code":"rawToHex(x)"},{"path":"https://r-spatial.github.io/sf/reference/rawToHex.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert raw vector(s) into hexadecimal character string(s) — rawToHex","text":"x raw vector, list raw vectors","code":""},{"path":"https://r-spatial.github.io/sf/reference/reexports.html","id":null,"dir":"Reference","previous_headings":"","what":"Objects exported from other packages — reexports","title":"Objects exported from other packages — reexports","text":"objects imported packages. Follow links see documentation. magrittr %>%","code":""},{"path":"https://r-spatial.github.io/sf/reference/s2.html","id":null,"dir":"Reference","previous_headings":"","what":"functions for spherical geometry, using s2 package — s2","title":"functions for spherical geometry, using s2 package — s2","text":"functions spherical geometry, using s2 package based google s2geometry.io library","code":""},{"path":"https://r-spatial.github.io/sf/reference/s2.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"functions for spherical geometry, using s2 package — s2","text":"","code":"sf_use_s2(use_s2) st_as_s2(x, ...) # S3 method for class 'sf' st_as_s2(x, ...) # S3 method for class 'sfc' st_as_s2( x, ..., oriented = getOption(\"s2_oriented\", FALSE) || isTRUE(attr(x, \"oriented\")), rebuild = FALSE )"},{"path":"https://r-spatial.github.io/sf/reference/s2.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"functions for spherical geometry, using s2 package — s2","text":"use_s2 logical; TRUE, use s2 spherical geometry package geographical coordinate operations x object class sf, sfc sfg ... passed oriented logical; FALSE, polygons cover half globe inverted; TRUE, reversal takes place assumed inside polygon left polygon's path. rebuild logical; call s2_rebuild geometry (think st_make_valid sphere)","code":""},{"path":"https://r-spatial.github.io/sf/reference/s2.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"functions for spherical geometry, using s2 package — s2","text":"sf_use_s2 returns value variable (re)setting , invisibly use_s2 missing.","code":""},{"path":"https://r-spatial.github.io/sf/reference/s2.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"functions for spherical geometry, using s2 package — s2","text":"st_as_s2 converts sf POLYGON object form readable s2.","code":""},{"path":"https://r-spatial.github.io/sf/reference/s2.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"functions for spherical geometry, using s2 package — s2","text":"","code":"m = rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1)) m1 = rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,0), c(-1,-1)) m0 = m[5:1,] mp = st_multipolygon(list( list(m, 0.8 * m0, 0.01 * m1 + 0.9), list(0.7* m, 0.6*m0), list(0.5 * m0), list(m+2), list(m+4,(.9*m0)+4) )) sf = st_sfc(mp, mp, crs = 'EPSG:4326') s2 = st_as_s2(sf)"},{"path":"https://r-spatial.github.io/sf/reference/sf-defunct.html","id":null,"dir":"Reference","previous_headings":"","what":"Deprecated functions in sf — sf-defunct","title":"Deprecated functions in sf — sf-defunct","text":"functions provided compatibility older version sf. eventually completely removed. Use st_read() instead st_read_db(). Use st_write() instead_of st_write_db()","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf-defunct.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Deprecated functions in sf — sf-defunct","text":"","code":"st_read_db( conn = NULL, table = NULL, query = NULL, geom_column = NULL, EWKB = TRUE, ... ) st_write_db( conn = NULL, obj, table = deparse(substitute(obj)), ..., drop = FALSE, append = FALSE )"},{"path":"https://r-spatial.github.io/sf/reference/sf-defunct.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Deprecated functions in sf — sf-defunct","text":"conn open database connection table table name query SQL query select records; see details geom_column deprecated. Geometry column name EWKB logical; WKB type EWKB? missing, defaults TRUE ... parameter(s) passed st_as_sf","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf-defunct.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Deprecated functions in sf — sf-defunct","text":"geom_column argument deprecated. function automatically find geometry type columns. RPostgreSQL drivers try cast character columns, can long wide tables.","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf-package.html","id":null,"dir":"Reference","previous_headings":"","what":"sf: Simple Features for R — sf-package","title":"sf: Simple Features for R — sf-package","text":"Support simple features, standardized way encode spatial vector data. Binds 'GDAL' reading writing data, 'GEOS' geometrical operations, 'PROJ' projection conversions datum transformations. Uses default 's2' package spherical geometry operations ellipsoidal (long/lat) coordinates.","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf-package.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"sf: Simple Features for R — sf-package","text":"Pebesma, E. Bivand, R. (2023). Spatial Data Science: Applications R. Chapman Hall/CRC. doi:10.1201/9780429459016 also found freely online https://r-spatial.org/book/ Pebesma, E., 2018. Simple Features R: Standardized Support Spatial Vector Data. R Journal 10 (1), 439-446, doi:10.32614/RJ-2018-009 (open access)","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/sf-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"sf: Simple Features for R — sf-package","text":"Maintainer: Edzer Pebesma edzer.pebesma@uni-muenster.de (ORCID) contributors: Roger Bivand (ORCID) [contributor] Etienne Racine [contributor] Michael Sumner [contributor] Ian Cook [contributor] Tim Keitt [contributor] Robin Lovelace [contributor] Hadley Wickham [contributor] Jeroen Ooms (ORCID) [contributor] Kirill Müller [contributor] Thomas Lin Pedersen [contributor] Dan Baston [contributor] Dewey Dunnington (ORCID) [contributor]","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf.html","id":null,"dir":"Reference","previous_headings":"","what":"Create sf object — sf","title":"Create sf object — sf","text":"Create sf, extends data.frame-like objects simple feature list column. convert data frame object sf, use st_as_sf()","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create sf object — sf","text":"","code":"st_sf( ..., agr = NA_agr_, row.names, stringsAsFactors = sf_stringsAsFactors(), crs, precision, sf_column_name = NULL, check_ring_dir = FALSE, sfc_last = TRUE ) # S3 method for class 'sf' x[i, j, ..., drop = FALSE, op = st_intersects] # S3 method for class 'sf' print(x, ..., n = getOption(\"sf_max_print\", default = 10))"},{"path":"https://r-spatial.github.io/sf/reference/sf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create sf object — sf","text":"... column elements binded sf object single list data.frame columns; least one columns shall geometry list-column class sfc list-column can converted sfc st_as_sfc. agr character vector; see details . row.names row.names created sf object stringsAsFactors logical; see st_read crs coordinate reference system, something suitable input st_crs precision numeric; see st_as_binary sf_column_name character; name active list-column simple feature geometries; case one sf_column_name NULL, first one taken. check_ring_dir see st_read sfc_last logical; TRUE, sfc columns always put last, otherwise column order left unmodified. x object class sf record selection, see [.data.frame, sf object work op argument j variable selection, see [.data.frame drop logical, default FALSE; TRUE drop geometry column return data.frame, else make geometry sticky return sf object. op function; geometrical binary predicate function apply simple feature object n maximum number features print; can set globally options(sf_max_print=...)","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create sf object — sf","text":"agr, attribute-geometry-relationship, specifies non-geometry attribute column relates geometry, can one following values: \"constant\", \"aggregate\", \"identity\". \"constant\" used attributes constant throughout geometry (e.g. land use), \"aggregate\" attribute aggregate value geometry (e.g. population density population count), \"identity\" attributes uniquely identifies geometry particular \"thing\", building ID city name. default value, NA_agr_, implies know. single value provided agr, cascaded across input columns; otherwise, named vector like c(feature1='constant', ...) set agr value 'constant' input column named feature1. See demo(nc) worked example . confronted data.frame-like object, st_sf try find geometry column class sfc, otherwise try convert list-columns available geometry column, using st_as_sfc. [.sf return data.frame vector geometry column (class sfc) dropped (drop=TRUE), sfc object geometry column selected, otherwise return sf object; see also [.data.frame; [.sf ... arguments passed op.","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create sf object — sf","text":"","code":"g = st_sfc(st_point(1:2)) st_sf(a=3,g) #> Simple feature collection with 1 feature and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2 #> CRS: NA #> a g #> 1 3 POINT (1 2) st_sf(g, a=3) #> Simple feature collection with 1 feature and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2 #> CRS: NA #> a g #> 1 3 POINT (1 2) st_sf(a=3, st_sfc(st_point(1:2))) # better to name it! #> Simple feature collection with 1 feature and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2 #> CRS: NA #> a st_sfc.st_point.1.2.. #> 1 3 POINT (1 2) # create empty structure with preallocated empty geometries: nrows <- 10 geometry = st_sfc(lapply(1:nrows, function(x) st_geometrycollection())) df <- st_sf(id = 1:nrows, geometry = geometry) g = st_sfc(st_point(1:2), st_point(3:4)) s = st_sf(a=3:4, g) s[1,] #> Simple feature collection with 1 feature and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2 #> CRS: NA #> a g #> 1 3 POINT (1 2) class(s[1,]) #> [1] \"sf\" \"data.frame\" s[,1] #> Simple feature collection with 2 features and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 3 ymax: 4 #> CRS: NA #> a g #> 1 3 POINT (1 2) #> 2 4 POINT (3 4) class(s[,1]) #> [1] \"sf\" \"data.frame\" s[,2] #> Simple feature collection with 2 features and 0 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 3 ymax: 4 #> CRS: NA #> g #> 1 POINT (1 2) #> 2 POINT (3 4) class(s[,2]) #> [1] \"sf\" \"data.frame\" g = st_sf(a=2:3, g) pol = st_sfc(st_polygon(list(cbind(c(0,3,3,0,0),c(0,0,3,3,0))))) h = st_sf(r = 5, pol) g[h,] #> Simple feature collection with 1 feature and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2 #> CRS: NA #> a g #> 1 2 POINT (1 2) h[g,] #> Simple feature collection with 1 feature and 1 field #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 3 ymax: 3 #> CRS: NA #> r pol #> 1 5 POLYGON ((0 0, 3 0, 3 3, 0 ..."},{"path":"https://r-spatial.github.io/sf/reference/sf_extSoftVersion.html","id":null,"dir":"Reference","previous_headings":"","what":"Provide the external dependencies versions of the libraries linked to sf — sf_extSoftVersion","title":"Provide the external dependencies versions of the libraries linked to sf — sf_extSoftVersion","text":"Provide external dependencies versions libraries linked sf","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf_extSoftVersion.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Provide the external dependencies versions of the libraries linked to sf — sf_extSoftVersion","text":"","code":"sf_extSoftVersion()"},{"path":"https://r-spatial.github.io/sf/reference/sf_project.html","id":null,"dir":"Reference","previous_headings":"","what":"directly transform a set of coordinates — sf_project","title":"directly transform a set of coordinates — sf_project","text":"directly transform set coordinates","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf_project.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"directly transform a set of coordinates — sf_project","text":"","code":"sf_add_proj_units() sf_project( from = character(0), to = character(0), pts, keep = FALSE, warn = TRUE, authority_compliant = st_axis_order() )"},{"path":"https://r-spatial.github.io/sf/reference/sf_project.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"directly transform a set of coordinates — sf_project","text":"character description source CRS, object class crs, pipeline describing transformation character description target CRS, object class crs pts two-, three- four-column numeric matrix, object can coerced matrix; columns 3 4 contain z t values. keep logical value controlling handling unprojectable points. keep TRUE, points yield Inf -Inf return value; otherwise error reported nothing returned. warn logical; TRUE, warn non-finite values generated authority_compliant logical; TRUE means handle axis order authority compliant (e.g. EPSG:4326 implying x=lat, y=lon), FALSE means use visualisation order (.e. always x=lon, y=lat)","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf_project.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"directly transform a set of coordinates — sf_project","text":"two-column numeric matrix transformed/converted coordinates, returning invalid values Inf","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf_project.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"directly transform a set of coordinates — sf_project","text":"sf_add_proj_units loads PROJ units link, us_in, ind_yd, ind_ft, ind_ch udunits database, returns TRUE invisibly success.","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf_project.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"directly transform a set of coordinates — sf_project","text":"","code":"sf_add_proj_units()"},{"path":"https://r-spatial.github.io/sf/reference/sfc.html","id":null,"dir":"Reference","previous_headings":"","what":"Create simple feature geometry list column — sfc","title":"Create simple feature geometry list column — sfc","text":"Create simple feature geometry list column, set class, add coordinate reference system precision. data.frame alternatives see st_sf(). convert foreign object sfc, see st_as_sfc()","code":""},{"path":"https://r-spatial.github.io/sf/reference/sfc.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create simple feature geometry list column — sfc","text":"","code":"st_sfc( ..., crs = NA_crs_, precision = 0, check_ring_dir = FALSE, dim, recompute_bbox = FALSE, oriented = NA ) # S3 method for class 'sfc' x[i, j, ..., op = st_intersects]"},{"path":"https://r-spatial.github.io/sf/reference/sfc.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create simple feature geometry list column — sfc","text":"... zero simple feature geometries (objects class sfg), single list objects; NULL values get replaced empty geometries. crs coordinate reference system: integer EPSG code, character proj4string precision numeric; see st_as_binary check_ring_dir see st_read dim character; function called without valid geometries, argument may carry right dimension set empty geometries recompute_bbox logical; use TRUE force recomputation bounding box oriented logical; TRUE, ring oriented left edges inside polygon; needed convering polygons larger half globe s2 x object class sfc record selection. Might also sfc/sf object work op argument j ignored op specified op function, geometrical binary predicate function apply sf/sfc object. Additional arguments can specified using ..., see examples.","code":""},{"path":"https://r-spatial.github.io/sf/reference/sfc.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create simple feature geometry list column — sfc","text":"object class sfc, classed list-column simple feature geometries.","code":""},{"path":"https://r-spatial.github.io/sf/reference/sfc.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create simple feature geometry list column — sfc","text":"simple feature geometry list-column list class c(\"stc_TYPE\", \"sfc\") often contains objects identical type; case mix types empty set, TYPE set superclass GEOMETRY. x dim attribute (.e. array matrix) op used.","code":""},{"path":"https://r-spatial.github.io/sf/reference/sfc.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create simple feature geometry list column — sfc","text":"","code":"pt1 = st_point(c(0,1)) pt2 = st_point(c(1,1)) (sfc = st_sfc(pt1, pt2)) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 1 ymax: 1 #> CRS: NA #> POINT (0 1) #> POINT (1 1) sfc[sfc[1], op = st_is_within_distance, dist = 0.5] #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 0 ymax: 1 #> CRS: NA #> POINT (0 1) d = st_sf(data.frame(a=1:2, geom=sfc))"},{"path":"https://r-spatial.github.io/sf/reference/sgbp.html","id":null,"dir":"Reference","previous_headings":"","what":"Methods for dealing with sparse geometry binary predicate lists — sgbp","title":"Methods for dealing with sparse geometry binary predicate lists — sgbp","text":"Methods dealing sparse geometry binary predicate lists","code":""},{"path":"https://r-spatial.github.io/sf/reference/sgbp.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Methods for dealing with sparse geometry binary predicate lists — sgbp","text":"","code":"# S3 method for class 'sgbp' print(x, ..., n = 10, max_nb = 10) # S3 method for class 'sgbp' t(x) # S3 method for class 'sgbp' as.matrix(x, ...) # S3 method for class 'sgbp' dim(x) # S3 method for class 'sgbp' Ops(e1, e2) # S3 method for class 'sgbp' as.data.frame(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/sgbp.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Methods for dealing with sparse geometry binary predicate lists — sgbp","text":"x object class sgbp ... ignored n integer; maximum number items print max_nb integer; maximum number neighbours print item e1 object class sgbp e2 object class sgbp","code":""},{"path":"https://r-spatial.github.io/sf/reference/sgbp.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Methods for dealing with sparse geometry binary predicate lists — sgbp","text":"sgbp sparse matrices, stored list integer vectors holding ordered TRUE indices row. means dense, \\(m \\times n\\) matrix Q list L, Q[,j] TRUE \\(j\\) element L[[]]. Reversed: \\(k\\) value L[[]][j], Q[,k] TRUE. == compares dimension index values, attributes two sgbp object; use identical check equality everything.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st.html","id":null,"dir":"Reference","previous_headings":"","what":"Create simple feature from a numeric vector, matrix or list — st","title":"Create simple feature from a numeric vector, matrix or list — st","text":"Create simple feature numeric vector, matrix list","code":""},{"path":"https://r-spatial.github.io/sf/reference/st.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create simple feature from a numeric vector, matrix or list — st","text":"","code":"st_point(x = c(NA_real_, NA_real_), dim = \"XYZ\") st_multipoint(x = matrix(numeric(0), 0, 2), dim = \"XYZ\") st_linestring(x = matrix(numeric(0), 0, 2), dim = \"XYZ\") st_polygon(x = list(), dim = if (length(x)) \"XYZ\" else \"XY\") st_multilinestring(x = list(), dim = if (length(x)) \"XYZ\" else \"XY\") st_multipolygon(x = list(), dim = if (length(x)) \"XYZ\" else \"XY\") st_geometrycollection(x = list(), dims = \"XY\") # S3 method for class 'sfg' print(x, ..., width = 0) # S3 method for class 'sfg' head(x, n = 10L, ...) # S3 method for class 'sfg' format(x, ..., width = 30) # S3 method for class 'sfg' c(..., recursive = FALSE, flatten = TRUE) # S3 method for class 'sfg' as.matrix(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create simple feature from a numeric vector, matrix or list — st","text":"x st_point, numeric vector (one-row-matrix) length 2, 3 4; st_linestring st_multipoint, numeric matrix points rows; st_polygon st_multilinestring, list numeric matrices points rows; st_multipolygon, list lists numeric matrices; st_geometrycollection list (non-geometrycollection) simple feature geometry (sfg) objects; see examples dim character, indicating dimensions: \"XY\", \"XYZ\", \"XYM\", \"XYZM\"; really needed three-dimensional points (can either XYZ XYM) empty geometries; see details dims character; specify dimensionality case empty (NULL) geometrycollection, case x empty list(). ... objects pasted together single simple feature width integer; number characters printed (max 30; 0 means print everything) n integer; number elements selected recursive logical; ignored flatten logical; TRUE, try simplify results; FALSE, return geometrycollection containing objects","code":""},{"path":"https://r-spatial.github.io/sf/reference/st.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create simple feature from a numeric vector, matrix or list — st","text":"object nature x, appropriate class attribute set .matrix returns set points form geometry single matrix, point row; use unlist(x, recursive = FALSE) get sets matrices.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create simple feature from a numeric vector, matrix or list — st","text":"\"XYZ\" refers coordinates third dimension represents altitude, \"XYM\" refers three-dimensional coordinates third dimension refers something else (\"M\" measure); checking sanity x may partial. flatten=TRUE, method may merge points multipoint structure, may preserve order, hence reverted. given fish, returns fish soup.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create simple feature from a numeric vector, matrix or list — st","text":"","code":"(p1 = st_point(c(1,2))) #> POINT (1 2) class(p1) #> [1] \"XY\" \"POINT\" \"sfg\" st_bbox(p1) #> xmin ymin xmax ymax #> 1 2 1 2 (p2 = st_point(c(1,2,3))) #> POINT Z (1 2 3) class(p2) #> [1] \"XYZ\" \"POINT\" \"sfg\" (p3 = st_point(c(1,2,3), \"XYM\")) #> POINT M (1 2 3) pts = matrix(1:10, , 2) (mp1 = st_multipoint(pts)) #> MULTIPOINT ((1 6), (2 7), (3 8), (4 9), (5 10)) pts = matrix(1:15, , 3) (mp2 = st_multipoint(pts)) #> MULTIPOINT Z ((1 6 11), (2 7 12), (3 8 13), (4 9 14), (5 10 15)) (mp3 = st_multipoint(pts, \"XYM\")) #> MULTIPOINT M ((1 6 11), (2 7 12), (3 8 13), (4 9 14), (5 10 15)) pts = matrix(1:20, , 4) (mp4 = st_multipoint(pts)) #> MULTIPOINT ZM ((1 6 11 16), (2 7 12 17), (3 8 13 18), (4 9 14 19), (5 10 15 20)) pts = matrix(1:10, , 2) (ls1 = st_linestring(pts)) #> LINESTRING (1 6, 2 7, 3 8, 4 9, 5 10) pts = matrix(1:15, , 3) (ls2 = st_linestring(pts)) #> LINESTRING Z (1 6 11, 2 7 12, 3 8 13, 4 9 14, 5 10 15) (ls3 = st_linestring(pts, \"XYM\")) #> LINESTRING M (1 6 11, 2 7 12, 3 8 13, 4 9 14, 5 10 15) pts = matrix(1:20, , 4) (ls4 = st_linestring(pts)) #> LINESTRING ZM (1 6 11 16, 2 7 12 17, 3 8 13 18, 4 9 14 19, 5 10 15 20) 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)) #> 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)) pts3 = lapply(pts, function(x) cbind(x, 0)) (ml2 = st_multilinestring(pts3)) #> 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)) (ml3 = st_multilinestring(pts3, \"XYM\")) #> 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)) pts4 = lapply(pts3, function(x) cbind(x, 0)) (ml4 = st_multilinestring(pts4)) #> 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)) 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) (pl1 = st_polygon(pts)) #> 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)) pts3 = lapply(pts, function(x) cbind(x, 0)) (pl2 = st_polygon(pts3)) #> 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)) (pl3 = st_polygon(pts3, \"XYM\")) #> 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)) pts4 = lapply(pts3, function(x) cbind(x, 0)) (pl4 = st_polygon(pts4)) #> 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)) pol1 = list(outer, hole1, hole2) pol2 = list(outer + 12, hole1 + 12) pol3 = list(outer + 24) mp = list(pol1,pol2,pol3) (mp1 = st_multipolygon(mp)) #> 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))) pts3 = lapply(mp, function(x) lapply(x, function(y) cbind(y, 0))) (mp2 = st_multipolygon(pts3)) #> 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))) (mp3 = st_multipolygon(pts3, \"XYM\")) #> 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))) pts4 = lapply(mp2, function(x) lapply(x, function(y) cbind(y, 0))) (mp4 = st_multipolygon(pts4)) #> 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))) (gc = st_geometrycollection(list(p1, ls1, pl1, mp1))) #> GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (1 6, 2 7, 3 8, 4 9, 5 10), 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)), 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)))) st_geometrycollection() # empty geometry #> GEOMETRYCOLLECTION EMPTY c(st_point(1:2), st_point(5:6)) #> MULTIPOINT ((1 2), (5 6)) c(st_point(1:2), st_multipoint(matrix(5:8,2))) #> MULTIPOINT ((1 2), (5 7), (6 8)) c(st_multipoint(matrix(1:4,2)), st_multipoint(matrix(5:8,2))) #> MULTIPOINT ((1 3), (2 4), (5 7), (6 8)) c(st_linestring(matrix(1:6,3)), st_linestring(matrix(11:16,3))) #> MULTILINESTRING ((1 4, 2 5, 3 6), (11 14, 12 15, 13 16)) c(st_multilinestring(list(matrix(1:6,3))), st_multilinestring(list(matrix(11:16,3)))) #> MULTILINESTRING ((1 4, 2 5, 3 6), (11 14, 12 15, 13 16)) pl = list(rbind(c(0,0), c(1,0), c(1,1), c(0,1), c(0,0))) c(st_polygon(pl), st_polygon(pl)) #> MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((0 0, 1 0, 1 1, 0 1, 0 0))) c(st_polygon(pl), st_multipolygon(list(pl))) #> MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((0 0, 1 0, 1 1, 0 1, 0 0))) c(st_linestring(matrix(1:6,3)), st_point(1:2)) #> GEOMETRYCOLLECTION (LINESTRING (1 4, 2 5, 3 6), POINT (1 2)) c(st_geometrycollection(list(st_point(1:2), st_linestring(matrix(1:6,3)))), st_geometrycollection(list(st_multilinestring(list(matrix(11:16,3)))))) #> GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (1 4, 2 5, 3 6), MULTILINESTRING ((11 14, 12 15, 13 16))) c(st_geometrycollection(list(st_point(1:2), st_linestring(matrix(1:6,3)))), st_multilinestring(list(matrix(11:16,3))), st_point(5:6), st_geometrycollection(list(st_point(10:11)))) #> GEOMETRYCOLLECTION (MULTILINESTRING ((11 14, 12 15, 13 16)), POINT (5 6), POINT (1 2), LINESTRING (1 4, 2 5, 3 6), POINT (10 11))"},{"path":"https://r-spatial.github.io/sf/reference/st_agr.html","id":null,"dir":"Reference","previous_headings":"","what":"get or set relation_to_geometry attribute of an sf object — st_agr","title":"get or set relation_to_geometry attribute of an sf object — st_agr","text":"get set relation_to_geometry attribute sf object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_agr.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"get or set relation_to_geometry attribute of an sf object — st_agr","text":"","code":"NA_agr_ st_agr(x, ...) st_agr(x) <- value st_set_agr(x, value)"},{"path":"https://r-spatial.github.io/sf/reference/st_agr.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"get or set relation_to_geometry attribute of an sf object — st_agr","text":"object class factor length 1.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_agr.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"get or set relation_to_geometry attribute of an sf object — st_agr","text":"x object class sf ... ignored value character, factor appropriate levels; named, names correspond non-geometry list-column columns x","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_agr.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"get or set relation_to_geometry attribute of an sf object — st_agr","text":"NA_agr_ agr object missing value.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_binary.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert sfc object to an WKB object — st_as_binary","title":"Convert sfc object to an WKB object — st_as_binary","text":"Convert sfc object WKB object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_binary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert sfc object to an WKB object — st_as_binary","text":"","code":"st_as_binary(x, ...) # S3 method for class 'sfc' st_as_binary( x, ..., EWKB = FALSE, endian = .Platform$endian, pureR = FALSE, precision = attr(x, \"precision\"), hex = FALSE ) # S3 method for class 'sfg' st_as_binary( x, ..., endian = .Platform$endian, EWKB = FALSE, pureR = FALSE, hex = FALSE, srid = 0 )"},{"path":"https://r-spatial.github.io/sf/reference/st_as_binary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert sfc object to an WKB object — st_as_binary","text":"x object convert ... ignored EWKB logical; use EWKB (PostGIS), (default) ISO-WKB? endian character; either \"big\" \"little\"; default: use platform pureR logical; use pure R solution, C++? precision numeric; zero, modify; reduce precision: negative values convert float (4-byte real); positive values convert round(x*precision)/precision. See details. hex logical; return (unclassed) hexadecimal encoded character vector? srid integer; override srid (can used srid unavailable locally).","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_binary.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Convert sfc object to an WKB object — st_as_binary","text":"st_as_binary called sfc objects way GDAL GEOS libraries, hence rounding (requested) fly e.g. computing spatial predicates like st_intersects. examples show round-trip sfc binary. precision model used, see also https://locationtech.github.io/jts/javadoc/org/locationtech/jts/geom/PrecisionModel.html. , written : “... specify 3 decimal places precision, use scale factor 1000. specify -3 decimal places precision (.e. rounding nearest 1000), use scale factor 0.001.”. Note coordinates, also Z M values (present) affected.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_binary.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert sfc object to an WKB object — st_as_binary","text":"","code":"# examples of setting precision: st_point(c(1/3, 1/6)) %>% st_sfc(precision = 1000) %>% st_as_binary %>% st_as_sfc #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0.333 ymin: 0.167 xmax: 0.333 ymax: 0.167 #> CRS: NA #> POINT (0.333 0.167) st_point(c(1/3, 1/6)) %>% st_sfc(precision = 100) %>% st_as_binary %>% st_as_sfc #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0.33 ymin: 0.17 xmax: 0.33 ymax: 0.17 #> CRS: NA #> POINT (0.33 0.17) st_point(1e6 * c(1/3, 1/6)) %>% st_sfc(precision = 0.01) %>% st_as_binary %>% st_as_sfc #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 333300 ymin: 166700 xmax: 333300 ymax: 166700 #> CRS: NA #> POINT (333300 166700) st_point(1e6 * c(1/3, 1/6)) %>% st_sfc(precision = 0.001) %>% st_as_binary %>% st_as_sfc #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 333000 ymin: 167000 xmax: 333000 ymax: 167000 #> CRS: NA #> POINT (333000 167000)"},{"path":"https://r-spatial.github.io/sf/reference/st_as_grob.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert sf* object to a grob — st_as_grob","title":"Convert sf* object to a grob — st_as_grob","text":"Convert sf* object grid graphics object (grob)","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_grob.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert sf* object to a grob — st_as_grob","text":"","code":"st_as_grob(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_as_grob.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert sf* object to a grob — st_as_grob","text":"x object converted object class grob ... passed xxxGrob function, e.g. gp = gpar(col = 'red')","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_sf.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert foreign object to an sf object — st_as_sf","title":"Convert foreign object to an sf object — st_as_sf","text":"Convert foreign object sf object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_sf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert foreign object to an sf object — st_as_sf","text":"","code":"st_as_sf(x, ...) # S3 method for class 'data.frame' st_as_sf( x, ..., agr = NA_agr_, coords, wkt, dim = \"XYZ\", remove = TRUE, na.fail = TRUE, sf_column_name = NULL ) # S3 method for class 'sf' st_as_sf(x, ...) # S3 method for class 'sfc' st_as_sf(x, ...) # S3 method for class 'Spatial' st_as_sf(x, ...) # S3 method for class 'map' st_as_sf(x, ..., fill = TRUE, group = TRUE) # S3 method for class 'ppp' st_as_sf(x, ...) # S3 method for class 'psp' st_as_sf(x, ...) # S3 method for class 'lpp' st_as_sf(x, ...) # S3 method for class 's2_geography' st_as_sf(x, ..., crs = st_crs(4326))"},{"path":"https://r-spatial.github.io/sf/reference/st_as_sf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert foreign object to an sf object — st_as_sf","text":"x object converted object class sf ... passed st_sf, might included named arguments crs precision agr character vector; see details section st_sf coords case point data: names numbers numeric columns holding coordinates wkt name number character column holds WKT encoded geometries dim specify 3- 4-dimensional points reflect: passed st_point (argument coords given) remove logical; coords wkt given, remove columns data.frame? na.fail logical; TRUE, raise error coordinates contain missing values sf_column_name character; name active list-column simple feature geometries; case one sf_column_name NULL, first one taken. fill logical; value fill used call map. group logical; TRUE, group id labels map prefix : crs coordinate reference system assigned; object class crs","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_sf.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Convert foreign object to an sf object — st_as_sf","text":"setting argument wkt annihilates use argument coords. x contains column called \"geometry\", coords result overwriting column sfc geometry list-column. Setting wkt replace column geometry list-column, unless remove FALSE. coords length 4, dim XYZM, four columns taken xmin, ymin, xmax, ymax corner coordinates rectangle, polygons returned.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_sf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert foreign object to an sf object — st_as_sf","text":"","code":"pt1 = st_point(c(0,1)) pt2 = st_point(c(1,1)) st_sfc(pt1, pt2) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 1 ymax: 1 #> CRS: NA #> POINT (0 1) #> POINT (1 1) d = data.frame(a = 1:2) d$geom = st_sfc(pt1, pt2) df = st_as_sf(d) d$geom = c(\"POINT(0 0)\", \"POINT(0 1)\") df = st_as_sf(d, wkt = \"geom\") d$geom2 = st_sfc(pt1, pt2) st_as_sf(d) # should warn #> Simple feature collection with 2 features and 2 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 1 ymax: 1 #> CRS: NA #> a geom geom2 #> 1 1 POINT(0 0) POINT (0 1) #> 2 2 POINT(0 1) POINT (1 1) if (require(sp, quietly = TRUE)) { data(meuse, package = \"sp\") meuse_sf = st_as_sf(meuse, coords = c(\"x\", \"y\"), crs = 28992, agr = \"constant\") meuse_sf[1:3,] summary(meuse_sf) } #> cadmium copper lead zinc #> Min. : 0.200 Min. : 14.00 Min. : 37.0 Min. : 113.0 #> 1st Qu.: 0.800 1st Qu.: 23.00 1st Qu.: 72.5 1st Qu.: 198.0 #> Median : 2.100 Median : 31.00 Median :123.0 Median : 326.0 #> Mean : 3.246 Mean : 40.32 Mean :153.4 Mean : 469.7 #> 3rd Qu.: 3.850 3rd Qu.: 49.50 3rd Qu.:207.0 3rd Qu.: 674.5 #> Max. :18.100 Max. :128.00 Max. :654.0 Max. :1839.0 #> #> elev dist om ffreq soil lime #> Min. : 5.180 Min. :0.00000 Min. : 1.000 1:84 1:97 0:111 #> 1st Qu.: 7.546 1st Qu.:0.07569 1st Qu.: 5.300 2:48 2:46 1: 44 #> Median : 8.180 Median :0.21184 Median : 6.900 3:23 3:12 #> Mean : 8.165 Mean :0.24002 Mean : 7.478 #> 3rd Qu.: 8.955 3rd Qu.:0.36407 3rd Qu.: 9.000 #> Max. :10.520 Max. :0.88039 Max. :17.000 #> NA's :2 #> landuse dist.m geometry #> W :50 Min. : 10.0 POINT :155 #> Ah :39 1st Qu.: 80.0 epsg:28992 : 0 #> Am :22 Median : 270.0 +proj=ster...: 0 #> Fw :10 Mean : 290.3 #> Ab : 8 3rd Qu.: 450.0 #> (Other):25 Max. :1000.0 #> NA's : 1 if (require(sp, quietly = TRUE)) { x = rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1)) x1 = 0.1 * x + 0.1 x2 = 0.1 * x + 0.4 x3 = 0.1 * x + 0.7 y = x + 3 y1 = x1 + 3 y3 = x3 + 3 m = matrix(c(3, 0), 5, 2, byrow = TRUE) z = x + m z1 = x1 + m z2 = x2 + m z3 = x3 + m p1 = Polygons(list( Polygon(x[5:1,]), Polygon(x2), Polygon(x3), Polygon(y[5:1,]), Polygon(y1), Polygon(x1), Polygon(y3)), \"ID1\") p2 = Polygons(list( Polygon(z[5:1,]), Polygon(z2), Polygon(z3), Polygon(z1)), \"ID2\") r = SpatialPolygons(list(p1,p2)) a = suppressWarnings(st_as_sf(r)) summary(a) demo(meuse, ask = FALSE, echo = FALSE) summary(st_as_sf(meuse)) summary(st_as_sf(meuse.grid)) summary(st_as_sf(meuse.area)) summary(st_as_sf(meuse.riv)) summary(st_as_sf(as(meuse.riv, \"SpatialLines\"))) pol.grd = as(meuse.grid, \"SpatialPolygonsDataFrame\") # summary(st_as_sf(pol.grd)) # summary(st_as_sf(as(pol.grd, \"SpatialLinesDataFrame\"))) } if (require(spatstat.geom)) { g = st_as_sf(gorillas) # select only the points: g[st_is(g, \"POINT\"),] } #> Loading required package: spatstat.geom #> Loading required package: spatstat.data #> Loading required package: spatstat.univar #> spatstat.univar 3.0-1 #> spatstat.geom 3.3-3 #> Simple feature collection with 647 features and 4 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 580797.3 ymin: 675238.7 xmax: 584945.3 ymax: 678313.5 #> CRS: NA #> First 10 features: #> group season date label geom #> 1 major dry 2006-01-06 point POINT (582518.4 676886.2) #> 2 major dry 2006-01-10 point POINT (581823 677422.7) #> 3 major dry 2006-01-15 point POINT (582131 676937.9) #> 4 major dry 2006-01-24 point POINT (582111.9 677420) #> 5 minor dry 2006-01-27 point POINT (582585.1 677509.7) #> 6 major dry 2006-01-28 point POINT (582302.3 677521.6) #> 7 major dry 2006-02-01 point POINT (583167.2 676730.5) #> 8 major dry 2006-02-03 point POINT (583584.5 677207.1) #> 9 major dry 2006-02-13 point POINT (583117.8 676850.3) #> 10 major dry 2006-02-15 point POINT (582902.8 676724.1) if (require(spatstat.linnet)) { data(chicago) plot(st_as_sf(chicago)[\"label\"]) plot(st_as_sf(chicago)[-1,\"label\"]) } #> Loading required package: spatstat.linnet #> Loading required package: spatstat.random #> spatstat.random 3.3-2 #> Loading required package: spatstat.explore #> Loading required package: nlme #> #> Attaching package: ‘nlme’ #> The following object is masked from ‘package:dplyr’: #> #> collapse #> spatstat.explore 3.3-3 #> Loading required package: spatstat.model #> Loading required package: rpart #> spatstat.model 3.3-2 #> spatstat.linnet 3.2-2"},{"path":"https://r-spatial.github.io/sf/reference/st_as_sfc.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert foreign geometry object to an sfc object — st_as_sfc","title":"Convert foreign geometry object to an sfc object — st_as_sfc","text":"Convert foreign geometry object sfc object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_sfc.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert foreign geometry object to an sfc object — st_as_sfc","text":"","code":"# S3 method for class 'pq_geometry' st_as_sfc( x, ..., EWKB = TRUE, spatialite = FALSE, pureR = FALSE, crs = NA_crs_ ) # S3 method for class 'list' st_as_sfc(x, ..., crs = NA_crs_) # S3 method for class 'blob' st_as_sfc(x, ...) # S3 method for class 'bbox' st_as_sfc(x, ...) # S3 method for class 'WKB' st_as_sfc( x, ..., EWKB = FALSE, spatialite = FALSE, pureR = FALSE, crs = NA_crs_ ) # S3 method for class 'raw' st_as_sfc(x, ...) # S3 method for class 'character' st_as_sfc(x, crs = NA_integer_, ..., GeoJSON = FALSE) # S3 method for class 'factor' st_as_sfc(x, ...) st_as_sfc(x, ...) # S3 method for class 'SpatialPoints' st_as_sfc(x, ..., precision = 0) # S3 method for class 'SpatialPixels' st_as_sfc(x, ..., precision = 0) # S3 method for class 'SpatialMultiPoints' st_as_sfc(x, ..., precision = 0) # S3 method for class 'SpatialLines' st_as_sfc(x, ..., precision = 0, forceMulti = FALSE) # S3 method for class 'SpatialPolygons' st_as_sfc(x, ..., precision = 0, forceMulti = FALSE) # S3 method for class 'map' st_as_sfc(x, ...) # S3 method for class 's2_geography' st_as_sfc( x, ..., crs = st_crs(4326), endian = match(.Platform$endian, c(\"big\", \"little\")) - 1L )"},{"path":"https://r-spatial.github.io/sf/reference/st_as_sfc.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert foreign geometry object to an sfc object — st_as_sfc","text":"x object convert ... arguments EWKB logical; TRUE, parse EWKB (extended WKB; PostGIS: ST_AsEWKB), otherwise ISO WKB (PostGIS: ST_AsBinary) spatialite logical; TRUE, WKB assumed spatialite dialect, see https://www.gaia-gis./gaia-sins/BLOB-Geometry.html; supported native endian-ness (.e., files written system endian-ness read). pureR logical; TRUE, use R code, FALSE, use compiled (C++) code; use TRUE endian-ness binary differs host machine (.Platform$endian). crs coordinate reference system assigned; object class crs GeoJSON logical; TRUE, try read geometries GeoJSON text strings geometry, see st_crs() precision precision value; see st_as_binary forceMulti logical; TRUE, force coercion MULTIPOLYGON MULTILINE objects, else autodetect endian integer; 0 1: defaults endian native machine","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_sfc.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Convert foreign geometry object to an sfc object — st_as_sfc","text":"converting WKB, object x either character vector typically obtained PostGIS (either leading \"0x\" without), list raw vectors representing features binary (raw) form. x character vector, vector containing well-known-text, Postgis EWKT GeoJSON representations single geometry vector element. x factor, converted character.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_sfc.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert foreign geometry object to an sfc object — st_as_sfc","text":"","code":"wkb = structure(list(\"01010000204071000000000000801A064100000000AC5C1441\"), class = \"WKB\") st_as_sfc(wkb, EWKB = TRUE) #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 181072 ymin: 333611 xmax: 181072 ymax: 333611 #> Projected CRS: Amersfoort / RD New #> POINT (181072 333611) wkb = structure(list(\"0x01010000204071000000000000801A064100000000AC5C1441\"), class = \"WKB\") st_as_sfc(wkb, EWKB = TRUE) #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 181072 ymin: 333611 xmax: 181072 ymax: 333611 #> Projected CRS: Amersfoort / RD New #> POINT (181072 333611) st_as_sfc(st_as_binary(st_sfc(st_point(0:1)))[[1]], crs = 4326) #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 0 ymax: 1 #> Geodetic CRS: WGS 84 #> POINT (0 1) st_as_sfc(\"SRID=3978;LINESTRING(1663106 -105415,1664320 -104617)\") #> Geometry set for 1 feature #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 1663106 ymin: -105415 xmax: 1664320 ymax: -104617 #> Projected CRS: NAD83 / Canada Atlas Lambert #> LINESTRING (1663106 -105415, 1664320 -104617)"},{"path":"https://r-spatial.github.io/sf/reference/st_as_text.html","id":null,"dir":"Reference","previous_headings":"","what":"Return Well-known Text representation of simple feature geometry or coordinate reference system — st_as_text","title":"Return Well-known Text representation of simple feature geometry or coordinate reference system — st_as_text","text":"Return Well-known Text representation simple feature geometry coordinate reference system","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_text.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return Well-known Text representation of simple feature geometry or coordinate reference system — st_as_text","text":"","code":"# S3 method for class 'crs' st_as_text(x, ..., projjson = FALSE, pretty = FALSE) st_as_text(x, ...) # S3 method for class 'sfg' st_as_text(x, ...) # S3 method for class 'sfc' st_as_text(x, ..., EWKT = FALSE)"},{"path":"https://r-spatial.github.io/sf/reference/st_as_text.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Return Well-known Text representation of simple feature geometry or coordinate reference system — st_as_text","text":"x object class sfg, sfc crs ... modifiers; particular digits can passed control number digits used projjson logical; TRUE, return projjson form (requires GDAL 3.1 PROJ 6.2), else return well-known-text form pretty logical; TRUE, print human-readable well-known-text representation coordinate reference system EWKT logical; TRUE, print SRID=xxx; WKT string epsg available","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_text.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Return Well-known Text representation of simple feature geometry or coordinate reference system — st_as_text","text":"returned WKT representation simple feature geometry conforms simple features access specification extensions (known EWKT, supported PostGIS simple features implementations addition SRID WKT string).","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_text.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Return Well-known Text representation of simple feature geometry or coordinate reference system — st_as_text","text":"improve conversion performance, lwgeom package can used (must installed beforehand) set Sys.setenv(\"LWGEOM_WKT\" = \"true\") environment variable. also result faster printing complex geometries. Note representation WKT different sf package may cause reproducibility problems. alternative solution use lwgeom::st_astext() wk::as_wkt() functions.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_text.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Return Well-known Text representation of simple feature geometry or coordinate reference system — st_as_text","text":"","code":"st_as_text(st_point(1:2)) #> [1] \"POINT (1 2)\" st_as_text(st_sfc(st_point(c(-90,40)), crs = 4326), EWKT = TRUE) #> [1] \"SRID=4326;POINT (-90 40)\""},{"path":"https://r-spatial.github.io/sf/reference/st_bbox.html","id":null,"dir":"Reference","previous_headings":"","what":"Return bounding of a simple feature or simple feature set — st_bbox","title":"Return bounding of a simple feature or simple feature set — st_bbox","text":"Return bounding simple feature simple feature set","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_bbox.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return bounding of a simple feature or simple feature set — st_bbox","text":"","code":"# S3 method for class 'bbox' is.na(x) st_bbox(obj, ...) # S3 method for class 'POINT' st_bbox(obj, ...) # S3 method for class 'MULTIPOINT' st_bbox(obj, ...) # S3 method for class 'LINESTRING' st_bbox(obj, ...) # S3 method for class 'POLYGON' st_bbox(obj, ...) # S3 method for class 'MULTILINESTRING' st_bbox(obj, ...) # S3 method for class 'MULTIPOLYGON' st_bbox(obj, ...) # S3 method for class 'GEOMETRYCOLLECTION' st_bbox(obj, ...) # S3 method for class 'MULTISURFACE' st_bbox(obj, ...) # S3 method for class 'MULTICURVE' st_bbox(obj, ...) # S3 method for class 'CURVEPOLYGON' st_bbox(obj, ...) # S3 method for class 'COMPOUNDCURVE' st_bbox(obj, ...) # S3 method for class 'POLYHEDRALSURFACE' st_bbox(obj, ...) # S3 method for class 'TIN' st_bbox(obj, ...) # S3 method for class 'TRIANGLE' st_bbox(obj, ...) # S3 method for class 'CIRCULARSTRING' st_bbox(obj, ...) # S3 method for class 'sfc' st_bbox(obj, ...) # S3 method for class 'sf' st_bbox(obj, ...) # S3 method for class 'Spatial' st_bbox(obj, ...) # S3 method for class 'Raster' st_bbox(obj, ...) # S3 method for class 'Extent' st_bbox(obj, ..., crs = NA_crs_) # S3 method for class 'numeric' st_bbox(obj, ..., crs = NA_crs_) NA_bbox_ FULL_bbox_ # S3 method for class 'bbox' format(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_bbox.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Return bounding of a simple feature or simple feature set — st_bbox","text":"object class bbox length 4. object class bbox length 4.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_bbox.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Return bounding of a simple feature or simple feature set — st_bbox","text":"x object class bbox obj object compute bounding box ... format.bbox, passed format format individual numbers crs object class crs, argument st_crs, specifying CRS bounding box.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_bbox.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Return bounding of a simple feature or simple feature set — st_bbox","text":"numeric vector length four, xmin, ymin, xmax ymax values; obj class sf, sfc, Spatial Raster, object returned class bbox, attribute crs method print bbox st_crs method retrieve coordinate reference system corresponding obj (hence bounding box). st_as_sfc methods bbox objects generate polygon around four bounding box points.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_bbox.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Return bounding of a simple feature or simple feature set — st_bbox","text":"NA_bbox_ represents missing value bbox object NA_bbox_ represents missing value bbox object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_bbox.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Return bounding of a simple feature or simple feature set — st_bbox","text":"","code":"a = st_sf(a = 1:2, geom = st_sfc(st_point(0:1), st_point(1:2)), crs = 4326) st_bbox(a) #> xmin ymin xmax ymax #> 0 1 1 2 st_as_sfc(st_bbox(a)) #> Geometry set for 1 feature #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 1 ymax: 2 #> Geodetic CRS: WGS 84 #> POLYGON ((0 1, 1 1, 1 2, 0 2, 0 1)) st_bbox(c(xmin = 16.1, xmax = 16.6, ymax = 48.6, ymin = 47.9), crs = st_crs(4326)) #> xmin ymin xmax ymax #> 16.1 47.9 16.6 48.6"},{"path":"https://r-spatial.github.io/sf/reference/st_break_antimeridian.html","id":null,"dir":"Reference","previous_headings":"","what":"Break antimeridian for plotting not centred on Greenwich — st_break_antimeridian","title":"Break antimeridian for plotting not centred on Greenwich — st_break_antimeridian","text":"Longitudes can broken antimeridian target central longitude permit plotting (usually world) line polygon objects centred chosen central longitude. method may used non-projected, geographical coordinates linestring polygon objects. s2 turned internally permit use rectangular bounding box. input geometries go outside [-180, 180] degrees longitude, protruding geometries also split using tol= values; case empty geometries dropped first.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_break_antimeridian.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Break antimeridian for plotting not centred on Greenwich — st_break_antimeridian","text":"","code":"st_break_antimeridian(x, lon_0 = 0, tol = 1e-04, ...) # S3 method for class 'sf' st_break_antimeridian(x, lon_0 = 0, tol = 1e-04, ...) # S3 method for class 'sfc' st_break_antimeridian(x, lon_0 = 0, tol = 1e-04, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_break_antimeridian.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Break antimeridian for plotting not centred on Greenwich — st_break_antimeridian","text":"x object class sf sfc lon_0 target central longitude (degrees) tol half break width (degrees, default 0.0001) ... ignored ","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_break_antimeridian.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Break antimeridian for plotting not centred on Greenwich — st_break_antimeridian","text":"","code":"# \\donttest{ if (require(\"maps\", quietly=TRUE)) { opar = par(mfrow=c(3, 2)) wld = st_as_sf(map(fill=FALSE, interior=FALSE, plot=FALSE), fill=FALSE) for (lon_0 in c(-170, -90, -10, 10, 90, 170)) { wld |> st_break_antimeridian(lon_0=lon_0) |> st_transform(paste0(\"+proj=natearth +lon_0=\", lon_0)) |> st_geometry() |> plot(main=lon_0) } par(opar) } #> Warning: st_break_antimeridian: longitude coordinates outside [-180, 180] #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Warning: st_break_antimeridian: longitude coordinates outside [-180, 180] #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Warning: st_break_antimeridian: longitude coordinates outside [-180, 180] #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Warning: st_break_antimeridian: longitude coordinates outside [-180, 180] #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Warning: st_break_antimeridian: longitude coordinates outside [-180, 180] #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Warning: st_break_antimeridian: longitude coordinates outside [-180, 180] #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on # }"},{"path":"https://r-spatial.github.io/sf/reference/st_cast.html","id":null,"dir":"Reference","previous_headings":"","what":"Cast geometry to another type: either simplify, or cast explicitly — st_cast","title":"Cast geometry to another type: either simplify, or cast explicitly — st_cast","text":"Cast geometry another type: either simplify, cast explicitly","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_cast.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Cast geometry to another type: either simplify, or cast explicitly — st_cast","text":"","code":"# S3 method for class 'MULTIPOLYGON' st_cast(x, to, ...) # S3 method for class 'MULTILINESTRING' st_cast(x, to, ...) # S3 method for class 'MULTIPOINT' st_cast(x, to, ...) # S3 method for class 'POLYGON' st_cast(x, to, ...) # S3 method for class 'LINESTRING' st_cast(x, to, ...) # S3 method for class 'POINT' st_cast(x, to, ...) # S3 method for class 'GEOMETRYCOLLECTION' st_cast(x, to, ...) # S3 method for class 'CIRCULARSTRING' st_cast(x, to, ...) # S3 method for class 'MULTISURFACE' st_cast(x, to, ...) # S3 method for class 'COMPOUNDCURVE' st_cast(x, to, ...) # S3 method for class 'MULTICURVE' st_cast(x, to, ...) # S3 method for class 'CURVE' st_cast(x, to, ...) st_cast(x, to, ...) # S3 method for class 'sfc' st_cast(x, to, ..., ids = seq_along(x), group_or_split = TRUE) # S3 method for class 'sf' st_cast(x, to, ..., warn = TRUE, do_split = TRUE) # S3 method for class 'sfc_CIRCULARSTRING' st_cast(x, to, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_cast.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Cast geometry to another type: either simplify, or cast explicitly — st_cast","text":"x object class sfg, sfc sf character; target type, missing, simplification tried; x type sfg (.e., single geometry) needs specified. ... ignored ids integer vector, denoting geometries grouped (default: grouping) group_or_split logical; TRUE, group split geometries; FALSE, carry 1-1 per-geometry conversion. warn logical; TRUE, warn attributes assigned sub-geometries do_split logical; TRUE, allow splitting geometries sub-geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_cast.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Cast geometry to another type: either simplify, or cast explicitly — st_cast","text":"object class successful, unmodified object unsuccessful. information gets lost type casting, warning raised. case missing, st_cast.sfc coerce combinations \"POINT\" \"MULTIPOINT\", \"LINESTRING\" \"MULTILINESTRING\", \"POLYGON\" \"MULTIPOLYGON\" \"MULTI...\" form, case geometries \"GEOMETRYCOLLECTION\" return list contents \"GEOMETRYCOLLECTION\" objects, else nothing. case specified, \"GEOMETRY\", geometries converted, else, st_cast try coerce elements ; ids may specified group e.g. \"POINT\" objects \"MULTIPOINT\", specified grouping takes place. e.g. \"sfc_MULTIPOINT\" cast \"sfc_POINT\", objects split, information gets lost, unless group_or_split FALSE.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_cast.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Cast geometry to another type: either simplify, or cast explicitly — st_cast","text":"converting GEOMETRYCOLLECTION COMPOUNDCURVE, MULTISURFACE CURVEPOLYGON, user responsible validity resulting object: checks carried software. converting mixed, GEOMETRY sets, may help first convert MULTI-type, see examples st_cast method sf objects can split geometries, e.g. cast MULTIPOINT multiple POINT features. case splitting, attributes repeated warning issued non-constant attributes assigned sub-geometries. merge feature geometries attribute values, use aggregate summarise.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_cast.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Cast geometry to another type: either simplify, or cast explicitly — st_cast","text":"","code":"# example(st_read) nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 mpl <- st_geometry(nc)[[4]] #st_cast(x) ## error 'argument \"to\" is missing, with no default' cast_all <- function(xg) { lapply(c(\"MULTIPOLYGON\", \"MULTILINESTRING\", \"MULTIPOINT\", \"POLYGON\", \"LINESTRING\", \"POINT\"), function(x) st_cast(xg, x)) } st_sfc(cast_all(mpl)) #> Warning: polygon from first part only #> Warning: line from first ring only #> Warning: point from first coordinate only #> Geometry set for 6 features #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: -76.33025 ymin: 36.07282 xmax: -75.77316 ymax: 36.55716 #> CRS: NA #> First 5 geometries: #> MULTIPOLYGON (((-76.00897 36.3196, -76.01735 36... #> MULTILINESTRING ((-76.00897 36.3196, -76.01735 ... #> MULTIPOINT ((-76.00897 36.3196), (-76.01735 36.... #> POLYGON ((-76.00897 36.3196, -76.01735 36.33773... #> LINESTRING (-76.00897 36.3196, -76.01735 36.337... ## no closing coordinates should remain for multipoint any(duplicated(unclass(st_cast(mpl, \"MULTIPOINT\")))) ## should be FALSE #> [1] FALSE ## number of duplicated coordinates in the linestrings should equal the number of polygon rings ## (... in this case, won't always be true) sum(duplicated(do.call(rbind, unclass(st_cast(mpl, \"MULTILINESTRING\")))) ) == sum(unlist(lapply(mpl, length))) ## should be TRUE #> [1] TRUE p1 <- structure(c(0, 1, 3, 2, 1, 0, 0, 0, 2, 4, 4, 0), .Dim = c(6L, 2L)) p2 <- structure(c(1, 1, 2, 1, 1, 2, 2, 1), .Dim = c(4L, 2L)) st_polygon(list(p1, p2)) #> POLYGON ((0 0, 1 0, 3 2, 2 4, 1 4, 0 0), (1 1, 1 2, 2 2, 1 1)) mls <- st_cast(st_geometry(nc)[[4]], \"MULTILINESTRING\") st_sfc(cast_all(mls)) #> Warning: keeping first linestring only #> Warning: keeping first coordinate only #> Geometry set for 6 features #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: -76.33025 ymin: 36.07282 xmax: -75.77316 ymax: 36.55716 #> CRS: NA #> First 5 geometries: #> MULTIPOLYGON (((-76.00897 36.3196, -76.01735 36... #> MULTILINESTRING ((-76.00897 36.3196, -76.01735 ... #> MULTIPOINT ((-76.00897 36.3196), (-76.01735 36.... #> POLYGON ((-76.00897 36.3196, -76.01735 36.33773... #> LINESTRING (-76.00897 36.3196, -76.01735 36.337... mpt <- st_cast(st_geometry(nc)[[4]], \"MULTIPOINT\") st_sfc(cast_all(mpt)) #> Warning: point from first coordinate only #> Geometry set for 6 features #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: -76.33025 ymin: 36.07282 xmax: -75.77316 ymax: 36.55716 #> CRS: NA #> First 5 geometries: #> MULTIPOLYGON (((-76.00897 36.3196, -76.01735 36... #> MULTILINESTRING ((-76.00897 36.3196, -76.01735 ... #> MULTIPOINT ((-76.00897 36.3196), (-76.01735 36.... #> POLYGON ((-76.00897 36.3196, -76.01735 36.33773... #> LINESTRING (-76.00897 36.3196, -76.01735 36.337... pl <- st_cast(st_geometry(nc)[[4]], \"POLYGON\") #> Warning: polygon from first part only st_sfc(cast_all(pl)) #> Warning: point from first coordinate only #> Geometry set for 6 features #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: -76.33025 ymin: 36.07282 xmax: -75.79885 ymax: 36.55716 #> CRS: NA #> First 5 geometries: #> MULTIPOLYGON (((-76.00897 36.3196, -76.01735 36... #> MULTILINESTRING ((-76.00897 36.3196, -76.01735 ... #> MULTIPOINT ((-76.00897 36.3196), (-76.01735 36.... #> POLYGON ((-76.00897 36.3196, -76.01735 36.33773... #> LINESTRING (-76.00897 36.3196, -76.01735 36.337... ls <- st_cast(st_geometry(nc)[[4]], \"LINESTRING\") #> Warning: line from first ring only st_sfc(cast_all(ls)) #> Warning: point from first coordinate only #> Geometry set for 6 features #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: -76.33025 ymin: 36.07282 xmax: -75.79885 ymax: 36.55716 #> CRS: NA #> First 5 geometries: #> MULTIPOLYGON (((-76.00897 36.3196, -76.01735 36... #> MULTILINESTRING ((-76.00897 36.3196, -76.01735 ... #> MULTIPOINT ((-76.00897 36.3196), (-76.01735 36.... #> POLYGON ((-76.00897 36.3196, -76.01735 36.33773... #> LINESTRING (-76.00897 36.3196, -76.01735 36.337... pt <- st_cast(st_geometry(nc)[[4]], \"POINT\") #> Warning: point from first coordinate only ## st_sfc(cast_all(pt)) ## Error: cannot create MULTIPOLYGON from POINT st_sfc(lapply(c(\"POINT\", \"MULTIPOINT\"), function(x) st_cast(pt, x))) #> Geometry set for 2 features #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: -76.00897 ymin: 36.3196 xmax: -76.00897 ymax: 36.3196 #> CRS: NA #> POINT (-76.00897 36.3196) #> MULTIPOINT ((-76.00897 36.3196)) s = st_multipoint(rbind(c(1,0))) st_cast(s, \"POINT\") #> Warning: point from first coordinate only #> POINT (1 0) # https://github.com/r-spatial/sf/issues/1930: pt1 <- st_point(c(0,1)) pt23 <- st_multipoint(matrix(c(1,2,3,4), ncol = 2, byrow = TRUE)) d <- st_sf(geom = st_sfc(pt1, pt23)) st_cast(d, \"POINT\") # will not convert the entire MULTIPOINT, and warns #> Warning: point from first coordinate only #> Simple feature collection with 2 features and 0 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 1 ymax: 2 #> CRS: NA #> geom #> 1 POINT (0 1) #> 2 POINT (1 2) st_cast(d, \"MULTIPOINT\") %>% st_cast(\"POINT\") #> Simple feature collection with 3 features and 0 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 3 ymax: 4 #> CRS: NA #> geom #> 1 POINT (0 1) #> 2 POINT (1 2) #> 3 POINT (3 4)"},{"path":"https://r-spatial.github.io/sf/reference/st_cast_sfc_default.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerce geometry to MULTI* geometry — st_cast_sfc_default","title":"Coerce geometry to MULTI* geometry — st_cast_sfc_default","text":"Mixes POINTS MULTIPOINTS, LINESTRING MULTILINESTRING, POLYGON MULTIPOLYGON returned MULTIPOINTS, MULTILINESTRING MULTIPOLYGONS respectively","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_cast_sfc_default.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerce geometry to MULTI* geometry — st_cast_sfc_default","text":"","code":"st_cast_sfc_default(x)"},{"path":"https://r-spatial.github.io/sf/reference/st_cast_sfc_default.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerce geometry to MULTI* geometry — st_cast_sfc_default","text":"x list geometries simple features","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_cast_sfc_default.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Coerce geometry to MULTI* geometry — st_cast_sfc_default","text":"Geometries already MULTI* left unchanged. Features cast single MULTI* geometry return GEOMETRYCOLLECTION","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_collection_extract.html","id":null,"dir":"Reference","previous_headings":"","what":"Given an object with geometries of type GEOMETRY or GEOMETRYCOLLECTION, return an object consisting only of elements of the specified type. — st_collection_extract","title":"Given an object with geometries of type GEOMETRY or GEOMETRYCOLLECTION, return an object consisting only of elements of the specified type. — st_collection_extract","text":"Similar ST_CollectionExtract PostGIS. sub-geometries specified type, empty geometry returned.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_collection_extract.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Given an object with geometries of type GEOMETRY or GEOMETRYCOLLECTION, return an object consisting only of elements of the specified type. — st_collection_extract","text":"","code":"st_collection_extract( x, type = c(\"POLYGON\", \"POINT\", \"LINESTRING\"), warn = FALSE ) # S3 method for class 'sfg' st_collection_extract( x, type = c(\"POLYGON\", \"POINT\", \"LINESTRING\"), warn = FALSE ) # S3 method for class 'sfc' st_collection_extract( x, type = c(\"POLYGON\", \"POINT\", \"LINESTRING\"), warn = FALSE ) # S3 method for class 'sf' st_collection_extract( x, type = c(\"POLYGON\", \"POINT\", \"LINESTRING\"), warn = FALSE )"},{"path":"https://r-spatial.github.io/sf/reference/st_collection_extract.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Given an object with geometries of type GEOMETRY or GEOMETRYCOLLECTION, return an object consisting only of elements of the specified type. — st_collection_extract","text":"x object class sf, sfc sfg mixed geometry (GEOMETRY GEOMETRYCOLLECTION). type character; one \"POLYGON\", \"POINT\", \"LINESTRING\" warn logical; TRUE, warn attributes assigned sub-geometries casting (see st_cast)","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_collection_extract.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Given an object with geometries of type GEOMETRY or GEOMETRYCOLLECTION, return an object consisting only of elements of the specified type. — st_collection_extract","text":"object class x, geometries consisting elements specified type. sfg objects, sfg object returned one geometry specified type, otherwise geometries combined sfc object relevant type. subgeometries input MULTI, subgeometries output MULTI.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_collection_extract.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Given an object with geometries of type GEOMETRY or GEOMETRYCOLLECTION, return an object consisting only of elements of the specified type. — st_collection_extract","text":"","code":"pt <- st_point(c(1, 0)) ls <- st_linestring(matrix(c(4, 3, 0, 0), ncol = 2)) poly1 <- st_polygon(list(matrix(c(5.5, 7, 7, 6, 5.5, 0, 0, -0.5, -0.5, 0), ncol = 2))) poly2 <- st_polygon(list(matrix(c(6.6, 8, 8, 7, 6.6, 1, 1, 1.5, 1.5, 1), ncol = 2))) multipoly <- st_multipolygon(list(poly1, poly2)) i <- st_geometrycollection(list(pt, ls, poly1, poly2)) j <- st_geometrycollection(list(pt, ls, poly1, poly2, multipoly)) st_collection_extract(i, \"POLYGON\") #> Geometry set for 2 features #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 5.5 ymin: -0.5 xmax: 8 ymax: 1.5 #> CRS: NA #> POLYGON ((5.5 0, 7 0, 7 -0.5, 6 -0.5, 5.5 0)) #> POLYGON ((6.6 1, 8 1, 8 1.5, 7 1.5, 6.6 1)) st_collection_extract(i, \"POINT\") #> POINT (1 0) st_collection_extract(i, \"LINESTRING\") #> LINESTRING (4 0, 3 0) ## A GEOMETRYCOLLECTION aa <- rbind(st_sf(a=1, geom = st_sfc(i)), st_sf(a=2, geom = st_sfc(j))) ## With sf objects st_collection_extract(aa, \"POLYGON\") #> Simple feature collection with 5 features and 1 field #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: 5.5 ymin: -0.5 xmax: 8 ymax: 1.5 #> CRS: NA #> a geom #> 1.2 1 MULTIPOLYGON (((5.5 0, 7 0,... #> 1.3 1 MULTIPOLYGON (((6.6 1, 8 1,... #> 2.2 2 MULTIPOLYGON (((5.5 0, 7 0,... #> 2.3 2 MULTIPOLYGON (((6.6 1, 8 1,... #> 2.4 2 MULTIPOLYGON (((5.5 0, 7 0,... st_collection_extract(aa, \"LINESTRING\") #> Simple feature collection with 2 features and 1 field #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 3 ymin: 0 xmax: 4 ymax: 0 #> CRS: NA #> a geom #> 1.1 1 LINESTRING (4 0, 3 0) #> 2.1 2 LINESTRING (4 0, 3 0) st_collection_extract(aa, \"POINT\") #> Simple feature collection with 2 features and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 0 xmax: 1 ymax: 0 #> CRS: NA #> a geom #> 1 1 POINT (1 0) #> 2 2 POINT (1 0) ## With sfc objects st_collection_extract(st_geometry(aa), \"POLYGON\") #> Geometry set for 5 features #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: 5.5 ymin: -0.5 xmax: 8 ymax: 1.5 #> CRS: NA #> MULTIPOLYGON (((5.5 0, 7 0, 7 -0.5, 6 -0.5, 5.5... #> MULTIPOLYGON (((6.6 1, 8 1, 8 1.5, 7 1.5, 6.6 1))) #> MULTIPOLYGON (((5.5 0, 7 0, 7 -0.5, 6 -0.5, 5.5... #> MULTIPOLYGON (((6.6 1, 8 1, 8 1.5, 7 1.5, 6.6 1))) #> MULTIPOLYGON (((5.5 0, 7 0, 7 -0.5, 6 -0.5, 5.5... st_collection_extract(st_geometry(aa), \"LINESTRING\") #> Geometry set for 2 features #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 3 ymin: 0 xmax: 4 ymax: 0 #> CRS: NA #> LINESTRING (4 0, 3 0) #> LINESTRING (4 0, 3 0) st_collection_extract(st_geometry(aa), \"POINT\") #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 0 xmax: 1 ymax: 0 #> CRS: NA #> POINT (1 0) #> POINT (1 0) ## A GEOMETRY of single types bb <- rbind( st_sf(a = 1, geom = st_sfc(pt)), st_sf(a = 2, geom = st_sfc(ls)), st_sf(a = 3, geom = st_sfc(poly1)), st_sf(a = 4, geom = st_sfc(multipoly)) ) st_collection_extract(bb, \"POLYGON\") #> Simple feature collection with 2 features and 1 field #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: 5.5 ymin: -0.5 xmax: 8 ymax: 1.5 #> CRS: NA #> a geom #> 3 3 MULTIPOLYGON (((5.5 0, 7 0,... #> 4 4 MULTIPOLYGON (((5.5 0, 7 0,... ## A GEOMETRY of mixed single types and GEOMETRYCOLLECTIONS cc <- rbind(aa, bb) st_collection_extract(cc, \"POLYGON\") #> Simple feature collection with 7 features and 1 field #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: 5.5 ymin: -0.5 xmax: 8 ymax: 1.5 #> CRS: NA #> a geom #> 1.2 1 MULTIPOLYGON (((5.5 0, 7 0,... #> 1.3 1 MULTIPOLYGON (((6.6 1, 8 1,... #> 2.2 2 MULTIPOLYGON (((5.5 0, 7 0,... #> 2.3 2 MULTIPOLYGON (((6.6 1, 8 1,... #> 2.4 2 MULTIPOLYGON (((5.5 0, 7 0,... #> 5 3 MULTIPOLYGON (((5.5 0, 7 0,... #> 6 4 MULTIPOLYGON (((5.5 0, 7 0,..."},{"path":"https://r-spatial.github.io/sf/reference/st_coordinates.html","id":null,"dir":"Reference","previous_headings":"","what":"retrieve coordinates in matrix form — st_coordinates","title":"retrieve coordinates in matrix form — st_coordinates","text":"retrieve coordinates matrix form","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_coordinates.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"retrieve coordinates in matrix form — st_coordinates","text":"","code":"st_coordinates(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_coordinates.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"retrieve coordinates in matrix form — st_coordinates","text":"x object class sf, sfc sfg ... ignored","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_coordinates.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"retrieve coordinates in matrix form — st_coordinates","text":"matrix coordinates (X, Y, possibly Z /M) rows, possibly followed integer indicators L1,...,L3 point structure coordinate belongs; POINT absent (coordinate feature), LINESTRING L1 refers feature, MULTILINESTRING L1 refers part L2 simple feature, POLYGON L1 refers main ring holes L2 simple feature, MULTIPOLYGON L1 refers main ring holes, L2 ring id MULTIPOLYGON, L3 simple feature. POLYGONS, L1 can used identify exterior rings inner holes. exterior ring L1 equal 1. Interior rings identified L1 greater 1. L2 can used differentiate feature. Whereas MULTIPOLYGON, L3 refers MULTIPOLYGON feature L2 refers component POLYGON.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crop.html","id":null,"dir":"Reference","previous_headings":"","what":"crop an sf object to a specific rectangle — st_crop","title":"crop an sf object to a specific rectangle — st_crop","text":"crop sf object specific rectangle","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crop.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"crop an sf object to a specific rectangle — st_crop","text":"","code":"st_crop(x, y, ...) # S3 method for class 'sfc' st_crop(x, y, ..., xmin, ymin, xmax, ymax) # S3 method for class 'sf' st_crop(x, y, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_crop.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"crop an sf object to a specific rectangle — st_crop","text":"x object class sf sfc y numeric vector named elements xmin, ymin, xmax ymax, object class bbox, object st_bbox method convert bbox object ... ignored xmin minimum x extent cropping area ymin minimum y extent cropping area xmax maximum x extent cropping area ymax maximum y extent cropping area","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crop.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"crop an sf object to a specific rectangle — st_crop","text":"setting arguments xmin, ymin, xmax ymax implies argument y gets ignored.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crop.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"crop an sf object to a specific rectangle — st_crop","text":"","code":"box = c(xmin = 0, ymin = 0, xmax = 1, ymax = 1) pol = st_sfc(st_buffer(st_point(c(.5, .5)), .6)) pol_sf = st_sf(a=1, geom=pol) plot(st_crop(pol, box)) plot(st_crop(pol_sf, st_bbox(box))) #> Warning: attribute variables are assumed to be spatially constant throughout all geometries # alternative: plot(st_crop(pol, xmin = 0, ymin = 0, xmax = 1, ymax = 1))"},{"path":"https://r-spatial.github.io/sf/reference/st_crs.html","id":null,"dir":"Reference","previous_headings":"","what":"Retrieve coordinate reference system from object — st_crs","title":"Retrieve coordinate reference system from object — st_crs","text":"Retrieve coordinate reference system sf sfc object Set replace retrieve coordinate reference system object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crs.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Retrieve coordinate reference system from object — st_crs","text":"","code":"st_crs(x, ...) # S3 method for class 'sf' st_crs(x, ...) # S3 method for class 'numeric' st_crs(x, ...) # S3 method for class 'character' st_crs(x, ...) # S3 method for class 'sfc' st_crs(x, ..., parameters = FALSE) # S3 method for class 'bbox' st_crs(x, ...) # S3 method for class 'CRS' st_crs(x, ...) # S3 method for class 'crs' st_crs(x, ...) st_crs(x) <- value # S3 method for class 'sf' st_crs(x) <- value # S3 method for class 'sfc' st_crs(x) <- value st_set_crs(x, value) NA_crs_ # S3 method for class 'crs' is.na(x) # S3 method for class 'crs' x$name # S3 method for class 'crs' format(x, ...) st_axis_order(authority_compliant = logical(0))"},{"path":"https://r-spatial.github.io/sf/reference/st_crs.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Retrieve coordinate reference system from object — st_crs","text":"object class crs length 2.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crs.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Retrieve coordinate reference system from object — st_crs","text":"x numeric, character, object class sf sfc ... ignored parameters logical; FALSE default; TRUE return list coordinate reference system parameters, named elements SemiMajor, InvFlattening, units_gdal, IsVertical, WktPretty, Wkt value one () character: string accepted GDAL, (ii) integer, valid EPSG value (numeric), (iii) object class crs. name element name authority_compliant logical; specify whether axis order handled compliant authority; omitted, current value printed.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crs.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Retrieve coordinate reference system from object — st_crs","text":"x numeric, return crs object EPSG:x; x character, return crs object x; x class sf sfc, return crs object. Object class crs, list elements input (length-1 character) wkt (length-1 character). Elements may NA valued; elements NA CRS missing valued, coordinates assumed relate arbitrary Cartesian coordinate system. st_axis_order returns (logical) current value called without argument, (invisibly) previous value set.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crs.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Retrieve coordinate reference system from object — st_crs","text":"*crs functions create, get, set replace crs attribute simple feature geometry list-column. attribute class crs, list consisting input (user input, e.g. \"EPSG:4326\" \"WGS84\" proj4string), wkt, automatically generated wkt2 representation crs. x identical wkt2 representation, CRS name, name used input field. Comparison two objects class crs uses GDAL function OGRSpatialReference::IsSame. case coordinate reference system replaced, transformation takes place warning raised stress . NA_crs_ crs object missing values input wkt. $ method crs objects retrieves named elements using GDAL interface; named elements include SemiMajor, SemiMinor, InvFlattening, IsGeographic, units_gdal, IsVertical, WktPretty, Wkt, Name, proj4string, epsg, yx, ud_unit, axes (may subject changes future GDAL versions). Note valid CRS corresponding proj4string. ud_unit returns valid units object NULL units missing. format.crs returns NA crs missing valued, else name crs different \"unknown\", else user input set, else \"proj4string\" representation; st_axis_order can used get set axis order: TRUE indicates axes order according authority (e.g. EPSG:4326 defining coordinates latitude,longitude pairs), FALSE indicates usual GIS (display) order (longitude,latitude). can useful data read, written, coordinates authority compliant order. return value current state (FALSE, default).","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crs.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Retrieve coordinate reference system from object — st_crs","text":"","code":"sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1))) sf = st_sf(a = 1:2, geom = sfc) st_crs(sf) = 4326 st_geometry(sf) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> Geodetic CRS: WGS 84 #> POINT (0 0) #> POINT (1 1) sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1))) st_crs(sfc) = 4326 sfc #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> Geodetic CRS: WGS 84 #> POINT (0 0) #> POINT (1 1) sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1))) sfc %>% st_set_crs(4326) %>% st_transform(3857) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 111319.5 ymax: 111325.1 #> Projected CRS: WGS 84 / Pseudo-Mercator #> POINT (0 0) #> POINT (111319.5 111325.1) st_crs(\"EPSG:3857\")$input #> [1] \"EPSG:3857\" st_crs(3857)$proj4string #> [1] \"+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs\" pt = st_sfc(st_point(c(0, 60)), crs = 4326) # st_axis_order() only has effect in GDAL >= 2.5.0: st_axis_order() # query default: FALSE means interpret pt as (longitude latitude) #> [1] FALSE st_transform(pt, 3857)[[1]] #> POINT (0 8399738) old_value = FALSE if (sf_extSoftVersion()[\"GDAL\"] >= \"2.5.0\") (old_value = st_axis_order(TRUE)) #> [1] FALSE # now interpret pt as (latitude longitude), as EPSG:4326 prescribes: st_axis_order() # query current value #> [1] TRUE st_transform(pt, 3857)[[1]] #> POINT (6679169 0) st_axis_order(old_value) # set back to old value"},{"path":"https://r-spatial.github.io/sf/reference/st_drivers.html","id":null,"dir":"Reference","previous_headings":"","what":"Get GDAL drivers — st_drivers","title":"Get GDAL drivers — st_drivers","text":"Get list available GDAL drivers","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_drivers.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get GDAL drivers — st_drivers","text":"","code":"st_drivers(what = \"vector\", regex)"},{"path":"https://r-spatial.github.io/sf/reference/st_drivers.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get GDAL drivers — st_drivers","text":"character: \"vector\" \"raster\", anything else return drivers. regex character; regular expression filter name long_name fields ","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_drivers.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get GDAL drivers — st_drivers","text":"data.frame driver metadata.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_drivers.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Get GDAL drivers — st_drivers","text":"drivers available depend installation GDAL/OGR, can vary; st_drivers() function shows drivers readable, may written. field vsi refers driver's capability read/create datasets VSI*L API. See GDAL website additional details driver support","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_drivers.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get GDAL drivers — st_drivers","text":"","code":"# The following driver lists depend on the GDAL setup and platform used: st_drivers() #> name #> ESRIC ESRIC #> FITS FITS #> PCIDSK PCIDSK #> netCDF netCDF #> PDS4 PDS4 #> VICAR VICAR #> JP2OpenJPEG JP2OpenJPEG #> PDF PDF #> MBTiles MBTiles #> BAG BAG #> EEDA EEDA #> OGCAPI OGCAPI #> ESRI Shapefile ESRI Shapefile #> MapInfo File MapInfo File #> UK .NTF UK .NTF #> LVBAG LVBAG #> OGR_SDTS OGR_SDTS #> S57 S57 #> DGN DGN #> OGR_VRT OGR_VRT #> REC REC #> Memory Memory #> CSV CSV #> NAS NAS #> GML GML #> GPX GPX #> LIBKML LIBKML #> KML KML #> GeoJSON GeoJSON #> GeoJSONSeq GeoJSONSeq #> ESRIJSON ESRIJSON #> TopoJSON TopoJSON #> Interlis 1 Interlis 1 #> Interlis 2 Interlis 2 #> OGR_GMT OGR_GMT #> GPKG GPKG #> SQLite SQLite #> ODBC ODBC #> WAsP WAsP #> PGeo PGeo #> MSSQLSpatial MSSQLSpatial #> OGR_OGDI OGR_OGDI #> PostgreSQL PostgreSQL #> MySQL MySQL #> OpenFileGDB OpenFileGDB #> DXF DXF #> CAD CAD #> FlatGeobuf FlatGeobuf #> Geoconcept Geoconcept #> GeoRSS GeoRSS #> GPSTrackMaker GPSTrackMaker #> VFK VFK #> PGDUMP PGDUMP #> OSM OSM #> GPSBabel GPSBabel #> OGR_PDS OGR_PDS #> WFS WFS #> OAPIF OAPIF #> SOSI SOSI #> Geomedia Geomedia #> EDIGEO EDIGEO #> SVG SVG #> CouchDB CouchDB #> Cloudant Cloudant #> Idrisi Idrisi #> ARCGEN ARCGEN #> XLS XLS #> ODS ODS #> XLSX XLSX #> Elasticsearch Elasticsearch #> Walk Walk #> Carto Carto #> AmigoCloud AmigoCloud #> SXF SXF #> Selafin Selafin #> JML JML #> PLSCENES PLSCENES #> CSW CSW #> VDV VDV #> GMLAS GMLAS #> MVT MVT #> NGW NGW #> MapML MapML #> TIGER TIGER #> AVCBin AVCBin #> AVCE00 AVCE00 #> HTTP HTTP #> long_name #> ESRIC Esri Compact Cache #> FITS Flexible Image Transport System #> PCIDSK PCIDSK Database File #> netCDF Network Common Data Format #> PDS4 NASA Planetary Data System 4 #> VICAR MIPL VICAR file #> JP2OpenJPEG JPEG-2000 driver based on OpenJPEG library #> PDF Geospatial PDF #> MBTiles MBTiles #> BAG Bathymetry Attributed Grid #> EEDA Earth Engine Data API #> OGCAPI OGCAPI #> ESRI Shapefile ESRI Shapefile #> MapInfo File MapInfo File #> UK .NTF UK .NTF #> LVBAG Kadaster LV BAG Extract 2.0 #> OGR_SDTS SDTS #> S57 IHO S-57 (ENC) #> DGN Microstation DGN #> OGR_VRT VRT - Virtual Datasource #> REC EPIInfo .REC #> Memory Memory #> CSV Comma Separated Value (.csv) #> NAS NAS - ALKIS #> GML Geography Markup Language (GML) #> GPX GPX #> LIBKML Keyhole Markup Language (LIBKML) #> KML Keyhole Markup Language (KML) #> GeoJSON GeoJSON #> GeoJSONSeq GeoJSON Sequence #> ESRIJSON ESRIJSON #> TopoJSON TopoJSON #> Interlis 1 Interlis 1 #> Interlis 2 Interlis 2 #> OGR_GMT GMT ASCII Vectors (.gmt) #> GPKG GeoPackage #> SQLite SQLite / Spatialite #> ODBC #> WAsP WAsP .map format #> PGeo ESRI Personal GeoDatabase #> MSSQLSpatial Microsoft SQL Server Spatial Database #> OGR_OGDI OGDI Vectors (VPF, VMAP, DCW) #> PostgreSQL PostgreSQL/PostGIS #> MySQL MySQL #> OpenFileGDB ESRI FileGDB #> DXF AutoCAD DXF #> CAD AutoCAD Driver #> FlatGeobuf FlatGeobuf #> Geoconcept Geoconcept #> GeoRSS GeoRSS #> GPSTrackMaker GPSTrackMaker #> VFK Czech Cadastral Exchange Data Format #> PGDUMP PostgreSQL SQL dump #> OSM OpenStreetMap XML and PBF #> GPSBabel GPSBabel #> OGR_PDS Planetary Data Systems TABLE #> WFS OGC WFS (Web Feature Service) #> OAPIF OGC API - Features #> SOSI Norwegian SOSI Standard #> Geomedia Geomedia .mdb #> EDIGEO French EDIGEO exchange format #> SVG Scalable Vector Graphics #> CouchDB CouchDB / GeoCouch #> Cloudant Cloudant / CouchDB #> Idrisi Idrisi Vector (.vct) #> ARCGEN Arc/Info Generate #> XLS MS Excel format #> ODS Open Document/ LibreOffice / OpenOffice Spreadsheet #> XLSX MS Office Open XML spreadsheet #> Elasticsearch Elastic Search #> Walk #> Carto Carto #> AmigoCloud AmigoCloud #> SXF Storage and eXchange Format #> Selafin Selafin #> JML OpenJUMP JML #> PLSCENES Planet Labs Scenes API #> CSW OGC CSW (Catalog Service for the Web) #> VDV VDV-451/VDV-452/INTREST Data Format #> GMLAS Geography Markup Language (GML) driven by application schemas #> MVT Mapbox Vector Tiles #> NGW NextGIS Web #> MapML MapML #> TIGER U.S. Census TIGER/Line #> AVCBin Arc/Info Binary Coverage #> AVCE00 Arc/Info E00 (ASCII) Coverage #> HTTP HTTP Fetching Wrapper #> write copy is_raster is_vector vsi #> ESRIC FALSE FALSE TRUE TRUE TRUE #> FITS TRUE FALSE TRUE TRUE FALSE #> PCIDSK TRUE FALSE TRUE TRUE TRUE #> netCDF TRUE TRUE TRUE TRUE TRUE #> PDS4 TRUE TRUE TRUE TRUE TRUE #> VICAR TRUE TRUE TRUE TRUE TRUE #> JP2OpenJPEG FALSE TRUE TRUE TRUE TRUE #> PDF TRUE TRUE TRUE TRUE TRUE #> MBTiles TRUE TRUE TRUE TRUE TRUE #> BAG TRUE TRUE TRUE TRUE TRUE #> EEDA FALSE FALSE FALSE TRUE FALSE #> OGCAPI FALSE FALSE TRUE TRUE TRUE #> ESRI Shapefile TRUE FALSE FALSE TRUE TRUE #> MapInfo File TRUE FALSE FALSE TRUE TRUE #> UK .NTF FALSE FALSE FALSE TRUE TRUE #> LVBAG FALSE FALSE FALSE TRUE TRUE #> OGR_SDTS FALSE FALSE FALSE TRUE TRUE #> S57 TRUE FALSE FALSE TRUE TRUE #> DGN TRUE FALSE FALSE TRUE TRUE #> OGR_VRT FALSE FALSE FALSE TRUE TRUE #> REC FALSE FALSE FALSE TRUE FALSE #> Memory TRUE FALSE FALSE TRUE FALSE #> CSV TRUE FALSE FALSE TRUE TRUE #> NAS FALSE FALSE FALSE TRUE TRUE #> GML TRUE FALSE FALSE TRUE TRUE #> GPX TRUE FALSE FALSE TRUE TRUE #> LIBKML TRUE FALSE FALSE TRUE TRUE #> KML TRUE FALSE FALSE TRUE TRUE #> GeoJSON TRUE FALSE FALSE TRUE TRUE #> GeoJSONSeq TRUE FALSE FALSE TRUE TRUE #> ESRIJSON FALSE FALSE FALSE TRUE TRUE #> TopoJSON FALSE FALSE FALSE TRUE TRUE #> Interlis 1 TRUE FALSE FALSE TRUE TRUE #> Interlis 2 TRUE FALSE FALSE TRUE TRUE #> OGR_GMT TRUE FALSE FALSE TRUE TRUE #> GPKG TRUE TRUE TRUE TRUE TRUE #> SQLite TRUE FALSE FALSE TRUE TRUE #> ODBC FALSE FALSE FALSE TRUE FALSE #> WAsP TRUE FALSE FALSE TRUE TRUE #> PGeo FALSE FALSE FALSE TRUE FALSE #> MSSQLSpatial TRUE FALSE FALSE TRUE FALSE #> OGR_OGDI FALSE FALSE FALSE TRUE FALSE #> PostgreSQL TRUE FALSE FALSE TRUE FALSE #> MySQL TRUE FALSE FALSE TRUE FALSE #> OpenFileGDB FALSE FALSE FALSE TRUE TRUE #> DXF TRUE FALSE FALSE TRUE TRUE #> CAD FALSE FALSE TRUE TRUE TRUE #> FlatGeobuf TRUE FALSE FALSE TRUE TRUE #> Geoconcept TRUE FALSE FALSE TRUE TRUE #> GeoRSS TRUE FALSE FALSE TRUE TRUE #> GPSTrackMaker TRUE FALSE FALSE TRUE TRUE #> VFK FALSE FALSE FALSE TRUE FALSE #> PGDUMP TRUE FALSE FALSE TRUE TRUE #> OSM FALSE FALSE FALSE TRUE TRUE #> GPSBabel TRUE FALSE FALSE TRUE FALSE #> OGR_PDS FALSE FALSE FALSE TRUE TRUE #> WFS FALSE FALSE FALSE TRUE TRUE #> OAPIF FALSE FALSE FALSE TRUE FALSE #> SOSI FALSE FALSE FALSE TRUE FALSE #> Geomedia FALSE FALSE FALSE TRUE FALSE #> EDIGEO FALSE FALSE FALSE TRUE TRUE #> SVG FALSE FALSE FALSE TRUE TRUE #> CouchDB TRUE FALSE FALSE TRUE FALSE #> Cloudant TRUE FALSE FALSE TRUE FALSE #> Idrisi FALSE FALSE FALSE TRUE TRUE #> ARCGEN FALSE FALSE FALSE TRUE TRUE #> XLS FALSE FALSE FALSE TRUE FALSE #> ODS TRUE FALSE FALSE TRUE TRUE #> XLSX TRUE FALSE FALSE TRUE TRUE #> Elasticsearch TRUE FALSE FALSE TRUE FALSE #> Walk FALSE FALSE FALSE TRUE FALSE #> Carto TRUE FALSE FALSE TRUE FALSE #> AmigoCloud TRUE FALSE FALSE TRUE FALSE #> SXF FALSE FALSE FALSE TRUE TRUE #> Selafin TRUE FALSE FALSE TRUE TRUE #> JML TRUE FALSE FALSE TRUE TRUE #> PLSCENES FALSE FALSE TRUE TRUE FALSE #> CSW FALSE FALSE FALSE TRUE FALSE #> VDV TRUE FALSE FALSE TRUE TRUE #> GMLAS FALSE TRUE FALSE TRUE TRUE #> MVT TRUE FALSE FALSE TRUE TRUE #> NGW TRUE TRUE TRUE TRUE FALSE #> MapML TRUE FALSE FALSE TRUE TRUE #> TIGER TRUE FALSE FALSE TRUE TRUE #> AVCBin FALSE FALSE FALSE TRUE TRUE #> AVCE00 FALSE FALSE FALSE TRUE TRUE #> HTTP FALSE FALSE TRUE TRUE FALSE st_drivers(\"raster\", \"GeoT\") #> name long_name write copy is_raster is_vector #> GTiff GTiff GeoTIFF TRUE TRUE TRUE FALSE #> COG COG Cloud optimized GeoTIFF generator FALSE TRUE TRUE FALSE #> vsi #> GTiff TRUE #> COG TRUE"},{"path":"https://r-spatial.github.io/sf/reference/st_geometry.html","id":null,"dir":"Reference","previous_headings":"","what":"Get, set, replace or rename geometry from an sf object — st_geometry","title":"Get, set, replace or rename geometry from an sf object — st_geometry","text":"Get, set, replace rename geometry sf object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_geometry.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get, set, replace or rename geometry from an sf object — st_geometry","text":"","code":"# S3 method for class 'sfc' st_geometry(obj, ...) st_geometry(obj, ...) # S3 method for class 'sf' st_geometry(obj, ...) # S3 method for class 'sfc' st_geometry(obj, ...) # S3 method for class 'sfg' st_geometry(obj, ...) st_geometry(x) <- value st_set_geometry(x, value) st_drop_geometry(x, ...) # S3 method for class 'sf' st_drop_geometry(x, ...) # Default S3 method st_drop_geometry(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_geometry.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get, set, replace or rename geometry from an sf object — st_geometry","text":"obj object class sf sfc ... ignored x object class data.frame sf value object class sfc, character set, replace, rename geometry x","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_geometry.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get, set, replace or rename geometry from an sf object — st_geometry","text":"st_geometry returns object class sfc, list-column geometries st_geometry returns object class sfc. Assigning geometry data.frame creates sf object, assigning sf object replaces geometry list-column.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_geometry.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Get, set, replace or rename geometry from an sf object — st_geometry","text":"applied data.frame value object class sfc, st_set_geometry st_geometry<- first check existence attribute sf_column overwrite , else look list-columns class sfc overwrite first , else write geometry list-column column named geometry. case value character x class sf, \"active\" geometry column set x[[value]]. replacement function applied sf objects overwrite geometry list-column, value NULL, remove coerce x data.frame. x class sf, st_drop_geometry drops geometry argument, reclasses accordingly; otherwise returns x unmodified.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_geometry.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get, set, replace or rename geometry from an sf object — st_geometry","text":"","code":"df = data.frame(a = 1:2) sfc = st_sfc(st_point(c(3,4)), st_point(c(10,11))) st_geometry(sfc) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 3 ymin: 4 xmax: 10 ymax: 11 #> CRS: NA #> POINT (3 4) #> POINT (10 11) st_geometry(df) <- sfc class(df) #> [1] \"sf\" \"data.frame\" st_geometry(df) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 3 ymin: 4 xmax: 10 ymax: 11 #> CRS: NA #> POINT (3 4) #> POINT (10 11) st_geometry(df) <- sfc # replaces st_geometry(df) <- NULL # remove geometry, coerce to data.frame sf <- st_set_geometry(df, sfc) # set geometry, return sf st_set_geometry(sf, NULL) # remove geometry, coerce to data.frame #> a #> 1 1 #> 2 2"},{"path":"https://r-spatial.github.io/sf/reference/st_geometry_type.html","id":null,"dir":"Reference","previous_headings":"","what":"Return geometry type of an object — st_geometry_type","title":"Return geometry type of an object — st_geometry_type","text":"Return geometry type object, factor","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_geometry_type.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return geometry type of an object — st_geometry_type","text":"","code":"st_geometry_type(x, by_geometry = TRUE)"},{"path":"https://r-spatial.github.io/sf/reference/st_geometry_type.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Return geometry type of an object — st_geometry_type","text":"x object class sf sfc by_geometry logical; TRUE, return geometry type geometry, else return geometry type set","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_geometry_type.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Return geometry type of an object — st_geometry_type","text":"factor geometry type simple feature geometry x, whole set","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_graticule.html","id":null,"dir":"Reference","previous_headings":"","what":"Compute graticules and their parameters — st_graticule","title":"Compute graticules and their parameters — st_graticule","text":"Compute graticules parameters","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_graticule.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compute graticules and their parameters — st_graticule","text":"","code":"st_graticule( x = c(-180, -90, 180, 90), crs = st_crs(x), datum = st_crs(4326), ..., lon = NULL, lat = NULL, ndiscr = 100, margin = 0.001 )"},{"path":"https://r-spatial.github.io/sf/reference/st_graticule.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compute graticules and their parameters — st_graticule","text":"x object class sf, sfc sfg numeric vector bounding box given (minx, miny, maxx, maxy). crs object class crs, display coordinate reference system datum either object class crs coordinate reference system graticules, NULL case grid coordinate system x drawn, NA, case empty sf object returned. ... ignored lon numeric; values degrees East meridians, associated datum lat numeric; values degrees North parallels, associated datum ndiscr integer; number points discretize parallel meridian margin numeric; small number trim longlat bounding box touches crosses +/-180 long +/-90 latitude.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_graticule.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compute graticules and their parameters — st_graticule","text":"object class sf additional attributes describing type (E: meridian, N: parallel) degree value, label, start end coordinates angle; see example.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_graticule.html","id":"use-of-graticules","dir":"Reference","previous_headings":"","what":"Use of graticules","title":"Compute graticules and their parameters — st_graticule","text":"cartographic visualization, use graticules advised, unless graphical output used measurement navigation, direction North important interpretation content, content intended display distortions artifacts created projection. Unnecessary use graticules adds visual clutter little relevant information. Use coastlines, administrative boundaries place names permits viewers output orient better graticule.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_graticule.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Compute graticules and their parameters — st_graticule","text":"","code":"library(sf) if (require(maps, quietly = TRUE)) { usa = st_as_sf(map('usa', plot = FALSE, fill = TRUE)) laea = st_crs(\"+proj=laea +lat_0=30 +lon_0=-95\") # Lambert equal area usa <- st_transform(usa, laea) bb = st_bbox(usa) bbox = st_linestring(rbind(c( bb[1],bb[2]),c( bb[3],bb[2]), c( bb[3],bb[4]),c( bb[1],bb[4]),c( bb[1],bb[2]))) g = st_graticule(usa) plot(usa, xlim = 1.2 * c(-2450853.4, 2186391.9), reset = FALSE) plot(g[1], add = TRUE, col = 'grey') plot(bbox, add = TRUE) points(g$x_start, g$y_start, col = 'red') points(g$x_end, g$y_end, col = 'blue') invisible(lapply(seq_len(nrow(g)), function(i) { if (g$type[i] == \"N\" && g$x_start[i] - min(g$x_start) < 1000) text(g$x_start[i], g$y_start[i], labels = parse(text = g$degree_label[i]), srt = g$angle_start[i], pos = 2, cex = .7) if (g$type[i] == \"E\" && g$y_start[i] - min(g$y_start) < 1000) text(g$x_start[i], g$y_start[i], labels = parse(text = g$degree_label[i]), srt = g$angle_start[i] - 90, pos = 1, cex = .7) if (g$type[i] == \"N\" && g$x_end[i] - max(g$x_end) > -1000) text(g$x_end[i], g$y_end[i], labels = parse(text = g$degree_label[i]), srt = g$angle_end[i], pos = 4, cex = .7) if (g$type[i] == \"E\" && g$y_end[i] - max(g$y_end) > -1000) text(g$x_end[i], g$y_end[i], labels = parse(text = g$degree_label[i]), srt = g$angle_end[i] - 90, pos = 3, cex = .7) })) plot(usa, graticule = st_crs(4326), axes = TRUE, lon = seq(-60,-130,by=-10)) }"},{"path":"https://r-spatial.github.io/sf/reference/st_is.html","id":null,"dir":"Reference","previous_headings":"","what":"test equality between the geometry type and a class or set of classes — st_is","title":"test equality between the geometry type and a class or set of classes — st_is","text":"test equality geometry type class set classes","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_is.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"test equality between the geometry type and a class or set of classes — st_is","text":"","code":"st_is(x, type)"},{"path":"https://r-spatial.github.io/sf/reference/st_is.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"test equality between the geometry type and a class or set of classes — st_is","text":"x object class sf, sfc sfg type character; class, set classes, test ","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_is.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"test equality between the geometry type and a class or set of classes — st_is","text":"","code":"st_is(st_point(0:1), \"POINT\") #> [1] TRUE sfc = st_sfc(st_point(0:1), st_linestring(matrix(1:6,,2))) st_is(sfc, \"POINT\") #> [1] TRUE FALSE st_is(sfc, \"POLYGON\") #> [1] FALSE FALSE st_is(sfc, \"LINESTRING\") #> [1] FALSE TRUE st_is(st_sf(a = 1:2, sfc), \"LINESTRING\") #> [1] FALSE TRUE st_is(sfc, c(\"POINT\", \"LINESTRING\")) #> [1] TRUE TRUE"},{"path":"https://r-spatial.github.io/sf/reference/st_is_full.html","id":null,"dir":"Reference","previous_headings":"","what":"predicate whether a geometry is equal to a POLYGON FULL — st_is_full","title":"predicate whether a geometry is equal to a POLYGON FULL — st_is_full","text":"predicate whether geometry equal POLYGON FULL","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_is_full.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"predicate whether a geometry is equal to a POLYGON FULL — st_is_full","text":"","code":"st_is_full(x, ...) # S3 method for class 'sfg' st_is_full(x, ..., is_longlat = NULL) # S3 method for class 'sfc' st_is_full(x, ...) # S3 method for class 'sf' st_is_full(x, ...) # S3 method for class 'bbox' st_is_full(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_is_full.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"predicate whether a geometry is equal to a POLYGON FULL — st_is_full","text":"x object class sfg, sfc sf ... ignored, except contains crs argument inform unspecified is_longlat is_longlat logical; output st_is_longlat parent sfc object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_is_full.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"predicate whether a geometry is equal to a POLYGON FULL — st_is_full","text":"logical, indicating whether geometries POLYGON FULL (spherical polygon covering entire sphere)","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_is_longlat.html","id":null,"dir":"Reference","previous_headings":"","what":"Assert whether simple feature coordinates are longlat degrees — st_is_longlat","title":"Assert whether simple feature coordinates are longlat degrees — st_is_longlat","text":"Assert whether simple feature coordinates longlat degrees","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_is_longlat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Assert whether simple feature coordinates are longlat degrees — st_is_longlat","text":"","code":"st_is_longlat(x)"},{"path":"https://r-spatial.github.io/sf/reference/st_is_longlat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Assert whether simple feature coordinates are longlat degrees — st_is_longlat","text":"x object class sf sfc, otherwise object class st_crs method returning crs object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_is_longlat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Assert whether simple feature coordinates are longlat degrees — st_is_longlat","text":"TRUE x geographic coordinates, FALSE projected coordinates, NA .na(st_crs(x)).","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_jitter.html","id":null,"dir":"Reference","previous_headings":"","what":"jitter geometries — st_jitter","title":"jitter geometries — st_jitter","text":"jitter geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_jitter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"jitter geometries — st_jitter","text":"","code":"st_jitter(x, amount, factor = 0.002)"},{"path":"https://r-spatial.github.io/sf/reference/st_jitter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"jitter geometries — st_jitter","text":"x object class sf sfc amount numeric; amount jittering applied; missing, amount set factor * bounding box diagonal; units coordinates. factor numeric; fractional amount jittering applied","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_jitter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"jitter geometries — st_jitter","text":"jitters coordinates amount runif(1, -amount, amount) added coordinates. x- y-coordinates jittered independently coordinates single geometry jittered amount, meaning geometry shape change. longlat data, latitude correction made jittering East North directions identical distance center bounding box x.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_jitter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"jitter geometries — st_jitter","text":"","code":"nc = st_read(system.file(\"gpkg/nc.gpkg\", package=\"sf\")) #> Reading layer `nc.gpkg' from data source #> `/home/runner/work/_temp/Library/sf/gpkg/nc.gpkg' using driver `GPKG' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 pts = st_centroid(st_geometry(nc)) plot(pts) plot(st_jitter(pts, .05), add = TRUE, col = 'red') plot(st_geometry(nc)) plot(st_jitter(st_geometry(nc), factor = .01), add = TRUE, col = '#ff8888')"},{"path":"https://r-spatial.github.io/sf/reference/st_join.html","id":null,"dir":"Reference","previous_headings":"","what":"spatial join, spatial filter — st_join","title":"spatial join, spatial filter — st_join","text":"spatial join, spatial filter","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_join.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"spatial join, spatial filter — st_join","text":"","code":"st_join(x, y, join, ...) # S3 method for class 'sf' st_join( x, y, join = st_intersects, ..., suffix = c(\".x\", \".y\"), left = TRUE, largest = FALSE ) st_filter(x, y, ...) # S3 method for class 'sf' st_filter(x, y, ..., .predicate = st_intersects)"},{"path":"https://r-spatial.github.io/sf/reference/st_join.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"spatial join, spatial filter — st_join","text":"x object class sf y object class sf join geometry predicate function profile st_intersects; see details ... st_join: arguments passed join function st_intersection largest TRUE; st_filter arguments passed .predicate function, e.g. prepared, pattern st_relate suffix length 2 character vector; see merge left logical; TRUE return left join, otherwise inner join; see details. see also left_join largest logical; TRUE, return x features augmented fields y largest overlap features x; see https://github.com/r-spatial/sf/issues/578 .predicate geometry predicate function profile st_intersects; see details","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_join.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"spatial join, spatial filter — st_join","text":"object class sf, joined based geometry","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_join.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"spatial join, spatial filter — st_join","text":"alternative values argument join : st_contains_properly, st_contains, st_covered_by, st_covers, st_crosses, st_disjoint, st_equals_exact, st_equals, st_is_within_distance, st_nearest_feature, st_overlaps, st_touches, st_within, st_relate (require pattern set), user-defined function profile left join returns records x object y fields non-matched records filled NA values; inner join returns records spatially match. replicate results st_within(x, y) need use st_join(x, y, join = \"st_within\", left = FALSE).","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_join.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"spatial join, spatial filter — st_join","text":"","code":"a = st_sf(a = 1:3, geom = st_sfc(st_point(c(1,1)), st_point(c(2,2)), st_point(c(3,3)))) b = st_sf(a = 11:14, geom = st_sfc(st_point(c(10,10)), st_point(c(2,2)), st_point(c(2,2)), st_point(c(3,3)))) st_join(a, b) #> Simple feature collection with 4 features and 2 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 1 xmax: 3 ymax: 3 #> CRS: NA #> a.x a.y geom #> 1 1 NA POINT (1 1) #> 2 2 12 POINT (2 2) #> 2.1 2 13 POINT (2 2) #> 3 3 14 POINT (3 3) st_join(a, b, left = FALSE) #> Simple feature collection with 3 features and 2 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 2 ymin: 2 xmax: 3 ymax: 3 #> CRS: NA #> a.x a.y geom #> 2 2 12 POINT (2 2) #> 2.1 2 13 POINT (2 2) #> 3 3 14 POINT (3 3) # two ways to aggregate y's attribute values outcome over x's geometries: st_join(a, b) %>% aggregate(list(.$a.x), mean) #> Simple feature collection with 3 features and 3 fields #> Attribute-geometry relationships: aggregate (2), identity (1) #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 1 xmax: 3 ymax: 3 #> CRS: NA #> Group.1 a.x a.y geometry #> 1 1 1 NA POINT (1 1) #> 2 2 2 12.5 POINT (2 2) #> 3 3 3 14.0 POINT (3 3) if (require(dplyr, quietly = TRUE)) { st_join(a, b) %>% group_by(a.x) %>% summarise(mean(a.y)) } #> Simple feature collection with 3 features and 2 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 1 xmax: 3 ymax: 3 #> CRS: NA #> # A tibble: 3 × 3 #> a.x `mean(a.y)` geom #> #> 1 1 NA (1 1) #> 2 2 12.5 (2 2) #> 3 3 14 (3 3) # example of largest = TRUE: nc <- st_transform(st_read(system.file(\"shape/nc.shp\", package=\"sf\")), 2264) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 gr = st_sf( label = apply(expand.grid(1:10, LETTERS[10:1])[,2:1], 1, paste0, collapse = \" \"), geom = st_make_grid(st_as_sfc(st_bbox(nc)))) gr$col = sf.colors(10, categorical = TRUE, alpha = .3) # cut, to check, NA's work out: gr = gr[-(1:30),] nc_j <- st_join(nc, gr, largest = TRUE) #> Warning: attribute variables are assumed to be spatially constant throughout all geometries # the two datasets: opar = par(mfrow = c(2,1), mar = rep(0,4)) plot(st_geometry(nc_j)) plot(st_geometry(gr), add = TRUE, col = gr$col) text(st_coordinates(st_centroid(gr)), labels = gr$label) #> Warning: st_centroid assumes attributes are constant over geometries # the joined dataset: plot(st_geometry(nc_j), border = 'black', col = nc_j$col) text(st_coordinates(st_centroid(nc_j)), labels = nc_j$label, cex = .8) #> Warning: st_centroid assumes attributes are constant over geometries plot(st_geometry(gr), border = 'green', add = TRUE) par(opar) # st_filter keeps the geometries in x where .predicate(x,y) returns any match in y for x st_filter(a, b) #> Simple feature collection with 2 features and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 2 ymin: 2 xmax: 3 ymax: 3 #> CRS: NA #> a geom #> 1 2 POINT (2 2) #> 2 3 POINT (3 3) # for an anti-join, use the union of y st_filter(a, st_union(b), .predicate = st_disjoint) #> Simple feature collection with 1 feature and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 1 xmax: 1 ymax: 1 #> CRS: NA #> a geom #> 1 1 POINT (1 1)"},{"path":"https://r-spatial.github.io/sf/reference/st_layers.html","id":null,"dir":"Reference","previous_headings":"","what":"Return properties of layers in a datasource — st_layers","title":"Return properties of layers in a datasource — st_layers","text":"Return properties layers datasource","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_layers.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return properties of layers in a datasource — st_layers","text":"","code":"st_layers(dsn, options = character(0), do_count = FALSE)"},{"path":"https://r-spatial.github.io/sf/reference/st_layers.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Return properties of layers in a datasource — st_layers","text":"dsn data source name (interpretation varies driver - drivers, dsn file name, may also folder, contain name access credentials database) options character; driver dependent dataset open options, multiple options supported. do_count logical; TRUE, count features reading , even count reported driver","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_layers.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Return properties of layers in a datasource — st_layers","text":"list object class sf_layers elements name name layer geomtype list layer geometry types features number features (reported; see do_count) fields number fields crs list layer crs object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_line_project_point.html","id":null,"dir":"Reference","previous_headings":"","what":"Project point on linestring, interpolate along a linestring — st_line_project_point","title":"Project point on linestring, interpolate along a linestring — st_line_project_point","text":"Project point linestring, interpolate along linestring","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_line_project_point.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Project point on linestring, interpolate along a linestring — st_line_project_point","text":"","code":"st_line_project(line, point, normalized = FALSE) st_line_interpolate(line, dist, normalized = FALSE)"},{"path":"https://r-spatial.github.io/sf/reference/st_line_project_point.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Project point on linestring, interpolate along a linestring — st_line_project_point","text":"line object class sfc LINESTRING geometry point object class sfc POINT geometry normalized logical; TRUE, use return distance normalised 0-1 dist numeric, vector distance value(s)","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_line_project_point.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Project point on linestring, interpolate along a linestring — st_line_project_point","text":"st_line_project returns distance(s) point(s) along line(s), projected line(s) st_line_interpolate returns point(s) dist(s), measured along (interpolated ) line(s)","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_line_project_point.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Project point on linestring, interpolate along a linestring — st_line_project_point","text":"arguments line, point dist recycled common length needed","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_line_project_point.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Project point on linestring, interpolate along a linestring — st_line_project_point","text":"","code":"st_line_project(st_as_sfc(\"LINESTRING (0 0, 10 10)\"), st_as_sfc(c(\"POINT (0 0)\", \"POINT (5 5)\"))) #> [1] 0.000000 7.071068 st_line_project(st_as_sfc(\"LINESTRING (0 0, 10 10)\"), st_as_sfc(\"POINT (5 5)\"), TRUE) #> [1] 0.5 st_line_interpolate(st_as_sfc(\"LINESTRING (0 0, 1 1)\"), 1) #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0.7071068 ymin: 0.7071068 xmax: 0.7071068 ymax: 0.7071068 #> CRS: NA #> POINT (0.7071068 0.7071068) st_line_interpolate(st_as_sfc(\"LINESTRING (0 0, 1 1)\"), 1, TRUE) #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 1 xmax: 1 ymax: 1 #> CRS: NA #> POINT (1 1)"},{"path":"https://r-spatial.github.io/sf/reference/st_line_sample.html","id":null,"dir":"Reference","previous_headings":"","what":"Sample points on a linear geometry — st_line_sample","title":"Sample points on a linear geometry — st_line_sample","text":"Sample points linear geometry","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_line_sample.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Sample points on a linear geometry — st_line_sample","text":"","code":"st_line_sample(x, n, density, type = \"regular\", sample = NULL)"},{"path":"https://r-spatial.github.io/sf/reference/st_line_sample.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Sample points on a linear geometry — st_line_sample","text":"x object class sf, sfc sfg n integer; number points choose per geometry; missing, n computed round(density * st_length(geom)). density numeric; density (points per distance unit) sampling, possibly vector length equal number features (otherwise recycled); density may class units. type character; indicate sampling type, either \"regular\" \"random\" sample numeric; vector numbers 0 1 indicating points sample - defined sample overrules n, density type.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_line_sample.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Sample points on a linear geometry — st_line_sample","text":"","code":"ls = st_sfc(st_linestring(rbind(c(0,0),c(0,1))), st_linestring(rbind(c(0,0),c(10,0)))) st_line_sample(ls, density = 1) #> Geometry set for 2 features #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 9.5 ymax: 0.5 #> CRS: NA #> MULTIPOINT ((0 0.5)) #> MULTIPOINT ((0.5 0), (1.5 0), (2.5 0), (3.5 0),... ls = st_sfc(st_linestring(rbind(c(0,0),c(0,1))), st_linestring(rbind(c(0,0),c(.1,0))), crs = 4326) try(st_line_sample(ls, density = 1/1000)) # error #> Error in st_line_sample(ls, density = 1/1000) : #> st_line_sample for longitude/latitude not supported; use st_segmentize? st_line_sample(st_transform(ls, 3857), n = 5) # five points for each line #> Geometry set for 2 features #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 10018.75 ymax: 100192.6 #> Projected CRS: WGS 84 / Pseudo-Mercator #> MULTIPOINT ((0 11132.51), (0 33397.54), (0 5566... #> MULTIPOINT ((1113.195 0), (3339.585 0), (5565.9... st_line_sample(st_transform(ls, 3857), n = c(1, 3)) # one and three points #> Geometry set for 2 features #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 9276.624 ymax: 55662.57 #> Projected CRS: WGS 84 / Pseudo-Mercator #> MULTIPOINT ((0 55662.57)) #> MULTIPOINT ((1855.325 0), (5565.975 0), (9276.6... st_line_sample(st_transform(ls, 3857), density = 1/1000) # one per km #> Geometry set for 2 features #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 10625.95 ymax: 110823.7 #> Projected CRS: WGS 84 / Pseudo-Mercator #> MULTIPOINT ((0 501.4646), (0 1504.394), (0 2507... #> MULTIPOINT ((505.9977 0), (1517.993 0), (2529.9... st_line_sample(st_transform(ls, 3857), density = c(1/1000, 1/10000)) # one per km, one per 10 km #> Geometry set for 2 features #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 5565.975 ymax: 110823.7 #> Projected CRS: WGS 84 / Pseudo-Mercator #> MULTIPOINT ((0 501.4646), (0 1504.394), (0 2507... #> MULTIPOINT ((5565.975 0)) st_line_sample(st_transform(ls, 3857), density = units::set_units(1, 1/km)) # one per km #> Geometry set for 2 features #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 10625.95 ymax: 110823.7 #> Projected CRS: WGS 84 / Pseudo-Mercator #> MULTIPOINT ((0 501.4646), (0 1504.394), (0 2507... #> MULTIPOINT ((505.9977 0), (1517.993 0), (2529.9... # five equidistant points including start and end: st_line_sample(st_transform(ls, 3857), sample = c(0, 0.25, 0.5, 0.75, 1)) #> Geometry set for 2 features #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 11131.95 ymax: 111325.1 #> Projected CRS: WGS 84 / Pseudo-Mercator #> MULTIPOINT ((0 0), (0 27831.29), (0 55662.57), ... #> MULTIPOINT ((0 0), (2782.987 0), (5565.975 0), ..."},{"path":"https://r-spatial.github.io/sf/reference/st_m_range.html","id":null,"dir":"Reference","previous_headings":"","what":"Return 'm' range of a simple feature or simple feature set — st_m_range","title":"Return 'm' range of a simple feature or simple feature set — st_m_range","text":"Return 'm' range simple feature simple feature set","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_m_range.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return 'm' range of a simple feature or simple feature set — st_m_range","text":"","code":"# S3 method for class 'm_range' is.na(x) st_m_range(obj, ...) # S3 method for class 'POINT' st_m_range(obj, ...) # S3 method for class 'MULTIPOINT' st_m_range(obj, ...) # S3 method for class 'LINESTRING' st_m_range(obj, ...) # S3 method for class 'POLYGON' st_m_range(obj, ...) # S3 method for class 'MULTILINESTRING' st_m_range(obj, ...) # S3 method for class 'MULTIPOLYGON' st_m_range(obj, ...) # S3 method for class 'GEOMETRYCOLLECTION' st_m_range(obj, ...) # S3 method for class 'MULTISURFACE' st_m_range(obj, ...) # S3 method for class 'MULTICURVE' st_m_range(obj, ...) # S3 method for class 'CURVEPOLYGON' st_m_range(obj, ...) # S3 method for class 'COMPOUNDCURVE' st_m_range(obj, ...) # S3 method for class 'POLYHEDRALSURFACE' st_m_range(obj, ...) # S3 method for class 'TIN' st_m_range(obj, ...) # S3 method for class 'TRIANGLE' st_m_range(obj, ...) # S3 method for class 'CIRCULARSTRING' st_m_range(obj, ...) # S3 method for class 'sfc' st_m_range(obj, ...) # S3 method for class 'sf' st_m_range(obj, ...) # S3 method for class 'numeric' st_m_range(obj, ..., crs = NA_crs_) NA_m_range_"},{"path":"https://r-spatial.github.io/sf/reference/st_m_range.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Return 'm' range of a simple feature or simple feature set — st_m_range","text":"object class m_range length 2.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_m_range.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Return 'm' range of a simple feature or simple feature set — st_m_range","text":"x object class m_range obj object compute m range ... ignored crs object class crs, argument st_crs, specifying CRS bounding box.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_m_range.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Return 'm' range of a simple feature or simple feature set — st_m_range","text":"numeric vector length two, mmin mmax values; obj class sf sfc object obj class sf sfc object returned class m_range","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_m_range.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Return 'm' range of a simple feature or simple feature set — st_m_range","text":"NA_m_range_ represents missing value m_range object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_m_range.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Return 'm' range of a simple feature or simple feature set — st_m_range","text":"","code":"a = st_sf(a = 1:2, geom = st_sfc(st_point(0:3), st_point(1:4)), crs = 4326) st_m_range(a) #> mmin mmax #> 3 4 st_m_range(c(mmin = 16.1, mmax = 16.6), crs = st_crs(4326)) #> mmin mmax #> 16.1 16.6"},{"path":"https://r-spatial.github.io/sf/reference/st_make_grid.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a regular tesselation over the bounding box of an sf or sfc object — st_make_grid","title":"Create a regular tesselation over the bounding box of an sf or sfc object — st_make_grid","text":"Create square hexagonal grid covering bounding box geometry sf sfc object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_make_grid.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a regular tesselation over the bounding box of an sf or sfc object — st_make_grid","text":"","code":"st_make_grid( x, cellsize = c(diff(st_bbox(x)[c(1, 3)]), diff(st_bbox(x)[c(2, 4)]))/n, offset = st_bbox(x)[c(\"xmin\", \"ymin\")], n = c(10, 10), crs = if (missing(x)) NA_crs_ else st_crs(x), what = \"polygons\", square = TRUE, flat_topped = FALSE )"},{"path":"https://r-spatial.github.io/sf/reference/st_make_grid.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a regular tesselation over the bounding box of an sf or sfc object — st_make_grid","text":"x object class sf sfc cellsize numeric length 1 2 target cellsize: square rectangular cells width height, hexagonal cells distance opposite edges (edge length cellsize/sqrt(3)). length units object can passed, area unit object area size square hexagonal cell. offset numeric length 2; lower left corner coordinates (x, y) grid n integer length 1 2, number grid cells x y direction (columns, rows) crs object class crs; coordinate reference system target grid case argument x missing, x missing, crs inherited. character; one : \"polygons\", \"corners\", \"centers\" square logical; FALSE, create hexagonal grid flat_topped logical; TRUE generate flat topped hexagons, else generate pointy topped","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_make_grid.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a regular tesselation over the bounding box of an sf or sfc object — st_make_grid","text":"Object class sfc (simple feature geometry list column) , depending square, square hexagonal polygons, corner points polygons, center points polygons.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_make_grid.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a regular tesselation over the bounding box of an sf or sfc object — st_make_grid","text":"","code":"plot(st_make_grid(what = \"centers\"), axes = TRUE) plot(st_make_grid(what = \"corners\"), add = TRUE, col = 'green', pch=3) sfc = st_sfc(st_polygon(list(rbind(c(0,0), c(1,0), c(1,1), c(0,0))))) plot(st_make_grid(sfc, cellsize = .1, square = FALSE)) plot(sfc, add = TRUE) # non-default offset: plot(st_make_grid(sfc, cellsize = .1, square = FALSE, offset = c(0, .05 / (sqrt(3)/2)))) plot(sfc, add = TRUE) nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 g = st_make_grid(nc) plot(g) plot(st_geometry(nc), add = TRUE) # g[nc] selects cells that intersect with nc: plot(g[nc], col = '#ff000088', add = TRUE)"},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_feature.html","id":null,"dir":"Reference","previous_headings":"","what":"get index of nearest feature — st_nearest_feature","title":"get index of nearest feature — st_nearest_feature","text":"get index nearest feature","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_feature.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"get index of nearest feature — st_nearest_feature","text":"","code":"st_nearest_feature( x, y, ..., check_crs = TRUE, longlat = isTRUE(st_is_longlat(x)) )"},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_feature.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"get index of nearest feature — st_nearest_feature","text":"x object class sfg, sfc sf y object class sfg, sfc sf; missing, features x compared remaining features x. ... ignored check_crs logical; x y checked CRS equality? longlat logical; x ellipsoidal coordinates?","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_feature.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"get index of nearest feature — st_nearest_feature","text":"feature (geometry) x index nearest feature (geometry) set y, remaining set x y missing; empty geometries result NA indexes","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_feature.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"get index of nearest feature — st_nearest_feature","text":"","code":"ls1 = st_linestring(rbind(c(0,0), c(1,0))) ls2 = st_linestring(rbind(c(0,0.1), c(1,0.1))) ls3 = st_linestring(rbind(c(0,1), c(1,1))) (l = st_sfc(ls1, ls2, ls3)) #> Geometry set for 3 features #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> LINESTRING (0 0, 1 0) #> LINESTRING (0 0.1, 1 0.1) #> LINESTRING (0 1, 1 1) p1 = st_point(c(0.1, -0.1)) p2 = st_point(c(0.1, 0.11)) p3 = st_point(c(0.1, 0.09)) p4 = st_point(c(0.1, 0.9)) (p = st_sfc(p1, p2, p3, p4)) #> Geometry set for 4 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0.1 ymin: -0.1 xmax: 0.1 ymax: 0.9 #> CRS: NA #> POINT (0.1 -0.1) #> POINT (0.1 0.11) #> POINT (0.1 0.09) #> POINT (0.1 0.9) try(st_nearest_feature(p, l)) #> [1] 1 2 2 3 try(st_nearest_points(p, l[st_nearest_feature(p,l)], pairwise = TRUE)) #> Geometry set for 4 features #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 0.1 ymin: -0.1 xmax: 0.1 ymax: 1 #> CRS: NA #> LINESTRING (0.1 -0.1, 0.1 0) #> LINESTRING (0.1 0.11, 0.1 0.1) #> LINESTRING (0.1 0.09, 0.1 0.1) #> LINESTRING (0.1 0.9, 0.1 1) r = sqrt(2)/10 b1 = st_buffer(st_point(c(.1,.1)), r) b2 = st_buffer(st_point(c(.9,.9)), r) b3 = st_buffer(st_point(c(.9,.1)), r) circles = st_sfc(b1, b2, b3) plot(circles, col = NA, border = 2:4) pts = st_sfc(st_point(c(.3,.1)), st_point(c(.6,.2)), st_point(c(.6,.6)), st_point(c(.4,.8))) plot(pts, add = TRUE, col = 1) # draw points to nearest circle: nearest = try(st_nearest_feature(pts, circles)) if (inherits(nearest, \"try-error\")) # GEOS 3.6.1 not available nearest = c(1, 3, 2, 2) ls = st_nearest_points(pts, circles[nearest], pairwise = TRUE) plot(ls, col = 5:8, add = TRUE) # compute distance between pairs of nearest features: st_distance(pts, circles[nearest], by_element = TRUE) #> [1] 0.05857864 0.17481378 0.28284271 0.36849479"},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_points.html","id":null,"dir":"Reference","previous_headings":"","what":"get nearest points between pairs of geometries — st_nearest_points","title":"get nearest points between pairs of geometries — st_nearest_points","text":"get nearest points pairs geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_points.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"get nearest points between pairs of geometries — st_nearest_points","text":"","code":"st_nearest_points(x, y, ...) # S3 method for class 'sfc' st_nearest_points(x, y, ..., pairwise = FALSE) # S3 method for class 'sfg' st_nearest_points(x, y, ...) # S3 method for class 'sf' st_nearest_points(x, y, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_points.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"get nearest points between pairs of geometries — st_nearest_points","text":"x object class sfg, sfc sf y object class sfg, sfc sf ... ignored pairwise logical; FALSE (default) return nearest points pairs, TRUE, return nearest points subsequent pairs.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_points.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"get nearest points between pairs of geometries — st_nearest_points","text":"sfc object two-point LINESTRING geometries point pairs first second geometry, length x * y, y cycling fastest. See examples ideas convert POINT geometries.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_points.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"get nearest points between pairs of geometries — st_nearest_points","text":"case x lies inside y, using S2, end points polygon boundaries, using GEOS end point identical x.","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_points.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"get nearest points between pairs of geometries — st_nearest_points","text":"","code":"r = sqrt(2)/10 pt1 = st_point(c(.1,.1)) pt2 = st_point(c(.9,.9)) pt3 = st_point(c(.9,.1)) b1 = st_buffer(pt1, r) b2 = st_buffer(pt2, r) b3 = st_buffer(pt3, r) (ls0 = st_nearest_points(b1, b2)) # sfg #> Geometry set for 1 feature #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 0.2 ymin: 0.2 xmax: 0.8 ymax: 0.8 #> CRS: NA #> LINESTRING (0.2 0.2, 0.8 0.8) (ls = st_nearest_points(st_sfc(b1), st_sfc(b2, b3))) # sfc #> Geometry set for 2 features #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 0.2 ymin: 0.1 xmax: 0.8 ymax: 0.8 #> CRS: NA #> LINESTRING (0.2 0.2, 0.8 0.8) #> LINESTRING (0.2414214 0.1, 0.7585786 0.1) plot(b1, xlim = c(-.2,1.2), ylim = c(-.2,1.2), col = NA, border = 'green') plot(st_sfc(b2, b3), add = TRUE, col = NA, border = 'blue') plot(ls, add = TRUE, col = 'red') nc = st_read(system.file(\"gpkg/nc.gpkg\", package=\"sf\")) #> Reading layer `nc.gpkg' from data source #> `/home/runner/work/_temp/Library/sf/gpkg/nc.gpkg' using driver `GPKG' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 plot(st_geometry(nc)) ls = st_nearest_points(nc[1,], nc) plot(ls, col = 'red', add = TRUE) pts = st_cast(ls, \"POINT\") # gives all start & end points #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only # starting, \"from\" points, corresponding to x: plot(pts[seq(1, 200, 2)], add = TRUE, col = 'blue') # ending, \"to\" points, corresponding to y: plot(pts[seq(2, 200, 2)], add = TRUE, col = 'green')"},{"path":"https://r-spatial.github.io/sf/reference/st_normalize.html","id":null,"dir":"Reference","previous_headings":"","what":"Normalize simple features — st_normalize","title":"Normalize simple features — st_normalize","text":"st_normalize transforms coordinates input feature fall 0 1. default current domain set bounding box input, domains can used well","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_normalize.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Normalize simple features — st_normalize","text":"","code":"st_normalize(x, domain = st_bbox(x), ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_normalize.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Normalize simple features — st_normalize","text":"x object class sf, sfc sfg domain domain x normalized length 4 vector form c(xmin, ymin, xmax, ymax). Defaults bounding box x ... ignored","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_normalize.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Normalize simple features — st_normalize","text":"","code":"p1 = st_point(c(7,52)) st_normalize(p1, domain = c(0, 0, 10, 100)) #> POINT (0.7 0.52) p2 = st_point(c(-30,20)) sfc = st_sfc(p1, p2, crs = 4326) sfc #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -30 ymin: 20 xmax: 7 ymax: 52 #> Geodetic CRS: WGS 84 #> POINT (7 52) #> POINT (-30 20) sfc_norm <- st_normalize(sfc) st_bbox(sfc_norm) #> xmin ymin xmax ymax #> 0 0 1 1"},{"path":"https://r-spatial.github.io/sf/reference/st_precision.html","id":null,"dir":"Reference","previous_headings":"","what":"Get precision — st_precision","title":"Get precision — st_precision","text":"Get precision Set precision","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_precision.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get precision — st_precision","text":"","code":"st_precision(x) st_set_precision(x, precision) st_precision(x) <- value"},{"path":"https://r-spatial.github.io/sf/reference/st_precision.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get precision — st_precision","text":"x object class sfc sf precision numeric, object class units distance units (see details); see st_as_binary . value precision value","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_precision.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Get precision — st_precision","text":"precision units object, object set precision must coordinate reference system compatible distance units. Setting precision direct effect coordinates geometries, merely set attribute tag sfc object. effect takes place st_as_binary , precise, C++ function CPL_write_wkb, simple feature geometries serialized well-known-binary (WKB). happens always routines called GEOS library (geometrical operations predicates), writing geometries using st_write write_sf, st_make_valid package lwgeom; also aggregate summarise default union geometries, calls GEOS library function. Routines libraries receive rounded coordinates, possibly return results based . st_as_binary contains example roundtrip sfc geometries WKB, order see rounding happening R data. reason support precision geometrical operations GEOS liblwgeom may work better reduced precision. writing data R external resources harder think good reason limiting precision.","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/st_precision.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get precision — st_precision","text":"","code":"x <- st_sfc(st_point(c(pi, pi))) st_precision(x) #> [1] 0 st_precision(x) <- 0.01 st_precision(x) #> [1] 0.01"},{"path":"https://r-spatial.github.io/sf/reference/st_read.html","id":null,"dir":"Reference","previous_headings":"","what":"Read simple features or layers from file or database — st_read","title":"Read simple features or layers from file or database — st_read","text":"Read simple features file database, retrieve layer names geometry type(s) Read PostGIS table directly DBI RPostgreSQL interface, converting Well-Know Binary geometries sfc","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_read.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Read simple features or layers from file or database — st_read","text":"","code":"st_read(dsn, layer, ...) # S3 method for class 'character' st_read( dsn, layer, ..., query = NA, options = NULL, quiet = FALSE, geometry_column = 1L, type = 0, promote_to_multi = TRUE, stringsAsFactors = sf_stringsAsFactors(), int64_as_string = FALSE, check_ring_dir = FALSE, fid_column_name = character(0), drivers = character(0), wkt_filter = character(0), optional = FALSE, use_stream = default_st_read_use_stream() ) read_sf(..., quiet = TRUE, stringsAsFactors = FALSE, as_tibble = TRUE) # S3 method for class 'DBIObject' st_read( dsn = NULL, layer = NULL, query = NULL, EWKB = TRUE, quiet = TRUE, as_tibble = FALSE, geometry_column = NULL, ... )"},{"path":"https://r-spatial.github.io/sf/reference/st_read.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Read simple features or layers from file or database — st_read","text":"dsn data source name (interpretation varies driver - drivers, dsn file name, may also folder, contain name access credentials database); case GeoJSON, dsn may character string holding geojson data. can also open database connection. layer layer name (varies driver, may file name without extension); case layer missing, st_read read first layer dsn, give warning (unless quiet = TRUE) print message multiple layers, give error layers dsn. dsn database connection, layer can table name database identifier (see Id). also possible omit layer rather use query argument. ... parameter(s) passed st_as_sf query SQL query select records; see details options character; driver dependent dataset open options, multiple options supported. possible values, see \"Open options\" section GDAL documentation corresponding driver, https://github.com/r-spatial/sf/issues/1157 example. quiet logical; suppress info name, driver, size spatial reference, signaling multiple layers geometry_column integer character; case multiple geometry fields, one take? type integer; ISO number desired simple feature type; see details. left zero, promote_to_multi TRUE, case mixed feature geometry types, conversion highest numeric type value found attempted. vector different values geometry column can given. promote_to_multi logical; case mix Point MultiPoint, LineString MultiLineString, Polygon MultiPolygon, convert Multi variety; defaults TRUE stringsAsFactors logical; logical: character vectors converted factors? Default read_sf R version >= 4.1.0 FALSE, st_read R version < 4.1.0 equal default.stringsAsFactors() int64_as_string logical; TRUE, Int64 attributes returned string; FALSE, returned double warning given precision lost (.e., values larger 2^53). check_ring_dir logical; TRUE, polygon ring directions checked necessary corrected (seen : exterior ring counter clockwise, holes clockwise) fid_column_name character; name column write feature IDs ; defaults drivers character; limited set driver short names tried (default: try ) wkt_filter character; WKT representation spatial filter (may used bounding box, selecting overlapping geometries); see examples optional logical; passed .data.frame; always TRUE as_tibble TRUE use_stream Use TRUE use experimental columnar interface introduced GDAL 3.6. as_tibble logical; returned table class tibble data.frame? EWKB logical; WKB type EWKB? missing, defaults TRUE","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_read.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Read simple features or layers from file or database — st_read","text":"object class sf layer successfully read; case argument layer missing data source dsn contain single layer, object class sf_layers returned layer names, geometry type(s). Note number layers may also zero.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_read.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Read simple features or layers from file or database — st_read","text":"geometry_column, see also https://gdal.org/en/latest/development/rfc/rfc41_multiple_geometry_fields.html values type see https://en.wikipedia.org/wiki/Well-known_text#Well-known_binary, note every target value may lead successful conversion. typical conversion POLYGON (3) MULTIPOLYGON (6) work; way around (type=3), secondary rings MULTIPOLYGONS may dropped without warnings. promote_to_multi handled per-geometry column basis; type may specified geometry column. Note stray files data source directories (*.dbf) may lead spurious errors accompanying *.shp missing. case problems reading shapefiles USB drives OSX, please see https://github.com/r-spatial/sf/issues/252. Reading shapefiles (data sources) directly zip files can done prepending path /vsizip/. part GDAL Virtual File Systems interface also supports .gz, curl, operations, including chaining; see https://gdal.org/en/latest/user/virtual_file_systems.html complete description examples. query character dsn query text handed 'ExecuteSQL' GDAL/OGR data set result creation new layer (layer ignored). See 'OGRSQL' https://gdal.org/en/latest/user/ogr_sql_dialect.html details. Please note 'FID' special field driver-dependent, may either 0-based (e.g. ESRI Shapefile), 1-based (e.g. MapInfo) arbitrary (e.g. OSM). features OGRSQL also likely driver dependent. available layer names may obtained st_layers. Care required properly escape use layer names. read_sf write_sf aliases st_read st_write, respectively, modified default arguments. read_sf write_sf quiet default: print information data source. read_sf returns sf-tibble rather sf-data.frame. write_sf delete layers default: overwrites existing files without asking warning. table given query , spatial reference system (crs) table queried available case stored geometry record (e.g., PostGIS, using EWKB) function automatically find geometry type columns drivers support . drivers, try cast character columns, can slow wide tables.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_read.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Read simple features or layers from file or database — st_read","text":"use system.file examples make sure examples run regardless R installed: typical users use system.file give file name directly, either full path relative current working directory (see getwd). \"Shapefiles\" consist several files basename reside directory, one extension .shp.","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/st_read.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Read simple features or layers from file or database — st_read","text":"","code":"nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 summary(nc) # note that AREA was computed using Euclidian area on lon/lat degrees #> AREA PERIMETER CNTY_ CNTY_ID #> Min. :0.0420 Min. :0.999 Min. :1825 Min. :1825 #> 1st Qu.:0.0910 1st Qu.:1.324 1st Qu.:1902 1st Qu.:1902 #> Median :0.1205 Median :1.609 Median :1982 Median :1982 #> Mean :0.1263 Mean :1.673 Mean :1986 Mean :1986 #> 3rd Qu.:0.1542 3rd Qu.:1.859 3rd Qu.:2067 3rd Qu.:2067 #> Max. :0.2410 Max. :3.640 Max. :2241 Max. :2241 #> NAME FIPS FIPSNO CRESS_ID #> Length:100 Length:100 Min. :37001 Min. : 1.00 #> Class :character Class :character 1st Qu.:37050 1st Qu.: 25.75 #> Mode :character Mode :character Median :37100 Median : 50.50 #> Mean :37100 Mean : 50.50 #> 3rd Qu.:37150 3rd Qu.: 75.25 #> Max. :37199 Max. :100.00 #> BIR74 SID74 NWBIR74 BIR79 #> Min. : 248 Min. : 0.00 Min. : 1.0 Min. : 319 #> 1st Qu.: 1077 1st Qu.: 2.00 1st Qu.: 190.0 1st Qu.: 1336 #> Median : 2180 Median : 4.00 Median : 697.5 Median : 2636 #> Mean : 3300 Mean : 6.67 Mean :1050.8 Mean : 4224 #> 3rd Qu.: 3936 3rd Qu.: 8.25 3rd Qu.:1168.5 3rd Qu.: 4889 #> Max. :21588 Max. :44.00 Max. :8027.0 Max. :30757 #> SID79 NWBIR79 geometry #> Min. : 0.00 Min. : 3.0 MULTIPOLYGON :100 #> 1st Qu.: 2.00 1st Qu.: 250.5 epsg:4267 : 0 #> Median : 5.00 Median : 874.5 +proj=long...: 0 #> Mean : 8.36 Mean : 1352.8 #> 3rd Qu.:10.25 3rd Qu.: 1406.8 #> Max. :57.00 Max. :11631.0 ## only three fields by select clause ## only two features by where clause nc_sql = st_read(system.file(\"shape/nc.shp\", package=\"sf\"), query = \"SELECT NAME, SID74, FIPS FROM \\\"nc\\\" WHERE BIR74 > 20000\") #> Reading query `SELECT NAME, SID74, FIPS FROM \"nc\" WHERE BIR74 > 20000' #> from data source `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 2 features and 3 fields #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: -81.06555 ymin: 34.82742 xmax: -78.49929 ymax: 35.50912 #> Geodetic CRS: NAD27 if (FALSE) { # \\dontrun{ library(sp) example(meuse, ask = FALSE, echo = FALSE) try(st_write(st_as_sf(meuse), \"PG:dbname=postgis\", \"meuse\", layer_options = \"OVERWRITE=true\")) try(st_meuse <- st_read(\"PG:dbname=postgis\", \"meuse\")) if (exists(\"st_meuse\")) summary(st_meuse) } # } if (FALSE) { # \\dontrun{ ## note that we need special escaping of layer within single quotes (nc.gpkg) ## and that geom needs to be included in the select, otherwise we don't detect it layer <- st_layers(system.file(\"gpkg/nc.gpkg\", package = \"sf\"))$name[1] nc_gpkg_sql = st_read(system.file(\"gpkg/nc.gpkg\", package = \"sf\"), query = sprintf(\"SELECT NAME, SID74, FIPS, geom FROM \\\"%s\\\" WHERE BIR74 > 20000\", layer)) } # } # spatial filter, as wkt: wkt = st_as_text(st_geometry(nc[1,])) # filter by (bbox overlaps of) first feature geometry: st_read(system.file(\"gpkg/nc.gpkg\", package=\"sf\"), wkt_filter = wkt) #> Reading layer `nc.gpkg' from data source #> `/home/runner/work/_temp/Library/sf/gpkg/nc.gpkg' using driver `GPKG' #> Simple feature collection with 4 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -81.91116 ymin: 35.98933 xmax: -80.87086 ymax: 36.58965 #> Geodetic CRS: NAD27 # read geojson from string: geojson_txt <- paste(\"{\\\"type\\\":\\\"MultiPoint\\\",\\\"coordinates\\\":\", \"[[3.2,4],[3,4.6],[3.8,4.4],[3.5,3.8],[3.4,3.6],[3.9,4.5]]}\") x = st_read(geojson_txt) #> Reading layer `OGRGeoJSON' from data source #> `{\"type\":\"MultiPoint\",\"coordinates\": [[3.2,4],[3,4.6],[3.8,4.4],[3.5,3.8],[3.4,3.6],[3.9,4.5]]}' #> using driver `GeoJSON' #> Simple feature collection with 1 feature and 0 fields #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 3 ymin: 3.6 xmax: 3.9 ymax: 4.6 #> Geodetic CRS: WGS 84 x #> Simple feature collection with 1 feature and 0 fields #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 3 ymin: 3.6 xmax: 3.9 ymax: 4.6 #> Geodetic CRS: WGS 84 #> geometry #> 1 MULTIPOINT ((3.2 4), (3 4.6... if (FALSE) { # \\dontrun{ library(RPostgreSQL) try(conn <- dbConnect(PostgreSQL(), dbname = \"postgis\")) if (exists(\"conn\") && !inherits(conn, \"try-error\")) { x = st_read(conn, \"meuse\", query = \"select * from meuse limit 3;\") x = st_read(conn, table = \"public.meuse\") print(st_crs(x)) # SRID resolved by the database, not by GDAL! dbDisconnect(conn) } } # }"},{"path":"https://r-spatial.github.io/sf/reference/st_relate.html","id":null,"dir":"Reference","previous_headings":"","what":"Compute DE9-IM relation between pairs of geometries, or match it to a given pattern — st_relate","title":"Compute DE9-IM relation between pairs of geometries, or match it to a given pattern — st_relate","text":"Compute DE9-IM relation pairs geometries, match given pattern","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_relate.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compute DE9-IM relation between pairs of geometries, or match it to a given pattern — st_relate","text":"","code":"st_relate(x, y, pattern = NA_character_, sparse = !is.na(pattern))"},{"path":"https://r-spatial.github.io/sf/reference/st_relate.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compute DE9-IM relation between pairs of geometries, or match it to a given pattern — st_relate","text":"x object class sf, sfc sfg y object class sf, sfc sfg pattern character; define pattern match , see details. sparse logical; sparse matrix returned (TRUE) dense matrix?","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_relate.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compute DE9-IM relation between pairs of geometries, or match it to a given pattern — st_relate","text":"case pattern given, st_relate returns dense character matrix; element [,j] nine characters, referring DE9-IM relationship x[] y[j], encoded IxIy,IxBy,IxEy,BxIy,BxBy,BxEy,ExIy,ExBy,ExEy refers interior, B boundary, E exterior, e.g. BxIy dimensionality intersection boundary x[] interior y[j], one : 0, 1, 2, F; digits denoting dimensionality intersection, F denoting intersection. pattern given, dense logical matrix sparse index list returned matches given pattern; see st_intersects description returned matrix list. See also https://en.wikipedia.org/wiki/DE-9IM explanation.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_relate.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Compute DE9-IM relation between pairs of geometries, or match it to a given pattern — st_relate","text":"","code":"p1 = st_point(c(0,0)) p2 = st_point(c(2,2)) pol1 = st_polygon(list(rbind(c(0,0),c(1,0),c(1,1),c(0,1),c(0,0)))) - 0.5 pol2 = pol1 + 1 pol3 = pol1 + 2 st_relate(st_sfc(p1, p2), st_sfc(pol1, pol2, pol3)) #> [,1] [,2] [,3] #> [1,] \"0FFFFF212\" \"FF0FFF212\" \"FF0FFF212\" #> [2,] \"FF0FFF212\" \"FF0FFF212\" \"0FFFFF212\" sfc = st_sfc(st_point(c(0,0)), st_point(c(3,3))) grd = st_make_grid(sfc, n = c(3,3)) st_intersects(grd) #> Sparse geometry binary predicate list of length 9, where the predicate #> was `intersects' #> 1: 1, 2, 4, 5 #> 2: 1, 2, 3, 4, 5, 6 #> 3: 2, 3, 5, 6 #> 4: 1, 2, 4, 5, 7, 8 #> 5: 1, 2, 3, 4, 5, 6, 7, 8, 9 #> 6: 2, 3, 5, 6, 8, 9 #> 7: 4, 5, 7, 8 #> 8: 4, 5, 6, 7, 8, 9 #> 9: 5, 6, 8, 9 st_relate(grd, pattern = \"****1****\") # sides, not corners, internals #> Sparse geometry binary predicate list of length 9, where the predicate #> was `relate_pattern' #> 1: 1, 2, 4 #> 2: 1, 2, 3, 5 #> 3: 2, 3, 6 #> 4: 1, 4, 5, 7 #> 5: 2, 4, 5, 6, 8 #> 6: 3, 5, 6, 9 #> 7: 4, 7, 8 #> 8: 5, 7, 8, 9 #> 9: 6, 8, 9 st_relate(grd, pattern = \"****0****\") # only corners touch #> Sparse geometry binary predicate list of length 9, where the predicate #> was `relate_pattern' #> 1: 5 #> 2: 4, 6 #> 3: 5 #> 4: 2, 8 #> 5: 1, 3, 7, 9 #> 6: 2, 8 #> 7: 5 #> 8: 4, 6 #> 9: 5 st_rook = function(a, b = a) st_relate(a, b, pattern = \"F***1****\") st_rook(grd) #> Sparse geometry binary predicate list of length 9, where the predicate #> was `relate_pattern' #> 1: 2, 4 #> 2: 1, 3, 5 #> 3: 2, 6 #> 4: 1, 5, 7 #> 5: 2, 4, 6, 8 #> 6: 3, 5, 9 #> 7: 4, 8 #> 8: 5, 7, 9 #> 9: 6, 8 # queen neighbours, see \\url{https://github.com/r-spatial/sf/issues/234#issuecomment-300511129} st_queen <- function(a, b = a) st_relate(a, b, pattern = \"F***T****\")"},{"path":"https://r-spatial.github.io/sf/reference/st_sample.html","id":null,"dir":"Reference","previous_headings":"","what":"sample points on or in (sets of) spatial features — st_sample","title":"sample points on or in (sets of) spatial features — st_sample","text":"Sample points (sets ) spatial features. default, returns pre-specified number points equal size (type = \"random\" exact = TRUE) approximation size otherwise. spatstat methods interfaced use size argument, see examples.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_sample.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"sample points on or in (sets of) spatial features — st_sample","text":"","code":"st_sample(x, size, ...) # S3 method for class 'sf' st_sample(x, size, ...) # S3 method for class 'sfc' st_sample( x, size, ..., type = \"random\", exact = TRUE, warn_if_not_integer = TRUE, by_polygon = FALSE, progress = FALSE, force = FALSE ) # S3 method for class 'sfg' st_sample(x, size, ...) # S3 method for class 'bbox' st_sample( x, size, ..., great_circles = FALSE, segments = units::set_units(2, \"degree\", mode = \"standard\") )"},{"path":"https://r-spatial.github.io/sf/reference/st_sample.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"sample points on or in (sets of) spatial features — st_sample","text":"x object class sf sfc size sample size(s) requested; either total size, numeric vector sample sizes feature geometry. sampling polygons, returned sampling size may differ requested size, bounding box sampled, sampled points intersecting polygon returned. ... passed sample multipoint sampling, spatstat functions spatstat sampling types (see details) type character; indicates spatial sampling type; one random, hexagonal (triangular really), regular, Fibonacci, one spatstat methods Thomas calling spatstat.random::rThomas (see Details). exact logical; length output exactly warn_if_not_integer logical; FALSE warning emitted size integer by_polygon logical; MULTIPOLYGON geometries, effort split POLYGON? See https://github.com/r-spatial/sf/issues/1480 specified size? TRUE default. applies polygons, type = \"random\". progress logical; TRUE show progress bar (size vector). force logical; TRUE continue sampled bounding box area 1e4 times area interest, else (default) stop error. error justified, try setting oriented=TRUE, see details. great_circles logical; TRUE, great circle arcs used connect bounding box vertices, FALSE parallels (graticules) segments units, numeric (degrees); segment sizes segmenting bounding box polygon great_circles FALSE","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_sample.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"sample points on or in (sets of) spatial features — st_sample","text":"sfc object containing sampled POINT geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_sample.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"sample points on or in (sets of) spatial features — st_sample","text":"function vectorised: samples size points across geometries object size single number, specified number points feature size vector integers equal length geometry x. x dimension 2 (polygons) geographical coordinates (long/lat), uniform random sampling sphere applied, see e.g. https://mathworld.wolfram.com/SpherePointPicking.html. regular hexagonal sampling polygons, resulting size approximation. parameter called offset can passed control (\"fix\") regular hexagonal sampling: polygons length 2 numeric vector (default: random point st_bbox(x)); lines use number like runif(1). Fibonacci sampling see: Alvaro Gonzalez, 2010. Measurement Areas Sphere Using Fibonacci Latitude-Longitude Lattices. Mathematical Geosciences 42(1), p. 49-64 regular sampling sphere, see also geosphere::regularCoordinates. Sampling methods package spatstat interfaced (see examples), need parameters set. instance, use spatstat.random::rThomas(), set type = \"Thomas\". sampling polygons one can specify oriented=TRUE make sure polygons larger half globe reverted, e.g. specifying polygon bounding box global dataset. st_sample method bbox default.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_sample.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"sample points on or in (sets of) spatial features — st_sample","text":"","code":"nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 p1 = st_sample(nc[1:3, ], 6) p2 = st_sample(nc[1:3, ], 1:3) plot(st_geometry(nc)[1:3]) plot(p1, add = TRUE) plot(p2, add = TRUE, pch = 2) x = st_sfc(st_polygon(list(rbind(c(0,0),c(90,0),c(90,90),c(0,90),c(0,0)))), crs = st_crs(4326)) plot(x, axes = TRUE, graticule = TRUE) if (sf_extSoftVersion()[\"proj.4\"] >= \"4.9.0\") plot(p <- st_sample(x, 1000), add = TRUE) if (require(lwgeom, quietly = TRUE)) { # for st_segmentize() x2 = st_transform(st_segmentize(x, 1e4), st_crs(\"+proj=ortho +lat_0=30 +lon_0=45\")) g = st_transform(st_graticule(), st_crs(\"+proj=ortho +lat_0=30 +lon_0=45\")) plot(x2, graticule = g) if (sf_extSoftVersion()[\"proj.4\"] >= \"4.9.0\") { p2 = st_transform(p, st_crs(\"+proj=ortho +lat_0=30 +lon_0=45\")) plot(p2, add = TRUE) } } x = st_sfc(st_polygon(list(rbind(c(0,0),c(90,0),c(90,10),c(0,90),c(0,0))))) # NOT long/lat: plot(x) p_exact = st_sample(x, 1000, exact = TRUE) p_not_exact = st_sample(x, 1000, exact = FALSE) length(p_exact); length(p_not_exact) #> [1] 1000 #> [1] 1000 plot(st_sample(x, 1000), add = TRUE) x = st_sfc(st_polygon(list(rbind(c(-180,-90),c(180,-90),c(180,90),c(-180,90),c(-180,-90)))), crs=st_crs(4326)) # FIXME: #if (sf_extSoftVersion()[\"proj.4\"] >= \"4.9.0\") { # p = st_sample(x, 1000) # st_sample(p, 3) #} # hexagonal: sfc = st_sfc(st_polygon(list(rbind(c(0,0), c(1,0), c(1,1), c(0,0))))) plot(sfc) h = st_sample(sfc, 100, type = \"hexagonal\") h1 = st_sample(sfc, 100, type = \"hexagonal\") plot(h, add = TRUE) plot(h1, col = 'red', add = TRUE) c(length(h), length(h1)) # approximate! #> [1] 97 99 pt = st_multipoint(matrix(1:20,,2)) ls = st_sfc(st_linestring(rbind(c(0,0),c(0,1))), st_linestring(rbind(c(0,0),c(.1,0))), st_linestring(rbind(c(0,1),c(.1,1))), st_linestring(rbind(c(2,2),c(2,2.00001)))) st_sample(ls, 80) #> Geometry set for 4 features (with 1 geometry empty) #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 0.08531849 ymax: 1 #> CRS: NA #> MULTIPOINT ((0 0.01737041), (0 0.8441574), (0 0... #> MULTIPOINT ((0.03337024 0), (0.03010541 0), (0.... #> MULTIPOINT ((0.04159846 1), (0.06942899 1), (0.... #> MULTIPOINT EMPTY plot(st_sample(ls, 80)) # spatstat example: if (require(spatstat.random)) { x <- sf::st_sfc(sf::st_polygon(list(rbind(c(0, 0), c(10, 0), c(10, 10), c(0, 0))))) # for spatstat.random::rThomas(), set type = \"Thomas\": pts <- st_sample(x, kappa = 1, mu = 10, scale = 0.1, type = \"Thomas\") } bbox = st_bbox( c(xmin = 0, xmax = 40, ymax = 70, ymin = 60), crs = st_crs('OGC:CRS84') ) set.seed(13531) s1 = st_sample(bbox, 400) st_bbox(s1) # within bbox #> xmin ymin xmax ymax #> 0.1809029 60.0231214 39.9875925 69.9900375 s2 = st_sample(bbox, 400, great_circles = TRUE) st_bbox(s2) # outside bbox #> xmin ymin xmax ymax #> 0.2031083 60.2048778 39.9612431 69.9107718"},{"path":"https://r-spatial.github.io/sf/reference/st_shift_longitude.html","id":null,"dir":"Reference","previous_headings":"","what":"Shift or re-center geographical coordinates for a Pacific view — st_shift_longitude","title":"Shift or re-center geographical coordinates for a Pacific view — st_shift_longitude","text":"longitudes < 0 added 360, avoid instance parts Alaska represented far left right plot values straddling 180 degrees. general, using projected coordinate reference system preferred, method permits geographical coordinate reference system used. sf equivalent recenter sp package ST_ShiftLongitude PostGIS.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_shift_longitude.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Shift or re-center geographical coordinates for a Pacific view — st_shift_longitude","text":"","code":"st_shift_longitude(x) # S3 method for class 'sfc' st_shift_longitude(x, ...) # S3 method for class 'sf' st_shift_longitude(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_shift_longitude.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Shift or re-center geographical coordinates for a Pacific view — st_shift_longitude","text":"x object class sf sfc ... ignored","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_shift_longitude.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Shift or re-center geographical coordinates for a Pacific view — st_shift_longitude","text":"","code":"## sfc pt1 = st_point(c(-170, 50)) pt2 = st_point(c(170, 50)) (sfc = st_sfc(pt1, pt2)) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -170 ymin: 50 xmax: 170 ymax: 50 #> CRS: NA #> POINT (-170 50) #> POINT (170 50) sfc = st_set_crs(sfc, 4326) st_shift_longitude(sfc) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 170 ymin: 50 xmax: 190 ymax: 50 #> Geodetic CRS: WGS 84 #> POINT (190 50) #> POINT (170 50) ## sf d = st_as_sf(data.frame(id = 1:2, geometry = sfc)) st_shift_longitude(d) #> Simple feature collection with 2 features and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 170 ymin: 50 xmax: 190 ymax: 50 #> Geodetic CRS: WGS 84 #> id geometry #> 1 1 POINT (190 50) #> 2 2 POINT (170 50)"},{"path":"https://r-spatial.github.io/sf/reference/st_transform.html","id":null,"dir":"Reference","previous_headings":"","what":"Transform or convert coordinates of simple feature — st_transform","title":"Transform or convert coordinates of simple feature — st_transform","text":"Transform convert coordinates simple feature","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_transform.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Transform or convert coordinates of simple feature — st_transform","text":"","code":"st_can_transform(src, dst) st_transform(x, crs, ...) # S3 method for class 'sfc' st_transform( x, crs = st_crs(x), ..., aoi = numeric(0), pipeline = character(0), reverse = FALSE, desired_accuracy = -1, allow_ballpark = TRUE, partial = TRUE, check = FALSE ) # S3 method for class 'sf' st_transform(x, crs = st_crs(x), ...) # S3 method for class 'sfg' st_transform(x, crs = st_crs(x), ...) # S3 method for class 'bbox' st_transform(x, crs, ..., densify = 21) st_wrap_dateline(x, options, quiet) # S3 method for class 'sfc' st_wrap_dateline(x, options = \"WRAPDATELINE=YES\", quiet = TRUE) # S3 method for class 'sf' st_wrap_dateline(x, options = \"WRAPDATELINE=YES\", quiet = TRUE) # S3 method for class 'sfg' st_wrap_dateline(x, options = \"WRAPDATELINE=YES\", quiet = TRUE) sf_proj_info(type = \"proj\", path)"},{"path":"https://r-spatial.github.io/sf/reference/st_transform.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Transform or convert coordinates of simple feature — st_transform","text":"src source crs dst destination crs x object class sf, sfc sfg crs target coordinate reference system: object class crs, input string st_crs ... ignored aoi area interest, degrees: WestLongitude, SouthLatitude, EastLongitude, NorthLatitude pipeline character; coordinate operation pipeline, overriding default operation reverse boolean; effect pipeline defined: TRUE, inverse operation pipeline applied desired_accuracy numeric; coordinate operations offer accuracy least one specified considered; negative value disables feature (requires GDAL >= 3.3) allow_ballpark logical; ballpark (low accuracy) transformations allowed? (requires GDAL >= 3.3) partial logical; allow partial projection, points geometry can projected (corresponds setting environment variable OGR_ENABLE_PARTIAL_REPROJECTION TRUE) check logical; TRUE, perform sanity check resulting polygons densify integer, number points discretizing lines bounding box corner points; see Details options character; \"WRAPDATELINE=YES\" function; another parameter used \"DATELINEOFFSET=10\" (10 default value) quiet logical; print options parsed? type character; one have_datum_files, proj, ellps, datum, units, path, prime_meridians; see Details. path character; PROJ search path set","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_transform.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Transform or convert coordinates of simple feature — st_transform","text":"st_can_transform returns boolean indicating whether coordinates CRS src can transformed CRS dst Transforms coordinates object new projection. Features transformed returned empty geometries. Transforms using pipeline= argument may fail ambiguity axis order specified coordinate reference system; need traditional GIS order, use \"OGC:CRS84\", \"EPSG:4326\". Extra care needed ESRI Shapefile format, WKT1 store axis order unambiguously. st_transform method sfg objects assumes CRS object available attribute name. method bbox objects densifies lines geographic coordinates along Cartesian lines, great circle arcs discussion using options, see https://github.com/r-spatial/sf/issues/280 https://github.com/r-spatial/sf/issues/1983 sf_proj_info lists available projections, ellipses, datums, units, data search path PROJ library type equal proj, ellps, datum, units path; type equals have_datum_files boolean returned indicating whether datum files installed accessible (checking conus). path returns PROJ_INFO.searchpath field directly, single string path separaters (: ;). PROJ >= 6, sf_proj_info provide option type = \"datums\". PROJ < 6 provide option type = \"prime_meridians\". PROJ >= 7.1.0, \"units\" query sf_proj_info returns to_meter variable numeric, previous versions return character vector containing numeric expression.","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/st_transform.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Transform or convert coordinates of simple feature — st_transform","text":"","code":"p1 = st_point(c(7,52)) p2 = st_point(c(-30,20)) sfc = st_sfc(p1, p2, crs = 4326) sfc #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -30 ymin: 20 xmax: 7 ymax: 52 #> Geodetic CRS: WGS 84 #> POINT (7 52) #> POINT (-30 20) st_transform(sfc, 3857) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -3339585 ymin: 2273031 xmax: 779236.4 ymax: 6800125 #> Projected CRS: WGS 84 / Pseudo-Mercator #> POINT (779236.4 6800125) #> POINT (-3339585 2273031) st_transform(st_sf(a=2:1, geom=sfc), \"EPSG:3857\") #> Simple feature collection with 2 features and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -3339585 ymin: 2273031 xmax: 779236.4 ymax: 6800125 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a geom #> 1 2 POINT (779236.4 6800125) #> 2 1 POINT (-3339585 2273031) if (sf_extSoftVersion()[\"GDAL\"] >= \"3.0.0\") { st_transform(sfc, pipeline = \"+proj=pipeline +step +proj=axisswap +order=2,1\") # reverse axes st_transform(sfc, pipeline = \"+proj=pipeline +step +proj=axisswap +order=2,1\", reverse = TRUE) # also reverse axes } #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -30 ymin: 20 xmax: 7 ymax: 52 #> CRS: NA #> POINT (7 52) #> POINT (-30 20) nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 st_area(nc[1,]) # area from long/lat #> 1137107793 [m^2] st_area(st_transform(nc[1,], 32119)) # NC state plane, m #> 1137598162 [m^2] st_area(st_transform(nc[1,], 2264)) # NC state plane, US foot #> 12244955726 [US_survey_foot^2] library(units) #> udunits database from /usr/share/xml/udunits/udunits2.xml set_units(st_area(st_transform(nc[1,], 2264)), m^2) #> 1137598162 [m^2] st_transform(structure(p1, proj4string = \"EPSG:4326\"), \"EPSG:3857\") #> POINT (779236.4 6800125) st_wrap_dateline(st_sfc(st_linestring(rbind(c(-179,0),c(179,0))), crs = 4326)) #> Geometry set for 1 feature #> Geometry type: MULTILINESTRING #> Dimension: XY #> Bounding box: xmin: -180 ymin: 0 xmax: 180 ymax: 0 #> Geodetic CRS: WGS 84 #> MULTILINESTRING ((-179 0, -180 0), (180 0, 179 0)) sf_proj_info(\"datum\") #> data frame with 0 columns and 0 rows"},{"path":"https://r-spatial.github.io/sf/reference/st_viewport.html","id":null,"dir":"Reference","previous_headings":"","what":"Create viewport from sf, sfc or sfg object — st_viewport","title":"Create viewport from sf, sfc or sfg object — st_viewport","text":"Create viewport sf, sfc sfg object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_viewport.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create viewport from sf, sfc or sfg object — st_viewport","text":"","code":"st_viewport(x, ..., bbox = st_bbox(x), asp)"},{"path":"https://r-spatial.github.io/sf/reference/st_viewport.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create viewport from sf, sfc or sfg object — st_viewport","text":"x object class sf, sfc sfg object ... parameters passed viewport bbox bounding box used aspect ratio asp numeric; target aspect ratio (y/x), see Details","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_viewport.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create viewport from sf, sfc or sfg object — st_viewport","text":"output call viewport","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_viewport.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create viewport from sf, sfc or sfg object — st_viewport","text":"parameters width, height, xscale yscale set aspect ratio honoured plot size maximized current viewport; others can passed ... asp missing, taken 1, except isTRUE(st_is_longlat(x)), case set 1.0 /cos(y), y middle latitude bounding box.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_viewport.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create viewport from sf, sfc or sfg object — st_viewport","text":"","code":"library(grid) #> #> Attaching package: ‘grid’ #> The following object is masked from ‘package:spatstat.geom’: #> #> as.mask nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 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')))))"},{"path":"https://r-spatial.github.io/sf/reference/st_write.html","id":null,"dir":"Reference","previous_headings":"","what":"Write simple features object to file or database — st_write","title":"Write simple features object to file or database — st_write","text":"Write simple features object file database","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_write.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Write simple features object to file or database — st_write","text":"","code":"st_write(obj, dsn, layer, ...) # S3 method for class 'sfc' st_write(obj, dsn, layer, ...) # S3 method for class 'sf' st_write( obj, dsn, layer = NULL, ..., driver = guess_driver_can_write(dsn), dataset_options = NULL, layer_options = NULL, quiet = FALSE, factorsAsCharacter = TRUE, append = NA, delete_dsn = FALSE, delete_layer = !is.na(append) && !append, fid_column_name = NULL, config_options = character(0) ) # S3 method for class 'data.frame' st_write(obj, dsn, layer = NULL, ...) write_sf(..., quiet = TRUE, append = FALSE, delete_layer = !append) st_delete( dsn, layer = character(0), driver = guess_driver_can_write(dsn), quiet = FALSE )"},{"path":"https://r-spatial.github.io/sf/reference/st_write.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Write simple features object to file or database — st_write","text":"obj object class sf sfc dsn data source name. Interpretation varies driver: can filename, folder, database name, Database Connection (officially test support RPostgres::Postgres() connections). layer layer name. Varies driver, may file name without extension; database connection, name table. layer missing, basename dsn taken. ... arguments passed dbWriteTable dsn Database Connection driver character; name driver used; missing dsn Database Connection, driver name guessed dsn; st_drivers() returns drivers available properties; links full driver documentation found https://gdal.org/en/latest/drivers/vector/index.html dataset_options character; driver dependent dataset creation options; multiple options supported. layer_options character; driver dependent layer creation options; multiple options supported. quiet logical; suppress info name, driver, size spatial reference factorsAsCharacter logical; convert factor levels character strings (TRUE, default), otherwise numbers factorsAsCharacter FALSE. database connections, factorsAsCharacter always TRUE. append logical; append existing layer, replace ? TRUE append, FALSE replace. default st_write NA raises error layer exists. default write_sf FALSE, overwrites existing data. See also next two arguments control overwrite behavior. delete_dsn logical; delete data source dsn attempting write? delete_layer logical; delete layer layer attempting write? default st_write FALSE raises error layer exists. default write_sf TRUE. fid_column_name character, name column feature IDs; specified, column longer written feature attribute. config_options character, named vector GDAL config options","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_write.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Write simple features object to file or database — st_write","text":"obj, invisibly","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_write.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Write simple features object to file or database — st_write","text":"Columns (variables) class supported dropped warning. updating existing layer, records appended updating object right variable names types. names match error raised. types match, behaviour undefined: GDAL may raise warnings errors fail silently. deleting layers data sources successful, error emitted. delete_dsn delete_layer handled care; former may erase complete directories databases. st_delete() deletes layer(s) data source, data source layers omitted; returns TRUE success, FALSE failure, invisibly.","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/st_write.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Write simple features object to file or database — st_write","text":"","code":"nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 st_write(nc, paste0(tempdir(), \"/\", \"nc.shp\")) #> Writing layer `nc' to data source #> `/tmp/RtmpPF9T6H/nc.shp' using driver `ESRI Shapefile' #> Writing 100 features with 14 fields and geometry type Multi Polygon. st_write(nc, paste0(tempdir(), \"/\", \"nc.shp\"), delete_layer = TRUE) # overwrites #> Deleting layer `nc' using driver `ESRI Shapefile' #> Writing layer `nc' to data source #> `/tmp/RtmpPF9T6H/nc.shp' using driver `ESRI Shapefile' #> Writing 100 features with 14 fields and geometry type Multi Polygon. if (require(sp, quietly = TRUE)) { data(meuse, package = \"sp\") # loads data.frame from sp meuse_sf = st_as_sf(meuse, coords = c(\"x\", \"y\"), crs = 28992) # writes X and Y as columns: st_write(meuse_sf, paste0(tempdir(), \"/\", \"meuse.csv\"), layer_options = \"GEOMETRY=AS_XY\") st_write(meuse_sf, paste0(tempdir(), \"/\", \"meuse.csv\"), layer_options = \"GEOMETRY=AS_WKT\", delete_dsn=TRUE) # overwrites if (FALSE) { # \\dontrun{ library(sp) example(meuse, ask = FALSE, echo = FALSE) try(st_write(st_as_sf(meuse), \"PG:dbname=postgis\", \"meuse_sf\", layer_options = c(\"OVERWRITE=yes\", \"LAUNDER=true\"))) demo(nc, ask = FALSE) try(st_write(nc, \"PG:dbname=postgis\", \"sids\", layer_options = \"OVERWRITE=true\")) } # } } #> Writing layer `meuse' to data source `/tmp/RtmpPF9T6H/meuse.csv' using driver `CSV' #> options: GEOMETRY=AS_XY #> Writing 155 features with 12 fields and geometry type Point. #> Deleting source `/tmp/RtmpPF9T6H/meuse.csv' using driver `CSV' #> Writing layer `meuse' to data source `/tmp/RtmpPF9T6H/meuse.csv' using driver `CSV' #> options: GEOMETRY=AS_WKT #> Writing 155 features with 12 fields and geometry type Point."},{"path":"https://r-spatial.github.io/sf/reference/st_z_range.html","id":null,"dir":"Reference","previous_headings":"","what":"Return 'z' range of a simple feature or simple feature set — st_z_range","title":"Return 'z' range of a simple feature or simple feature set — st_z_range","text":"Return 'z' range simple feature simple feature set","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_z_range.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return 'z' range of a simple feature or simple feature set — st_z_range","text":"","code":"# S3 method for class 'z_range' is.na(x) st_z_range(obj, ...) # S3 method for class 'POINT' st_z_range(obj, ...) # S3 method for class 'MULTIPOINT' st_z_range(obj, ...) # S3 method for class 'LINESTRING' st_z_range(obj, ...) # S3 method for class 'POLYGON' st_z_range(obj, ...) # S3 method for class 'MULTILINESTRING' st_z_range(obj, ...) # S3 method for class 'MULTIPOLYGON' st_z_range(obj, ...) # S3 method for class 'GEOMETRYCOLLECTION' st_z_range(obj, ...) # S3 method for class 'MULTISURFACE' st_z_range(obj, ...) # S3 method for class 'MULTICURVE' st_z_range(obj, ...) # S3 method for class 'CURVEPOLYGON' st_z_range(obj, ...) # S3 method for class 'COMPOUNDCURVE' st_z_range(obj, ...) # S3 method for class 'POLYHEDRALSURFACE' st_z_range(obj, ...) # S3 method for class 'TIN' st_z_range(obj, ...) # S3 method for class 'TRIANGLE' st_z_range(obj, ...) # S3 method for class 'CIRCULARSTRING' st_z_range(obj, ...) # S3 method for class 'sfc' st_z_range(obj, ...) # S3 method for class 'sf' st_z_range(obj, ...) # S3 method for class 'numeric' st_z_range(obj, ..., crs = NA_crs_) NA_z_range_"},{"path":"https://r-spatial.github.io/sf/reference/st_z_range.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Return 'z' range of a simple feature or simple feature set — st_z_range","text":"object class z_range length 2.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_z_range.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Return 'z' range of a simple feature or simple feature set — st_z_range","text":"x object class z_range obj object compute z range ... ignored crs object class crs, argument st_crs, specifying CRS bounding box.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_z_range.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Return 'z' range of a simple feature or simple feature set — st_z_range","text":"numeric vector length two, zmin zmax values; obj class sf sfc object returned class z_range","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_z_range.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Return 'z' range of a simple feature or simple feature set — st_z_range","text":"NA_z_range_ represents missing value z_range object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_z_range.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Return 'z' range of a simple feature or simple feature set — st_z_range","text":"","code":"a = st_sf(a = 1:2, geom = st_sfc(st_point(0:2), st_point(1:3)), crs = 4326) st_z_range(a) #> zmin zmax #> 2 3 st_z_range(c(zmin = 16.1, zmax = 16.6), crs = st_crs(4326)) #> zmin zmax #> 16.1 16.6"},{"path":"https://r-spatial.github.io/sf/reference/st_zm.html","id":null,"dir":"Reference","previous_headings":"","what":"Drop or add Z and/or M dimensions from feature geometries — st_zm","title":"Drop or add Z and/or M dimensions from feature geometries — st_zm","text":"Drop Z /M dimensions feature geometries, resetting classes appropriately","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_zm.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Drop or add Z and/or M dimensions from feature geometries — st_zm","text":"","code":"st_zm(x, ..., drop = TRUE, what = \"ZM\")"},{"path":"https://r-spatial.github.io/sf/reference/st_zm.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Drop or add Z and/or M dimensions from feature geometries — st_zm","text":"x object class sfg, sfc sf ... ignored drop logical; drop, (FALSE) add? character dimensions drop add","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_zm.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Drop or add Z and/or M dimensions from feature geometries — st_zm","text":"combinations drop=TRUE, = \"ZM\", drop=FALSE, =\"Z\" supported far. latter case, x XY geometry, zero values added Z dimension.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_zm.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Drop or add Z and/or M dimensions from feature geometries — st_zm","text":"","code":"st_zm(st_linestring(matrix(1:32,8))) #> LINESTRING (1 9, 2 10, 3 11, 4 12, 5 13, 6 14, 7 15, 8 16) x = st_sfc(st_linestring(matrix(1:32,8)), st_linestring(matrix(1:8,2))) st_zm(x) #> Geometry set for 2 features #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 1 ymin: 3 xmax: 8 ymax: 16 #> CRS: NA #> LINESTRING (1 9, 2 10, 3 11, 4 12, 5 13, 6 14, ... #> LINESTRING (1 3, 2 4) a = st_sf(a = 1:2, geom=x) st_zm(a) #> Simple feature collection with 2 features and 1 field #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 1 ymin: 3 xmax: 8 ymax: 16 #> CRS: NA #> a geom #> 1 1 LINESTRING (1 9, 2 10, 3 11... #> 2 2 LINESTRING (1 3, 2 4)"},{"path":"https://r-spatial.github.io/sf/reference/stars.html","id":null,"dir":"Reference","previous_headings":"","what":"functions only exported to be used internally by stars — stars","title":"functions only exported to be used internally by stars — stars","text":"functions exported used internally stars","code":""},{"path":"https://r-spatial.github.io/sf/reference/stars.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"functions only exported to be used internally by stars — stars","text":"","code":".get_layout(bb, n, total_size, key.pos, key.width, mfrow = NULL, main = NULL) .degAxis(side, at, labels, ..., lon, lat, ndiscr, reset) .image_scale( z, col, breaks = NULL, key.pos, add.axis = TRUE, at = NULL, ..., axes = FALSE, key.length, logz = FALSE, lab = \"\", cex.axis = par(\"cex.axis\") ) .image_scale_factor( z, col, key.pos, add.axis = TRUE, ..., axes = FALSE, key.width, key.length, cex.axis = par(\"cex.axis\") )"},{"path":"https://r-spatial.github.io/sf/reference/stars.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"functions only exported to be used internally by stars — stars","text":"bb ignore n ignore total_size ignore key.pos ignore key.width ignore mfrow length-2 integer vector number rows, columns main main sub title side ignore ignore labels ignore ... ignore lon ignore lat ignore ndiscr ignore reset ignore z ignore col ignore breaks ignore add.axis ignore axes ignore key.length ignore logz ignore lab ignore cex.axis see par","code":""},{"path":"https://r-spatial.github.io/sf/reference/summary.sfc.html","id":null,"dir":"Reference","previous_headings":"","what":"Summarize simple feature column — summary.sfc","title":"Summarize simple feature column — summary.sfc","text":"Summarize simple feature column","code":""},{"path":"https://r-spatial.github.io/sf/reference/summary.sfc.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Summarize simple feature column — summary.sfc","text":"","code":"# S3 method for class 'sfc' summary(object, ..., maxsum = 7L, maxp4s = 10L)"},{"path":"https://r-spatial.github.io/sf/reference/summary.sfc.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Summarize simple feature column — summary.sfc","text":"object object class sfc ... ignored maxsum maximum number classes summarize simple feature column maxp4s maximum number characters print PROJ string","code":""},{"path":"https://r-spatial.github.io/sf/reference/tibble.html","id":null,"dir":"Reference","previous_headings":"","what":"Summarize simple feature type for tibble — tibble","title":"Summarize simple feature type for tibble — tibble","text":"Summarize simple feature type / item tibble","code":""},{"path":"https://r-spatial.github.io/sf/reference/tibble.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Summarize simple feature type for tibble — tibble","text":"","code":"type_sum.sfc(x, ...) obj_sum.sfc(x) pillar_shaft.sfc(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/tibble.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Summarize simple feature type for tibble — tibble","text":"x object class sfc ... ignored","code":""},{"path":"https://r-spatial.github.io/sf/reference/tibble.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Summarize simple feature type for tibble — tibble","text":"see type_sum","code":""},{"path":"https://r-spatial.github.io/sf/reference/tidyverse.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidyverse methods for sf objects — tidyverse","title":"Tidyverse methods for sf objects — tidyverse","text":"Tidyverse methods sf objects. Geometries sticky, use .data.frame let dplyr's methods drop . Use methods loading tidyverse package generic (loading package tidyverse).","code":""},{"path":"https://r-spatial.github.io/sf/reference/tidyverse.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidyverse methods for sf objects — tidyverse","text":"","code":"filter.sf(.data, ..., .dots) arrange.sf(.data, ..., .dots) group_by.sf(.data, ..., add = FALSE) ungroup.sf(x, ...) rowwise.sf(x, ...) mutate.sf(.data, ..., .dots) transmute.sf(.data, ..., .dots) select.sf(.data, ...) rename.sf(.data, ...) rename_with.sf(.data, .fn, .cols, ...) slice.sf(.data, ..., .dots) summarise.sf(.data, ..., .dots, do_union = TRUE, is_coverage = FALSE) distinct.sf(.data, ..., .keep_all = FALSE) gather.sf( data, key, value, ..., na.rm = FALSE, convert = FALSE, factor_key = FALSE ) pivot_longer.sf( data, cols, names_to = \"name\", names_prefix = NULL, names_sep = NULL, names_pattern = NULL, names_ptypes = NULL, names_transform = NULL, names_repair = \"check_unique\", values_to = \"value\", values_drop_na = FALSE, values_ptypes = NULL, values_transform = NULL, ... ) pivot_wider.sf( data, ..., id_cols = NULL, id_expand = FALSE, names_from = name, names_prefix = \"\", names_sep = \"_\", names_glue = NULL, names_sort = FALSE, names_vary = \"fastest\", names_expand = FALSE, names_repair = \"check_unique\", values_from = value, values_fill = NULL, values_fn = NULL, unused_fn = NULL ) spread.sf( data, key, value, fill = NA, convert = FALSE, drop = TRUE, sep = NULL ) sample_n.sf(tbl, size, replace = FALSE, weight = NULL, .env = parent.frame()) sample_frac.sf( tbl, size = 1, replace = FALSE, weight = NULL, .env = parent.frame() ) group_split.sf(.tbl, ..., .keep = TRUE) nest.sf(.data, ...) separate.sf( data, col, into, sep = \"[^[:alnum:]]+\", remove = TRUE, convert = FALSE, extra = \"warn\", fill = \"warn\", ... ) separate_rows.sf(data, ..., sep = \"[^[:alnum:]]+\", convert = FALSE) unite.sf(data, col, ..., sep = \"_\", remove = TRUE) unnest.sf(data, ..., .preserve = NULL) drop_na.sf(x, ...) inner_join.sf(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ...) left_join.sf(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ...) right_join.sf(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ...) full_join.sf(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ...) semi_join.sf(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ...) anti_join.sf(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ...)"},{"path":"https://r-spatial.github.io/sf/reference/tidyverse.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidyverse methods for sf objects — tidyverse","text":".data data object class sf ... arguments .dots see corresponding function package dplyr add see corresponding function dplyr x, y pair data frames, data frame extensions (e.g. tibble), lazy data frames (e.g. dbplyr dtplyr). See Methods, , details. .fn, .cols see original docs do_union logical; case summary create geometry column, geometries created unioning using st_union, simply combining using st_combine? Using st_union resolves internal boundaries, case unioning points, likely change order points; see Details. is_coverage logical; do_union TRUE, use optimized algorithm features form polygonal coverage (overlaps) .keep_all see corresponding function dplyr data see original function docs key see original function docs value see original function docs na.rm see original function docs convert see separate_rows factor_key see original function docs cols see original function docs names_to, names_pattern, names_ptypes, names_transform see tidyr::pivot_longer() names_prefix, names_sep, names_repair see original function docs. values_to, values_drop_na, values_ptypes, values_transform See tidyr::pivot_longer() id_cols, id_expand, names_from, names_sort, names_glue, names_vary, names_expand see tidyr::pivot_wider() values_from, values_fill, values_fn, unused_fn see tidyr::pivot_wider() fill see original function docs drop see original function docs sep see separate_rows tbl see original function docs size see original function docs replace see original function docs weight see original function docs .env see original function docs .tbl see original function docs .keep see original function docs col see separate see separate remove see separate extra see separate .preserve see unnest join specification created join_by(), character vector variables join . NULL, default, *_join() perform natural join, using variables common across x y. message lists variables can check correct; suppress message supplying explicitly. join different variables x y, use join_by() specification. example, join_by(== b) match x$y$b. join multiple variables, use join_by() specification multiple expressions. example, join_by(== b, c == d) match x$y$b x$c y$d. column names x y, can shorten listing variable names, like join_by(, c). join_by() can also used perform inequality, rolling, overlap joins. See documentation ?join_by details types joins. simple equality joins, can alternatively specify character vector variable names join . example, = c(\"\", \"b\") joins x$y$x$b y$b. variable names differ x y, use named character vector like = c(\"x_a\" = \"y_a\", \"x_b\" = \"y_b\"). perform cross-join, generating combinations x y, see cross_join(). copy x y data source, copy TRUE, y copied src x. allows join tables across srcs, potentially expensive operation must opt . suffix non-joined duplicate variables x y, suffixes added output disambiguate . character vector length 2.","code":""},{"path":"https://r-spatial.github.io/sf/reference/tidyverse.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidyverse methods for sf objects — tidyverse","text":"object class sf","code":""},{"path":"https://r-spatial.github.io/sf/reference/tidyverse.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Tidyverse methods for sf objects — tidyverse","text":"select keeps geometry regardless whether selected ; deselect , first pipe .data.frame let dplyr's select drop . case one arguments (expressions) summarise call creates geometry list-column, first (active) geometry returned object. case, geometry column created, depending value do_union. case do_union FALSE, summarise simply combine geometries using c.sfg. polygons sharing boundary combined, leads geometries invalid; see instance https://github.com/r-spatial/sf/issues/681. distinct gives distinct records attributes geometries distinct; st_equals used find geometries distinct. nest assumes simple feature geometry list-column among columns nested.","code":""},{"path":"https://r-spatial.github.io/sf/reference/tidyverse.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidyverse methods for sf objects — tidyverse","text":"","code":"if (require(dplyr, quietly = TRUE)) { nc = read_sf(system.file(\"shape/nc.shp\", package=\"sf\")) nc %>% filter(AREA > .1) %>% plot() # plot 10 smallest counties in grey: st_geometry(nc) %>% plot() nc %>% select(AREA) %>% arrange(AREA) %>% slice(1:10) %>% plot(add = TRUE, col = 'grey') title(\"the ten counties with smallest area\") nc2 <- nc %>% mutate(area10 = AREA/10) nc %>% slice(1:2) } #> Warning: plotting the first 10 out of 14 attributes; use max.plot = 14 to plot all #> Simple feature collection with 2 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -81.74107 ymin: 36.23436 xmax: -80.90344 ymax: 36.58965 #> Geodetic CRS: NAD27 #> # A tibble: 2 × 15 #> AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 NWBIR74 #> #> 1 0.114 1.44 1825 1825 Ashe 37009 37009 5 1091 1 10 #> 2 0.061 1.23 1827 1827 Alleg… 37005 37005 3 487 0 10 #> # ℹ 4 more variables: BIR79 , SID79 , NWBIR79 , #> # geometry # plot 10 smallest counties in grey: if (require(dplyr, quietly = TRUE)) { st_geometry(nc) %>% plot() nc %>% select(AREA) %>% arrange(AREA) %>% slice(1:10) %>% plot(add = TRUE, col = 'grey') title(\"the ten counties with smallest area\") } if (require(dplyr, quietly = TRUE)) { nc$area_cl = cut(nc$AREA, c(0, .1, .12, .15, .25)) nc %>% group_by(area_cl) %>% class() } #> [1] \"sf\" \"grouped_df\" \"tbl_df\" \"tbl\" \"data.frame\" if (require(dplyr, quietly = TRUE)) { nc2 <- nc %>% mutate(area10 = AREA/10) } if (require(dplyr, quietly = TRUE)) { nc %>% transmute(AREA = AREA/10) %>% class() } #> [1] \"sf\" \"tbl_df\" \"tbl\" \"data.frame\" if (require(dplyr, quietly = TRUE)) { nc %>% select(SID74, SID79) %>% names() nc %>% select(SID74, SID79) %>% class() } #> [1] \"sf\" \"tbl_df\" \"tbl\" \"data.frame\" if (require(dplyr, quietly = TRUE)) { nc2 <- nc %>% rename(area = AREA) } if (require(dplyr, quietly = TRUE)) { nc %>% slice(1:2) } #> Simple feature collection with 2 features and 15 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -81.74107 ymin: 36.23436 xmax: -80.90344 ymax: 36.58965 #> Geodetic CRS: NAD27 #> # A tibble: 2 × 16 #> AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 NWBIR74 #> #> 1 0.114 1.44 1825 1825 Ashe 37009 37009 5 1091 1 10 #> 2 0.061 1.23 1827 1827 Alleg… 37005 37005 3 487 0 10 #> # ℹ 5 more variables: BIR79 , SID79 , NWBIR79 , #> # geometry , area_cl if (require(dplyr, quietly = TRUE)) { nc$area_cl = cut(nc$AREA, c(0, .1, .12, .15, .25)) nc.g <- nc %>% group_by(area_cl) nc.g %>% summarise(mean(AREA)) nc.g %>% summarise(mean(AREA)) %>% plot(col = grey(3:6 / 7)) nc %>% as.data.frame %>% summarise(mean(AREA)) } #> mean(AREA) #> 1 0.12626 if (require(dplyr, quietly = TRUE)) { nc[c(1:100, 1:10), ] %>% distinct() %>% nrow() } #> [1] 100 if (require(tidyr, quietly = TRUE) && require(dplyr, quietly = TRUE) && \"geometry\" %in% names(nc)) { nc %>% select(SID74, SID79) %>% gather(\"VAR\", \"SID\", -geometry) %>% summary() } #> geometry VAR SID #> MULTIPOLYGON :200 Length:200 Min. : 0.000 #> epsg:4267 : 0 Class :character 1st Qu.: 2.000 #> +proj=long...: 0 Mode :character Median : 5.000 #> Mean : 7.515 #> 3rd Qu.: 9.000 #> Max. :57.000 if (require(tidyr, quietly = TRUE) && require(dplyr, quietly = TRUE) && \"geometry\" %in% names(nc)) { nc$row = 1:100 # needed for spread to work nc %>% select(SID74, SID79, geometry, row) %>% gather(\"VAR\", \"SID\", -geometry, -row) %>% spread(VAR, SID) %>% head() } #> Simple feature collection with 6 features and 3 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -81.74107 ymin: 36.07282 xmax: -75.77316 ymax: 36.58965 #> Geodetic CRS: NAD27 #> # A tibble: 6 × 4 #> geometry row SID74 SID79 #> #> 1 (((-81.47276 36.23436, -81.54084 36.27251, -81.56198 36.273… 1 1 0 #> 2 (((-81.23989 36.36536, -81.24069 36.37942, -81.26284 36.405… 2 0 3 #> 3 (((-80.45634 36.24256, -80.47639 36.25473, -80.53688 36.256… 3 5 6 #> 4 (((-76.00897 36.3196, -76.01735 36.33773, -76.03288 36.3359… 4 1 2 #> 5 (((-77.21767 36.24098, -77.23461 36.2146, -77.29861 36.2115… 5 9 3 #> 6 (((-76.74506 36.23392, -76.98069 36.23024, -76.99475 36.235… 6 7 5 if (require(tidyr, quietly = TRUE) && require(dplyr, quietly = TRUE)) { storms.sf = st_as_sf(storms, coords = c(\"long\", \"lat\"), crs = 4326) x <- storms.sf %>% group_by(name, year) %>% nest trs = lapply(x$data, function(tr) st_cast(st_combine(tr), \"LINESTRING\")[[1]]) %>% st_sfc(crs = 4326) trs.sf = st_sf(x[,1:2], trs) plot(trs.sf[\"year\"], axes = TRUE) }"},{"path":"https://r-spatial.github.io/sf/reference/transform.sf.html","id":null,"dir":"Reference","previous_headings":"","what":"transform method for sf objects — transform.sf","title":"transform method for sf objects — transform.sf","text":"Can used create modify attribute variables; transforming geometries see st_transform, functions starting st_.","code":""},{"path":"https://r-spatial.github.io/sf/reference/transform.sf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"transform method for sf objects — transform.sf","text":"","code":"# S3 method for class 'sf' transform(`_data`, ...)"},{"path":"https://r-spatial.github.io/sf/reference/transform.sf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"transform method for sf objects — transform.sf","text":"_data object class sf ... arguments form new_variable = expression","code":""},{"path":"https://r-spatial.github.io/sf/reference/transform.sf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"transform method for sf objects — transform.sf","text":"","code":"a = data.frame(x1 = 1:3, x2 = 5:7) st_geometry(a) = st_sfc(st_point(c(0,0)), st_point(c(1,1)), st_point(c(2,2))) transform(a, x1_sq = x1^2) #> Simple feature collection with 3 features and 3 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 2 #> CRS: NA #> x1 x2 x1_sq geometry #> 1 1 5 1 POINT (0 0) #> 2 2 6 4 POINT (1 1) #> 3 3 7 9 POINT (2 2) transform(a, x1_x2 = x1*x2) #> Simple feature collection with 3 features and 3 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 2 #> CRS: NA #> x1 x2 x1_x2 geometry #> 1 1 5 5 POINT (0 0) #> 2 2 6 12 POINT (1 1) #> 3 3 7 21 POINT (2 2)"},{"path":"https://r-spatial.github.io/sf/reference/valid.html","id":null,"dir":"Reference","previous_headings":"","what":"Check validity or make an invalid geometry valid — valid","title":"Check validity or make an invalid geometry valid — valid","text":"Checks whether geometry valid, makes invalid geometry valid","code":""},{"path":"https://r-spatial.github.io/sf/reference/valid.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check validity or make an invalid geometry valid — valid","text":"","code":"st_is_valid(x, ...) # S3 method for class 'sfc' st_is_valid(x, ..., NA_on_exception = TRUE, reason = FALSE) # S3 method for class 'sf' st_is_valid(x, ...) # S3 method for class 'sfg' st_is_valid(x, ...) st_make_valid(x, ...) # S3 method for class 'sfg' st_make_valid(x, ...) # S3 method for class 'sfc' st_make_valid( x, ..., oriented = FALSE, s2_options = s2::s2_options(snap = s2::s2_snap_precision(1e+07), ...), geos_method = \"valid_structure\", geos_keep_collapsed = TRUE )"},{"path":"https://r-spatial.github.io/sf/reference/valid.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check validity or make an invalid geometry valid — valid","text":"x object class sfg, sfc sf ... passed s2_options NA_on_exception logical; TRUE, polygons otherwise raise GEOS error (exception, e.g. POLYGON zero less 4 points, LINESTRING one point) return NA rather raising error, suppress warning messages (e.g. self-intersection); FALSE, regular GEOS errors warnings emitted. reason logical; TRUE, return character , geometry, reason invalidity, NA exception, \"Valid Geometry\" otherwise. oriented logical; relevant st_is_longlat(x) TRUE; see s2 s2_options relevant st_is_longlat(x) TRUE; options s2_rebuild, see s2_options Details. geos_method character; either \"valid_linework\" (Original method, combines rings set noded lines extracts valid polygons linework) \"valid_structure\" (Structured method, first makes rings valid merges shells subtracts holes shells generate valid result. Assumes holes shells correctly categorized.) (requires GEOS >= 3.10.1) geos_keep_collapsed logical; parameter set FALSE, \"valid_structure\" method keep component collapsed lower dimensionality. example, ring collapsing line, line collapsing point (requires GEOS >= 3.10.1)","code":""},{"path":"https://r-spatial.github.io/sf/reference/valid.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Check validity or make an invalid geometry valid — valid","text":"st_is_valid returns logical vector indicating geometries x whether valid. st_make_valid returns object topologically valid geometry. Object class x","code":""},{"path":"https://r-spatial.github.io/sf/reference/valid.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Check validity or make an invalid geometry valid — valid","text":"projected geometries, st_make_valid uses lwgeom_makevalid method also used PostGIS command ST_makevalid GEOS version linked smaller 3.8.0, otherwise version shipped GEOS; geometries ellipsoidal coordinates s2::s2_rebuild used. s2_options specified x non-zero precision set, precision value used value s2_snap_precision, passed s2_options, rather 1e7 default.","code":""},{"path":"https://r-spatial.github.io/sf/reference/valid.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check validity or make an invalid geometry valid — valid","text":"","code":"p1 = st_as_sfc(\"POLYGON((0 0, 0 10, 10 0, 10 10, 0 0))\") st_is_valid(p1) #> [1] FALSE st_is_valid(st_sfc(st_point(0:1), p1[[1]]), reason = TRUE) #> [1] \"Valid Geometry\" \"Self-intersection[5 5]\" library(sf) x = st_sfc(st_polygon(list(rbind(c(0,0),c(0.5,0),c(0.5,0.5),c(0.5,0),c(1,0),c(1,1),c(0,1),c(0,0))))) suppressWarnings(st_is_valid(x)) #> [1] FALSE y = st_make_valid(x) st_is_valid(y) #> [1] TRUE y %>% st_cast() #> Geometry set for 1 feature #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> POLYGON ((0 0, 0 1, 1 1, 1 0, 0.5 0, 0 0))"},{"path":"https://r-spatial.github.io/sf/reference/vctrs.html","id":null,"dir":"Reference","previous_headings":"","what":"vctrs methods for sf objects — vctrs","title":"vctrs methods for sf objects — vctrs","text":"vctrs methods sf objects","code":""},{"path":"https://r-spatial.github.io/sf/reference/vctrs.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"vctrs methods for sf objects — vctrs","text":"","code":"vec_ptype2.sfc(x, y, ...) # Default S3 method vec_ptype2.sfc(x, y, ..., x_arg = \"x\", y_arg = \"y\") # S3 method for class 'sfc' vec_ptype2.sfc(x, y, ...) vec_cast.sfc(x, to, ...) # S3 method for class 'sfc' vec_cast.sfc(x, to, ...) # Default S3 method vec_cast.sfc(x, to, ...)"},{"path":"https://r-spatial.github.io/sf/reference/vctrs.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"vctrs methods for sf objects — vctrs","text":"x, y Vector types. ... dots future extensions must empty. x_arg, y_arg Argument names x y. Type cast . NULL, x returned .","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-19","dir":"Changelog","previous_headings":"","what":"version 1.0-19","title":"version 1.0-19","text":"fix type checks C++ GDAL area length computation functions, anticipating GDAL 3.10.0; #2466, #2468, #2469 @rsbivand @rouault improve test empty geometries, changed 1.0-18; #2463 gdal_utils() ogrinfo argument read_only , TRUE (options includes \"-ro\"), opens datasource read-mode (#2460; sf 1.0-17); default datasource opened update (read-write) mode (since sf 1.0-17; #2420) sf -> ppp conversion .ppp.sf() accepts data.frame marks instead just 1 column #2450, @agila5","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-18","dir":"Changelog","previous_headings":"","what":"version 1.0-18","title":"version 1.0-18","text":"CRAN release: 2024-10-11 support POLYGON FULL simple feature geometry, representing entire Earth surface, used s2geometry; #2441 st_sfc() argument oriented , set TRUE, adds attribute oriented=TRUE sfc object, indicating object reoriented conversion s2_geography (avoiding using global option s2_oriented); st_as_sfc.bbox() sets TRUE; #2441 fix build failure GDAL < 3.4.0 #2436 st_simplify() now accepts feature-wise tolerance values s2 switched #2442","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-17","dir":"Changelog","previous_headings":"","what":"version 1.0-17","title":"version 1.0-17","text":"CRAN release: 2024-09-06 add st_transform() method bbox objects; uses OGRCoordinateTransformation::TransformBounds(), densifying first antemeridian proof; #2415 st_filter.sf() correctly scopes x y arguments using !! operator; #2416 [.sfc [<-.sfc use matrix/array type subsetting sfc objects dim attribute add st_exterior_ring() extract exterior rings (remove holes); #2406 add text.sf(), text.sfc(), points.sf(), points.sfc() annotate base plots geometry centroids; #2399 st_sf() longer strips tbl tbl_df class labels; #2378 st_layers() returns object class c(\"sf_layers\", \"data.frame\"), dedicated print method. dim XYZM, sf_as_sf.data.frame() interprets length 4 coords argument specify corners rectangular polygon; #2357 st_interpolate_aw() gains na.rm argument, removing features NA attributes interpolating; #830 merge.sf() longer renames geometry column; #2334","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-16","dir":"Changelog","previous_headings":"","what":"version 1.0-16","title":"version 1.0-16","text":"CRAN release: 2024-03-24 st_join() longer renames geometry column; #2327 st_sample() works unprojected polygon geometry crosses antemeridian; #2331 clean modernization S3 registration methods tests; #2285, #2288, #2316, #2341, #2342, @olivroy [.sfc works setting argument op; #2320 st_sample() polygons sensitive setting oriented = TRUE prevent wrongly correcting ring directions; #2308 add support GDAL footprint utility (requiring GDAL >= 3.8.0) gdal_utils; #2305, @goergen95 existing environment variables PROJ_LIB PROJ_DATA () ignored sf binary CRAN installations (win + macos), effectively overwriting R session restoring exit; happen environment variable R_SF_USE_PROJ_DATA set true. #2298 add st_line_project() find far point projected line; #2291 add st_line_interpolate() obtain point certain distance along line; #2291","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-15","dir":"Changelog","previous_headings":"","what":"version 1.0-15","title":"version 1.0-15","text":"CRAN release: 2023-12-18 add st_perimeter() generic cover geographic projected coordinates; #268, #2279, @JosiahParry add st_sample() method bbox, special provisions ellipsoidal coordinates; #2283 documentation clean-@olivroy; #2266, #2285 st_convex_hull() uses s2::s2_convex_hull() geodetic coordinates; #2250 add directed argument st_line_merge(); #2264 st_union.sfc() given x y works consistently across geodetic projected objects; #2262 st_union.sf() given x y unions pairwise by_feature = TRUE; #2259 st_read() work around issue GPKG driver wkt_filter set; #2248 st_read() uses GDAL’s stream reading use_stream = TRUE; #2238 @paleolimbot st_transform() responds -session changes sf_proj_network(); #2166 plot.sf(): key.width sensitive pointsize graphics parameter par(\"ps\"); keys factor levels suggest proper size won’t fit. plot.sf(): key.pos can hold second value [0, 1] determining relative position key available space [<-.sf fixes agr attribute broken; #2211 env. variable ADD_SF_NAMESPACE set true, sf objects get new attribute, .sf_namespace, forces loading sf namespace loaded far, e.g. proper printing plotting sf object; #2212 Mike Mahoney distinct.sf() type-safe sf objects zero rows; #2204 summarise.sf() raises error .given across() geometry; #2207 st_write() matches fields name first, position; matters formats pre-defined names, GPX; #2202","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-14","dir":"Changelog","previous_headings":"","what":"version 1.0-14","title":"version 1.0-14","text":"CRAN release: 2023-07-11 fix plot.sf() using key multiple factor variables; #2196, #2195 fix use .numeric_version test, upcoming change r-devel code tidy-ing: fix many lintr suggestions, thanks Michael Chirico (#2181 - #2191)","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-13","dir":"Changelog","previous_headings":"","what":"version 1.0-13","title":"version 1.0-13","text":"CRAN release: 2023-05-24 gdal_utils() adds \"ogrinfo\" utility (requires GDAL >= 3.7.0); #2160 st_as_sf() catches errors setting invalid crs values, raised Jon Skøien add rename_with.sf() method; #1472 use GEOS’ overlayNG routines (GEOS) Intersection, Difference, Union SymDifference; #2143 added duplicated.sf(); #2138, #2140, thanks @bart1 select.sf() allows selecting column twice different names; #1886 st_as_sf.ppplist() deprecated; #1926 st_cast() handles empty geometries; #1961 don’t repeat longlat messages summarise.sf(); #1519 fix random sampling sphere; #2133","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-12","dir":"Changelog","previous_headings":"","what":"version 1.0-12","title":"version 1.0-12","text":"CRAN release: 2023-03-19 update NAMESPACE useDynLib(sf, .registration=TRUE); #2127 thanks @eddelbuettel fix call gdal_addo(); #2124 fix issues came older GDAL version, use GDAL_VERSION_NUM consistently; #2123 #2121 #2119","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-11","dir":"Changelog","previous_headings":"","what":"version 1.0-11","title":"version 1.0-11","text":"CRAN release: 2023-03-15 st_make_grid() also accepts area units cellsize, square hexagonal grids; #1505 add st_concave_hull(), concave hulls, GEOS >= 3.11.0; #1964 add st_triangulate_constrained(), constrained Delaunay triangulation, GEOS >= 3.10.0; #1964 clean retrieval length angle units WKT representations; https://lists.osgeo.org/pipermail/gdal-dev/2023-March/056994.html conversion GEOS uses GEOS_PREC_VALID_OUTPUT flag, makes sure “[o]utput always valid. Collapsed geometry elements (including polygons lines) removed.”","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-10","dir":"Changelog","previous_headings":"","what":"version 1.0-10","title":"version 1.0-10","text":"CRAN release: 2023-03-12 gdal_utils() config_options argument set GDAL options, just like st_write(); #2003 fix slow writing logical vectors st_write(); #1409; #1689 st_drivers() argument regex filter driver (long) name; #2090 drop C++11 system requirement c.sfc() (, consequently, dplyr::bind_rows()) gives error components different CRS; #1884 data imported maps associated Clark 1866 ellipsoid; #2080 fix importing legacy SpatialPolygon objects without comments; #2063, #2069, https://github.com/rstudio/leaflet/issues/833 st_read() longer errors mixes XY XYZ geometries; #2046 #1592 plot.sf(), numeric breaks given legend key always plotted; #2065 st_crs()$axes returns data.frame axes properties (name, orientation, conversion factor) GDAL >= 3.0.0 clean unit handling geometry measures (length, area, distance) crs; st_crs(x)$ud_unit returns NULL units unknown; #2049 st_write() substitutes NA crs ENGCRS[\"Undefined Cartesian SRS unknown unit\"]; #2049, #2054 st_can_transform() checks whether transformation two crs exists; see https://github.com/dieghernan/tidyterra/issues/64; #2049 matrix returned st_coordinates() row names, reduce output size","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-9","dir":"Changelog","previous_headings":"","what":"version 1.0-9","title":"version 1.0-9","text":"CRAN release: 2022-11-08 adjust changes R-devel handles POSIXlt; #2028 add st_break_antimeridian(); #1983, #1991 Roger Bivand add Fibonacci spatial sampling type st_sample() use global options(\"sf_use_s2\") determine whether use s2, rather value local environment; #1977 fix utils mdiminfo mdimtranslate gdal_utils() extend arguments gdal_read_mdim() needed stars::read_mdim() stars >= 0.5-7; add gdal_write_mdim() add drop_na() method sf objects; #1975","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-8","dir":"Changelog","previous_headings":"","what":"version 1.0-8","title":"version 1.0-8","text":"CRAN release: 2022-07-14 st_drop_geometry.default() returns x unmodified; sf_project() accepts 3- 4-column matrices, containing z t values; optimization st_sfc() @paleolimbot; #1938, #1925 [<-.sfc() recomputes bounding box; st_sfc() gets parameter compute_bbox; #1965 add new algorithm drop option st_make_valid() using GEOS GEOS >= 3.10.1; #1655 add st_minimum_rotated_rectangle(), available GEOS >= 3.9.0; #1953 fix st_sample() type = \"hexagonal\" corner case (n=1), add progress argument progress bar; #1945 add package pbapply Suggests; #1945 add pdf driver windows build; #1942 clarify pipeline argument st_transform() axis order ambiguous; #1934 handle argument xpd calls plot.sfc_POLYGON() plot.sfc_MULTIPOLYGON() add pivot_wider() method, Henning Teickner; #1915 add gdal_addo() add remove overviews raster images; #1921 st_layers() returns crs layer crs list crs objects restore st_graticule() behaviour pre-sf 1.0-0; https://github.com/tidyverse/ggplot2/issues/4571 gdal_metadata() sets metadata item names properly st_read() gains argument optional passed .data.frame avoid changing column names; #1916 GPX files autodetected st_read(); #1917 unnecessary coordinate names returned st_sample(), making output size smaller; #1879","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-7","dir":"Changelog","previous_headings":"","what":"version 1.0-7","title":"version 1.0-7","text":"CRAN release: 2022-03-07 st_drop_geometry() generic; #1914 st_crs(x)$ud_unit returns unit coordinate reference system x geometric predicates return sgbp objects omitting self-intersections etc. passing remove_self = TRUE unique symmetric relationship passing retain_unique = TRUE (... needed); simplifies identifying (removing) duplicated geometries; duplicates identified e.g. st_equals(x, retain_unique = TRUE) |> unlist() |> unique(); #1893 fix compile issue GDAL < 2.5.0 introduced 1.0-6; #1899","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-6","dir":"Changelog","previous_headings":"","what":"version 1.0-6","title":"version 1.0-6","text":"CRAN release: 2022-02-04 adapt new spatstat.random package; #1892 st_geometry<-() also allows rename geometry column sf object; #1890 sf objects, st_as_sfc() method alias st_geometry(); #1882 st_make_grid() speeded ; #1579 thanks Krzysztof Dyba remove direct indirect dependencies rgeos rgdal; #1869 use stats::dist rather GEOS symmetric point-point Euclidian distance computation; #1874","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-5","dir":"Changelog","previous_headings":"","what":"version 1.0-5","title":"version 1.0-5","text":"CRAN release: 2021-12-17 package startup message reports status sf_use_s2(); #1782 sf_use_s2() uses message() report change; #1782 st_sample() using regular sampling ellipsoidal coordinates “works” coordinates Cartesian; #1837","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-4","dir":"Changelog","previous_headings":"","what":"version 1.0-4","title":"version 1.0-4","text":"CRAN release: 2021-11-14 new function st_delete() deletes data source, layer(s) within data source; #1828 fix memory leak WKT1_ESRI retrieval; #1690","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-3","dir":"Changelog","previous_headings":"","what":"version 1.0-3","title":"version 1.0-3","text":"CRAN release: 2021-10-07 cope GEOS >= 3.10.0 handles illegal geometries (e.g., non-closed rings); #1807 crs objects $srid method extract SRID (authority “name:code”); #1804 st_as_grob() methods sfc_* objects correctly handle empty geometries; #1789 help Hiroaki Yutani writing objects NA CRS GeoPackage, assign “Unknown Cartesian CRS” first - line using Cartesian geometry operations objects NA CRS; #1776 add coerce method sgbp sparseMatrix; #1750 fix st_cast() GEOMETRYCOLLECTIONS containing empty geometries; #1767 fix st_is_valid() bogus polygons projected coordinates; #1666, #1760; #1761","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-2","dir":"Changelog","previous_headings":"","what":"version 1.0-2","title":"version 1.0-2","text":"CRAN release: 2021-07-26 st_read() st_write() using GDAL handle binary attributes (OFTBinary fields) ; #1721 pivot_longer method added sf objects (data.frame method works, raises warning) rbind.sf preserves primary geometry column; #1717 configure constrains using --static Darwin platform; #1702, #1712, #1713 old-style crs objects created sf < 0.9-0 generate message, cause warning future. st_crs() called WKT2 text input, input field replaced CRS name (one). GEOS (>= 3.9.0) operations use GEOSGeom_setPrecision_r set precision geometries; #1535 st_read() specified query ignores argument layers, warns given; #1444","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-1","dir":"Changelog","previous_headings":"","what":"version 1.0-1","title":"version 1.0-1","text":"CRAN release: 2021-06-29 fix regression st_intersection(): using s2 attributes assigned wrongly; #1704 crs (sf) CRS (sp) conversion longer needs validation rgdal; https://github.com/edzer/sp/issues/107 retrieve ESRI’s WKT version CRS st_crs(id)$WKT1_ESRI; #1690","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-0","dir":"Changelog","previous_headings":"","what":"version 1.0-0","title":"version 1.0-0","text":"CRAN release: 2021-06-09 add s2 Imports: add Dewey Dunnington contributors sf_use_s2() prints message using s2 switched . use s2 spherical geometry default coordinates ellipsoidal. can switched (defaulting planar geometry, using GEOS, sf < 1.0-0) setting environment variable _SF_USE_S2 false package sf loaded, sf_use_s2(FALSE); #1649 st_nearest_feature() missing y returns nearest features remaining set x; https://github.com/r-spatial/s2/issues/111 st_write() gains argument config_options set GDAL config options; #1618 fix regression sf_project(..., keep = TRUE); #1635","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-8","dir":"Changelog","previous_headings":"","what":"version 0.9-8","title":"version 0.9-8","text":"CRAN release: 2021-03-17 add st_as_sf() method terra’s SpatVector class; #1567 distinct.sf() works default variables, keeps active geometry active; #1613 improve (fix?) polygonize/contour code; #1608 sf_proj_network() reports whether PROJ uses network (CDN) grids, can switch , can set CDN url. st_write() returns obj, invisibly; #1597 fix regression n-ary st_intersection(), #1595, introduced #1549 st_inscribed_circle() computes maximum inscribed circle polygons (requires GEOS >= 3.9.0) allow st_cast() COMPOUNDCURVE, MULTISURFACE CURVEPOLYGON GEOMETRYCOLLECTION, back; #1573 Fixed bug st_as_grob() plotting mix MULTI non-MULTI geometries base type","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-7","dir":"Changelog","previous_headings":"","what":"version 0.9-7","title":"version 0.9-7","text":"CRAN release: 2021-01-06 n-ary st_intersection() skips failing geometries, rather returning error; #1549 use s2_centroid() geographical coordinates sf_use_s2() TRUE. st_as_text() method crs objects can return projjson (GDAL >= 3.1.0 PROJ > 6.2.0) st_transform() longer warns conversions like \"+proj=ob_tran +o_proj=longlat +o_lat_p=45 +o_lon_p=30\" st_as_wkb() takes srid wkt field crs input field doesn’t contain ; #1490 plot.sf() adds key.pos=0 option run logic behind key without plotting ; #1487 fix bug select.sf() selected variables renamed; #1483 st_as_sf.stars(..., merge = TRUE) now works CRS NA; #1389 add (dynamically loaded) as_wkb() methods sf, sfc sfg, making st_as_s2() unnecessary st_as_s2() transforms non-longlat objects EPSG:4326 first","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-6","dir":"Changelog","previous_headings":"","what":"version 0.9-6","title":"version 0.9-6","text":"CRAN release: 2020-09-13 gdal_utils() print (GDAL-style) progress bar quiet = FALSE (except info mdiminfo) fix CPL_gdal_warper multi bands; https://github.com/r-spatial/stars/issues/320 sf_proj_search_paths() retrieves sets proj search path (GDAL > 3.0.3) loading sf, sf_use_s2() set FALSE unless environment variable _SF_USE_S2 equals true (changes TRUE sf 1.0-0) resolve GDAL/PROJ version vulnerabilities CRS-crs conversion; #1479 st_sample() gains argument, by_polygon, clevery sample MULTIPOLYGON geometries; #1480 st_sample() accepts non-integer sample sizes, (suppressable) warning handles values sizes round zero; #1480 gdal_utils() adds utils mdiminfo mdimtranslate (requires GDAL >= 3.1) st_union() gains argument is_coverage, , set TRUE, leads much faster unioning case features form coverage (polygons don’t overlap); #1462 Don Baston fix gdal_utils(\"translate\") locking input file; #1452 st_make_grid() longer selects cells intersecting x; #1447 use s2::s2_dwithin_matrix() st_is_within_distance(); #1367","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-5","dir":"Changelog","previous_headings":"","what":"version 0.9-5","title":"version 0.9-5","text":"CRAN release: 2020-07-14 package s2 >= 1.0.1 available: support spherical geometry operators (predicates, transformers, measures, nearest point/feature) geographic coordinates package s2 now default switched , can switched sf_use_s2(TRUE); see https://www.r-spatial.org/r/2020/06/17/s2.html vignette sf7. planned switched default sf 1.0-0. drop Z /M coordinate st_as_s2(), message geometry predicates transformers gain … argument pass s2::s2_options() dplyr::select() now ensures geometry column sticks back rather front data frame; #1425 dplyr::rename() now preserves active geometry column even renamed; #1431 proj units query adjusted PROJ 7.1.0 release; #1434","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-4","dir":"Changelog","previous_headings":"","what":"version 0.9-4","title":"version 0.9-4","text":"CRAN release: 2020-06-12 empty geom generators take care XYZ etc dim; #1400 write_sf() read_sf() longer warn reading tables without geometries st_write() writes non-spatial tables given plain data.frame tbl_df; #1345 default stringsAsFactors st_read st_sf FALSE R version >= 4.1.0 sf method dplyr::select() supports renaming geometry column; #1415","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-3","dir":"Changelog","previous_headings":"","what":"version 0.9-3","title":"version 0.9-3","text":"CRAN release: 2020-05-04 st_is_valid() generic Windows CRAN binaries use GDAL 3.0.4, PROJ 6.3.1 GEOS 3.8.0, thanks Jeroen Ooms’ rwinlib work; #1275 plot.sf() gains extent argument set extent (xlim, ylim) plot; extent must object st_bbox() method, sf stars object; #1193","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-2","dir":"Changelog","previous_headings":"","what":"version 0.9-2","title":"version 0.9-2","text":"CRAN release: 2020-04-14 st_axis_order(TRUE) gives error GDAL version < 2.5.0 loading PROJ units link, us_in, ind_yd, ind_ft, ind_ch udunits database longer done package load time, function sf_add_proj_units() called. fix line sampling small densities; #1365 sf_project() handles crs objects PROJ version 6 using proj.4 string representations. avoid using isFALSE st_write(); #1342 fix regression gdal_utils(\"translate\", ...); #1339","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-1","dir":"Changelog","previous_headings":"","what":"version 0.9-1","title":"version 0.9-1","text":"CRAN release: 2020-04-06 fix invalid read bug st_m_range(); #1332 st_crs(4326) == st_crs(\"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs\") returns TRUE GDAL >= 3.0, irrespective authority compliance axis order; see #1331 https://github.com/ropensci/scrubr/issues/34 sf_project() parameter authority_compliant return coordinates “visualisation order”; TRUE returns coordinates authority compliant axis order (e.g. EPSG:4326 latitude longitude); default st_axis_order(). fix test Solaris certain GDAL/PROJ versions fix error reading category table GDAL; https://github.com/r-spatial/stars/issues/245","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-0","dir":"Changelog","previous_headings":"","what":"version 0.9-0","title":"version 0.9-0","text":"CRAN release: 2020-03-24 see r-spatial blog post: https://www.r-spatial.org/r/2020/03/17/wkt.html modify crs objects reflect post-proj4string world (#1146; #1225): crs objects contain two fields, input user input (), wkt well-known-text (WKT2) representation coordinate reference system. crs objects $ method dynamically retrieve epsg (integer) proj4string representation, using e.g. x$epsg. support PostGIS 3 using WKT new-style crs objects; #1234, #1303, #1308 @etiennebr st_write_db() st_read_db() defunct. Use st_write st_read instead. st_write() uses append, replacing (deprecating) argument update; st_write fails layer already exists append set explicitly TRUE (append) FALSE (overwrite); #1266 st_proj_info() renamed sf_proj_info; sf_proj_info can get set PROJ data search path use CDN; #1277 adapt new dplyr version; https://github.com/tidyverse/dplyr/issues/4917 st_sample() generic write stars rasters wkt info, rather proj4strings GEOS >= 3.8.0, st_make_valid provided sf rather lwgeom #989 allow single-sided buffers linear geometries; #1001 add st_reverse() methods reverse points linestring (requires GEOS >= 3.7.0); #1246 st_make_grid() returns grid cells points intersect target geometry, bounding box; #1260 allow PROJ >= 7; #1254 st_geometry_type() accepts by_geometry argument; #1264","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-08-1","dir":"Changelog","previous_headings":"","what":"version 0.8-1","title":"version 0.8-1","text":"CRAN release: 2020-01-28 st_as_sf.map() longer requires maptools sp; dropped dependency maptools. work around bug 6.0.0 <= PROJ < 6.3.1: replace +init=epsg:XXXX ... strings XXXX EPSG integer, work around bug PROJ; see https://github.com/OSGeo/PROJ/pull/1875 links therein. ... arguments present, raise warning ignored. st_as_sf.map() longer requires maptools sp; drop dependency maptools. conversion spatstat classes owin, ppp psp sf classes longer use maptools; #1204 gdal_utils() processes open options -oo -doo properly; https://github.com/ITSLeeds/geofabric/issues/12 st_sample() directly interfaces spatstat sampling methods, e.g. type = \"Thomas\" calls spatstat::rThomas converting input arguments (window) converts returned ppp object sf’s POINT geometries; #1204 help Ege Rubak Jakub Nowosad sf_project() gains option keep = TRUE return Inf values points projectable; #1228 support vctrs methods geometry list columns; makes unnest work (#1172); #1196 Lionel Henry st_as_sf.pq_geometry() converts binary geom columns RPostgres::dbGetQuery; #1195 st_cast() can convert MULTICURVE MULTILINESTRING; #1194 st_read() gains parameter wkt_filter spatially filtering features read; #1192 st_area() st_length() handle +to_meter argument PROJ strings; #1170 add st_filter() generic filtering spatial features ; #1148 new UBSAN error wkb_read() resolved; #1154, #1152 new method st_shift_longitude() re-center data Pacific view. #1218 output st_as_text() MULTIPOINT nested parentheses around points. E.g., MULTIPOINT ((0 0), (1 1)) instead MULTIPOINT (0 0, 1 1); #1219, #1221","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-08-0","dir":"Changelog","previous_headings":"","what":"version 0.8-0","title":"version 0.8-0","text":"CRAN release: 2019-09-17 fix tests PROJ 6.2.0 accepting +units= fixes tidyr 1.0-0 release; attempt port nest.sf() unnest.sf(); #1068, #1145 gdal_utils() better closes connections use; #1143 st_write() gains drivers options, limit drivers attempted; #1142 rather replacing, st_write() write_sf() append existing layer update=TRUE; #1126 improve plotting POSIXct Date attributes (Date requiring classInt >= 0.4-2) NULL geometries read GDAL returned empty geometries; #1119 gdal_utils('rasterize', ...) accepts non-existing destinations, defined e.g. resolution extent options (see #1116 example), overwrites needed (see #1136 example) add Dan Baston contributor; #1120 many others addition NULL, st_sfc() also converts NA values empty geometries; #1114. st_join() generic","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-7","dir":"Changelog","previous_headings":"","what":"version 0.7-7","title":"version 0.7-7","text":"CRAN release: 2019-07-24 plot() handles POSIXct values legend constructor functions like st_linestring() check break NA coordinates; #1101, #1102","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-6","dir":"Changelog","previous_headings":"","what":"version 0.7-6","title":"version 0.7-6","text":"CRAN release: 2019-07-05 examples st_write write temporary R session directory","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-5","dir":"Changelog","previous_headings":"","what":"version 0.7-5","title":"version 0.7-5","text":"CRAN release: 2019-07-03 (x, \"Spatial\") gives proper error message empty geometries; #1093 st_cast() takes care empty polygons; #1094 st_nearest_* functions warn case used geographic coordinates; #1081 st_union() longer segfaults zero row sf objects; #1077 st_transform() longer breaks zero row sf objects; #1075 PROJ >= 6.1.0 available sf comes datum files (case statically linked Windows OSX CRAN binaries), PROJ_LIB longer temporarily overwritten, PROJ C api used set datum path; #1074, suggested Jeroen Ooms sf compiles GDAL 3.x PROJ 6.1.0, using new proj.h interface; #1070 st_distance() returns NA empty geometries, rather 0; #1055","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-4","dir":"Changelog","previous_headings":"","what":"version 0.7-4","title":"version 0.7-4","text":"CRAN release: 2019-04-25 add example voronoi polygons can tied back points contain; #1030 st_difference(x, y), x sfc zero feature geometries, returns x; #1024 don’t reset (base) plot device add = TRUE == != return NA one operands empty geometry; #1013 st_intersects() generic drop requiring proj_api.h favor proj.h, enables compatibility PROJ 6.0.0 GDAL 2.5.0-dev; #988 fix regression binary predicates introduced #855; #999 reported Barry Rowlingson fix bug gdal_utils util warper certain GDAL/OS combinations; https://github.com/r-spatial/stars/issues/117 c.sfc() ignores type (class) empty sfc objects choosing result type; #985, #982 rename default value distance \"Euclidean\", rather \"distance\" st_distance()","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-3","dir":"Changelog","previous_headings":"","what":"version 0.7-3","title":"version 0.7-3","text":"CRAN release: 2019-02-21 add argument exact st_sample(), defaulting FALSE; #896 fixed n-ary st_difference() cases geometries entirely contained others; #975, Jonathan Marshall faster Ops.sfc(), added st_normalize(); #973 Thomas Lin Pedersen new grob constructor sfc objects; #971 Thomas Lin Pedersen; add Thomas contributor add group_split() group_map() methods sf objects (experimental); #969 make st_interpolate_aw() generic; argument col plot GEOMETRY sfc’s NA (open) (multi) polygon geometries","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-2","dir":"Changelog","previous_headings":"","what":"version 0.7-2","title":"version 0.7-2","text":"CRAN release: 2018-12-20 feature IDs longer returned names geometry list column, optionally returned st_read attribute column; #812 plotting multiple attributes, plot.sf adds (single, common) key key.pos set precision can specified distance units; #901 support log-scale color legend setting logz TRUE plot.sf st_intersects() etc. prepare y y polygons x points; #885 Dan Baston st_write() (write_sf()) returns first argument, invisibly; #889","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-1","dir":"Changelog","previous_headings":"","what":"version 0.7-1","title":"version 0.7-1","text":"CRAN release: 2018-10-24 fix bug broke n-ary st_intersection() platforms using clang; #867","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-0","dir":"Changelog","previous_headings":"","what":"version 0.7-0","title":"version 0.7-0","text":"CRAN release: 2018-10-17 adds several interfaces GDAL functions, meant used package stars st_read() receives query argument can run queries OGR datasets; #834, Barry Rowlingson Michael Sumner read_sf() longer first creates tibbles data.frames, creates directly; #853, db propagation Etienne Racine check difference compile-time run-time GEOS versions; #844 GEOS routines () robust memory leaks, using unique pointers; #822, #845, Dan Baston st_buffer() receives buffer styles endCapStyle, joinStyle mitreLimit; #833, #842 Michael Sumner","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-06-4","dir":"Changelog","previous_headings":"","what":"version 0.6-4","title":"version 0.6-4","text":"st_area() generic; https://github.com/r-spatial/stars/issues/32 st_write() resolves ~ correctly; #456 read write feature IDs sfc list column names; #812 st_centroid() works empty geometries, returning empty point #769 add st_nearest_points(), obtain (LINESTRING connecting ) two nearest points pairs geometries; #788 add hexagonal tiling st_make_grid() add regular hexagonal sampling st_sample() fixes PROJ 5.0.1; #545 fixes GDAL 2.3.0; #759 st_sample() supports regular sampling LINESTRING; #725 @statnmap Support reading writing database Pool objects; #756 fix plotting sf objects without attributes; #755 add reference R Journal article CITATION","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-06-3","dir":"Changelog","previous_headings":"","what":"version 0.6-3","title":"version 0.6-3","text":"CRAN release: 2018-05-17 move dependency RPostgreSQL Imports: back Suggests: st_centroid.sf() st_point_on_surface.sf also warn attributes constant geometries. summarise() allows user define geometries summaries; #714, Kirill Mueller plot.sf() emits warning col length 1 nrow(x), requires pal (rather col) set palette factors. plot.sf() provides control legend keys using key.length key.width, decrease default key length; #731 sgbp objects receive .data.frame method; #715","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-06-2","dir":"Changelog","previous_headings":"","what":"version 0.6-2","title":"version 0.6-2","text":"CRAN release: 2018-04-25 GDAL read/write supports logical variables; #722 add st_crop() simplify cropping objects rectangular area; #720 fix bug [<- columns added sf object; #718 use dynamic registration S3 methods, similar hms ; #710 Kirill Mueller (partially) address writing GPKG network drive, writing temp file first; #628 add Kirill Mueller contributor st_make_grid() faster; #708, Dan Baston st_read() st_write() generic, methods directly reading writing database connections; st_read_db st_write_db deprecated; #558, thanks Etienne Racine @etiennebr Package RPostgreSQL moved Suggests Imports restore compatibility GDAL 2.0.x versions (won’t gdal_utils); #686 read_sf() can also read tables without geometry; #684, Andy Teucher","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-06-1","dir":"Changelog","previous_headings":"","what":"version 0.6-1","title":"version 0.6-1","text":"CRAN release: 2018-03-22 method distinct() works; #669, #672 +, -, * / pairs geometries (sfg, sfc) return geometric union, difference, intersection symmetric difference, respectively. st_cast() MULTIPOLYGON MULTILINESTRING work properly; #660 Rcpp interfaces needed package stars moved sf; pkg stars R-, sf needs linking GDAL. gdal_utils() interfaces 9 gdal utils using C++ API improve resetting (base) plots; add reset = FALSE call plot enable adding plots legend st_read() returns data.frame table contains geometries, rather giving error; emit warning case. See https://stat.ethz.ch/pipermail/r-sig-geo/2018-February/026344.html move pillar Imports: Suggests: update new rwinlib distribution gdal (adds JPG2000); #639 speed computation centroids largest polygon; #623 add st_as_sfc.raw method Bugfix: binary operations (st_intersection, st_difference, etc) longer fail operating data frames class \"tbl_df\" common column names; #644","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-06-0","dir":"Changelog","previous_headings":"","what":"version 0.6-0","title":"version 0.6-0","text":"CRAN release: 2018-01-06 add pillar Imports: provide method printing WKT geometries tibbles st_as_text, subsequently format print, use argument digits (options(digits = n)) control number digits used printing coordinates; default options(\"digits\"), typically 7. st_is_within_distance works geographic coordinates st_cast MULTIPOLYGON MULTILINESTRING longer changes number features/feature geometries, conversion MULTIPOLYGON LINESTRING (typically) ; #596 st_distance long/lat geographic coordinates uses lwgeom, accepting geometry types; argument dist_fun deprecated consequence, distance calculations different sf versions 0.5-5 earlier; #593 add package lwgeom Suggests; st_area, st_length, st_distance, st_segmentize long/lat CRS use package lwgeom instead geosphere; #593 st_length returns zero polygon-type geometries; #593 present, add units attribute default plot title; #591 add unnest method, depends tidyr > 0.7-2; #570 PR @karldw add largest option st_join get largest intersection match ; #547, @tiernanmartin change default maximum number feature print 10, controllable options(sf_max_print); #556 add Hausdorff (Frechet GEOS 3.7.0) options st_distance; add par densified versions add st_snap, snapping geometries geometries, within tolerance make st_wrap_dateline generic, methods sf, sfc sfg; #541 plot.sf st_as_grob (used ggplot2) robust misspecified ring directions (holes direction exterior rings), using rule = \"evenodd\"; #540 functions depending liblwgeom (st_make_valid, st_geohash, st_plit) moved package, https://github.com/r-spatial/lwgeom; argument use_gdal st_transform deprecated, instead one can use lwgeom::st_transform_proj; sf longer tries link liblwgeom; #509, #537, #487 st_read, st_sf st_sfc gain parameter check_ring_dir (default: FALSE) checks ring directions corrects : exterior counter clockwise, holes clockwise, seen . get rid classInt::classIntervals warning number unique values smaller number breaks asked ","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-05-5","dir":"Changelog","previous_headings":"","what":"version 0.5-5","title":"version 0.5-5","text":"CRAN release: 2017-10-31 classInt Imports:, break package checks add vignettes 5: plotting sf objects 6: miscellaneous; #324 add (default) color key plot.sf single map plotted, contributed @hughjonesd; #528 st_as_sfc can read EWKT; #530 argument max.plot takes default options(sf_max.plot=n), present; #516 plot.sf gets arguments pal specify color palette function; #526 plot.sf gets arguments breaks nbreaks; add support classInt::classIntervals styles finding class intervals (using breaks) add st_as_sf methods ppp, lpp psp objects spatstat. allow direct route proj.4 ignoring GDAL (requiring liblwgeom); #509, #511 add print method crs objects; #517 sf_extSoftVersion reveals whether GDAL linked GEOS; #510 better check input st_polygon; #514 add st_node, similar rgeos::gNode support reading OFTInteger64List fields; #508 sparse geometric binary predicate lists class, sgbp, attributes region.id predicate; #234, #524 prevent st_split stopping R session; #492 st_intersection, st_union also print message used directly long/lat coordinates; #496 add rep method sfc objects comparing two crs objects uses GDAL function IsSame; #180 add st_collection_extract, , given object geometries type GEOMETRY GEOMETRYCOLLECTION, returns object consisting elements specified type; Andy Teucher, #482 st_write exports GeoJSON UTF-8 encoding Windows; #444 move package methods Imports: Depends: ; #478 deal better precision setting propagation; #476 fix bug st_layers case layers geometry; #334 clarify argument envelope st_voronoi; #474 change aggregate make return geometry ‘’, padding attributes NA needed; #453","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-05-4","dir":"Changelog","previous_headings":"","what":"version 0.5-4","title":"version 0.5-4","text":"CRAN release: 2017-08-28 fix compatibility problems introduced tidyr 0.7-0 using rlang magic convert path names UTF-8 st_read, st_write st_layers; #471 st_sfc converts NULL values empty geometries, correctly identifies empty POINTs; #466, #463 st_write abbreviates column names driver ESRI Shapefile; #464 add of_largest_polygon argument st_centroid, get centroid largest polygon; #450 fix use st_relate join predicate st_join; #454 fix bug st_intersects empty second argument crash; #458 produce better WKT; #463 fix bug st_cast.sf; #461, #462 change st_read SRS assignment logic; corrects reading projected geojson gdal 2.2.0; #449 st_intersection etc. tbl also return tbl; #448 [.sf preserves class, e.g. tbl; #448","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-05-3","dir":"Changelog","previous_headings":"","what":"version 0.5-3","title":"version 0.5-3","text":"CRAN release: 2017-07-30 support propagate Proj.4 +units=xx length units; #446 allow arith ops empty sfc objects st_graticule return empty graticule object argument datum NA; export as_Spatial, make easier packages convert sfc objects without importing sf st_distance gains parameter by_element obtain pairwise distances; #437 add ability aggregate using simple feature argument; #429 make op argument [.sf work speed st_coordinates POINT geometries; #433 fix performance regression st_bbox; #418 correct bug st_union, st_difference st_sym_difference introduced 0.5-2; #431 inform gdal CRS always proj4string, never epsg; see #424 properly deal kilometre units; #424 (fixed Karl Dunkle Werner) add st_is_within_distance, return sparse index matrix; #419 st_graticule work world2 (0,360); #421, #422, fixed Ben Best st_graticule return graticules native crs; https://github.com/tidyverse/ggplot2/issues/2200 (WIP) st_graticule support data NA_crs_; https://github.com/tidyverse/ggplot2/issues/2199 fix bug joining sf-tibble tibble; #414 read gdal StringList, RealList, IntegerList fields list-column; #416","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-05-2","dir":"Changelog","previous_headings":"","what":"version 0.5-2","title":"version 0.5-2","text":"CRAN release: 2017-07-12 made ready rwinlib/gdal2; #408 make [.sf selections including NA values like x[c(1,NA,2)]; #403 add [<- method sfc objects; automatically replaces NULL empty geometry; #411 add st_point_on_surface() return point guaranteed surface (standard compliance) read_sf returns sf-tibble, object class c(\"sf\", \"tbl_df\", \"tbl\", \"data.frame\") work around dplyr::filter dispatching geometry column subsetting sf::[.sfc allow units object dist argument st_buffer; must convertable arc_degree geographic, length unit non-geographic data; #399 prevent gdal crashing trying st_transform empty geometry; #398 add st_as_sfc method bbox, returning bbox polygon; #377 strip file name extension default layer name st_write; #392 st_sf replace NULL values sfc list-column appropriate empty geometry; #372 allow setting ndiscr ggplot2::coords_sf improve graticule plotting geom_sf; #396","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-05-1","dir":"Changelog","previous_headings":"","what":"version 0.5-1","title":"version 0.5-1","text":"CRAN release: 2017-06-23 add spatial indexes binary geometry operations; #394 http://r-spatial.org/r/2017/06/22/spatial-index.html drastically reduce memory footprint st_intersection similar; #394 support RSQLite 2.0 providing st_as_sfc method list columns class blob drop dependency dbplyr","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-05-0","dir":"Changelog","previous_headings":"","what":"version 0.5-0","title":"version 0.5-0","text":"CRAN release: 2017-06-15 better handle empty/NULL geometries shapefiles; #351 add unite_.sf method deprecate FUN argument st_join; #376 improve graticule tic label placement ggplot2; #375 https://github.com/tidyverse/ggplot2/issues/2119 improve configure logic deal libraries installed custom locations; #335 fix bug geom_sf wouldn’t deal Z /M geoms; #373 return conveniently typed empty geoms; #372 fix subsetting [ sf using drop = TRUE, #370 addition m, allow rad units st_segmentize add example st_read GeoJSON string; #185 add separate_.sf method add st_split split geometries (available compiled liblwgeom), #359 fix bug reading writing dates (months 1 ): #358 [.sf [.sfc also select sfg object, accept geometric predicate function optional arguments; #352 reading GDAL, empty (NULL) geometries longer result error; creation, longer automatically give GEOMETRY object; #351 plotting ggplot2::geom_sf, empty geometries longer break; grid functions return nullGrob() ; #351 arith operations empty geometries longer break give warnings; #351 st_as_sf.data.frame default break NA values coordinates; #342 st_join accept arguments, passed join function (e.g. pattern st_relate) WKB reader throw error () malformed inputs, check buffer bounds","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-04-3","dir":"Changelog","previous_headings":"","what":"version 0.4-3","title":"version 0.4-3","text":"CRAN release: 2017-05-15 back-port do_union argument dplyr <= 0.5.0, using lazyeval strings returned OGR/GDAL get encoding set UTF-8, making work non-UTF-8 platforms; #5 $.crs retrieves proj4string components, st_crs(4326)$datum addition epsg proj4string let st_geohash return geohash (average) points (sf linked liblwgeom)","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-04-2","dir":"Changelog","previous_headings":"","what":"version 0.4-2","title":"version 0.4-2","text":"CRAN release: 2017-05-05 summarise.sf always returns sf object, also global (non-grouped) summaries. summarise.sf gains argument do_union determines whether union geometries summary given, st_combine (resolving boundaries); #331 rename argument union aggregate.sf do_union, consistency summarise; #331 add nest_ method sf objects st_relate gets pattern parameter, rgeos::gRelate; add examples get rook queen neighbour lists using ; #234 support direct reading spatialite sqlite geometry wkb blobs build proper support cbind rbind methods sf, work (documented) arguments class sf; dplyr::bind_cols st_sf(data.frame(sf, df)) work binding data.frames sf object. st_segmentize() st_line_sample() accept units arguments document problem reading shapefiles USB drives OSX; #252 improve docs st_is_valid st_make_valid; #296 coercing sf data.frame works better; #298 st_line_sample gains argument sample specify points t.b. sampled; #299 #300 thanks @joethorley add compatibility upcoming dplyr 0.6.0; #304 #42 write GDAL fields name, number, fixing KML problem #308 st_write gains arguments delete_layer delete_dsn allow overwrite capability #307 #274 write_sf defaults delete_layer=TRUE, silently overwriting layers ’re already present compatibility GDAL 2.2beta0; #303; #309 replace st_write_db version fast large datasets (#285), thanks Josh London take memory leaking examples tests aggregate method sf objects assumes argument identical stats::aggregate st_wrap_dateline wraps (cuts ) geometries crossing antimeridian, longer cross .","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-04-1","dir":"Changelog","previous_headings":"","what":"version 0.4-1","title":"version 0.4-1","text":"CRAN release: 2017-03-28 restore 3.3.0 c++11 requirement st_read respects time read UTC st_write writes time always UTC, since GDAL mechanism define local timezones “unknown” “local” st_length works POINT MULTIPOINT (returning 0); POLYGON MULTIPOLYGON converted MULTILINESTRING computing length, thus giving polygon perimeter (#268) st_write update depend driver; databases, default TRUE, otherwise FALSE (refers update database, overwriting table database, default succeed); #274 st_read supports reading objects multiple geometry columns #257 #255 support writing (exporting) objects non-standard columns, units POSIXlt #264 catch dependencies GEOS 3.3.5 (hence 0.4-0 CRAN binary MacOSX) #260","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-04-0","dir":"Changelog","previous_headings":"","what":"version 0.4-0","title":"version 0.4-0","text":"CRAN release: 2017-03-21 st_is_valid catch corrupt geometries , returning NA case (requiring GEOS 3.5.0) add st_make_valid, available sf linked liblwgeom add st_coordinates method, returning coordinates matrix indexes remove unlist.sfg add .matrix.sfg; .matrix.sfg add indexes coordinates add st_bind_cols method improve handling features can’t projected support uniform sampling polygons sphere add st_sample, sampling points multipoints, linestrings, polygons add c method sfc objects import export magrittr::%>% support ggplot’ing geometrycollections drop C++11 requirement, allowing build older R versions add st_proj_info, modelled rgdal::projInfo overwriting datasets st_write() longer allowed; update=TRUE appends , permitted driver supports appending. st_write gains argument, update, TRUE try append existing datasets (#204) added list corresponding function migration sp, rgdal rgeos sf https://github.com/edzer/sfr/wiki/migrating remove deprecated st_list rename st_makegrid st_make_grid, st_linemerge st_line_merge add NEWS.md file (#207) faster conversion data.frame POINT sf object, using st_as_sf (Michael Sumner) rbind method sf objects keeps coordinate reference system","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-03-4-feb-6-2017","dir":"Changelog","previous_headings":"","what":"version 0.3-4, Feb 6, 2017","title":"version 0.3-4, Feb 6, 2017","text":"CRAN release: 2017-02-06 add st_contains_properly spatial predicate GEOS functions (geometry operations) accept XYZ geometries (ignore Z) make prepared = TRUE default geometry binary operations","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-03-2-feb-4-2017","dir":"Changelog","previous_headings":"","what":"version 0.3-2, Feb 4, 2017","title":"version 0.3-2, Feb 4, 2017","text":"CRAN release: 2017-02-04 add user interrupt checks GEOS geometry operations make st_graticule something useful polar projections make st_graticule return NA labels labels useless add merge.sf methods merge sf object data.frame (#193) add st_join table joins based (user-defined) spatial predicates add dplyr-style non-spatial joins sf objects (left_join, full_join etc.) (#193) allow multiple non-gathered variables (#196) add missing meridian st_graticule (#198)","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-03-1-jan-31-2017","dir":"Changelog","previous_headings":"","what":"version 0.3-1, Jan 31, 2017","title":"version 0.3-1, Jan 31, 2017","text":"CRAN release: 2017-01-31 add merge method (#193) st_graticule laea (#198) allow st_buffer feature-dependent buffer distance (#197) spread return sf object (#196) clarify overwrite = TRUE write docs fix st_as_sf.map (#194) add prepared arg spatial binary predicates, speed large intersections add st_voronoi interface (requires lib GEOS >= 3.5.0) add st_as_sf methods map objects (library maps) add RStudio project file st_bbox return bbox object st_crs method rename st_drop_zm st_zm, general handling Z M allow 3D coordinates returned, +proj=geocent (#172; #103) fix NA_integer_ handling shapefiles /O (#184) add fix st_agr API, set get attribute--geometry relationships","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-02-8-jan-5-2017","dir":"Changelog","previous_headings":"","what":"version 0.2-8, Jan 5, 2017","title":"version 0.2-8, Jan 5, 2017","text":"CRAN release: 2017-01-05","code":""}] +[{"path":"https://r-spatial.github.io/sf/CONDUCT.html","id":null,"dir":"","previous_headings":"","what":"Contributor Code of Conduct","title":"Contributor Code of Conduct","text":"contributors maintainers project, pledge respect people contribute reporting issues, posting feature requests, updating documentation, submitting pull requests patches, activities. committed making participation project harassment-free experience everyone, regardless level experience, gender, gender identity expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion. Examples unacceptable behavior participants include use sexual language imagery, derogatory comments personal attacks, trolling, public private harassment, insults, unprofessional conduct. Project maintainers right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct. Project maintainers follow Code Conduct may removed project team. Instances abusive, harassing, otherwise unacceptable behavior may reported opening issue contacting one project maintainers. Code Conduct adapted Contributor Covenant (http:contributor-covenant.org), version 1.0.0, available http://contributor-covenant.org/version/1/0/0/","code":""},{"path":"https://r-spatial.github.io/sf/PROPOSAL.html","id":null,"dir":"","previous_headings":"","what":"Simple Features for R","title":"Simple Features for R","text":"Applicant: Edzer Pebesma, Institute Geoinformatics, University Muenster, Germany; edzer.pebesma@uni-muenster.de Supporting authors: Edzer Pebesma, Roger Bivand, Michael Sumner, Robert Hijmans, Virgilio Gómez-Rubio Simple features open (OGC ISO) interface standard access manipulation spatial vector data (points, lines, polygons). includes standard SQL schema supports storage, retrieval, query update feature collections via SQL interface. commonly used databases provide interface. GeoJSON standard encoding simple features JSON, used JavaScript MongoDB. Well-known-text (WKT) text representation simple features used often linked data; well-known-binary ([WKB] (https://en.wikipedia.org/wiki/Well-known_text)) standard binary representation used databases. Simple Feature Access defines coordinate reference systems, makes easy move data longitude-latitude projections back forth standardized way. GDAL open source C++ library reading writing raster vector data 225 drivers (supported file formats, data base connectors, web service interfaces). GDAL used practically open source geospatial projects many industry products (including ESRI’s ArcGIS, ERDAS, FME). provides coordinate transformations (built top PROJ.4) geometric operations (e.g. polygon intersections, unions, buffers distance). Standards coordinate transformations change time; changes typically adopted directly GDAL/PROJ.4 easily find way R-packages mapproj. Since 2005, CRAN package sp provides classes methods spatial (point, line, polygon raster) data. approach sp takes similar xts zoo handle time index time series data: objects store spatial geometries separately associated attribute data, matching order. Package spacetime, CRAN since 2010, extends sp xts handle data varies space time. Today, 221 CRAN packages depend , import link sp, 259 including Suggests; including recursive dependencies numbers 376 5040. implementation sp follow simple features, rather practice used time release, following ESRI shapefiles implemented. cluster packages around sp shown Andrie de Vries’ blog CRAN’s network structure green. -CRAN package rgdal2 interface GDAL 2.0, uses raw pointers interface features, import data R, using GDAL handle everything. CRAN Package wkb, contributed Tibco Software, converts WKB representations several simple feature classes corresponding classes sp, seems needed Tibco software purposes.","code":""},{"path":"https://r-spatial.github.io/sf/PROPOSAL.html","id":"the-problem","dir":"","previous_headings":"","what":"The problem","title":"Simple Features for R","text":"problems solve : R can currently represent simple features directly. can read simple feature classes sp classes, uses representation , can write data back without loss information furnished ancilliary metadata encoded comment attribute Polygons object. instance internally distinguish POLYGON MULTIPOLYGON deal several simple feature classes, including TIN GEOMETRYCOLLECTION, handle CURVE geometries. current implementation lines vector data package sp partly ambiguous (slot ringDir slot hole indicate whether Polygon hole superceded comment attribute), complicated (exterior polygon hole belong - handled comment attribute), considered difficult work (S4). current implementation hard maintain contains incremental changes baseline predated industry-standard OGC/ISO (Simple Feature Interface Specification). lack support simple features makes current interfaces open source libraries (GDAL/OGR PROJ.4: rgdal, GEOS: rgeos) difficult understand maintain, even though work specification. current implementation scale model coordinates. desirable R packages offered opportunity migrate --date libraries coordinate transformations (providing proper support datum transformation), avoid make simplifying assumptions (e.g., spatial data come longitude/latitude using datum WGS84; web maps use web Mercator). users benefit solving problems? mainly affect use data bases modern javascript-based web APIs largely converged adopting simple features (CartoDB), well need simpler light-weight handling spatial data R. also reduce effort users developers understand way spatial information represented R, making easier build upon reuse R code , lead good, sustainable shared R code base. longer run affect users packages currently reusing sp classes, manage migrate sp exclusively use simple feature classes representing vector data. Since recent 2.0 release GDAL integrates raster vector data, R package mirrors classes makes possible implement operations -database (similar DBI, RPostgreSQL dplyr ), making possible R manipulate spatial data fit memory. Big Data analysis R often proceeds connecting R database holds data. commonly used commercial open source databases store spatial point, line polygon data form simple features. Representing simple features R simplify big data analysis spatial data.","code":""},{"path":"https://r-spatial.github.io/sf/PROPOSAL.html","id":"the-plan","dir":"","previous_headings":"","what":"The plan","title":"Simple Features for R","text":"want solve problem carrying following steps (M1 refers month 1): develop R package implements simple features R, simple yet gives users access complete data, includes S3 representation extends data.frame (M1-3) add package C++ interface GDAL 2.0, read write simple feature data, interface functionality (coordinate transformation, geometry operations) (M3-8) develop prototypically implement migration path sp become compliant simple features (M7-12) write user-oriented tutorial vignettes showing use files, data base connections, web API’s, leaflet, ggmap, dplyr (M7-10) write tutorial vignette R package writers reusing package (M10) Collect process community feed back (M6-12). Failure modes recovery plan: Failure mode: S3 classes simple represent simple features class hierarchy. Recovery plan: try () using list column geometry, nested lists represent nested structures; (ii) use WKT character column; (iii) using WKB blob column Migrating sp breaks downstream packages. Recovery plan: involve Roger Bivand, Barry Rowlingson, Robert Hijmans (raster) Tim Keitt (rgdal/rgdal2) proceed; patient smooth problems together package maintainers.","code":""},{"path":"https://r-spatial.github.io/sf/PROPOSAL.html","id":"how-can-the-isc-help","dir":"","previous_headings":"","what":"How can the ISC help","title":"Simple Features for R","text":"following table contains cost items. visit Roger anticipated halfway project; communications use skype. project planned duration 12 months.","code":""},{"path":"https://r-spatial.github.io/sf/PROPOSAL.html","id":"dissemination","dir":"","previous_headings":"","what":"Dissemination","title":"Simple Features for R","text":"Development take place github, information shared reactions contributions invited r-sig-geo, well StackOverflow GIS StackExchange. project use Apache 2.0 license maximum dissemination (similar GDAL, uses X/MIT). work published 4 blogs (quarterly), announced r-sig-geo (3300 subscribers), intermediary results presented UseR! 2016. final result published paper either submitted R Journal Journal Statistical Software; paper available publication package vignette.","code":""},{"path":"https://r-spatial.github.io/sf/PROPOSAL.html","id":"user-slides","dir":"","previous_headings":"","what":"UseR! slides","title":"Simple Features for R","text":"UseR! 2016 slides found .","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"what-is-a-feature","dir":"Articles","previous_headings":"","what":"What is a feature?","title":"1. Simple Features for R","text":"feature thought thing, object real world, building tree. case objects, often consist objects. case features : set features can form single feature. forest stand can feature, forest can feature, city can feature. satellite image pixel can feature, complete image can feature . Features geometry describing Earth feature located, attributes, describe properties. geometry tree can delineation crown, stem, point indicating centre. properties may include height, color, diameter breast height particular date, . standard says: “simple feature defined OpenGIS Abstract specification spatial non-spatial attributes. Spatial attributes geometry valued, simple features based 2D geometry linear interpolation vertices.” see soon standard extend coverage beyond 2D beyond linear interpolation. , take simple features data structures operations described standard.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"dimensions","dir":"Articles","previous_headings":"What is a feature?","what":"Dimensions","title":"1. Simple Features for R","text":"geometries composed points. Points coordinates 2-, 3- 4-dimensional space. points geometry dimensionality. addition X Y coordinates, two optional additional dimensions: Z coordinate, denoting altitude M coordinate (rarely used), denoting measure associated point, rather feature whole (case feature attribute); examples time measurement, measurement error coordinates four possible cases : two-dimensional points refer x y, easting northing, longitude latitude, refer XY three-dimensional points XYZ three-dimensional points XYM four-dimensional points XYZM (third axis Z, fourth M)","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"simple-feature-geometry-types","dir":"Articles","previous_headings":"What is a feature?","what":"Simple feature geometry types","title":"1. Simple Features for R","text":"following seven simple feature types common, instance ones used GeoJSON: geometry types can also (typed) empty set, containing zero coordinates (POINT standard clear represent empty geometry). Empty geometries can thought analogue missing (NA) attributes, NULL values empty lists. remaining geometries 10 rarer, increasingly find implementations: Note CIRCULASTRING, COMPOUNDCURVE CURVEPOLYGON described SFA standard, SQL-MM part 3 standard. descriptions copied PostGIS manual.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"coordinate-reference-system","dir":"Articles","previous_headings":"What is a feature?","what":"Coordinate reference system","title":"1. Simple Features for R","text":"Coordinates can placed Earth’s surface coordinate reference system (CRS) known; may spheroid CRS WGS84, projected, two-dimensional (Cartesian) CRS UTM zone Web Mercator, CRS three-dimensions, including time. Similarly, M-coordinates need attribute reference system, e.g. measurement unit.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"how-simple-features-in-r-are-organized","dir":"Articles","previous_headings":"","what":"How simple features in R are organized","title":"1. Simple Features for R","text":"Package sf represents simple features native R objects. Similar PostGIS, functions methods sf operate spatial data prefixed st_, refers spatial type; makes easily findable command-line completion. Simple features implemented R native data, using simple data structures (S3 classes, lists, matrix, vector). Typical use involves reading, manipulating writing sets features, attributes geometries. attributes typically stored data.frame objects (similar tbl_df), also store feature geometries data.frame column. Since geometries single-valued, put list-column, list length equal number records data.frame, list element holding simple feature geometry feature. three classes used represent simple features : sf, table (data.frame) feature attributes feature geometries, contains sfc, list-column geometries feature (record), composed sfg, feature geometry individual simple feature. now discuss three classes.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"sf-objects-with-simple-features","dir":"Articles","previous_headings":"How simple features in R are organized","what":"sf: objects with simple features","title":"1. Simple Features for R","text":"usually work geometries single simple features, datasets consisting sets features attributes, two put together sf (simple feature) objects. following command reads nc dataset file contained sf package: (Note users use system.file() give filename directly, shapefiles consist one file, identical basename, reside directory.) short report printed gives file name, driver (ESRI Shapefile), mentions 100 features (records, represented rows) 14 fields (attributes, represented columns). object class meaning extends (“” ) data.frame, single list-column geometries, held column name print first three features, see attribute values abridged version geometry give following output: output see: green simple feature: single record, data.frame row, consisting attributes geometry blue single simple feature geometry (object class sfg) red simple feature list-column (object class sfc, column data.frame) although geometries native R objects, printed well-known text Methods sf objects : also possible create data.frame objects geometry list-columns class sf, e.g. : However, objects: longer register column geometry list-column longer plot method, lack dedicated methods listed class sf","code":"library(sf) ## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE nc <- st_read(system.file(\"shape/nc.shp\", package=\"sf\")) ## Reading layer `nc' from data source ## `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' ## Simple feature collection with 100 features and 14 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 ## Geodetic CRS: NAD27 class(nc) ## [1] \"sf\" \"data.frame\" attr(nc, \"sf_column\") ## [1] \"geometry\" print(nc[9:15], n = 3) methods(class = \"sf\") ## [1] [ [[<- ## [3] [<- $<- ## [5] aggregate as.data.frame ## [7] cbind coerce ## [9] dbDataType dbWriteTable ## [11] duplicated identify ## [13] initialize merge ## [15] plot points ## [17] print rbind ## [19] show slotsFromS3 ## [21] st_agr st_agr<- ## [23] st_area st_as_s2 ## [25] st_as_sf st_as_sfc ## [27] st_bbox st_boundary ## [29] st_break_antimeridian st_buffer ## [31] st_cast st_centroid ## [33] st_collection_extract st_concave_hull ## [35] st_convex_hull st_coordinates ## [37] st_crop st_crs ## [39] st_crs<- st_difference ## [41] st_drop_geometry st_exterior_ring ## [43] st_filter st_geometry ## [45] st_geometry<- st_inscribed_circle ## [47] st_interpolate_aw st_intersection ## [49] st_intersects st_is_full ## [51] st_is_valid st_is ## [53] st_join st_line_merge ## [55] st_m_range st_make_valid ## [57] st_minimum_rotated_rectangle st_nearest_points ## [59] st_node st_normalize ## [61] st_point_on_surface st_polygonize ## [63] st_precision st_reverse ## [65] st_sample st_segmentize ## [67] st_set_precision st_shift_longitude ## [69] st_simplify st_snap ## [71] st_sym_difference st_transform ## [73] st_triangulate_constrained st_triangulate ## [75] st_union st_voronoi ## [77] st_wrap_dateline st_write ## [79] st_z_range st_zm ## [81] text transform ## see '?methods' for accessing help and source code nc.no_sf <- as.data.frame(nc) class(nc.no_sf) ## [1] \"data.frame\""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"sfc-simple-feature-geometry-list-column","dir":"Articles","previous_headings":"How simple features in R are organized","what":"sfc: simple feature geometry list-column","title":"1. Simple Features for R","text":"column sf data.frame contains geometries list, class sfc. can retrieve geometry list-column case nc$geom nc[[15]], general way uses st_geometry(): Geometries printed abbreviated form, can view complete geometry selecting , e.g. first one : way printed called well-known text, part standards. word MULTIPOLYGON followed three parentheses, can consist multiple polygons, form MULTIPOLYGON(POL1,POL2), POL1 might consist exterior ring zero interior rings, (EXT1,HOLE1,HOLE2). Sets coordinates belonging single polygon held together parentheses, get ((crds_ext)(crds_hole1)(crds_hole2)) crds_ comma-separated set coordinates ring. leads case , MULTIPOLYGON(((crds_ext))) refers exterior ring (1), without holes (2), first polygon (3) - hence three parentheses. can see single polygon rings: polygons dataset multiple exterior rings; can identified : Following MULTIPOLYGON datastructure, R list lists lists matrices. instance, get first 3 coordinate pairs second exterior ring (first ring always exterior) geometry feature 4 : Geometry columns class, Methods geometry list-columns include: Coordinate reference systems (st_crs() st_transform()) discussed section coordinate reference systems. st_as_wkb() st_as_text() convert geometry list-columns well-known-binary well-known-text, explained . st_bbox() retrieves coordinate bounding box. Attributes include:","code":"(nc_geom <- st_geometry(nc)) ## Geometry set for 100 features ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 ## Geodetic CRS: NAD27 ## First 5 geometries: ## MULTIPOLYGON (((-81.47276 36.23436, -81.54084 3... ## MULTIPOLYGON (((-81.23989 36.36536, -81.24069 3... ## MULTIPOLYGON (((-80.45634 36.24256, -80.47639 3... ## MULTIPOLYGON (((-76.00897 36.3196, -76.01735 36... ## MULTIPOLYGON (((-77.21767 36.24098, -77.23461 3... nc_geom[[1]] ## MULTIPOLYGON (((-81.47276 36.23436, -81.54084 36.27251, -81.56198 36.27359, -81.63306 36.34069, -81.74107 36.39178, -81.69828 36.47178, -81.7028 36.51934, -81.67 36.58965, -81.3453 36.57286, -81.34754 36.53791, -81.32478 36.51368, -81.31332 36.4807, -81.26624 36.43721, -81.26284 36.40504, -81.24069 36.37942, -81.23989 36.36536, -81.26424 36.35241, -81.32899 36.3635, -81.36137 36.35316, -81.36569 36.33905, -81.35413 36.29972, -81.36745 36.2787, -81.40639 36.28505, -81.41233 36.26729, -81.43104 36.26072, -81.45289 36.23959, -81.47276 36.23436))) par(mar = c(0,0,1,0)) plot(nc[1], reset = FALSE) # reset = FALSE: we want to add to a plot with a legend plot(nc[1,1], col = 'grey', add = TRUE) par(mar = c(0,0,1,0)) (w <- which(sapply(nc_geom, length) > 1)) ## [1] 4 56 57 87 91 95 plot(nc[w,1], col = 2:7) nc_geom[[4]][[2]][[1]][1:3,] ## [,1] [,2] ## [1,] -76.02717 36.55672 ## [2,] -75.99866 36.55665 ## [3,] -75.91192 36.54253 class(nc_geom) ## [1] \"sfc_MULTIPOLYGON\" \"sfc\" methods(class = 'sfc') ## [1] [ [<- ## [3] as.data.frame c ## [5] coerce format ## [7] identify initialize ## [9] Ops points ## [11] print rep ## [13] show slotsFromS3 ## [15] st_area st_as_binary ## [17] st_as_grob st_as_s2 ## [19] st_as_sf st_as_text ## [21] st_bbox st_boundary ## [23] st_break_antimeridian st_buffer ## [25] st_cast st_centroid ## [27] st_collection_extract st_concave_hull ## [29] st_convex_hull st_coordinates ## [31] st_crop st_crs ## [33] st_crs<- st_difference ## [35] st_exterior_ring st_geometry ## [37] st_inscribed_circle st_intersection ## [39] st_intersects st_is_full ## [41] st_is_valid st_is ## [43] st_line_merge st_m_range ## [45] st_make_valid st_minimum_rotated_rectangle ## [47] st_nearest_points st_node ## [49] st_normalize st_point_on_surface ## [51] st_polygonize st_precision ## [53] st_reverse st_sample ## [55] st_segmentize st_set_precision ## [57] st_shift_longitude st_simplify ## [59] st_snap st_sym_difference ## [61] st_transform st_triangulate_constrained ## [63] st_triangulate st_union ## [65] st_voronoi st_wrap_dateline ## [67] st_write st_z_range ## [69] st_zm str ## [71] summary text ## [73] vec_cast.sfc vec_ptype2.sfc ## see '?methods' for accessing help and source code attributes(nc_geom) ## $n_empty ## [1] 0 ## ## $crs ## Coordinate Reference System: ## User input: NAD27 ## wkt: ## GEOGCRS[\"NAD27\", ## DATUM[\"North American Datum 1927\", ## ELLIPSOID[\"Clarke 1866\",6378206.4,294.978698213898, ## LENGTHUNIT[\"metre\",1]]], ## PRIMEM[\"Greenwich\",0, ## ANGLEUNIT[\"degree\",0.0174532925199433]], ## CS[ellipsoidal,2], ## AXIS[\"latitude\",north, ## ORDER[1], ## ANGLEUNIT[\"degree\",0.0174532925199433]], ## AXIS[\"longitude\",east, ## ORDER[2], ## ANGLEUNIT[\"degree\",0.0174532925199433]], ## ID[\"EPSG\",4267]] ## ## $class ## [1] \"sfc_MULTIPOLYGON\" \"sfc\" ## ## $precision ## [1] 0 ## ## $bbox ## xmin ymin xmax ymax ## -84.32385 33.88199 -75.45698 36.58965"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"mixed-geometry-types","dir":"Articles","previous_headings":"How simple features in R are organized","what":"Mixed geometry types","title":"1. Simple Features for R","text":"class nc_geom c(\"sfc_MULTIPOLYGON\", \"sfc\"): sfc shared geometry types, sfc_TYPE TYPE indicating type particular geometry hand. two “special” types: GEOMETRYCOLLECTION, GEOMETRY. GEOMETRYCOLLECTION indicates geometries may contain mix geometry types, Still, geometries single type. second GEOMETRY, indicates geometries geometry list-column varying type: two fundamentally different: GEOMETRY superclass without instances, GEOMETRYCOLLECTION geometry instance. GEOMETRY list-columns occur read data source mix geometry types. GEOMETRYCOLLECTION single feature’s geometry: intersection two feature polygons may consist points, lines polygons, see example .","code":"(mix <- st_sfc(st_geometrycollection(list(st_point(1:2))), st_geometrycollection(list(st_linestring(matrix(1:4,2)))))) ## Geometry set for 2 features ## Geometry type: GEOMETRYCOLLECTION ## Dimension: XY ## Bounding box: xmin: 1 ymin: 2 xmax: 2 ymax: 4 ## CRS: NA ## GEOMETRYCOLLECTION (POINT (1 2)) ## GEOMETRYCOLLECTION (LINESTRING (1 3, 2 4)) class(mix) ## [1] \"sfc_GEOMETRYCOLLECTION\" \"sfc\" (mix <- st_sfc(st_point(1:2), st_linestring(matrix(1:4,2)))) ## Geometry set for 2 features ## Geometry type: GEOMETRY ## Dimension: XY ## Bounding box: xmin: 1 ymin: 2 xmax: 2 ymax: 4 ## CRS: NA ## POINT (1 2) ## LINESTRING (1 3, 2 4) class(mix) ## [1] \"sfc_GEOMETRY\" \"sfc\""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"sfg-simple-feature-geometry","dir":"Articles","previous_headings":"How simple features in R are organized","what":"sfg: simple feature geometry","title":"1. Simple Features for R","text":"Simple feature geometry (sfg) objects carry geometry single feature, e.g. point, linestring polygon. Simple feature geometries implemented R native data, using following rules single POINT numeric vector set points, e.g. LINESTRING ring POLYGON matrix, row containing point set list Creator functions rarely used practice, since typically bulk read write spatial data. useful illustration: means can represent 2-, 3- 4-dimensional coordinates. geometry objects inherit sfg (simple feature geometry), also type (e.g. POINT), dimension (e.g. XYM) class name. figure illustrates six seven common types. exception POINT single point geometry, remaining six common single simple feature geometry types correspond single features (single records, rows data.frame) created like objects created shown : Geometries can also empty, ","code":"(x <- st_point(c(1,2))) ## POINT (1 2) str(x) ## 'XY' num [1:2] 1 2 (x <- st_point(c(1,2,3))) ## POINT Z (1 2 3) str(x) ## 'XYZ' num [1:3] 1 2 3 (x <- st_point(c(1,2,3), \"XYM\")) ## POINT M (1 2 3) str(x) ## 'XYM' num [1:3] 1 2 3 (x <- st_point(c(1,2,3,4))) ## POINT ZM (1 2 3 4) str(x) ## 'XYZM' num [1:4] 1 2 3 4 st_zm(x, drop = TRUE, what = \"ZM\") ## POINT (1 2) p <- rbind(c(3.2,4), c(3,4.6), c(3.8,4.4), c(3.5,3.8), c(3.4,3.6), c(3.9,4.5)) (mp <- st_multipoint(p)) ## MULTIPOINT ((3.2 4), (3 4.6), (3.8 4.4), (3.5 3.8), (3.4 3.6), (3.9 4.5)) s1 <- rbind(c(0,3),c(0,4),c(1,5),c(2,5)) (ls <- st_linestring(s1)) ## LINESTRING (0 3, 0 4, 1 5, 2 5) s2 <- rbind(c(0.2,3), c(0.2,4), c(1,4.8), c(2,4.8)) s3 <- rbind(c(0,4.4), c(0.6,5)) (mls <- st_multilinestring(list(s1,s2,s3))) ## MULTILINESTRING ((0 3, 0 4, 1 5, 2 5), (0.2 3, 0.2 4, 1 4.8, 2 4.8), (0 4.4, 0.6 5)) p1 <- rbind(c(0,0), c(1,0), c(3,2), c(2,4), c(1,4), c(0,0)) p2 <- rbind(c(1,1), c(1,2), c(2,2), c(1,1)) pol <-st_polygon(list(p1,p2)) p3 <- rbind(c(3,0), c(4,0), c(4,1), c(3,1), c(3,0)) p4 <- rbind(c(3.3,0.3), c(3.8,0.3), c(3.8,0.8), c(3.3,0.8), c(3.3,0.3))[5:1,] p5 <- rbind(c(3,3), c(4,2), c(4,3), c(3,3)) (mpol <- st_multipolygon(list(list(p1,p2), list(p3,p4), list(p5)))) ## MULTIPOLYGON (((0 0, 1 0, 3 2, 2 4, 1 4, 0 0), (1 1, 1 2, 2 2, 1 1)), ((3 0, 4 0, 4 1, 3 1, 3 0), (3.3 0.3, 3.3 0.8, 3.8 0.8, 3.8 0.3, 3.3 0.3)), ((3 3, 4 2, 4 3, 3 3))) (gc <- st_geometrycollection(list(mp, mpol, ls))) ## GEOMETRYCOLLECTION (MULTIPOINT ((3.2 4), (3 4.6), (3.8 4.4), (3.5 3.8), (3.4 3.6), (3.9 4.5)), MULTIPOLYGON (((0 0, 1 0, 3 2, 2 4, 1 4, 0 0), (1 1, 1 2, 2 2, 1 1)), ((3 0, 4 0, 4 1, 3 1, 3 0), (3.3 0.3, 3.3 0.8, 3.8 0.8, 3.8 0.3, 3.3 0.3)), ((3 3, 4 2, 4 3, 3 3))), LINESTRING (0 3, 0 4, 1 5, 2 5)) (x <- st_geometrycollection()) ## GEOMETRYCOLLECTION EMPTY length(x) ## [1] 0"},{"path":[]},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"wkt-and-wkb","dir":"Articles","previous_headings":"How simple features in R are organized > Well-known text, well-known binary, precision","what":"WKT and WKB","title":"1. Simple Features for R","text":"Well-known text (WKT) well-known binary (WKB) two encodings simple feature geometries. Well-known text, e.g. seen (without leading ## [1] quotes), human-readable. Coordinates usually floating point numbers, moving large amounts information text slow imprecise. reason, use well-known binary (WKB) encoding WKT WKB can transformed back R native objects GDAL, GEOS, spatial databases GIS read write WKB fast precise. Conversion R native objects WKB done package sf compiled (C++/Rcpp) code, making reusable fast route /O simple feature geometries R.","code":"x <- st_linestring(matrix(10:1,5)) st_as_text(x) ## [1] \"LINESTRING (10 5, 9 4, 8 3, 7 2, 6 1)\" st_as_binary(x) ## [1] 01 02 00 00 00 05 00 00 00 00 00 00 00 00 00 24 40 00 00 00 00 00 00 14 40 ## [26] 00 00 00 00 00 00 22 40 00 00 00 00 00 00 10 40 00 00 00 00 00 00 20 40 00 ## [51] 00 00 00 00 00 08 40 00 00 00 00 00 00 1c 40 00 00 00 00 00 00 00 40 00 00 ## [76] 00 00 00 00 18 40 00 00 00 00 00 00 f0 3f st_as_sfc(\"LINESTRING(10 5, 9 4, 8 3, 7 2, 6 1)\")[[1]] ## LINESTRING (10 5, 9 4, 8 3, 7 2, 6 1) st_as_sfc(structure(list(st_as_binary(x)), class = \"WKB\"))[[1]] ## LINESTRING (10 5, 9 4, 8 3, 7 2, 6 1)"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"precision","dir":"Articles","previous_headings":"How simple features in R are organized > Well-known text, well-known binary, precision","what":"Precision","title":"1. Simple Features for R","text":"One attributes geometry list-column (sfc) precision: double number , non-zero, causes rounding conversion WKB, might help certain geometrical operations succeed otherwise fail due floating point representation. model GEOS, copies Java Topology Suite (JTS), works like : precision zero (default, unspecified), nothing modified negative values convert float (4-byte real) precision positive values convert round(x*precision)/precision. precision model, see also , written : “… specify 3 decimal places precision, use scale factor 1000. specify -3 decimal places precision (.e. rounding nearest 1000), use scale factor 0.001.” Note coordinates, also Z M values (present) affected. Choosing values precision may require experimenting.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"reading-and-writing","dir":"Articles","previous_headings":"How simple features in R are organized","what":"Reading and writing","title":"1. Simple Features for R","text":"’ve seen , reading spatial data external file can done : can suppress output adding argument quiet=TRUE using otherwise nearly identical quiet Writing takes place fashion, using st_write(): repeat , get error message file already exists, can overwrite : quiet alternative default,","code":"filename <- system.file(\"shape/nc.shp\", package=\"sf\") nc <- st_read(filename) ## Reading layer `nc' from data source ## `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' ## Simple feature collection with 100 features and 14 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 ## Geodetic CRS: NAD27 nc <- read_sf(filename) st_write(nc, \"nc.shp\") ## Writing layer `nc' to data source `nc.shp' using driver `ESRI Shapefile' ## Writing 100 features with 14 fields and geometry type Multi Polygon. st_write(nc, \"nc.shp\", delete_layer = TRUE) ## Deleting layer `nc' using driver `ESRI Shapefile' ## Writing layer `nc' to data source `nc.shp' using driver `ESRI Shapefile' ## Writing 100 features with 14 fields and geometry type Multi Polygon. write_sf(nc, \"nc.shp\") # silently overwrites"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"driver-specific-options","dir":"Articles","previous_headings":"How simple features in R are organized > Reading and writing","what":"Driver-specific options","title":"1. Simple Features for R","text":"dsn layer arguments st_read() st_write() denote data source name optionally layer name. exact interpretation well options support vary per driver, GDAL driver documentation best consulted . instance, PostGIS table database postgis might read : PG: string indicates concerns PostGIS driver, followed database name, possibly port user credentials. layer driver arguments specified, st_read() tries guess datasource, else simply reads first layer, giving warning case . st_read() typically reads coordinate reference system proj4string, EPSG (SRID). GDAL retrieve SRID (EPSG code) proj4string strings, , needed, set user. See also section coordinate reference systems. st_drivers() returns data.frame listing available drivers, metadata: names, whether driver can write, whether raster /vector driver. drivers can read. Reading common data formats illustrated : st_layers(dsn) lists layers present data source dsn, gives number fields, features geometry type layer: see case, number features NA xml file whole file needs read, may costly large files. can force counting : Another example reading kml kmz files :","code":"meuse <- st_read(\"PG:dbname=postgis\", \"meuse\") st_layers(system.file(\"osm/overpass.osm\", package=\"sf\")) Sys.setenv(OSM_USE_CUSTOM_INDEXING=\"NO\") st_layers(system.file(\"osm/overpass.osm\", package=\"sf\"), do_count = TRUE) # Download .shp data u_shp <- \"http://coagisweb.cabq.gov/datadownload/biketrails.zip\" download.file(u_shp, \"biketrails.zip\") unzip(\"biketrails.zip\") u_kmz <- \"http://coagisweb.cabq.gov/datadownload/BikePaths.kmz\" download.file(u_kmz, \"BikePaths.kmz\") # Read file formats biketrails_shp <- st_read(\"biketrails.shp\") if(Sys.info()[1] == \"Linux\") # may not work if not Linux biketrails_kmz <- st_read(\"BikePaths.kmz\") u_kml = \"http://www.northeastraces.com/oxonraces.com/nearme/safe/6.kml\" download.file(u_kml, \"bikeraces.kml\") bikraces <- st_read(\"bikeraces.kml\")"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"crud","dir":"Articles","previous_headings":"How simple features in R are organized > Reading and writing","what":"Create, read, update and delete","title":"1. Simple Features for R","text":"GDAL provides crud (create, read, update, delete) functions persistent storage. st_read() (read_sf()) used reading. st_write() (write_sf()) creates, following arguments control update delete: update=TRUE causes existing data source updated, exists; option default TRUE database drivers, database updated adding table. delete_layer=TRUE causes st_write try open data source delete layer; errors given data source present, layer exist data source. delete_dsn=TRUE causes st_write delete data source present, writing layer newly created data source. error given data source exist. option handled care, may wipe complete directories databases.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"connection-to-spatial-databases","dir":"Articles","previous_headings":"How simple features in R are organized > Reading and writing","what":"Connection to spatial databases","title":"1. Simple Features for R","text":"Read write functions, st_read() st_write(), can handle connections spatial databases read WKB WKT directly without using GDAL. Although intended use DBI interface, current use testing functions limited PostGIS.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"crs","dir":"Articles","previous_headings":"How simple features in R are organized","what":"Coordinate reference systems and transformations","title":"1. Simple Features for R","text":"Coordinate reference systems (CRS) like measurement units coordinates: specify location Earth particular coordinate pair refers . saw sfc objects (geometry list-columns) two attributes store CRS: epsg proj4string. implies geometries geometry list-column must CRS. may NA, e.g. case CRS unknown, work local coordinate systems (e.g. inside building, body, abstract space). proj4string generic, string-based description CRS, understood PROJ library. defines projection types (often) defines parameter values particular projections, hence can cover infinite amount different projections. library (also used GDAL) provides functions convert transform different CRS. epsg integer ID particular, known CRS can resolved proj4string. proj4string values can resolved back corresponding epsg ID, always work. importance epsg values stored data besides proj4string values epsg refers particular, well-known CRS, whose parameters may change (improve) time; fixing proj4string may remove possibility benefit improvements, limit provenance datasets, may help reproducibility. Coordinate reference system transformations can carried using st_transform(), e.g. converting longitudes/latitudes NAD27 web mercator (EPSG:3857) can done :","code":"nc.web_mercator <- st_transform(nc, 3857) st_geometry(nc.web_mercator)[[4]][[2]][[1]][1:3,] ## [,1] [,2] ## [1,] -8463267 4377519 ## [2,] -8460094 4377510 ## [3,] -8450437 4375553"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"conversion-including-to-and-from-sp","dir":"Articles","previous_headings":"How simple features in R are organized","what":"Conversion, including to and from sp","title":"1. Simple Features for R","text":"sf objects objects deriving Spatial (package sp) can coerced ways: Spatial* objects support MULTILINESTRING MULTIPOLYGON, LINESTRING POLYGON geometries automatically coerced MULTI form. converting Spatial* sf, geometries consist single POLYGON (possibly holes), POLYGON otherwise geometries returned MULTIPOLYGON: mix POLYGON MULTIPOLYGON (common shapefiles) created. Argument forceMulti=TRUE override , create MULTIPOLYGONs cases. LINES situation identical.","code":"showMethods(\"coerce\", classes = \"sf\") ## Function: coerce (package methods) ## from=\"sf\", to=\"Spatial\" ## from=\"Spatial\", to=\"sf\" methods(st_as_sf) ## [1] st_as_sf.data.frame* st_as_sf.lpp* st_as_sf.map* ## [4] st_as_sf.owin* st_as_sf.ppp* st_as_sf.ppplist* ## [7] st_as_sf.psp* st_as_sf.s2_geography* st_as_sf.sf* ## [10] st_as_sf.sfc* st_as_sf.Spatial* st_as_sf.SpatVector* ## see '?methods' for accessing help and source code methods(st_as_sfc) ## [1] st_as_sfc.bbox* st_as_sfc.blob* ## [3] st_as_sfc.character* st_as_sfc.dimensions* ## [5] st_as_sfc.factor* st_as_sfc.list* ## [7] st_as_sfc.map* st_as_sfc.owin* ## [9] st_as_sfc.pq_geometry* st_as_sfc.psp* ## [11] st_as_sfc.raw* st_as_sfc.s2_geography* ## [13] st_as_sfc.sf* st_as_sfc.SpatialLines* ## [15] st_as_sfc.SpatialMultiPoints* st_as_sfc.SpatialPixels* ## [17] st_as_sfc.SpatialPoints* st_as_sfc.SpatialPolygons* ## [19] st_as_sfc.tess* st_as_sfc.WKB* ## see '?methods' for accessing help and source code # anticipate that sp::CRS will expand proj4strings: p4s <- \"+proj=longlat +datum=NAD27 +no_defs +ellps=clrk66 +nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat\" st_crs(nc) <- p4s # anticipate geometry column name changes: names(nc)[15] = \"geometry\" attr(nc, \"sf_column\") = \"geometry\" nc.sp <- as(nc, \"Spatial\") class(nc.sp) ## [1] \"SpatialPolygonsDataFrame\" ## attr(,\"package\") ## [1] \"sp\" nc2 <- st_as_sf(nc.sp) all.equal(nc, nc2) ## [1] \"Attributes: < Component \\\"class\\\": Lengths (4, 2) differ (string compare on first 2) >\" ## [2] \"Attributes: < Component \\\"class\\\": 1 string mismatch >\" ## [3] \"Component \\\"geometry\\\": Attributes: < Component \\\"crs\\\": Component \\\"input\\\": 1 string mismatch >\" ## [4] \"Component \\\"geometry\\\": Attributes: < Component \\\"crs\\\": Component \\\"wkt\\\": 1 string mismatch >\""},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"geometrycollection","dir":"Articles","previous_headings":"How simple features in R are organized","what":"Geometrical operations","title":"1. Simple Features for R","text":"standard simple feature access defines number geometrical operations. st_is_valid() st_is_simple() return Boolean indicating whether geometry valid simple. st_distance() returns dense numeric matrix distances geometries. st_relate() returns character matrix DE9-IM values pair geometries: st_intersects(), st_disjoint(), st_touches(), st_crosses(), st_within(), st_contains(), st_overlaps(), st_equals(), st_covers(), st_covered_by(), st_equals_exact() st_is_within_distance() return sparse matrix (sgbp object) matching (TRUE) indexes, full logical matrix: st_buffer(), st_boundary(), st_convexhull(), st_union_cascaded, st_simplify, st_triangulate(), st_polygonize(), st_centroid(), st_segmentize(), st_union() return new geometries, e.g.: st_intersection(), st_union(), st_difference(), st_sym_difference() return new geometries function pairs geometries: following code shows computing intersection two polygons may yield GEOMETRYCOLLECTION point, line polygon:","code":"st_is_valid(nc[1:2,]) ## [1] TRUE TRUE x = st_transform(nc, 32119) st_distance(x[c(1,4,22),], x[c(1, 33,55,56),]) ## Units: [m] ## [,1] [,2] [,3] [,4] ## [1,] 0.00 312184.9 128341.85 475623.3 ## [2,] 440561.15 114939.7 590434.80 0.0 ## [3,] 18944.03 352719.1 78756.89 517527.8 st_relate(nc[1:5,], nc[1:4,]) ## although coordinates are longitude/latitude, st_relate assumes that they are ## planar ## [,1] [,2] [,3] [,4] ## [1,] \"2FFF1FFF2\" \"FF2F11212\" \"FF2FF1212\" \"FF2FF1212\" ## [2,] \"FF2F11212\" \"2FFF1FFF2\" \"FF2F11212\" \"FF2FF1212\" ## [3,] \"FF2FF1212\" \"FF2F11212\" \"2FFF1FFF2\" \"FF2FF1212\" ## [4,] \"FF2FF1212\" \"FF2FF1212\" \"FF2FF1212\" \"2FFF1FFF2\" ## [5,] \"FF2FF1212\" \"FF2FF1212\" \"FF2FF1212\" \"FF2FF1212\" st_intersects(nc[1:5,], nc[1:4,]) ## Sparse geometry binary predicate list of length 5, where the predicate ## was `intersects' ## 1: 1, 2 ## 2: 1, 2, 3 ## 3: 2, 3 ## 4: 4 ## 5: (empty) st_intersects(nc[1:5,], nc[1:4,], sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] TRUE TRUE FALSE FALSE ## [2,] TRUE TRUE TRUE FALSE ## [3,] FALSE TRUE TRUE FALSE ## [4,] FALSE FALSE FALSE TRUE ## [5,] FALSE FALSE FALSE FALSE sel <- c(1,5,14) geom = st_geometry(nc.web_mercator[sel,]) buf <- st_buffer(geom, dist = 30000) plot(buf, border = 'red') plot(geom, add = TRUE) plot(st_buffer(geom, -5000), add = TRUE, border = 'blue') par(mar = rep(0,4)) u <- st_union(nc) plot(u) opar <- par(mfrow = c(1, 2)) a <- st_polygon(list(cbind(c(0,0,7.5,7.5,0),c(0,-1,-1,0,0)))) b <- st_polygon(list(cbind(c(0,1,2,3,4,5,6,7,7,0),c(1,0,.5,0,0,0.5,-0.5,-0.5,1,1)))) plot(a, ylim = c(-1,1)) title(\"intersecting two polygons:\") plot(b, add = TRUE, border = 'red') (i <- st_intersection(a,b)) ## GEOMETRYCOLLECTION (POLYGON ((7 0, 7 -0.5, 6 -0.5, 5.5 0, 7 0)), LINESTRING (4 0, 3 0), POINT (1 0)) plot(a, ylim = c(-1,1)) title(\"GEOMETRYCOLLECTION\") plot(b, add = TRUE, border = 'red') plot(i, add = TRUE, col = 'green', lwd = 2) par(opar)"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"non-simple-and-non-valid-geometries","dir":"Articles","previous_headings":"How simple features in R are organized","what":"Non-simple and non-valid geometries","title":"1. Simple Features for R","text":"Non-simple geometries instance self-intersecting lines (left); non-valid geometries instance polygons slivers (middle) self-intersections (right).","code":"library(sf) x1 <- st_linestring(cbind(c(0,1,0,1),c(0,1,1,0))) x2 <- st_polygon(list(cbind(c(0,1,1,1,0,0),c(0,0,1,0.6,1,0)))) x3 <- st_polygon(list(cbind(c(0,1,0,1,0),c(0,1,1,0,0)))) st_is_simple(st_sfc(x1)) ## [1] FALSE st_is_valid(st_sfc(x2,x3)) ## [1] FALSE FALSE"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"units","dir":"Articles","previous_headings":"","what":"Units","title":"1. Simple Features for R","text":"possible geometric operations st_distance(), st_length() st_area() report results units attribute appropriate CRS: units package can used convert units: result can stripped attributes needs :","code":"a <- st_area(nc[1,]) attributes(a) ## $units ## $numerator ## [1] \"m\" \"m\" ## ## $denominator ## character(0) ## ## attr(,\"class\") ## [1] \"symbolic_units\" ## ## $class ## [1] \"units\" units::set_units(a, km^2) # result in square kilometers ## 1137.108 [km^2] units::set_units(a, ha) # result in hectares ## 113710.8 [ha] as.numeric(a) ## [1] 1137107793"},{"path":"https://r-spatial.github.io/sf/articles/sf1.html","id":"how-attributes-relate-to-geometries","dir":"Articles","previous_headings":"","what":"How attributes relate to geometries","title":"1. Simple Features for R","text":"(eventually topic new vignette; now explain last attribute sf objects) standard documents simple features detailed geometric aspects features, say nearly nothing attributes, except values understood another reference system (units measurement, e.g. implemented package units). . variables like air temperature, interpolation usually makes sense, others like human body temperature doesn’t. difference air temperature field, continues sensors, body temperature object property doesn’t extend beyond body – spatial statistics bodies called point pattern, temperature point marks. geometries non-zero size (positive length area), attribute values may refer every sub-geometry (every point), may summarize geometry. example, state’s population density summarizes whole state, meaningful estimate population density give point inside state without context state. hand, land use geological maps give polygons constant land use geology, every point inside polygon class. properties spatially extensive, meaning attributes summed two geometries merged: population example. properties spatially intensive, averaged, population density example. Simple feature objects class sf agr attribute points attribute-geometry-relationship, attributes relate geometry. can defined creation time: specified, field filled NA values, non-NA, one three possibilities: information (still done) can instance either return missing values generate warnings aggregate value point location inside polygon retrieved, list implicit assumptions made retrieving attribute values points inside polygon relation_to_geometry missing. decide attributes geometry split: nothing case attribute constant, give error warning case aggregate, change relation_to_geometry constant case identity. reading: S. Scheider, B. Gräler, E. Pebesma, C. Stasch, 2016. Modelling spatio-temporal information generation. Int J Geographic Information Science, 30 (10), 1980-2008. (open access) Stasch, C., S. Scheider, E. Pebesma, W. Kuhn, 2014. Meaningful Spatial Prediction Aggregation. Environmental Modelling & Software, 51, (149–165, open access).","code":"nc <- st_read(system.file(\"shape/nc.shp\", package=\"sf\"), agr = c(AREA = \"aggregate\", PERIMETER = \"aggregate\", CNTY_ = \"identity\", CNTY_ID = \"identity\", NAME = \"identity\", FIPS = \"identity\", FIPSNO = \"identity\", CRESS_ID = \"identity\", BIR74 = \"aggregate\", SID74 = \"aggregate\", NWBIR74 = \"aggregate\", BIR79 = \"aggregate\", SID79 = \"aggregate\", NWBIR79 = \"aggregate\")) ## Reading layer `nc' from data source ## `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' ## Simple feature collection with 100 features and 14 fields ## Attribute-geometry relationships: aggregate (8), identity (6) ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 ## Geodetic CRS: NAD27 st_agr(nc) ## AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID ## aggregate aggregate identity identity identity identity identity identity ## BIR74 SID74 NWBIR74 BIR79 SID79 NWBIR79 ## aggregate aggregate aggregate aggregate aggregate aggregate ## Levels: constant aggregate identity data(meuse, package = \"sp\") meuse_sf <- st_as_sf(meuse, coords = c(\"x\", \"y\"), crs = 28992, agr = \"constant\") st_agr(meuse_sf) ## cadmium copper lead zinc elev dist om ffreq ## constant constant constant constant constant constant constant constant ## soil lime landuse dist.m ## constant constant constant constant ## Levels: constant aggregate identity"},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"reading-and-writing-through-gdal","dir":"Articles","previous_headings":"","what":"Reading and writing through GDAL","title":"2. Reading, Writing and Converting Simple Features","text":"Geospatial Data Abstraction Library (GDAL) Swiss Army Knife spatial data: reads writes vector raster data practically every file format, database, significance. Package sf reads writes using GDAL using st_read() st_write(). data model GDAL uses needs data source, may file, directory, database layer, single geospatial dataset inside file directory e.g. table database. specification driver (.e., format) driver-specific reading writing data sources, layers may sound complex, needed map 200 data formats! Package sf tries hard simplify possible (e.g. file contains single layer), vignette try point options.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"using-st_read","dir":"Articles","previous_headings":"Reading and writing through GDAL","what":"Using st_read","title":"2. Reading, Writing and Converting Simple Features","text":"example, read North Carolina counties SIDS dataset, comes shipped sf package : Typical users use file name path fname, first set R’s working directory setwd() use file name without path. see single argument used find datasource layer. works datasource contains single layer. case number layers zero (e.g. database tables), error message given. case layers one, first layer returned, message warning given: message points st_layers() command, lists driver layers datasource, e.g. particular layer can now read e.g. st_layers() option count number features case missing: datasources (e.g. OSM xml files) report number features, need completely read . GDAL allows one geometry column feature layer; reported st_layers(). case layer contains geometries attributes (fields), st_read() still returns sf object, geometry column . see GDAL automatically detects driver (file format) datasource, trying turn. st_read() follows conventions base R, similar reads tabular data data.frames. means character data read, default factors. insist retrieving character data character vectors, argument stringsAsFactors can set FALSE: Alternatively, user can set global option stringsAsFactors, effect:","code":"library(sf) ## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE fname <- system.file(\"shape/nc.shp\", package=\"sf\") fname ## [1] \"/home/runner/work/_temp/Library/sf/shape/nc.shp\" nc <- st_read(fname) ## Reading layer `nc' from data source ## `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' ## Simple feature collection with 100 features and 14 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 ## Geodetic CRS: NAD27 > st_read(\"PG:dbname=postgis\") Multiple layers are present in data source PG:dbname=postgis, reading layer `meuse'. Use `st_layers' to list all layer names and their type in a data source. Set the `layer' argument in `st_read' to read a particular layer. Reading layer `meuse' from data source `PG:dbname=postgis' using driver `PostgreSQL' Simple feature collection with 155 features and 12 fields geometry type: POINT dimension: XY bbox: xmin: 178605 ymin: 329714 xmax: 181390 ymax: 333611 epsg (SRID): 28992 proj4string: +proj=sterea +lat_0=52.15616055555555 ... Warning message: In eval(substitute(expr), envir, enclos) : automatically selected the first layer in a data source containing more than one. > st_layers(\"PG:dbname=postgis\") Driver: PostgreSQL Available layers: layer_name geometry_type features fields 1 meuse Point 155 12 2 meuse_sf Point 155 12 3 sids Multi Polygon 100 14 4 meuse_tbl Point 155 13 5 meuse_tbl2 Point 155 13 > st_read(\"PG:dbname=postgis\", \"sids\") st_read(fname, stringsAsFactors = FALSE) options(stringsAsFactors = FALSE) st_read(fname) ## Reading layer `nc' from data source ## `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' ## Simple feature collection with 100 features and 14 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 ## Geodetic CRS: NAD27"},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"using-st_write","dir":"Articles","previous_headings":"Reading and writing through GDAL","what":"Using st_write","title":"2. Reading, Writing and Converting Simple Features","text":"write simple features object file, need least two arguments, object filename: file name taken data source name. default layer name basename (filename without path) data source name. , st_write() needs guess driver. command , instance, equivalent : guessing drivers works explained next section.","code":"st_write(nc, \"nc1.shp\") st_write(nc, dsn = \"nc1.shp\", layer = \"nc.shp\", driver = \"ESRI Shapefile\") ## Writing layer `nc' to data source `nc1.shp' using driver `ESRI Shapefile' ## Writing 100 features with 14 fields and geometry type Multi Polygon."},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"guessing-a-driver-for-output","dir":"Articles","previous_headings":"Reading and writing through GDAL","what":"Guessing a driver for output","title":"2. Reading, Writing and Converting Simple Features","text":"output driver guessed datasource name, either extension (.shp: ESRI Shapefile), prefix (PG:: PostgreSQL). list extensions corresponding driver (short driver name) : list prefixes :","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"dataset-and-layer-reading-or-creation-options","dir":"Articles","previous_headings":"Reading and writing through GDAL","what":"Dataset and layer reading or creation options","title":"2. Reading, Writing and Converting Simple Features","text":"Various GDAL drivers options influences reading writing process, example driver table already exists database: append records table overwrite : case table exists option specified, driver give error. Driver-specific options documented driver manual gdal. Multiple options can given multiple strings options. st_read(), options; st_write(), one needs distinguish dataset_options layer_options, first related opening dataset, second creating layers dataset.","code":"st_write(st_as_sf(meuse), \"PG:dbname=postgis\", \"meuse\", layer_options = \"OVERWRITE=true\")"},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"reading-and-writing-directly-to-and-from-spatial-databases","dir":"Articles","previous_headings":"","what":"Reading and writing directly to and from spatial databases","title":"2. Reading, Writing and Converting Simple Features","text":"Package sf supports reading writing spatial databases using DBI interface. far, testing mainly done PostGIS, databases might work may also need work. example reading : see second example query given. query may contain spatial predicates, way work massive spatial datasets R without read completely memory. Similarly, tables can written: , default table (layer) name taken object name (meuse). Argument drop informs drop (remove) table writing; logical argument binary determines whether use well-known binary well-known text writing geometry (well-known binary faster lossless).","code":"library(RPostgreSQL) conn = dbConnect(PostgreSQL(), dbname = \"postgis\") meuse = st_read(conn, \"meuse\") meuse_1_3 = st_read(conn, query = \"select * from meuse limit 3;\") dbDisconnect(conn) conn = dbConnect(PostgreSQL(), dbname = \"postgis\") st_write(conn, meuse, drop = TRUE) dbDisconnect(conn)"},{"path":[]},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"conversion-to-and-from-well-known-text","dir":"Articles","previous_headings":"Conversion to other formats: WKT, WKB, sp","what":"Conversion to and from well-known text","title":"2. Reading, Writing and Converting Simple Features","text":"usual form see simple features printed well-known text: can create well-known text strings explicitly using st_as_text: can convert back WKT using st_as_sfc():","code":"st_point(c(0,1)) ## POINT (0 1) st_linestring(matrix(0:9,ncol=2,byrow=TRUE)) ## LINESTRING (0 1, 2 3, 4 5, 6 7, 8 9) x = st_linestring(matrix(0:9,ncol=2,byrow=TRUE)) str = st_as_text(x) x ## LINESTRING (0 1, 2 3, 4 5, 6 7, 8 9) st_as_sfc(str) ## Geometry set for 1 feature ## Geometry type: LINESTRING ## Dimension: XY ## Bounding box: xmin: 0 ymin: 1 xmax: 8 ymax: 9 ## CRS: NA ## LINESTRING (0 1, 2 3, 4 5, 6 7, 8 9)"},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"conversion-to-and-from-well-known-binary","dir":"Articles","previous_headings":"Conversion to other formats: WKT, WKB, sp","what":"Conversion to and from well-known binary","title":"2. Reading, Writing and Converting Simple Features","text":"Well-known binary created simple features st_as_binary(): object returned st_as_binary() class WKB either list raw vectors, single raw vector. can converted hexadecimal character vector using rawToHex(): Converting back sf uses st_as_sfc():","code":"x = st_linestring(matrix(0:9,ncol=2,byrow=TRUE)) (x = st_as_binary(x)) ## [1] 01 02 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f0 3f ## [26] 00 00 00 00 00 00 00 40 00 00 00 00 00 00 08 40 00 00 00 00 00 00 10 40 00 ## [51] 00 00 00 00 00 14 40 00 00 00 00 00 00 18 40 00 00 00 00 00 00 1c 40 00 00 ## [76] 00 00 00 00 20 40 00 00 00 00 00 00 22 40 class(x) ## [1] \"raw\" rawToHex(x) ## [1] \"0102000000050000000000000000000000000000000000f03f000000000000004000000000000008400000000000001040000000000000144000000000000018400000000000001c4000000000000020400000000000002240\" x = st_as_binary(st_sfc(st_point(0:1), st_point(5:6))) st_as_sfc(x) ## Geometry set for 2 features ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 0 ymin: 1 xmax: 5 ymax: 6 ## CRS: NA ## POINT (0 1) ## POINT (5 6)"},{"path":"https://r-spatial.github.io/sf/articles/sf2.html","id":"conversion-to-and-from-sp","dir":"Articles","previous_headings":"Conversion to other formats: WKT, WKB, sp","what":"Conversion to and from sp","title":"2. Reading, Writing and Converting Simple Features","text":"Spatial objects maintained package sp can converted simple feature objects geometries st_as_sf() st_as_sfc(), respectively: example : Conversion simple feature objects class sf sfc corresponding Spatial* objects done using method, coercing Spatial:","code":"methods(st_as_sf) ## [1] st_as_sf.data.frame* st_as_sf.lpp* st_as_sf.map* ## [4] st_as_sf.owin* st_as_sf.ppp* st_as_sf.ppplist* ## [7] st_as_sf.psp* st_as_sf.s2_geography* st_as_sf.sf* ## [10] st_as_sf.sfc* st_as_sf.Spatial* st_as_sf.SpatVector* ## see '?methods' for accessing help and source code methods(st_as_sfc) ## [1] st_as_sfc.bbox* st_as_sfc.blob* ## [3] st_as_sfc.character* st_as_sfc.dimensions* ## [5] st_as_sfc.factor* st_as_sfc.list* ## [7] st_as_sfc.map* st_as_sfc.owin* ## [9] st_as_sfc.pq_geometry* st_as_sfc.psp* ## [11] st_as_sfc.raw* st_as_sfc.s2_geography* ## [13] st_as_sfc.sf* st_as_sfc.SpatialLines* ## [15] st_as_sfc.SpatialMultiPoints* st_as_sfc.SpatialPixels* ## [17] st_as_sfc.SpatialPoints* st_as_sfc.SpatialPolygons* ## [19] st_as_sfc.tess* st_as_sfc.WKB* ## see '?methods' for accessing help and source code library(sp) data(meuse) coordinates(meuse) = ~x+y m.sf = st_as_sf(meuse) opar = par(mar=rep(0,4)) plot(m.sf) ## Warning: plotting the first 10 out of 12 attributes; use max.plot = 12 to plot ## all x = st_sfc(st_point(c(5,5)), st_point(c(6,9)), crs = 4326) as(x, \"Spatial\") ## SpatialPoints: ## coords.x1 coords.x2 ## [1,] 5 5 ## [2,] 6 9 ## Coordinate Reference System (CRS) arguments: +proj=longlat +datum=WGS84 ## +no_defs"},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"type-transformations","dir":"Articles","previous_headings":"","what":"Type transformations","title":"3. Manipulating Simple Feature Geometries","text":"sections discusses simple feature geometries one type can converted another. converting lines polygons, see also st_polygonize() .","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"for-single-geometries","dir":"Articles","previous_headings":"Type transformations","what":"For single geometries","title":"3. Manipulating Simple Feature Geometries","text":"single geometries, st_cast() convert XX MULTIXX, e.g. LINESTRING MULTILINESTRING convert MULTIXX XX MULTIXX length one (else, still convert warn loss information) convert MULTIXX XX MULTIXX length one, warn loss information convert GEOMETRYCOLLECTION length one component Examples first three types : Examples fourth type :","code":"library(sf) ## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE suppressPackageStartupMessages(library(dplyr)) st_point(c(1,1)) %>% st_cast(\"MULTIPOINT\") ## MULTIPOINT ((1 1)) st_multipoint(rbind(c(1,1))) %>% st_cast(\"POINT\") ## Warning in st_cast.MULTIPOINT(., \"POINT\"): point from first coordinate only ## POINT (1 1) st_multipoint(rbind(c(1,1),c(2,2))) %>% st_cast(\"POINT\") ## Warning in st_cast.MULTIPOINT(., \"POINT\"): point from first coordinate only ## POINT (1 1) st_geometrycollection(list(st_point(c(1,1)))) %>% st_cast(\"POINT\") ## POINT (1 1)"},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"for-collections-of-geometry-sfc-and-simple-feature-collections-sf","dir":"Articles","previous_headings":"Type transformations","what":"For collections of geometry (sfc) and simple feature collections (sf)","title":"3. Manipulating Simple Feature Geometries","text":"noted reading geometries using st_read(), type argument can used control class returned geometry: option handled GDAL library; case failure convert target type, original types returned, case mix POLYGON MULTIPOLYGON geometries, leading GEOMETRY superclass. try read multipolygons polygons, secondary rings multipolygons get lost. functions return objects mixed geometry type (GEOMETRY), downstream functions st_write() may difficulty handling . cases, st_cast() may help modify type. sets geometry objects (sfc) simple feature sets (sf),st_cast` can used specifying target type, without specifying . target type given, st_cast() tries smart two cases: class object GEOMETRY, elements identical type, elements length-one GEOMETRYCOLLECTION objects, case GEOMETRYCOLLECTION objects replaced content (may GEOMETRY mix ) Examples :","code":"shp = system.file(\"shape/nc.shp\", package=\"sf\") class(st_geometry(st_read(shp, quiet = TRUE))) ## [1] \"sfc_MULTIPOLYGON\" \"sfc\" class(st_geometry(st_read(shp, quiet = TRUE, type = 3))) ## [1] \"sfc_POLYGON\" \"sfc\" class(st_geometry(st_read(shp, quiet = TRUE, type = 1))) ## [1] \"sfc_GEOMETRY\" \"sfc\" ls <- st_linestring(rbind(c(0,0),c(1,1),c(2,1))) mls <- st_multilinestring(list(rbind(c(2,2),c(1,3)), rbind(c(0,0),c(1,1),c(2,1)))) (sfc <- st_sfc(ls,mls)) ## Geometry set for 2 features ## Geometry type: GEOMETRY ## Dimension: XY ## Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 3 ## CRS: NA ## LINESTRING (0 0, 1 1, 2 1) ## MULTILINESTRING ((2 2, 1 3), (0 0, 1 1, 2 1)) st_cast(sfc, \"MULTILINESTRING\") ## Geometry set for 2 features ## Geometry type: MULTILINESTRING ## Dimension: XY ## Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 3 ## CRS: NA ## MULTILINESTRING ((0 0, 1 1, 2 1)) ## MULTILINESTRING ((2 2, 1 3), (0 0, 1 1, 2 1)) sf <- st_sf(a = 5:4, geom = sfc) st_cast(sf, \"MULTILINESTRING\") ## Simple feature collection with 2 features and 1 field ## Geometry type: MULTILINESTRING ## Dimension: XY ## Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 3 ## CRS: NA ## a geom ## 1 5 MULTILINESTRING ((0 0, 1 1,... ## 2 4 MULTILINESTRING ((2 2, 1 3)... ls <- st_linestring(rbind(c(0,0),c(1,1),c(2,1))) mls1 <- st_multilinestring(list(rbind(c(2,2),c(1,3)), rbind(c(0,0),c(1,1),c(2,1)))) mls2 <- st_multilinestring(list(rbind(c(4,4),c(4,3)), rbind(c(2,2),c(2,1),c(3,1)))) (sfc <- st_sfc(ls,mls1,mls2)) ## Geometry set for 3 features ## Geometry type: GEOMETRY ## Dimension: XY ## Bounding box: xmin: 0 ymin: 0 xmax: 4 ymax: 4 ## CRS: NA ## LINESTRING (0 0, 1 1, 2 1) ## MULTILINESTRING ((2 2, 1 3), (0 0, 1 1, 2 1)) ## MULTILINESTRING ((4 4, 4 3), (2 2, 2 1, 3 1)) class(sfc[2:3]) ## [1] \"sfc_MULTILINESTRING\" \"sfc\" class(st_cast(sfc[2:3])) ## [1] \"sfc_MULTILINESTRING\" \"sfc\" gc1 <- st_geometrycollection(list(st_linestring(rbind(c(0,0),c(1,1),c(2,1))))) gc2 <- st_geometrycollection(list(st_multilinestring(list(rbind(c(2,2),c(1,3)), rbind(c(0,0),c(1,1),c(2,1)))))) gc3 <- st_geometrycollection(list(st_multilinestring(list(rbind(c(4,4),c(4,3)), rbind(c(2,2),c(2,1),c(3,1)))))) (sfc <- st_sfc(gc1,gc2,gc3)) ## Geometry set for 3 features ## Geometry type: GEOMETRYCOLLECTION ## Dimension: XY ## Bounding box: xmin: 0 ymin: 0 xmax: 4 ymax: 4 ## CRS: NA ## GEOMETRYCOLLECTION (LINESTRING (0 0, 1 1, 2 1)) ## GEOMETRYCOLLECTION (MULTILINESTRING ((2 2, 1 3)... ## GEOMETRYCOLLECTION (MULTILINESTRING ((4 4, 4 3)... class(st_cast(sfc)) ## [1] \"sfc_GEOMETRY\" \"sfc\" class(st_cast(st_cast(sfc), \"MULTILINESTRING\")) ## [1] \"sfc_MULTILINESTRING\" \"sfc\""},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"affine-transformations","dir":"Articles","previous_headings":"","what":"Affine transformations","title":"3. Manipulating Simple Feature Geometries","text":"Affine transformations transformations type f(x)=xA+bf(x) = xA + b, matrix AA used flatten, scale /rotate, bb translate xx. Low-level examples : Just make point, can instance rotate counties North Carolina 90 degrees clockwise around centroid, shrink 75% original size:","code":"(p = st_point(c(0,2))) ## POINT (0 2) p + 1 ## POINT (1 3) p + c(1,2) ## POINT (1 4) p + p ## POINT (0 4) p * p ## POINT (0 4) rot = function(a) matrix(c(cos(a), sin(a), -sin(a), cos(a)), 2, 2) p * rot(pi/4) ## POINT (1.414214 1.414214) p * rot(pi/2) ## POINT (2 1.224647e-16) p * rot(pi) ## POINT (2.449294e-16 -2) nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\"), quiet = TRUE) ncg = st_geometry(nc) plot(ncg, border = 'grey') cntrd = st_centroid(ncg) ncg2 = (ncg - cntrd) * rot(pi/2) * .75 + cntrd plot(ncg2, add = TRUE) plot(cntrd, col = 'red', add = TRUE, cex = .5)"},{"path":[]},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"getting-and-setting-coordinate-reference-systems-of-sf-objects","dir":"Articles","previous_headings":"Coordinate reference systems conversion and transformation","what":"Getting and setting coordinate reference systems of sf objects","title":"3. Manipulating Simple Feature Geometries","text":"coordinate reference system objects class sf sfc obtained st_crs(), replaced st_crs<-: alternative, pipe-friendly version st_crs<- ","code":"library(sf) geom = st_sfc(st_point(c(0,1)), st_point(c(11,12))) s = st_sf(a = 15:16, geometry = geom) st_crs(s) ## Coordinate Reference System: NA s1 = s st_crs(s1) <- 4326 st_crs(s1) ## Coordinate Reference System: ## User input: EPSG:4326 ## wkt: ## GEOGCRS[\"WGS 84\", ## ENSEMBLE[\"World Geodetic System 1984 ensemble\", ## MEMBER[\"World Geodetic System 1984 (Transit)\"], ## MEMBER[\"World Geodetic System 1984 (G730)\"], ## MEMBER[\"World Geodetic System 1984 (G873)\"], ## MEMBER[\"World Geodetic System 1984 (G1150)\"], ## MEMBER[\"World Geodetic System 1984 (G1674)\"], ## MEMBER[\"World Geodetic System 1984 (G1762)\"], ## MEMBER[\"World Geodetic System 1984 (G2139)\"], ## ELLIPSOID[\"WGS 84\",6378137,298.257223563, ## LENGTHUNIT[\"metre\",1]], ## ENSEMBLEACCURACY[2.0]], ## PRIMEM[\"Greenwich\",0, ## ANGLEUNIT[\"degree\",0.0174532925199433]], ## CS[ellipsoidal,2], ## AXIS[\"geodetic latitude (Lat)\",north, ## ORDER[1], ## ANGLEUNIT[\"degree\",0.0174532925199433]], ## AXIS[\"geodetic longitude (Lon)\",east, ## ORDER[2], ## ANGLEUNIT[\"degree\",0.0174532925199433]], ## USAGE[ ## SCOPE[\"Horizontal component of 3D system.\"], ## AREA[\"World.\"], ## BBOX[-90,-180,90,180]], ## ID[\"EPSG\",4326]] s2 = s st_crs(s2) <- \"+proj=longlat +datum=WGS84\" all.equal(s1, s2) ## [1] \"Component \\\"geometry\\\": Attributes: < Component \\\"crs\\\": Component \\\"input\\\": 1 string mismatch >\" ## [2] \"Component \\\"geometry\\\": Attributes: < Component \\\"crs\\\": Component \\\"wkt\\\": 1 string mismatch >\" s1 %>% st_set_crs(4326) ## Simple feature collection with 2 features and 1 field ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 0 ymin: 1 xmax: 11 ymax: 12 ## Geodetic CRS: WGS 84 ## a geometry ## 1 15 POINT (0 1) ## 2 16 POINT (11 12)"},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"coordinate-reference-system-transformations","dir":"Articles","previous_headings":"Coordinate reference systems conversion and transformation","what":"Coordinate reference system transformations","title":"3. Manipulating Simple Feature Geometries","text":"change coordinate reference system one non-missing value another non-missing value, CRS changed without modifying coordinates, warning issued reproject values: cleaner way better expresses intention generate warning first wipe CRS assigning missing value, set intended value. carry coordinate conversion transformation, use st_transform() see coordinates actually modified (projected).","code":"s3 <- s1 %>% st_set_crs(4326) %>% st_set_crs(3857) ## Warning: st_crs<- : replacing crs does not reproject data; use st_transform for ## that s3 <- s1 %>% st_set_crs(NA) %>% st_set_crs(3857) s3 <- s1 %>% st_transform(3857) s3 ## Simple feature collection with 2 features and 1 field ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 0 ymin: 111325.1 xmax: 1224514 ymax: 1345708 ## Projected CRS: WGS 84 / Pseudo-Mercator ## a geometry ## 1 15 POINT (0 111325.1) ## 2 16 POINT (1224514 1345708)"},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"geometrical-operations","dir":"Articles","previous_headings":"","what":"Geometrical operations","title":"3. Manipulating Simple Feature Geometries","text":"geometrical operations st_op(x) st_op2(x,y) work sf objects sfc objects x y; since operations work geometries, non-geometry parts sf object simply discarded. Also, binary operations st_op2(x,y) called single argument, st_op2(x), handled st_op2(x,x). illustrate geometrical operations simple dataset:","code":"b0 = st_polygon(list(rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1)))) b1 = b0 + 2 b2 = b0 + c(-0.2, 2) x = st_sfc(b0, b1, b2) a0 = b0 * 0.8 a1 = a0 * 0.5 + c(2, 0.7) a2 = a0 + 1 a3 = b0 * 0.5 + c(2, -0.5) y = st_sfc(a0,a1,a2,a3) plot(x, border = 'red') plot(y, border = 'green', add = TRUE)"},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"unary-operations","dir":"Articles","previous_headings":"Geometrical operations","what":"Unary operations","title":"3. Manipulating Simple Feature Geometries","text":"st_is_valid() returns whether polygon geometries topologically valid: st_is_simple() whether line geometries simple: st_area() returns area polygon geometries, st_length() length line geometries:","code":"b0 = st_polygon(list(rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1)))) b1 = st_polygon(list(rbind(c(-1,-1), c(1,-1), c(1,1), c(0,-1), c(-1,-1)))) st_is_valid(st_sfc(b0,b1)) ## [1] TRUE FALSE s = st_sfc(st_linestring(rbind(c(0,0), c(1,1))), st_linestring(rbind(c(0,0), c(1,1),c(0,1),c(1,0)))) st_is_simple(s) ## [1] TRUE FALSE st_area(x) ## [1] 4 4 4 st_area(st_sfc(st_point(c(0,0)))) ## [1] 0 st_length(st_sfc(st_linestring(rbind(c(0,0),c(1,1),c(1,2))), st_linestring(rbind(c(0,0),c(1,0))))) ## [1] 2.414214 1.000000 st_length(st_sfc(st_multilinestring(list(rbind(c(0,0),c(1,1),c(1,2))),rbind(c(0,0),c(1,0))))) # ignores 2nd part! ## [1] 2.414214"},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"binary-operations-distance-and-relate","dir":"Articles","previous_headings":"Geometrical operations","what":"Binary operations: distance and relate","title":"3. Manipulating Simple Feature Geometries","text":"st_distance() computes shortest distance matrix geometries; dense matrix: st_relate() returns dense character matrix DE9-IM relationships pair geometries: element [,j] matrix nine characters, referring relationship x[] y[j], encoded IxIy,IxBy,IxEy,BxIy,BxBy,BxEy,ExIy,ExBy,ExEyI_xI_y,I_xB_y,I_xE_y,B_xI_y,B_xB_y,B_xE_y,E_xI_y,E_xB_y,E_xE_y II refers interior, BB boundary, EE exterior, e.g. BxIyB_xI_y dimensionality intersection boundary BxB_x x[] interior IyI_y y[j], one {0,1,2,F}, indicating zero-, one-, two-dimension intersection, (F) intersection, respectively.","code":"st_distance(x,y) ## [,1] [,2] [,3] [,4] ## [1,] 0.0000000 0.6 0 0.500000 ## [2,] 0.2828427 0.0 0 1.000000 ## [3,] 0.2000000 0.8 0 1.220656 st_relate(x,y) ## [,1] [,2] [,3] [,4] ## [1,] \"212FF1FF2\" \"FF2FF1212\" \"212101212\" \"FF2FF1212\" ## [2,] \"FF2FF1212\" \"212101212\" \"212101212\" \"FF2FF1212\" ## [3,] \"FF2FF1212\" \"FF2FF1212\" \"212101212\" \"FF2FF1212\""},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"binary-logical-operations","dir":"Articles","previous_headings":"Geometrical operations","what":"Binary logical operations:","title":"3. Manipulating Simple Feature Geometries","text":"Binary logical operations return either sparse matrix dense matrix list element sparse matrix contains indices TRUE elements row dense matrix. large geometry sets, dense matrices take lot memory mostly filled FALSE values, hence default return sparse matrix. st_intersects() returns every geometry pair whether intersect (dense matrix), elements intersect (sparse). Note st_intersection() package returns geometry intersection instead logicals st_intersects() (see next section vignette). binary predicates include (using sparse readability):","code":"st_intersects(x,y) ## Sparse geometry binary predicate list of length 3, where the predicate ## was `intersects' ## 1: 1, 3 ## 2: 2, 3 ## 3: 3 st_intersects(x, x, sparse = FALSE) ## [,1] [,2] [,3] ## [1,] TRUE TRUE TRUE ## [2,] TRUE TRUE FALSE ## [3,] TRUE FALSE TRUE st_intersects(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] TRUE FALSE TRUE FALSE ## [2,] FALSE TRUE TRUE FALSE ## [3,] FALSE FALSE TRUE FALSE st_disjoint(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] FALSE TRUE FALSE TRUE ## [2,] TRUE FALSE FALSE TRUE ## [3,] TRUE TRUE FALSE TRUE st_touches(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] FALSE FALSE FALSE FALSE ## [2,] FALSE FALSE FALSE FALSE ## [3,] FALSE FALSE FALSE FALSE st_crosses(s, s, sparse = FALSE) ## [,1] [,2] ## [1,] FALSE FALSE ## [2,] FALSE FALSE st_within(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] FALSE FALSE FALSE FALSE ## [2,] FALSE FALSE FALSE FALSE ## [3,] FALSE FALSE FALSE FALSE st_contains(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] TRUE FALSE FALSE FALSE ## [2,] FALSE FALSE FALSE FALSE ## [3,] FALSE FALSE FALSE FALSE st_overlaps(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] FALSE FALSE TRUE FALSE ## [2,] FALSE TRUE TRUE FALSE ## [3,] FALSE FALSE TRUE FALSE st_equals(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] FALSE FALSE FALSE FALSE ## [2,] FALSE FALSE FALSE FALSE ## [3,] FALSE FALSE FALSE FALSE st_covers(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] TRUE FALSE FALSE FALSE ## [2,] FALSE FALSE FALSE FALSE ## [3,] FALSE FALSE FALSE FALSE st_covered_by(x, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] FALSE FALSE FALSE FALSE ## [2,] FALSE FALSE FALSE FALSE ## [3,] FALSE FALSE FALSE FALSE st_covered_by(y, y, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] TRUE FALSE FALSE FALSE ## [2,] FALSE TRUE FALSE FALSE ## [3,] FALSE FALSE TRUE FALSE ## [4,] FALSE FALSE FALSE TRUE st_equals_exact(x, y,0.001, sparse = FALSE) ## [,1] [,2] [,3] [,4] ## [1,] FALSE FALSE FALSE FALSE ## [2,] FALSE FALSE FALSE FALSE ## [3,] FALSE FALSE FALSE FALSE"},{"path":"https://r-spatial.github.io/sf/articles/sf3.html","id":"operations-returning-a-geometry","dir":"Articles","previous_headings":"Geometrical operations","what":"Operations returning a geometry","title":"3. Manipulating Simple Feature Geometries","text":"intersection two geometries geometry covered ; obtained st_intersection(): Note st_intersects() returns logical matrix indicating whether geometry pair intersects (see previous section vignette). get everything intersection, use st_difference() st_sym_difference(): st_segmentize() adds points straight line sections lines polygon object: st_polygonize() polygonizes multilinestring, long points form closed polygon:","code":"u = st_union(x) plot(u) par(mfrow=c(1,2), mar = rep(0,4)) plot(st_buffer(u, 0.2)) plot(u, border = 'red', add = TRUE) plot(st_buffer(u, 0.2), border = 'grey') plot(u, border = 'red', add = TRUE) plot(st_buffer(u, -0.2), add = TRUE) plot(st_boundary(x)) par(mfrow = c(1:2)) plot(st_convex_hull(x)) plot(st_convex_hull(u)) par(mfrow = c(1,1)) par(mfrow=c(1,2)) plot(x) plot(st_centroid(x), add = TRUE, col = 'red') plot(x) plot(st_centroid(u), add = TRUE, col = 'red') plot(x) plot(y, add = TRUE) plot(st_intersection(st_union(x),st_union(y)), add = TRUE, col = 'red') par(mfrow=c(2,2), mar = c(0,0,1,0)) plot(x, col = '#ff333388'); plot(y, add=TRUE, col='#33ff3388') title(\"x: red, y: green\") plot(x, border = 'grey') plot(st_difference(st_union(x),st_union(y)), col = 'lightblue', add = TRUE) title(\"difference(x,y)\") plot(x, border = 'grey') plot(st_difference(st_union(y),st_union(x)), col = 'lightblue', add = TRUE) title(\"difference(y,x)\") plot(x, border = 'grey') plot(st_sym_difference(st_union(y),st_union(x)), col = 'lightblue', add = TRUE) title(\"sym_difference(x,y)\") par(mfrow=c(1,3),mar=c(1,1,0,0)) pts = rbind(c(0,0),c(1,0),c(2,1),c(3,1)) ls = st_linestring(pts) plot(ls) points(pts) ls.seg = st_segmentize(ls, 0.3) plot(ls.seg) pts = ls.seg points(pts) pol = st_polygon(list(rbind(c(0,0),c(1,0),c(1,1),c(0,1),c(0,0)))) pol.seg = st_segmentize(pol, 0.3) plot(pol.seg, col = 'grey') points(pol.seg[[1]]) par(mfrow=c(1,2),mar=c(0,0,1,0)) mls = st_multilinestring(list(matrix(c(0,0,0,1,1,1,0,0),,2,byrow=TRUE))) x = st_polygonize(mls) plot(mls, col = 'grey') title(\"multilinestring\") plot(x, col = 'grey') title(\"polygon\")"},{"path":"https://r-spatial.github.io/sf/articles/sf4.html","id":"subsetting-feature-sets","dir":"Articles","previous_headings":"","what":"Subsetting feature sets","title":"4. Manipulating Simple Features","text":"can subset feature sets using square bracket notation use drop argument drop geometries: can also use spatial object row selector, select features intersect another spatial feature: see result set Ashe included, default value argument op [.sf st_intersects(), Ashe intersects . exclude self-intersection using predicate st_touches() (overlapping features don’t touch): Using dplyr, can calling predicate directly:","code":"nc[1, \"NWBIR74\"] ## Simple feature collection with 1 feature and 1 field ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: 1193283 ymin: 913341.9 xmax: 1340555 ymax: 1044158 ## Projected CRS: NAD83 / North Carolina (ftUS) ## NWBIR74 geometry ## 1 10 MULTIPOLYGON (((1270814 913... nc[1, \"NWBIR74\", drop = TRUE] ## [1] 10 ## attr(,\"class\") ## [1] \"numeric\" Ashe = nc[nc$NAME == \"Ashe\",] class(Ashe) ## [1] \"sf\" \"data.frame\" nc[Ashe,] ## Simple feature collection with 4 features and 14 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: 1142157 ymin: 823092 xmax: 1448920 ymax: 1044158 ## Projected CRS: NAD83 / North Carolina (ftUS) ## AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 ## 1 0.114 1.442 1825 1825 Ashe 37009 37009 5 1091 1 ## 2 0.061 1.231 1827 1827 Alleghany 37005 37005 3 487 0 ## 18 0.199 1.984 1874 1874 Wilkes 37193 37193 97 3146 4 ## 19 0.081 1.288 1880 1880 Watauga 37189 37189 95 1323 1 ## NWBIR74 BIR79 SID79 NWBIR79 geometry ## 1 10 1364 0 19 MULTIPOLYGON (((1270814 913... ## 2 10 542 3 12 MULTIPOLYGON (((1340555 959... ## 18 200 3725 7 222 MULTIPOLYGON (((1402677 837... ## 19 17 1775 1 33 MULTIPOLYGON (((1171158 868... Ashe = nc[nc$NAME == \"Ashe\",] nc[Ashe, op = st_touches] ## Simple feature collection with 3 features and 14 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: 1142157 ymin: 823092 xmax: 1448920 ymax: 1035641 ## Projected CRS: NAD83 / North Carolina (ftUS) ## AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 ## 2 0.061 1.231 1827 1827 Alleghany 37005 37005 3 487 0 ## 18 0.199 1.984 1874 1874 Wilkes 37193 37193 97 3146 4 ## 19 0.081 1.288 1880 1880 Watauga 37189 37189 95 1323 1 ## NWBIR74 BIR79 SID79 NWBIR79 geometry ## 2 10 542 3 12 MULTIPOLYGON (((1340555 959... ## 18 200 3725 7 222 MULTIPOLYGON (((1402677 837... ## 19 17 1775 1 33 MULTIPOLYGON (((1171158 868... nc %>% filter(lengths(st_touches(., Ashe)) > 0) ## Simple feature collection with 3 features and 14 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: 1142157 ymin: 823092 xmax: 1448920 ymax: 1035641 ## Projected CRS: NAD83 / North Carolina (ftUS) ## AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 ## 1 0.061 1.231 1827 1827 Alleghany 37005 37005 3 487 0 ## 2 0.199 1.984 1874 1874 Wilkes 37193 37193 97 3146 4 ## 3 0.081 1.288 1880 1880 Watauga 37189 37189 95 1323 1 ## NWBIR74 BIR79 SID79 NWBIR79 geometry ## 1 10 542 3 12 MULTIPOLYGON (((1340555 959... ## 2 200 3725 7 222 MULTIPOLYGON (((1402677 837... ## 3 17 1775 1 33 MULTIPOLYGON (((1171158 868..."},{"path":"https://r-spatial.github.io/sf/articles/sf4.html","id":"aggregating-or-summarizing-feature-sets","dir":"Articles","previous_headings":"","what":"Aggregating or summarizing feature sets","title":"4. Manipulating Simple Features","text":"Suppose want compare 1974 fraction SID (sudden infant death) counties intersect Ashe remaining ones. can :","code":"a <- aggregate(nc[, c(\"SID74\", \"BIR74\")], list(Ashe_nb = lengths(st_intersects(nc, Ashe)) > 0), sum) (a <- a %>% mutate(frac74 = SID74 / BIR74) %>% select(frac74)) ## Simple feature collection with 2 features and 1 field ## Geometry type: GEOMETRY ## Dimension: XY ## Bounding box: xmin: 406262.2 ymin: 48374.87 xmax: 3052887 ymax: 1044158 ## Projected CRS: NAD83 / North Carolina (ftUS) ## frac74 geometry ## 1 0.0020406588 MULTIPOLYGON (((454152.6 58... ## 2 0.0009922276 POLYGON ((1372054 837052.3,... plot(a[2], col = c(grey(.8), grey(.5))) plot(st_geometry(Ashe), border = '#ff8888', add = TRUE, lwd = 2)"},{"path":"https://r-spatial.github.io/sf/articles/sf4.html","id":"joining-two-feature-sets-based-on-attributes","dir":"Articles","previous_headings":"","what":"Joining two feature sets based on attributes","title":"4. Manipulating Simple Features","text":"usual join verbs base R (merge) dplyr (left_join(), etc) work sf objects well; joining takes place attributes (ignoring geometries). case matching geometry, empty geometry substituted. second argument data.frame (similar), sf object:","code":"x = st_sf(a = 1:2, geom = st_sfc(st_point(c(0,0)), st_point(c(1,1)))) y = data.frame(a = 2:3) merge(x, y) ## Simple feature collection with 1 feature and 1 field ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 1 ymin: 1 xmax: 1 ymax: 1 ## CRS: NA ## a geom ## 1 2 POINT (1 1) merge(x, y, all = TRUE) ## Simple feature collection with 3 features and 1 field (with 1 geometry empty) ## Geometry type: GEOMETRY ## Dimension: XY ## Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 ## CRS: NA ## a geom ## 1 1 POINT (0 0) ## 2 2 POINT (1 1) ## 3 3 GEOMETRYCOLLECTION EMPTY right_join(x, y) ## Joining with `by = join_by(a)` ## Simple feature collection with 2 features and 1 field (with 1 geometry empty) ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 1 ymin: 1 xmax: 1 ymax: 1 ## CRS: NA ## a geom ## 1 2 POINT (1 1) ## 2 3 POINT EMPTY"},{"path":"https://r-spatial.github.io/sf/articles/sf4.html","id":"joining-two-feature-sets-based-on-geometries","dir":"Articles","previous_headings":"","what":"Joining two feature sets based on geometries","title":"4. Manipulating Simple Features","text":"joining based spatial intersections (kind), st_join() used: join method left join, retaining records first attribute: geometry retained first argument. spatial join predicate can controlled function compatible st_intersects() (default), e.g.","code":"x = st_sf(a = 1:3, geom = st_sfc(st_point(c(1,1)), st_point(c(2,2)), st_point(c(3,3)))) y = st_buffer(x, 0.1) x = x[1:2,] y = y[2:3,] plot(st_geometry(x), xlim = c(.5, 3.5)) plot(st_geometry(y), add = TRUE) st_join(x, y) ## Simple feature collection with 2 features and 2 fields ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 1 ymin: 1 xmax: 2 ymax: 2 ## CRS: NA ## a.x a.y geom ## 1 1 NA POINT (1 1) ## 2 2 2 POINT (2 2) st_join(y, x) ## Simple feature collection with 2 features and 2 fields ## Geometry type: POLYGON ## Dimension: XY ## Bounding box: xmin: 1.9 ymin: 1.9 xmax: 3.1 ymax: 3.1 ## CRS: NA ## a.x a.y geom ## 2 2 2 POLYGON ((2.1 2, 2.099863 1... ## 3 3 NA POLYGON ((3.1 3, 3.099863 2... st_join(x, y, join = st_covers) # no matching y records: points don't cover circles ## Simple feature collection with 2 features and 2 fields ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: 1 ymin: 1 xmax: 2 ymax: 2 ## CRS: NA ## a.x a.y geom ## 1 1 NA POINT (1 1) ## 2 2 NA POINT (2 2) st_join(y, x, join = st_covers) # matches for those circles covering a point ## Simple feature collection with 2 features and 2 fields ## Geometry type: POLYGON ## Dimension: XY ## Bounding box: xmin: 1.9 ymin: 1.9 xmax: 3.1 ymax: 3.1 ## CRS: NA ## a.x a.y geom ## 2 2 2 POLYGON ((2.1 2, 2.099863 1... ## 3 3 NA POLYGON ((3.1 3, 3.099863 2..."},{"path":[]},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"geometry-only-sfc","dir":"Articles","previous_headings":"Plot methods for sf and sfc objects","what":"Geometry only: sfc","title":"5. Plotting Simple Features","text":"Geometry list-columns (objects class sfc, obtained st_geometry method) show geometry: can annotated colors, symbols, etc., usual base plots, e.g. points added polygon plot : legends, titles can added afterwards. border = NA removes polygon borders. can seen, axes plotted sensitive CRS, case longitude/latitude coordinates, degree symbols orientation added axes = TRUE.","code":"library(sf) ## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE demo(nc, ask = FALSE, echo = FALSE) plot(st_geometry(nc)) plot(st_geometry(nc), col = sf.colors(12, categorical = TRUE), border = 'grey', axes = TRUE) plot(st_geometry(st_centroid(nc)), pch = 3, col = 'red', add = TRUE) ## Warning: st_centroid assumes attributes are constant over geometries"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"geometry-with-attributes-sf","dir":"Articles","previous_headings":"Plot methods for sf and sfc objects","what":"Geometry with attributes: sf","title":"5. Plotting Simple Features","text":"default plot sf object multi-plot attributes, reasonable maximum: warning attributes can reasonably plotted. One can increase maximum number maps plotted row/column layout chosen plotting area maximally filled. default value max.plot can controlled, e.g. setting global option sf_max.plot:","code":"plot(nc) ## Warning: plotting the first 9 out of 14 attributes; use max.plot = 14 to plot ## all plot(nc, max.plot = 14) options(sf_max.plot=1) plot(nc)"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"color-key-place-and-size","dir":"Articles","previous_headings":"","what":"Color key place and size","title":"5. Plotting Simple Features","text":"case single attribute selected, default color key given side plot leaves much possible room plotted map; nc : can controlled, set particular side (1=, 2=left, 3=4=right): size color key can controlled, using either relative units (number 0 1) absolute units (like lcm(2) 2 cm): Keys factor variables bit different, typically don’t want rotate text :","code":"plot(nc[\"AREA\"]) plot(nc[\"AREA\"], key.pos = 4) plot(nc[\"AREA\"], key.pos = 1, axes = TRUE, key.width = lcm(1.3), key.length = 1.0) nc$f = cut(nc$AREA, 10) plot(nc[\"f\"], axes = TRUE, key.pos = 4, pal = sf.colors(10), key.width = lcm(5))"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"class-intervals","dir":"Articles","previous_headings":"","what":"Class intervals","title":"5. Plotting Simple Features","text":"Color breaks (class intervals) can controlled plot arguments breaks nbreaks. nbreaks specifies number breaks; breaks either vector break values: breaks used indicate breaks-finding method passed style argument classInt::classIntervals(). default value, pretty, results rounded class breaks, side effect nbreaks may honoured approximately. methods include \"equal\" break data range \"nbreaks\" equal classes, \"quantile\" use quantiles class breaks, \"jenks\", used software.","code":"plot(nc[\"AREA\"], breaks = c(0,.05,.1,.15,.2,.25)) plot(nc[\"AREA\"], breaks = \"jenks\")"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"how-does-sf-project-geographic-coordinates","dir":"Articles","previous_headings":"","what":"How does sf project geographic coordinates?","title":"5. Plotting Simple Features","text":"Package sf plots projected maps native projection, meaning easting northing mapped linearly x y axis, keeping aspect ratio 1 (one unit east equals one unit north). geographic data, coordinates constitute degrees longitude latitude, chooses equirectangular projection (also called equidistant circular), center plot (bounding box) one unit north equals one unit east. Proj.4 also lets project data projection, plot , apart values along axes, otherwise identical ","code":"plot(st_geometry(nc), axes = TRUE) lat_ts = mean(st_bbox(nc)[c(2,4)]) # latitude of true scale eqc = st_transform(nc, paste0(\"+proj=eqc +lat_ts=\", lat_ts)) plot(st_geometry(eqc), axes = TRUE)"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"graticules","dir":"Articles","previous_headings":"","what":"Graticules","title":"5. Plotting Simple Features","text":"Graticules grid lines along equal longitude (meridians) latitude (parallels) , depending projection used, often plot curved lines map, giving reference terms longitude latitude. sf::st_graticule() tries create graticule grid arbitrary maps. infinitely many projections, likely many cases succeed well, examples welcomed sf issues. following plot shows graticule geometry , see graticule reach plot boundaries (cut bounding box usa), axes show projected coordinates. compute graticule within plotting function, know plotting region can compute plot margins, add axes graticule units: can also pass crs object graticule obtain graticule datum different default (WGS84). st_graticule() takes parameters, can pass object returned graticule parameter plot, get finer control: still doesn’t look great – completely controlling plotting region base plots easy.","code":"library(maps) usa = st_as_sf(map('usa', plot = FALSE, fill = TRUE)) laea = st_crs(\"+proj=laea +lat_0=30 +lon_0=-95\") # Lambert equal area usa <- st_transform(usa, laea) g = st_graticule(usa) plot(st_geometry(g), axes = TRUE) plot(usa, graticule = TRUE, key.pos = NULL, axes = TRUE) g = st_graticule(usa, lon = seq(-130,-65,5)) plot(usa, graticule = g, key.pos = NULL, axes = TRUE, xlim = st_bbox(usa)[c(1,3)], ylim = st_bbox(usa)[c(2,4)], xaxs = \"i\", yaxs = \"i\")"},{"path":[]},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"grid-st_as_grob","dir":"Articles","previous_headings":"Plotting sf objects with other packages","what":"grid: st_as_grob","title":"5. Plotting Simple Features","text":"Package sf provides number methods st_as_grob(): convert simple simple feature objects grob (“graphics objects”) objects; grobs graphic primitives grid plotting package. methods can used plotting packages build grid, ggplot2 (uses geom_sf()) tmap. addition, st_viewport() can used set grid viewport sf object, aspect ratio similar plot.sf().","code":"methods(st_as_grob) ## [1] st_as_grob.CIRCULARSTRING* st_as_grob.COMPOUNDCURVE* ## [3] st_as_grob.CURVEPOLYGON* st_as_grob.GEOMETRYCOLLECTION* ## [5] st_as_grob.LINESTRING* st_as_grob.MULTILINESTRING* ## [7] st_as_grob.MULTIPOINT* st_as_grob.MULTIPOLYGON* ## [9] st_as_grob.MULTISURFACE* st_as_grob.POINT* ## [11] st_as_grob.POLYGON* st_as_grob.sfc* ## [13] st_as_grob.sfc_CIRCULARSTRING* st_as_grob.sfc_LINESTRING* ## [15] st_as_grob.sfc_MULTILINESTRING* st_as_grob.sfc_MULTIPOINT* ## [17] st_as_grob.sfc_MULTIPOLYGON* st_as_grob.sfc_POINT* ## [19] st_as_grob.sfc_POLYGON* ## see '?methods' for accessing help and source code"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"ggplot2","dir":"Articles","previous_headings":"Plotting sf objects with other packages","what":"ggplot2","title":"5. Plotting Simple Features","text":"contains geom specially simple feature objects, support graticule white lines background using sf::st_graticule(). Support currently good polygons; lines points, mileage may vary. Polygons can colored using aes: sets maps can plotted facet plots rearranging sf object, e.g. ","code":"library(ggplot2) ggplot() + geom_sf(data = usa) ggplot() + geom_sf(data = nc, aes(fill = BIR74)) + scale_y_continuous(breaks = 34:36) library(dplyr) ## ## Attaching package: 'dplyr' ## The following objects are masked from 'package:stats': ## ## filter, lag ## The following objects are masked from 'package:base': ## ## intersect, setdiff, setequal, union library(tidyr) nc2 <- nc %>% select(SID74, SID79, geom) %>% gather(VAR, SID, -geom) ggplot() + geom_sf(data = nc2, aes(fill = SID)) + facet_wrap(~VAR, ncol = 1) + scale_y_continuous(breaks = 34:36)"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"mapview","dir":"Articles","previous_headings":"Plotting sf objects with other packages","what":"mapview","title":"5. Plotting Simple Features","text":"Package mapview creates interactive maps html pages, using package leaflet workhorse. Extensive examples found . example obtained gives map interactive: can zoom pan, query features clicking .","code":"library(mapview) mapviewOptions(fgb = FALSE) # needed when creating web pages mapview(nc[\"BIR74\"], col.regions = sf.colors(10), fgb = FALSE)"},{"path":"https://r-spatial.github.io/sf/articles/sf5.html","id":"tmap","dir":"Articles","previous_headings":"Plotting sf objects with other packages","what":"tmap","title":"5. Plotting Simple Features","text":"Package tmap another package plotting maps, emphasis production-ready maps. tmap also interactive leaflet maps: Replotting last map non-interactive mode simple : draft version book Elegant informative maps tmap Martijn Tennekes Jakub Nowosad found https://r-tmap.github.io/","code":"library(tmap) qtm(nc) tmap_mode(\"view\") tm_shape(nc) + tm_fill(\"BIR74\", palette = sf.colors(5)) ttm() tmap_last()"},{"path":"https://r-spatial.github.io/sf/articles/sf6.html","id":"what-is-this-epsg-code-all-about","dir":"Articles","previous_headings":"","what":"What is this EPSG code all about?","title":"6. Miscellaneous","text":"EPSG stands maintained, well-understood registry spatial reference systems, maintained International Association Oil & Gas Producers (IOGP). EPSG stands authority, e.g. EPSG:4326 stands spatial reference system ID 4326 maintained EPSG authority. website EPSG registry found epsg.org domain. Using 4326 instead EPSG:4326 allowed (EPSG default authority) latter form, EPSG:4326 better (less ambiguous).","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf6.html","id":"why-should-we-use-ogccrs84-instead-of-epsg4326","dir":"Articles","previous_headings":"","what":"Why should we use OGC:CRS84 instead of EPSG:4326?","title":"6. Miscellaneous","text":"EPSG:4326 formally defines coordinate axes order latitude-longitude, practically data sources software environments use longitude-latitude axis order. OGC:CRS84 equivalent EPSG:4326 except defines coordinate axis order longitude-latitude, removing ambiguity speak. See also st_axis_order()","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf6.html","id":"how-does-sf-deal-with-secondary-geometry-columns","dir":"Articles","previous_headings":"","what":"How does sf deal with secondary geometry columns?","title":"6. Miscellaneous","text":"sf objects can one geometry list-column, always one geometry column considered active, returned st_geometry(). multiple geometry columns, default print methods reports one active: can switch active geometry using st_geometry<- st_set_geometry(), ","code":"library(sf) ## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE demo(nc, ask = FALSE, echo = FALSE) nc$geom2 = st_centroid(st_geometry(nc)) print(nc, n = 2) ## Simple feature collection with 100 features and 14 fields ## Attribute-geometry relationships: aggregate (8), identity (6), NA's (1) ## Active geometry column: geom ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 ## Geodetic CRS: NAD27 ## First 2 features: ## AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 ## 1 0.114 1.442 1825 1825 Ashe 37009 37009 5 1091 1 ## 2 0.061 1.231 1827 1827 Alleghany 37005 37005 3 487 0 ## NWBIR74 BIR79 SID79 NWBIR79 geom ## 1 10 1364 0 19 MULTIPOLYGON (((-81.47276 3... ## 2 10 542 3 12 MULTIPOLYGON (((-81.23989 3... ## geom2 ## 1 POINT (-81.49823 36.4314) ## 2 POINT (-81.12513 36.49111) plot(st_geometry(nc)) st_geometry(nc) <- \"geom2\" plot(st_geometry(nc))"},{"path":"https://r-spatial.github.io/sf/articles/sf6.html","id":"does-st_simplify-preserve-topology","dir":"Articles","previous_headings":"","what":"Does st_simplify preserve topology?","title":"6. Miscellaneous","text":"st_simplify() topology-preserving function, level individual feature geometries. means, simply said, applying , polygon still polygon. However two features longer shared boundary, applying st_simplify object guarantee resulting object two polygons still boundary common, since simplification done independently, feature geometry.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf6.html","id":"why-do-my-dplyr-verbs-not-work-for-sf-objects","dir":"Articles","previous_headings":"","what":"Why do my dplyr verbs not work for sf objects?","title":"6. Miscellaneous","text":"! However, many developers like write scripts never load packages address functions sf:: prefix, works moment dplyr generic like select sf object needed: one call dplyr::select (won’t know search package sf) sf::select (doesn’t exist)? Neither works. One case simply load sf, e.g. ","code":"i = sf::st_intersects(sf1, sf2) library(sf)"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"7. Spherical geometry in sf using s2geometry","text":"vignette describes spherical geometry implies, package sf uses s2geometry library (http://s2geometry.io) geometrical measures, predicates transformations. sf loaded, report whether s2 used; can switched (resorting flat space geometry) sf_use_s2(FALSE). package’s functions start s2_ way sf function names start st_. sf functions automatically use s2 functions working ellipsoidal coordinates; case, e.g. st_voronoi(), warning like emitted.","code":"library(sf) ## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE ## ## Attaching package: 'sf' ## The following object is masked from 'package:lwgeom': ## ## st_perimeter library(s2) Warning message: In st_voronoi.sfc(st_geometry(x), st_sfc(envelope), dTolerance, : st_voronoi does not correctly triangulate longitude/latitude data"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"projected-and-geographic-coordinates","dir":"Articles","previous_headings":"","what":"Projected and geographic coordinates","title":"7. Spherical geometry in sf using s2geometry","text":"Spatial coordinates either refer projected (Cartesian) coordinates, meaning associated points flat space, unprojected geographic coordinates, refer angles (latitude, longitude) pointing locations sphere (ellipsoid). flat space also referred R2R^2, sphere S2S^2 Package sf implements simple features, standard point, line, polygon geometries geometries built points (nodes) connected straight lines (edges). simple feature standard say much suitability dealing geographic coordinates, topological relational system builds upon (DE9-IM) refer R2R^2, two-dimensional flat space. Yet, data routinely served exchanged using geographic coordinates. Using software assumes R2R^2, flat space may work problems, although sf version 0.9-x functions place spherical/ellipsoidal computations (package lwgeom, computing area, length, distance, segmentizing), also happily warned user R2R^2, flat computations coordinates messages like hinting responsibility user take care potential problems. however leaves ambiguities, e.g. whether LINESTRING(-179 0,179 0) passes POINT(0 0), passes POINT(180 0) whether straight line, cutting Earth’s surface, curved line following Earth’s surface Starting sf version 1.0, provide spatial object geographical coordinate reference system, sf uses new package s2 (Dunnington, Pebesma, Rubak 2020) spherical geometry, functions computing pretty much measures, predicates transformations sphere. means: hodge-podge functions working R2R^2, annoying messages, ellipsoid considerable speed increase functions computations ellipsoid (considered accurate, also slower) s2 package really wrapper around C++ s2geometry library written Google, used many products (e.g. Google Maps, Google Earth Engine, Bigquery GIS) translated several programming languages. projected coordinates sf continues work R2R^2 .","code":"although coordinates are longitude/latitude, st_intersects assumes that they are planar"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"fundamental-differences","dir":"Articles","previous_headings":"","what":"Fundamental differences","title":"7. Spherical geometry in sf using s2geometry","text":"Compared geometry R2R^2, DE9-IM, s2 package brings fundamentally new concepts, discussed first.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"polygons-on-s2-divide-the-sphere-in-two-parts","dir":"Articles","previous_headings":"Fundamental differences","what":"Polygons on S2S^2 divide the sphere in two parts","title":"7. Spherical geometry in sf using s2geometry","text":"sphere (S2S^2), polygon defines two areas; following exterior ring, need define inside, definition left side enclosing edges. also means can flip polygon (inverting edge order) obtain part globe, addition empty polygon (empty set) can full polygon (entire globe). Simple feature geometries obey ring direction : exterior rings counter clockwise, interior (hole) rings clockwise, sense obsolete difference exterior ring interior rings defined position (exterior, followed zero interior). sf::read_sf() argument check_ring_dir checks, corrects, ring directions many (legacy) datasets wrong ring directions. wrong ring directions, many things still work. S2S^2, ring direction essential. reason, st_as_s2 argument oriented = FALSE, check correct ring directions, assuming exterior rings occupy area smaller half globe: default conversion sf s2 uses oriented = FALSE, get example oceans computed difference full polygon representing entire globe, countries, shown orthographic projection: (Note printing POLYGON FULL valid WKT according simple feature standard, include .) can now calculate proportion Earth’s surface covered oceans:","code":"nc = read_sf(system.file(\"gpkg/nc.gpkg\", package=\"sf\")) # wrong ring directions s2_area(st_as_s2(nc, oriented = FALSE)[1:3]) # corrects ring direction, correct area: ## [1] 1137107793 610916077 1423145355 s2_area(st_as_s2(nc, oriented = TRUE)[1:3]) # wrong direction: Earth's surface minus area ## [1] 5.100649e+14 5.100655e+14 5.100646e+14 nc = read_sf(system.file(\"gpkg/nc.gpkg\", package=\"sf\"), check_ring_dir = TRUE) s2_area(st_as_s2(nc, oriented = TRUE)[1:3]) # no second correction needed here: ## [1] 1137107793 610916077 1423145355 all(units::drop_units(st_area(nc)) == s2_area(st_as_s2(nc, oriented = FALSE))) ## [1] TRUE g = st_as_sfc(\"POLYGON FULL\", crs = 'EPSG:4326') g ## Geometry set for 1 feature ## Geometry type: POLYGON ## Dimension: XY ## Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 ## Geodetic CRS: WGS 84 ## POLYGON FULL options(s2_oriented = TRUE) # don't change orientation from here on co = st_as_sf(s2_data_countries()) oc = st_difference(g, st_union(co)) # oceans b = st_buffer(st_as_sfc(\"POINT(-30 52)\", crs = 'EPSG:4326'), 9800000) # visible half i = st_intersection(b, oc) # visible ocean plot(st_transform(i, \"+proj=ortho +lat_0=52 +lon_0=-30\"), col = 'blue') st_area(oc) / st_area(g) ## 0.711301 [1]"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"semi-open-polygon-boundaries","dir":"Articles","previous_headings":"Fundamental differences","what":"Semi-open polygon boundaries","title":"7. Spherical geometry in sf using s2geometry","text":"Polygons s2geometry can CLOSED: contain boundaries, point boundary intersects polygon OPEN: contain boundaries, points boundary intersect polygon SEMI-OPEN: contain part boundaries, boundary non-overlapping polygons contained one polygon. principle DE9-IM model deals interior, boundary exterior, intersection predicates sensitive (difference contains covers boundaries). DE9-IM however uniquely assign points polygons polygons form polygon coverage (overlaps, shared boundaries). means count points polygon, points fall shared polygon boundaries, either miss (contains) count double (covers, intersects); might lead bias require post-processing. Using SEMI-OPEN non-overlapping polygons guarantees every point assigned maximally one polygon intersection. corresponds e.g. handled grid (raster) coverage, every grid cell (typically) contains upper-left corner upper left sides.","code":"a = st_as_sfc(\"POINT(0 0)\", crs = 'EPSG:4326') b = st_as_sfc(\"POLYGON((0 0,1 0,1 1,0 1,0 0))\", crs = 'EPSG:4326') st_intersects(a, b, model = \"open\") ## Sparse geometry binary predicate list of length 1, where the predicate ## was `intersects' ## 1: (empty) st_intersects(a, b, model = \"closed\") ## Sparse geometry binary predicate list of length 1, where the predicate ## was `intersects' ## 1: 1 st_intersects(a, b, model = \"semi-open\") # a toss ## Sparse geometry binary predicate list of length 1, where the predicate ## was `intersects' ## 1: (empty) st_intersects(a, b) # default: closed ## Sparse geometry binary predicate list of length 1, where the predicate ## was `intersects' ## 1: 1"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"bounding-cap-bounding-rectangle","dir":"Articles","previous_headings":"Fundamental differences","what":"Bounding cap, bounding rectangle","title":"7. Spherical geometry in sf using s2geometry","text":"Computing minimum maximum values coordinate ranges, sf st_bbox(), limited value spherical coordinates due spherical space, area covered necessarily covered coordinate range. Two examples: small regions covering antimeridian (longitude +/- 180) end huge longitude range, doesn’t make clear antimeridian spanned regions including pole end latitude range extending +/- 90 S2 two alternatives: bounding cap bounding rectangle: cap reports bounding cap (circle) mid point (lat, lng) angle around point. bounding rectangle reports _lo _hi bounds lat lng coordinates. Note Fiji, lng_lo higher lng_hi indicates region covers (crosses) antimeridian.","code":"fiji = s2_data_countries(\"Fiji\") aa = s2_data_countries(\"Antarctica\") s2_bounds_cap(fiji) ## lng lat angle ## 1 178.7459 -17.15444 1.801369 s2_bounds_rect(c(fiji,aa)) ## lng_lo lat_lo lng_hi lat_hi ## 1 177.285 -18.28799 -179.7933 -16.02088 ## 2 -180.000 -90.00000 180.0000 -63.27066"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"switching-between-s2-and-geos","dir":"Articles","previous_headings":"","what":"Switching between S2 and GEOS","title":"7. Spherical geometry in sf using s2geometry","text":"two-dimensional R2R^2 library formerly used sf GEOS, sf can instrumented use GEOS s2. First ask s2 used default: can switch (use GEOS) switch (use s2) ","code":"sf_use_s2() ## [1] TRUE sf_use_s2(FALSE) ## Spherical geometry (s2) switched off sf_use_s2(TRUE) ## Spherical geometry (s2) switched on"},{"path":[]},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"area","dir":"Articles","previous_headings":"Measures","what":"Area","title":"7. Spherical geometry in sf using s2geometry","text":"","code":"options(s2_oriented = FALSE) # correct orientation from here on library(sf) library(units) ## udunits database from /usr/share/xml/udunits/udunits2.xml nc = read_sf(system.file(\"gpkg/nc.gpkg\", package=\"sf\")) sf_use_s2(TRUE) a1 = st_area(nc) sf_use_s2(FALSE) ## Spherical geometry (s2) switched off a2 = st_area(nc) plot(a1, a2) abline(0, 1) summary((a1 - a2)/a1) ## Min. 1st Qu. Median Mean 3rd Qu. Max. ## -2.638e-04 -1.650e-04 -7.133e-05 -6.448e-05 1.598e-05 2.817e-04"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"length","dir":"Articles","previous_headings":"Measures","what":"Length","title":"7. Spherical geometry in sf using s2geometry","text":"","code":"nc_ls = st_cast(nc, \"MULTILINESTRING\") sf_use_s2(TRUE) ## Spherical geometry (s2) switched on l1 = st_length(nc_ls) sf_use_s2(FALSE) ## Spherical geometry (s2) switched off l2 = st_length(nc_ls) plot(l1 , l2) abline(0, 1) summary((l1-l2)/l1) ## Min. 1st Qu. Median Mean 3rd Qu. Max. ## -0.0012301 -0.0004396 -0.0001258 -0.0001123 0.0001742 0.0009660"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"distances","dir":"Articles","previous_headings":"Measures","what":"Distances","title":"7. Spherical geometry in sf using s2geometry","text":"","code":"sf_use_s2(TRUE) ## Spherical geometry (s2) switched on d1 = st_distance(nc, nc[1:10,]) sf_use_s2(FALSE) ## Spherical geometry (s2) switched off d2 = st_distance(nc, nc[1:10,]) plot(as.vector(d1), as.vector(d2)) abline(0, 1) summary(as.vector(d1)-as.vector(d2)) ## Min. 1st Qu. Median Mean 3rd Qu. Max. ## -1424.5 -613.2 -236.5 -319.5 0.0 460.1"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"predicates","dir":"Articles","previous_headings":"","what":"Predicates","title":"7. Spherical geometry in sf using s2geometry","text":"unary binary predicates available s2, except st_relate() pattern. addition, using s2 predicates, depending model, intersections neighbours reported model closed (default):","code":"sf_use_s2(TRUE) ## Spherical geometry (s2) switched on st_intersects(nc[1:3,], nc[1:3,]) # self-intersections + neighbours ## Sparse geometry binary predicate list of length 3, where the predicate ## was `intersects' ## 1: 1, 2 ## 2: 1, 2, 3 ## 3: 2, 3 sf_use_s2(TRUE) st_intersects(nc[1:3,], nc[1:3,], model = \"semi-open\") # only self-intersections ## Sparse geometry binary predicate list of length 3, where the predicate ## was `intersects' ## 1: 1 ## 2: 2 ## 3: 3"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"transformations","dir":"Articles","previous_headings":"","what":"Transformations","title":"7. Spherical geometry in sf using s2geometry","text":"st_intersection(), st_union(), st_difference(), st_sym_difference() available s2 equivalents. N-ary intersection difference (yet) present; cascaded union present; unioning feature work s2.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"buffers","dir":"Articles","previous_headings":"Transformations","what":"Buffers","title":"7. Spherical geometry in sf using s2geometry","text":"Buffers can calculated features geographic coordinates follows, using unprojected object representing UK example: plots show can adjust level spatial precision results s2 buffer operations max_cells argument, set 1000 default. Deciding appropriate value balance excessive detail increasing computational resources (represented uk_buffer2, bottom left) excessive simplification (bottom right). Note buffers created s2 always follow s2 cell boundaries, never smooth. Hence, choosing large number max_cells leads seemingly smooth , zoomed , complex buffers. achieve similar result first transform result use sf::st_buffer(). simple benchmark shows computational efficiency s2 geometry engine comparison transforming creating buffers: result previous benchmarks emphasizes point trade-offs geographic resolution computational resources, something web developers working geographic services Google Maps understand well. case default setting 1000 cells, runs slightly faster default transform -> buffer workflow, probably appropriate given low resolution input geometry representing UK.","code":"uk = s2_data_countries(\"United Kingdom\") class(uk) ## [1] \"s2_geography\" \"wk_vctr\" uk_sfc = st_as_sfc(uk) uk_buffer = st_buffer(uk_sfc, dist = 20000) uk_buffer2 = st_buffer(uk_sfc, dist = 20000, max_cells = 10000) uk_buffer3 = st_buffer(uk_sfc, dist = 20000, max_cells = 100) class(uk_buffer) ## [1] \"sfc_MULTIPOLYGON\" \"sfc\" plot(uk_sfc) plot(uk_buffer) plot(uk_buffer2) plot(uk_buffer3) uk_sf = st_as_sf(uk) # the sf way system.time({ uk_projected = st_transform(uk_sfc, 27700) uk_buffer_sf = st_buffer(uk_projected, dist = 20000) }) ## user system elapsed ## 0.023 0.000 0.022 # sf way with few than the 30 segments in the buffer system.time({ uk_projected = st_transform(uk_sfc, 27700) uk_buffer_sf2 = st_buffer(uk_projected, dist = 20000, nQuadSegs = 4) }) ## user system elapsed ## 0.009 0.000 0.008 # s2 with default cell size system.time({ uk_buffer = s2_buffer_cells(uk, distance = 20000) }) ## user system elapsed ## 0.03 0.00 0.03 # s2 with 10000 cells system.time({ uk_buffer2 = s2_buffer_cells(uk, distance = 20000, max_cells = 10000) }) ## user system elapsed ## 0.282 0.000 0.282 # s2 with 100 cells system.time({ uk_buffer2 = s2_buffer_cells(uk, distance = 20000, max_cells = 100) }) ## user system elapsed ## 0.003 0.000 0.003"},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"st_buffer-or-st_is_within_distance","dir":"Articles","previous_headings":"Transformations","what":"st_buffer or st_is_within_distance?","title":"7. Spherical geometry in sf using s2geometry","text":"discussed sf issue tracker, deciding workflows selecting appropriate levels level geographic resolution can iterative process. st_buffer() powered GEOS, R2R^2 data, smooth (nearly) exact. st_buffer() powered S2S^2 rougher, complex, non-smooth, may need tuning. common pattern st_buffer() used : compute buffers around set features x (points, lines, polygons) within buffers, find occurrences spatial variable y aggregate (e.g. count points, average raster variable like precipitation population density) work aggregated values (discard buffer) case, working geographic coordinates, may pay compute buffers, instead directly work st_is_within_distance() select, feature x, features y within certain distance d x. S2S^2 version function uses spatial indexes, fast large datasets.","code":""},{"path":"https://r-spatial.github.io/sf/articles/sf7.html","id":"references","dir":"Articles","previous_headings":"Transformations","what":"References","title":"7. Spherical geometry in sf using s2geometry","text":"Dewey Dunnington, Edzer Pebesma Ege Rubak, 2020. s2: Spherical Geometry Operators Using S2S^2 Geometry Library. https://r-spatial.github.io/s2/, https://github.com/r-spatial/s2","code":""},{"path":"https://r-spatial.github.io/sf/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Edzer Pebesma. Author, maintainer. Roger Bivand. Contributor. Etienne Racine. Contributor. Michael Sumner. Contributor. Ian Cook. Contributor. Tim Keitt. Contributor. Robin Lovelace. Contributor. Hadley Wickham. Contributor. Jeroen Ooms. Contributor. Kirill Müller. Contributor. Thomas Lin Pedersen. Contributor. Dan Baston. Contributor. Dewey Dunnington. Contributor.","code":""},{"path":"https://r-spatial.github.io/sf/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Pebesma, E., & Bivand, R. (2023). Spatial Data Science: Applications R. Chapman Hall/CRC. https://doi.org/10.1201/9780429459016 Pebesma, E., 2018. Simple Features R: Standardized Support Spatial Vector Data. R Journal 10 (1), 439-446, https://doi.org/10.32614/RJ-2018-009","code":"@Book{, author = {Edzer Pebesma and Roger Bivand}, title = {{Spatial Data Science: With applications in R}}, year = {2023}, publisher = {{Chapman and Hall/CRC}}, url = {https://r-spatial.org/book/}, doi = {10.1201/9780429459016}, } @Article{, author = {Edzer Pebesma}, title = {{Simple Features for R: Standardized Support for Spatial Vector Data}}, year = {2018}, journal = {{The R Journal}}, doi = {10.32614/RJ-2018-009}, url = {https://doi.org/10.32614/RJ-2018-009}, pages = {439--446}, volume = {10}, number = {1}, }"},{"path":"https://r-spatial.github.io/sf/index.html","id":"simple-features-for-r","dir":"","previous_headings":"","what":"Simple Features for R","title":"Simple Features for R","text":"package provides simple features access R. Blogs, links • Cheatsheet • Installing • Contributing • Acknowledgment • cite Package sf: represents simple features records data.frame tibble geometry list-column represents natively R 17 simple feature types dimensions (XY, XYZ, XYM, XYZM) interfaces GEOS geometrical operations projected coordinates, (R package s2) s2geometry geometrical operations ellipsoidal coordinates interfaces GDAL, supporting driver options, Date POSIXct list-columns interfaces PRØJ coordinate reference system conversion transformation uses well-known-binary serialisations written C++/Rcpp fast /O GDAL GEOS reads writes spatial databases PostGIS using DBI lwgeom selected liblwgeom/PostGIS functions stars raster data, raster vector data cubes (spatial time series) sfnetworks geospatial network data (Illustration (c) 2018 Allison Horst)","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"books-journal-articles-blogs-presentations-vignettes-sp-sf-wiki","dir":"","previous_headings":"","what":"Books, journal articles, blogs, presentations, vignettes, sp-sf wiki","title":"Simple Features for R","text":"open access R Journal article summarizes package two books: Spatial Data Science: applications R, Geocomputation R package vignettes: first, second, third, fourth, fifth, sixth, seventh blog posts: first, second, third, fourth original R Consortium ISC proposal, R Consortium blog post presentations: rstudio::conf 2018 (video), UseR! 2016 wiki page describing sp-sf migration","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"cheatsheet","dir":"","previous_headings":"","what":"Cheatsheet","title":"Simple Features for R","text":"CC 4.0 Ryan Garnett","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"installing","dir":"","previous_headings":"","what":"Installing","title":"Simple Features for R","text":"Install either CRAN : install binary packages Windows MacOS, unless configured R tries install source packages; case, see . Install development versions GitHub :","code":"install.packages(\"sf\") library(remotes) install_github(\"r-spatial/sf\")"},{"path":"https://r-spatial.github.io/sf/index.html","id":"windows","dir":"","previous_headings":"Installing","what":"Windows","title":"Simple Features for R","text":"Installing sf source works Windows Rtools installed.","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"macos","dir":"","previous_headings":"Installing","what":"MacOS","title":"Simple Features for R","text":"MacOS users strongly encouraged install sf binary packages CRAN, unless familiar compilers, linking, C++ source code, homebrew. easiest way install gdal using Homebrew. Recent versions Homebrew include full-featured --date gdal formula, installs proj gdal time: gdal installed, able install sf package source R. current version proj homebrew, installation requires additional configuration: development version: using sf rgdal together, necessary install rgdal source using configuration: Alternatively, instructions explain install gdal using kyngchaos frameworks. Mac OS 11 Big Sur source install instruction, see ","code":"brew install pkg-config brew install gdal install.packages(\"sf\", type = \"source\", configure.args = \"--with-proj-lib=$(brew --prefix)/lib/\") library(remotes) install_github(\"r-spatial/sf\", configure.args = \"--with-proj-lib=$(brew --prefix)/lib/\") install.packages(\"rgdal\", type = \"source\", configure.args = c(\"--with-proj-lib=$(brew --prefix)/lib/\", \"--with-proj-include=$(brew --prefix)/include/\"))"},{"path":"https://r-spatial.github.io/sf/index.html","id":"linux","dir":"","previous_headings":"Installing","what":"Linux","title":"Simple Features for R","text":"Unix-alikes, GDAL (>= 2.0.1), GEOS (>= 3.4.0) Proj.4 (>= 4.8.0) required.","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"ubuntu","dir":"","previous_headings":"Installing > Linux","what":"Ubuntu","title":"Simple Features for R","text":"Dependencies recent versions Ubuntu (18.04 later) available official repositories; can install : However, get --date versions dependencies GDAL, recommend adding ubuntugis-unstable PPA package repositories installing follows: Adding PPA required installing sf older versions Ubuntu (e.g. Xenial). Another option, advanced users, install dependencies source; see e.g. older Travis config file hints.","code":"apt-get -y update && apt-get install -y libudunits2-dev libgdal-dev libgeos-dev libproj-dev sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable sudo apt-get update sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev libsqlite0-dev"},{"path":"https://r-spatial.github.io/sf/index.html","id":"fedora","dir":"","previous_headings":"Installing > Linux","what":"Fedora","title":"Simple Features for R","text":"following command installs required dependencies:","code":"sudo dnf install gdal-devel proj-devel geos-devel sqlite-devel udunits2-devel"},{"path":"https://r-spatial.github.io/sf/index.html","id":"arch","dir":"","previous_headings":"Installing > Linux","what":"Arch","title":"Simple Features for R","text":"Get gdal, proj, geos podofo main repos, udunits AUR:","code":"pacman -S gdal proj geos arrow podofo yay/pacaur/yaourt/whatever -S udunits"},{"path":"https://r-spatial.github.io/sf/index.html","id":"renv-or-conda","dir":"","previous_headings":"Installing > Linux","what":"renv or conda","title":"Simple Features for R","text":"several reports sf fails install source package R used renv, R installed conda environment. experience , please raise issue , try sort renv developers conda maintainers, try use binary installs sf package, e.g. r2u, Posit package manager","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"other","dir":"","previous_headings":"Installing > Linux","what":"Other","title":"Simple Features for R","text":"install Debian, rocker geospatial Dockerfiles may helpful. Ubuntu Dockerfiles found .","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"multiple-gdal-geos-andor-proj-versions-on-your-system","dir":"","previous_headings":"Installing","what":"Multiple GDAL, GEOS and/or PROJ versions on your system","title":"Simple Features for R","text":"use dynamic linking (installation source) multiple versions libraries installed (e.g. one ubuntugis-unstable, another installed source /usr/local/lib) general work, even setting LD_LIBRARY_PATH manually. See reason .","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"lwgeom","dir":"","previous_headings":"Installing","what":"lwgeom","title":"Simple Features for R","text":"Functions methods require liblwgeom, including ellipsoidal (spherical Euclidean) metrics (area, distances), provide used lwgeom, also CRAN.","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"contributing","dir":"","previous_headings":"","what":"Contributing","title":"Simple Features for R","text":"Contributions sorts welcome, issues pull requests preferred ways sharing . contributing pull requests, please adhere package style (package code use = rather <-; don’t change indentation; tab stops 4 spaces preferred). project released Contributor Code Conduct. participating project, agree abide terms.","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"how-to-cite","dir":"","previous_headings":"","what":"How to cite","title":"Simple Features for R","text":"Package sf can cited : Edzer Pebesma, 2018. Simple Features R: Standardized Support Spatial Vector Data. R Journal 10:1, 439-446. Pebesma, E.; Bivand, R. (2023). Spatial Data Science: Applications R (1st ed.). 314 pages. Chapman Hall/CRC.","code":""},{"path":"https://r-spatial.github.io/sf/index.html","id":"acknowledgment","dir":"","previous_headings":"","what":"Acknowledgment","title":"Simple Features for R","text":"project gratefully acknowledges financial support ","code":""},{"path":"https://r-spatial.github.io/sf/reference/Ops.html","id":null,"dir":"Reference","previous_headings":"","what":"Arithmetic operators for simple feature geometries — Ops","title":"Arithmetic operators for simple feature geometries — Ops","text":"Arithmetic operators simple feature geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/Ops.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Arithmetic operators for simple feature geometries — Ops","text":"","code":"# S3 method for class 'sfg' Ops(e1, e2) # S3 method for class 'sfc' Ops(e1, e2)"},{"path":"https://r-spatial.github.io/sf/reference/Ops.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Arithmetic operators for simple feature geometries — Ops","text":"e1 object class sfg sfc e2 numeric, object class sfg; case e1 class sfc also object class sfc allowed","code":""},{"path":"https://r-spatial.github.io/sf/reference/Ops.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Arithmetic operators for simple feature geometries — Ops","text":"object class sfg","code":""},{"path":"https://r-spatial.github.io/sf/reference/Ops.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Arithmetic operators for simple feature geometries — Ops","text":"case e2 numeric, +, -, *, /, %% %/% add, subtract, multiply, divide, modulo, integer-divide e2. case e2 n x n matrix, * matrix-multiplies / multiplies inverse. e2 sfg object, |, /, & %/% result geometric union, difference, intersection symmetric difference respectively, == != return geometric ()equality, using st_equals. e2 sfg sfc object, operations + - POINT geometries. e1 class sfc, e2 length 2 numeric, considered two-dimensional point (needed repeated ) operations + -, cases individual numbers repeated; see commented examples. reported (https://github.com/r-spatial/sf/issues/2067) certain ATLAS versions result invalid polygons, final point ring longer equal first point. case, setting precisions st_set_precision may help.","code":""},{"path":"https://r-spatial.github.io/sf/reference/Ops.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Arithmetic operators for simple feature geometries — Ops","text":"","code":"st_point(c(1,2,3)) + 4 #> POINT Z (5 6 7) st_point(c(1,2,3)) * 3 + 4 #> POINT Z (7 10 13) m = matrix(0, 2, 2) diag(m) = c(1, 3) # affine: st_point(c(1,2)) * m + c(2,5) #> POINT (3 11) # world in 0-360 range: if (require(maps, quietly = TRUE)) { w = st_as_sf(map('world', plot = FALSE, fill = TRUE)) w2 = (st_geometry(w) + c(360,90)) %% c(360) - c(0,90) w3 = st_wrap_dateline(st_set_crs(w2 - c(180,0), 4326)) + c(180,0) plot(st_set_crs(w3, 4326), axes = TRUE) } #> Warning: GDAL Error 1: TopologyException: Input geom 0 is invalid: Self-intersection at 16.123485685639235 -84.347832314219417 #> Warning: GDAL Error 1: TopologyException: Input geom 0 is invalid: Self-intersection at 16.123485685639235 -84.347832314219417 (mp <- st_point(c(1,2)) + st_point(c(3,4))) # MULTIPOINT (1 2, 3 4) #> POINT (4 6) mp - st_point(c(3,4)) # POINT (1 2) #> POINT (1 2) opar = par(mfrow = c(2,2), mar = c(0, 0, 1, 0)) a = st_buffer(st_point(c(0,0)), 2) b = a + c(2, 0) p = function(m) { plot(c(a,b)); plot(eval(parse(text=m)), col=grey(.9), add = TRUE); title(m) } o = lapply(c('a | b', 'a / b', 'a & b', 'a %/% b'), p) par(opar) sfc = st_sfc(st_point(0:1), st_point(2:3)) sfc + c(2,3) # added to EACH geometry #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 2 ymin: 4 xmax: 4 ymax: 6 #> CRS: NA #> POINT (2 4) #> POINT (4 6) sfc * c(2,3) # first geometry multiplied by 2, second by 3 #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 2 xmax: 6 ymax: 9 #> CRS: NA #> POINT (0 2) #> POINT (6 9) nc = st_transform(st_read(system.file(\"gpkg/nc.gpkg\", package=\"sf\")), 32119) # nc state plane, m #> Reading layer `nc.gpkg' from data source #> `/home/runner/work/_temp/Library/sf/gpkg/nc.gpkg' using driver `GPKG' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 b = st_buffer(st_centroid(st_union(nc)), units::set_units(50, km)) # shoot a hole in nc: plot(st_geometry(nc) / b, col = grey(.9))"},{"path":"https://r-spatial.github.io/sf/reference/aggregate.sf.html","id":null,"dir":"Reference","previous_headings":"","what":"aggregate an sf object — aggregate.sf","title":"aggregate an sf object — aggregate.sf","text":"aggregate sf object, possibly union-ing geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/aggregate.sf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"aggregate an sf object — aggregate.sf","text":"","code":"# S3 method for class 'sf' aggregate( x, by, FUN, ..., do_union = TRUE, simplify = TRUE, join = st_intersects )"},{"path":"https://r-spatial.github.io/sf/reference/aggregate.sf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"aggregate an sf object — aggregate.sf","text":"x object class sf either list grouping vectors length equal nrow(x) (see aggregate), object class sf sfc geometries used generate groupings, using binary predicate specified argument join FUN function passed aggregate, case ids specified attributes need grouped ... arguments passed FUN do_union logical; grouped geometries unioned using st_union? See details. simplify logical; see aggregate join logical spatial predicate function use simple features object geometry; see st_join","code":""},{"path":"https://r-spatial.github.io/sf/reference/aggregate.sf.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"aggregate an sf object — aggregate.sf","text":"sf object aggregated attributes geometries; additional grouping variables names names(ids) named Group.ids[[]]; see aggregate.","code":""},{"path":"https://r-spatial.github.io/sf/reference/aggregate.sf.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"aggregate an sf object — aggregate.sf","text":"case do_union FALSE, aggregate simply combine geometries using c.sfg. polygons sharing boundary combined, leads geometries invalid; see https://github.com/r-spatial/sf/issues/681.","code":""},{"path":"https://r-spatial.github.io/sf/reference/aggregate.sf.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"aggregate an sf object — aggregate.sf","text":"work using formula notation involving ~ defined aggregate.","code":""},{"path":"https://r-spatial.github.io/sf/reference/aggregate.sf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"aggregate an sf object — aggregate.sf","text":"","code":"m1 = cbind(c(0, 0, 1, 0), c(0, 1, 1, 0)) m2 = cbind(c(0, 1, 1, 0), c(0, 0, 1, 0)) pol = st_sfc(st_polygon(list(m1)), st_polygon(list(m2))) set.seed(1985) d = data.frame(matrix(runif(15), ncol = 3)) p = st_as_sf(x = d, coords = 1:2) plot(pol) plot(p, add = TRUE) (p_ag1 = aggregate(p, pol, mean)) #> Simple feature collection with 2 features and 1 field #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> X3 geometry #> 1 0.5951766 POLYGON ((0 0, 0 1, 1 1, 0 0)) #> 2 0.2997908 POLYGON ((0 0, 1 0, 1 1, 0 0)) plot(p_ag1) # geometry same as pol # works when x overlaps multiple objects in 'by': p_buff = st_buffer(p, 0.2) plot(p_buff, add = TRUE) (p_ag2 = aggregate(p_buff, pol, mean)) # increased mean of second #> Simple feature collection with 2 features and 1 field #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> X3 geometry #> 1 0.5951766 POLYGON ((0 0, 0 1, 1 1, 0 0)) #> 2 0.5958297 POLYGON ((0 0, 1 0, 1 1, 0 0)) # with non-matching features m3 = cbind(c(0, 0, -0.1, 0), c(0, 0.1, 0.1, 0)) pol = st_sfc(st_polygon(list(m3)), st_polygon(list(m1)), st_polygon(list(m2))) (p_ag3 = aggregate(p, pol, mean)) #> Simple feature collection with 3 features and 1 field #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: -0.1 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> X3 geometry #> 1 NA POLYGON ((0 0, 0 0.1, -0.1 ... #> 2 0.5951766 POLYGON ((0 0, 0 1, 1 1, 0 0)) #> 3 0.2997908 POLYGON ((0 0, 1 0, 1 1, 0 0)) plot(p_ag3) # In case we need to pass an argument to the join function: (p_ag4 = aggregate(p, pol, mean, join = function(x, y) st_is_within_distance(x, y, dist = 0.3))) #> Simple feature collection with 3 features and 1 field #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: -0.1 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> X3 geometry #> 1 NA POLYGON ((0 0, 0 0.1, -0.1 ... #> 2 0.5951766 POLYGON ((0 0, 0 1, 1 1, 0 0)) #> 3 0.5999887 POLYGON ((0 0, 1 0, 1 1, 0 0))"},{"path":"https://r-spatial.github.io/sf/reference/bind.html","id":null,"dir":"Reference","previous_headings":"","what":"Bind rows (features) of sf objects — bind","title":"Bind rows (features) of sf objects — bind","text":"Bind rows (features) sf objects Bind columns (variables) sf objects","code":""},{"path":"https://r-spatial.github.io/sf/reference/bind.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Bind rows (features) of sf objects — bind","text":"","code":"# S3 method for class 'sf' rbind(..., deparse.level = 1) # S3 method for class 'sf' cbind(..., deparse.level = 1, sf_column_name = NULL) st_bind_cols(...)"},{"path":"https://r-spatial.github.io/sf/reference/bind.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Bind rows (features) of sf objects — bind","text":"... objects bind; note rbind cbind methods, objects class sf; see dotsMethods deparse.level integer; see rbind sf_column_name character; specifies active geometry; passed st_sf","code":""},{"path":"https://r-spatial.github.io/sf/reference/bind.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Bind rows (features) of sf objects — bind","text":"cbind called multiple sf objects warns multiple geometry columns present geometry column use specified using argument sf_column_name; see also st_sf.","code":""},{"path":"https://r-spatial.github.io/sf/reference/bind.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Bind rows (features) of sf objects — bind","text":"rbind cbind non-standard method dispatch (see cbind): rbind cbind method sf objects called arguments binded class sf. need cbind e.g. data.frame sf, use data.frame directly use st_sf result, use bind_cols; see examples. st_bind_cols deprecated; use cbind instead.","code":""},{"path":"https://r-spatial.github.io/sf/reference/bind.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Bind rows (features) of sf objects — bind","text":"","code":"crs = st_crs(3857) a = st_sf(a=1, geom = st_sfc(st_point(0:1)), crs = crs) b = st_sf(a=1, geom = st_sfc(st_linestring(matrix(1:4,2))), crs = crs) c = st_sf(a=4, geom = st_sfc(st_multilinestring(list(matrix(1:4,2)))), crs = crs) rbind(a,b,c) #> Simple feature collection with 3 features and 1 field #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 2 ymax: 4 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a geom #> 1 1 POINT (0 1) #> 2 1 LINESTRING (1 3, 2 4) #> 3 4 MULTILINESTRING ((1 3, 2 4)) rbind(a,b) #> Simple feature collection with 2 features and 1 field #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 2 ymax: 4 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a geom #> 1 1 POINT (0 1) #> 2 1 LINESTRING (1 3, 2 4) rbind(a,b) #> Simple feature collection with 2 features and 1 field #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 2 ymax: 4 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a geom #> 1 1 POINT (0 1) #> 2 1 LINESTRING (1 3, 2 4) rbind(b,c) #> Simple feature collection with 2 features and 1 field #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: 1 ymin: 3 xmax: 2 ymax: 4 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a geom #> 1 1 LINESTRING (1 3, 2 4) #> 2 4 MULTILINESTRING ((1 3, 2 4)) cbind(a,b,c) # warns #> Simple feature collection with 1 feature and 3 fields #> Active geometry column: geom #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 0 ymax: 1 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a a.1 a.2 geom geom.1 geom.2 #> 1 1 1 4 POINT (0 1) LINESTRING (1 3, 2 4) MULTILINESTRING ((1 3, 2 4)) if (require(dplyr, quietly = TRUE)) dplyr::bind_cols(a,b) #> #> Attaching package: ‘dplyr’ #> The following objects are masked from ‘package:stats’: #> #> filter, lag #> The following objects are masked from ‘package:base’: #> #> intersect, setdiff, setequal, union #> New names: #> • `a` -> `a...1` #> • `geom` -> `geom...2` #> • `a` -> `a...3` #> • `geom` -> `geom...4` #> a...1 geom...2 a...3 geom...4 #> 1 1 POINT (0 1) 1 LINESTRING (1 3, 2 4) c = st_sf(a=4, geomc = st_sfc(st_multilinestring(list(matrix(1:4,2)))), crs = crs) cbind(a,b,c, sf_column_name = \"geomc\") #> Simple feature collection with 1 feature and 3 fields #> Active geometry column: geomc #> Geometry type: MULTILINESTRING #> Dimension: XY #> Bounding box: xmin: 1 ymin: 3 xmax: 2 ymax: 4 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a a.1 a.2 geom geom.1 geomc #> 1 1 1 4 POINT (0 1) LINESTRING (1 3, 2 4) MULTILINESTRING ((1 3, 2 4)) df = data.frame(x=3) st_sf(data.frame(c, df)) #> Simple feature collection with 1 feature and 2 fields #> Geometry type: MULTILINESTRING #> Dimension: XY #> Bounding box: xmin: 1 ymin: 3 xmax: 2 ymax: 4 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a x geomc #> 1 4 3 MULTILINESTRING ((1 3, 2 4)) if (require(dplyr, quietly = TRUE)) dplyr::bind_cols(c, df) #> Simple feature collection with 1 feature and 2 fields #> Geometry type: MULTILINESTRING #> Dimension: XY #> Bounding box: xmin: 1 ymin: 3 xmax: 2 ymax: 4 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a x geomc #> 1 4 3 MULTILINESTRING ((1 3, 2 4))"},{"path":"https://r-spatial.github.io/sf/reference/coerce-methods.html","id":null,"dir":"Reference","previous_headings":"","what":"Methods to coerce simple features to Spatial* and Spatial*DataFrame objects — as","title":"Methods to coerce simple features to Spatial* and Spatial*DataFrame objects — as","text":"as_Spatial() allows convert sf sfc Spatial*DataFrame Spatial* sp compatibility. can also use (x, \"Spatial\") transform sp objects sf sfc (x, \"sf\").","code":""},{"path":"https://r-spatial.github.io/sf/reference/coerce-methods.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Methods to coerce simple features to Spatial* and Spatial*DataFrame objects — as","text":"","code":"as_Spatial(from, cast = TRUE, IDs = paste0(\"ID\", seq_along(from)))"},{"path":"https://r-spatial.github.io/sf/reference/coerce-methods.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Methods to coerce simple features to Spatial* and Spatial*DataFrame objects — as","text":"object class sf, sfc_POINT, sfc_MULTIPOINT, sfc_LINESTRING, sfc_MULTILINESTRING, sfc_POLYGON, sfc_MULTIPOLYGON. cast logical; TRUE, st_cast() converting, e.g. GEOMETRY objects mix POLYGON MULTIPOLYGON cast MULTIPOLYGON. IDs character vector IDs Spatial* geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/coerce-methods.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Methods to coerce simple features to Spatial* and Spatial*DataFrame objects — as","text":"geometry-object deriving Spatial, appropriate class","code":""},{"path":"https://r-spatial.github.io/sf/reference/coerce-methods.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Methods to coerce simple features to Spatial* and Spatial*DataFrame objects — as","text":"Package sp supports three dimensions POINT MULTIPOINT (SpatialPoint*). geometries must two-dimensional (XY). Dimensions can dropped using st_zm() = \"M\" = \"ZM\". converting simple features (.e., sf objects) Spatial counterpart, use (obj, \"Spatial\")","code":""},{"path":"https://r-spatial.github.io/sf/reference/coerce-methods.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Methods to coerce simple features to Spatial* and Spatial*DataFrame objects — as","text":"","code":"nc <- st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 if (require(sp, quietly = TRUE)) { # convert to SpatialPolygonsDataFrame spdf <- as_Spatial(nc) # identical to spdf <- as(nc, \"Spatial\") # convert to SpatialPolygons as(st_geometry(nc), \"Spatial\") # back to sf as(spdf, \"sf\") } #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 #> First 10 features: #> AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 #> 1 0.114 1.442 1825 1825 Ashe 37009 37009 5 1091 1 #> 2 0.061 1.231 1827 1827 Alleghany 37005 37005 3 487 0 #> 3 0.143 1.630 1828 1828 Surry 37171 37171 86 3188 5 #> 4 0.070 2.968 1831 1831 Currituck 37053 37053 27 508 1 #> 5 0.153 2.206 1832 1832 Northampton 37131 37131 66 1421 9 #> 6 0.097 1.670 1833 1833 Hertford 37091 37091 46 1452 7 #> 7 0.062 1.547 1834 1834 Camden 37029 37029 15 286 0 #> 8 0.091 1.284 1835 1835 Gates 37073 37073 37 420 0 #> 9 0.118 1.421 1836 1836 Warren 37185 37185 93 968 4 #> 10 0.124 1.428 1837 1837 Stokes 37169 37169 85 1612 1 #> NWBIR74 BIR79 SID79 NWBIR79 geometry #> 1 10 1364 0 19 MULTIPOLYGON (((-81.47276 3... #> 2 10 542 3 12 MULTIPOLYGON (((-81.23989 3... #> 3 208 3616 6 260 MULTIPOLYGON (((-80.45634 3... #> 4 123 830 2 145 MULTIPOLYGON (((-76.00897 3... #> 5 1066 1606 3 1197 MULTIPOLYGON (((-77.21767 3... #> 6 954 1838 5 1237 MULTIPOLYGON (((-76.74506 3... #> 7 115 350 2 139 MULTIPOLYGON (((-76.00897 3... #> 8 254 594 2 371 MULTIPOLYGON (((-76.56251 3... #> 9 748 1190 2 844 MULTIPOLYGON (((-78.30876 3... #> 10 160 2038 5 176 MULTIPOLYGON (((-80.02567 3..."},{"path":"https://r-spatial.github.io/sf/reference/dbDataType.html","id":null,"dir":"Reference","previous_headings":"","what":"Determine database type for R vector — dbDataType,PostgreSQLConnection,sf-method","title":"Determine database type for R vector — dbDataType,PostgreSQLConnection,sf-method","text":"Determine database type R vector Determine database type R vector","code":""},{"path":"https://r-spatial.github.io/sf/reference/dbDataType.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Determine database type for R vector — dbDataType,PostgreSQLConnection,sf-method","text":"","code":"# S4 method for class 'PostgreSQLConnection,sf' dbDataType(dbObj, obj) # S4 method for class 'DBIObject,sf' dbDataType(dbObj, obj)"},{"path":"https://r-spatial.github.io/sf/reference/dbDataType.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Determine database type for R vector — dbDataType,PostgreSQLConnection,sf-method","text":"dbObj DBIObject driver connection. obj Object convert","code":""},{"path":"https://r-spatial.github.io/sf/reference/dbWriteTable.html","id":null,"dir":"Reference","previous_headings":"","what":"Write sf object to Database — dbWriteTable,PostgreSQLConnection,character,sf-method","title":"Write sf object to Database — dbWriteTable,PostgreSQLConnection,character,sf-method","text":"Write sf object Database Write sf object Database","code":""},{"path":"https://r-spatial.github.io/sf/reference/dbWriteTable.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Write sf object to Database — dbWriteTable,PostgreSQLConnection,character,sf-method","text":"","code":"# S4 method for class 'PostgreSQLConnection,character,sf' dbWriteTable( conn, name, value, ..., row.names = FALSE, overwrite = FALSE, append = FALSE, field.types = NULL, binary = TRUE ) # S4 method for class 'DBIObject,character,sf' dbWriteTable( conn, name, value, ..., row.names = FALSE, overwrite = FALSE, append = FALSE, field.types = NULL, binary = TRUE )"},{"path":"https://r-spatial.github.io/sf/reference/dbWriteTable.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Write sf object to Database — dbWriteTable,PostgreSQLConnection,character,sf-method","text":"conn DBIObject name character vector names (table names, fields, keywords). value data.frame. ... placeholder future use. row.names Add row.name column, vector length nrow(obj) containing row.names; default FALSE. overwrite try drop table writing; default FALSE. append Append rows existing table; default FALSE. field.types default NULL. Allows override type conversion R PostgreSQL. See dbDataType() details. binary Send geometries serialized Well-Known Binary (WKB); FALSE, uses Well-Known Text (WKT). Defaults TRUE (WKB).","code":""},{"path":"https://r-spatial.github.io/sf/reference/db_drivers.html","id":null,"dir":"Reference","previous_headings":"","what":"Drivers for which update should be TRUE by default — db_drivers","title":"Drivers for which update should be TRUE by default — db_drivers","text":"Drivers update TRUE default","code":""},{"path":"https://r-spatial.github.io/sf/reference/db_drivers.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Drivers for which update should be TRUE by default — db_drivers","text":"","code":"db_drivers"},{"path":"https://r-spatial.github.io/sf/reference/db_drivers.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Drivers for which update should be TRUE by default — db_drivers","text":"object class character length 12.","code":""},{"path":"https://r-spatial.github.io/sf/reference/dot-stop_geos.html","id":null,"dir":"Reference","previous_headings":"","what":"Internal functions — .stop_geos","title":"Internal functions — .stop_geos","text":"Internal functions","code":""},{"path":"https://r-spatial.github.io/sf/reference/dot-stop_geos.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Internal functions — .stop_geos","text":"","code":".stop_geos(msg)"},{"path":"https://r-spatial.github.io/sf/reference/dot-stop_geos.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Internal functions — .stop_geos","text":"msg error message","code":""},{"path":"https://r-spatial.github.io/sf/reference/extension_map.html","id":null,"dir":"Reference","previous_headings":"","what":"Map extension to driver — extension_map","title":"Map extension to driver — extension_map","text":"Map extension driver","code":""},{"path":"https://r-spatial.github.io/sf/reference/extension_map.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Map extension to driver — extension_map","text":"","code":"extension_map"},{"path":"https://r-spatial.github.io/sf/reference/extension_map.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Map extension to driver — extension_map","text":"object class list length 26.","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal.html","id":null,"dir":"Reference","previous_headings":"","what":"functions to interact with gdal not meant to be called directly by users (but e.g. by stars::read_stars) — gdal","title":"functions to interact with gdal not meant to be called directly by users (but e.g. by stars::read_stars) — gdal","text":"functions interact gdal meant called directly users (e.g. stars::read_stars)","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"functions to interact with gdal not meant to be called directly by users (but e.g. by stars::read_stars) — gdal","text":"","code":"gdal_read( x, ..., options = character(0), driver = character(0), read_data = TRUE, NA_value = NA_real_, RasterIO_parameters = list() ) gdal_write( x, ..., file, driver = \"GTiff\", options = character(0), type = \"Float32\", NA_value = NA_real_, geotransform, update = FALSE, scale_offset = c(1, 0) ) gdal_inv_geotransform(gt) gdal_crs(file, options = character(0)) gdal_metadata( file, domain_item = character(0), options = character(0), parse = TRUE ) gdal_subdatasets(file, options = character(0), name = TRUE) gdal_polygonize( x, mask = NULL, file = tempfile(), driver = \"GTiff\", use_integer = TRUE, geotransform, breaks = classInt::classIntervals(na.omit(as.vector(x[[1]])))$brks, use_contours = FALSE, contour_lines = FALSE, connect8 = FALSE, ... ) gdal_rasterize(sf, x, gt, file, driver = \"GTiff\", options = character()) gdal_extract( f, pts, resampling = c(\"nearest\", \"bilinear\", \"cubic\", \"cubicspline\") ) gdal_read_mdim( file, array_name = character(0), options = character(0), offset = integer(0), count = integer(0), step = integer(0), proxy = FALSE, debug = FALSE ) gdal_write_mdim( file, driver, dimx, cdl, wkt, xy, ..., root_group_options = character(0), options = character(0), as_float = TRUE ) gdal_create(f, nxy, values, crs, xlim, ylim)"},{"path":"https://r-spatial.github.io/sf/reference/gdal.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"functions to interact with gdal not meant to be called directly by users (but e.g. by stars::read_stars) — gdal","text":"x character vector, possibly length larger 1 one raster read ... ignored options character; driver specific options regarding reading creating dataset driver character; driver short name; empty vector, driver auto-detected. read_data logical; FALSE, imagery metadata returned NA_value (double) non-NA value use missing values; NA, writing missing values specially flagged output dataset, reading default (dataset) missing values used (present / set). RasterIO_parameters list named parameters GDAL's RasterIO; see stars::read_stars documentation. file file name type gdal write type geotransform length 6 numeric vector GDAL geotransform parameters. update logical; TRUE existing raster file pixel values shall updated. scale_offset length 2 numeric; contains scale offset values gt double vector length 6 domain_item character vector length 0, 1 (domain), 2 (domain item); use \"\" default domain, use NA_character_ query domain names. parse logical; metadata parsed named list (TRUE) returned character data? name logical; retrieve name subdataset? FALSE, retrieve description mask stars object NA mask (0 NA), NULL use_integer boolean; TRUE, raster values read (rounded ) unsigned 32-bit integers values; FALSE read 32-bit floating points numbers. former supposedly faster. breaks numeric vector break values contour polygons (lines) use_contours logical; contour_lines logical; connect8 logical; TRUE use 8 connection algorithm, rather 4 sf object class sf f character; file name pts points matrix resampling character; resampling method; method cubic cubicspline, stars_proxy objects used GDAL version >= 3.10.0 array_name array name offset offset (pixels) count number pixels read step step size (pixels) proxy logical; return proxy object? debug logical; print debug messages? dimx integer named vector dimensions object cdl list variables, named dim attribute wkt character; WKT crs xy character; names spatial x y dimension root_group_options character; driver specific options regarding creation root group as_float logical; TRUE write 4-byte floating point numbers, FALSE write 8-byte doubles. nxy integer vector length 2 values fill value crs object class crs xlim numeric ylim numeric","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"functions to interact with gdal not meant to be called directly by users (but e.g. by stars::read_stars) — gdal","text":"object class crs, see st_crs. named list metadata items gdal_subdatasets returns zero-length list file subdatasets, else named list subdatasets.","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"functions to interact with gdal not meant to be called directly by users (but e.g. by stars::read_stars) — gdal","text":"functions exported single purpose used package stars, meant used directly may change disappear without prior notice deprecation warnings. gdal_inv_geotransform returns inverse geotransform gdal_crs reads coordinate reference system GDAL data set get_metadata gets metadata raster layer gdal_subdatasets returns subdatasets gdal dataset","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"functions to interact with gdal not meant to be called directly by users (but e.g. by stars::read_stars) — gdal","text":"","code":"if (FALSE) { # \\dontrun{ f = system.file(\"tif/L7_ETMs.tif\", package=\"stars\") f = system.file(\"nc/avhrr-only-v2.19810901.nc\", package = \"stars\") gdal_metadata(f) gdal_metadata(f, NA_character_) try(gdal_metadata(f, \"wrongDomain\")) gdal_metadata(f, c(\"\", \"AREA_OR_POINT\")) } # }"},{"path":"https://r-spatial.github.io/sf/reference/gdal_addo.html","id":null,"dir":"Reference","previous_headings":"","what":"Add or remove overviews to/from a raster image — gdal_addo","title":"Add or remove overviews to/from a raster image — gdal_addo","text":"add remove overviews /raster image","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal_addo.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add or remove overviews to/from a raster image — gdal_addo","text":"","code":"gdal_addo( file, overviews = c(2, 4, 8, 16), method = \"NEAREST\", layers = integer(0), options = character(0), config_options = character(0), clean = FALSE, read_only = FALSE )"},{"path":"https://r-spatial.github.io/sf/reference/gdal_addo.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add or remove overviews to/from a raster image — gdal_addo","text":"file character; file name overviews integer; overview levels method character; method create overview; one : nearest, average, rms, gauss, cubic, cubicspline, lanczos, average_mp, average_magphase, mode layers integer; layers create overviews (default: ) options character; dataset opening options config_options named character vector GDAL config options, like c(option1=value1, option2=value2) clean logical; TRUE remove overviews, add read_only logical; TRUE, add overviews another file extension .ovr added file","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal_addo.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add or remove overviews to/from a raster image — gdal_addo","text":"TRUE, invisibly, success","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/gdal_utils.html","id":null,"dir":"Reference","previous_headings":"","what":"Native interface to gdal utils — gdal_utils","title":"Native interface to gdal utils — gdal_utils","text":"Native interface gdal utils","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal_utils.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Native interface to gdal utils — gdal_utils","text":"","code":"gdal_utils( util = \"info\", source, destination, options = character(0), quiet = !(util %in% c(\"info\", \"gdalinfo\", \"ogrinfo\", \"vectorinfo\", \"mdiminfo\")) || (\"-multi\" %in% options), processing = character(0), colorfilename = character(0), config_options = character(0), read_only = FALSE )"},{"path":"https://r-spatial.github.io/sf/reference/gdal_utils.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Native interface to gdal utils — gdal_utils","text":"util character; one info, warp, rasterize, translate, vectortranslate (ogr2ogr), buildvrt, demprocessing, nearblack, grid, mdiminfo mdimtranslate (last two requiring GDAL 3.1), ogrinfo (requiring GDAL 3.7), footprint (requiring GDAL 3.8) source character; name input layer(s); warp, buidvrt mdimtranslate can one destination character; name output layer options character; options utility quiet logical; TRUE, suppress printing output info mdiminfo, suppress printing progress processing character; processing options demprocessing colorfilename character; name color file demprocessing (mandatory processing=\"color-relief\") config_options named character vector GDAL config options, like c(option1=value1, option2=value2) read_only logical; ogrinfo: TRUE, source opened read-mode","code":""},{"path":"https://r-spatial.github.io/sf/reference/gdal_utils.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Native interface to gdal utils — gdal_utils","text":"info returns character vector raster metadata; utils return (invisibly) logical indicating success (.e., TRUE); case failure, error raised.","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/gdal_utils.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Native interface to gdal utils — gdal_utils","text":"","code":"if (sf_extSoftVersion()[\"GDAL\"] > \"2.1.0\") { # info utils can be used to list information about a raster # dataset. More info: https://gdal.org/programs/gdalinfo.html in_file <- system.file(\"tif/geomatrix.tif\", package = \"sf\") gdal_utils(\"info\", in_file, options = c(\"-mm\", \"-proj4\")) # vectortranslate utils can be used to convert simple features data between # file formats. More info: https://gdal.org/programs/ogr2ogr.html in_file <- system.file(\"shape/storms_xyz.shp\", package=\"sf\") out_file <- paste0(tempfile(), \".gpkg\") gdal_utils( util = \"vectortranslate\", source = in_file, destination = out_file, # output format must be specified for GDAL < 2.3 options = c(\"-f\", \"GPKG\") ) # The parameters can be specified as c(\"name\") or c(\"name\", \"value\"). The # vectortranslate utils can perform also various operations during the # conversion process. For example, we can reproject the features during the # translation. gdal_utils( util = \"vectortranslate\", source = in_file, destination = out_file, options = c( \"-f\", \"GPKG\", # output file format for GDAL < 2.3 \"-s_srs\", \"EPSG:4326\", # input file SRS \"-t_srs\", \"EPSG:2264\", # output file SRS \"-overwrite\" ) ) st_read(out_file) # The parameter s_srs had to be specified because, in this case, the in_file # has no associated SRS. st_read(in_file) } #> Driver: GTiff/GeoTIFF #> Files: /home/runner/work/_temp/Library/sf/tif/geomatrix.tif #> Size is 20, 20 #> Coordinate System is: #> PROJCRS[\"WGS 84 / UTM zone 11N\", #> BASEGEOGCRS[\"WGS 84\", #> ENSEMBLE[\"World Geodetic System 1984 ensemble\", #> MEMBER[\"World Geodetic System 1984 (Transit)\"], #> MEMBER[\"World Geodetic System 1984 (G730)\"], #> MEMBER[\"World Geodetic System 1984 (G873)\"], #> MEMBER[\"World Geodetic System 1984 (G1150)\"], #> MEMBER[\"World Geodetic System 1984 (G1674)\"], #> MEMBER[\"World Geodetic System 1984 (G1762)\"], #> MEMBER[\"World Geodetic System 1984 (G2139)\"], #> ELLIPSOID[\"WGS 84\",6378137,298.257223563, #> LENGTHUNIT[\"metre\",1]], #> ENSEMBLEACCURACY[2.0]], #> PRIMEM[\"Greenwich\",0, #> ANGLEUNIT[\"degree\",0.0174532925199433]], #> ID[\"EPSG\",4326]], #> CONVERSION[\"UTM zone 11N\", #> METHOD[\"Transverse Mercator\", #> ID[\"EPSG\",9807]], #> PARAMETER[\"Latitude of natural origin\",0, #> ANGLEUNIT[\"degree\",0.0174532925199433], #> ID[\"EPSG\",8801]], #> PARAMETER[\"Longitude of natural origin\",-117, #> ANGLEUNIT[\"degree\",0.0174532925199433], #> ID[\"EPSG\",8802]], #> PARAMETER[\"Scale factor at natural origin\",0.9996, #> SCALEUNIT[\"unity\",1], #> ID[\"EPSG\",8805]], #> PARAMETER[\"False easting\",500000, #> LENGTHUNIT[\"metre\",1], #> ID[\"EPSG\",8806]], #> PARAMETER[\"False northing\",0, #> LENGTHUNIT[\"metre\",1], #> ID[\"EPSG\",8807]]], #> CS[Cartesian,2], #> AXIS[\"(E)\",east, #> ORDER[1], #> LENGTHUNIT[\"metre\",1]], #> AXIS[\"(N)\",north, #> ORDER[2], #> LENGTHUNIT[\"metre\",1]], #> USAGE[ #> SCOPE[\"Engineering survey, topographic mapping.\"], #> AREA[\"Between 120°W and 114°W, northern hemisphere between equator and 84°N, onshore and offshore. Canada - Alberta; British Columbia (BC); Northwest Territories (NWT); Nunavut. Mexico. United States (USA).\"], #> BBOX[0,-120,84,-114]], #> ID[\"EPSG\",32611]] #> Data axis to CRS axis mapping: 1,2 #> PROJ.4 string is: #> '+proj=utm +zone=11 +datum=WGS84 +units=m +no_defs' #> GeoTransform = #> 1841001.75, 1.5, -5 #> 1144003.25, -5, -1.5 #> Metadata: #> AREA_OR_POINT=Point #> Image Structure Metadata: #> INTERLEAVE=BAND #> Corner Coordinates: #> Upper Left ( 1841001.750, 1144003.250) (104d50'47.45\"W, 10d 7'13.55\"N) #> Lower Left ( 1840901.750, 1143973.250) (104d50'50.69\"W, 10d 7'12.72\"N) #> Upper Right ( 1841031.750, 1143903.250) (104d50'46.60\"W, 10d 7'10.33\"N) #> Lower Right ( 1840931.750, 1143873.250) (104d50'49.85\"W, 10d 7' 9.50\"N) #> Center ( 1840966.750, 1143938.250) (104d50'48.65\"W, 10d 7'11.53\"N) #> Band 1 Block=20x20 Type=Byte, ColorInterp=Gray #> Computed Min/Max=74.000,255.000 #> Reading layer `storms_xyz' from data source #> `/tmp/RtmpokzaW8/file1d2f48fe6ba9.gpkg' using driver `GPKG' #> Simple feature collection with 71 features and 0 fields #> Geometry type: LINESTRING #> Dimension: XYZ #> Bounding box: xmin: -5785269 ymin: -8509454 xmax: 25097160 ymax: 15846560 #> z_range: zmin: 924 zmax: 1017 #> Projected CRS: NAD83 / North Carolina (ftUS) #> Reading layer `storms_xyz' from data source #> `/home/runner/work/_temp/Library/sf/shape/storms_xyz.shp' using driver `ESRI Shapefile' #> Simple feature collection with 71 features and 0 fields #> Geometry type: LINESTRING #> Dimension: XYZ #> Bounding box: xmin: -102.2 ymin: 8.3 xmax: 0 ymax: 59.5 #> z_range: zmin: 924 zmax: 1017 #> CRS: NA"},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_ops.html","id":null,"dir":"Reference","previous_headings":"","what":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","title":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","text":"Perform geometric set operations simple feature geometry collections","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_ops.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","text":"","code":"st_intersection(x, y, ...) # S3 method for class 'sfc' st_intersection(x, y, ...) # S3 method for class 'sf' st_intersection(x, y, ...) st_difference(x, y, ...) # S3 method for class 'sfc' st_difference(x, y, ...) st_sym_difference(x, y, ...) st_snap(x, y, tolerance)"},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_ops.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","text":"x object class sf, sfc sfg y object class sf, sfc sfg ... arguments passed s2_options tolerance tolerance values used st_snap; numeric value object class units; may tolerance values feature x","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_ops.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","text":"intersection, difference symmetric difference two sets geometries. returned object class first argument (x) non-empty geometries resulting applying operation geometry pairs x y. case x class sf, matching attributes original object(s) added. sfc geometry list-column returned carries attribute idx, n--2 matrix every row index corresponding entries x y, respectively.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_ops.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","text":"using GEOS using s2, spatial index built argument x; see https://r-spatial.org/r/2017/06/22/spatial-index.html. reference STR tree algorithm : Leutenegger, Scott T., Mario . Lopez, Jeffrey Edgington. \"STR: simple efficient algorithm R-tree packing.\" Data Engineering, 1997. Proceedings. 13th international conference . IEEE, 1997. pdf, search Google Scholar. called missing y, sfc method st_intersection returns non-empty intersections geometries x; attribute idx contains list-column indexes contributing geometries. called missing y, sf method st_intersection returns sf object attributes taken contributing feature lowest index; two fields added: n.overlaps number overlapping features x, list-column origins indexes overlapping features. st_difference called single argument, overlapping areas erased geometries indexed greater numbers argument x; geometries empty contained fully inside geometries higher priority removed entirely. st_difference.sfc method single argument returns object \"idx\" attribute original index returned geometries. st_snap snaps vertices segments geometry another geometry's vertices. y contains one geometry, geometries merged collection snapping collection. (GEOS docs:) \"snap distance tolerance used control snapping performed. Snapping one geometry another can improve robustness overlay operations eliminating nearly-coincident edges (cause problems noding intersection calculation). much snapping can result invalid topology created, number location snapped vertices decided using heuristics determine safe snap. can result potential snaps omitted, however.\"","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_ops.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","text":"find whether pairs simple feature geometries intersect, use function st_intersects instead st_intersection. using GEOS using s2 polygons contain boundary. using s2 determined model defaults s2_options, can overridden via ... argument, e.g. model = \"closed\" force DE-9IM compliant behaviour polygons (reproduce GEOS results).","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_ops.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Geometric operations on pairs of simple feature geometry sets — geos_binary_ops","text":"","code":"set.seed(131) library(sf) m = rbind(c(0,0), c(1,0), c(1,1), c(0,1), c(0,0)) p = st_polygon(list(m)) n = 100 l = vector(\"list\", n) for (i in 1:n) l[[i]] = p + 10 * runif(2) s = st_sfc(l) plot(s, col = sf.colors(categorical = TRUE, alpha = .5)) title(\"overlapping squares\") d = st_difference(s) # sequential differences: s1, s2-s1, s3-s2-s1, ... plot(d, col = sf.colors(categorical = TRUE, alpha = .5)) title(\"non-overlapping differences\") i = st_intersection(s) # all intersections plot(i, col = sf.colors(categorical = TRUE, alpha = .5)) title(\"non-overlapping intersections\") summary(lengths(st_overlaps(s, s))) # includes self-counts! #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0.00 2.00 3.50 3.66 5.00 8.00 summary(lengths(st_overlaps(d, d))) #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0 0 0 0 0 0 summary(lengths(st_overlaps(i, i))) #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0 0 0 0 0 0 sf = st_sf(s) i = st_intersection(sf) # all intersections plot(i[\"n.overlaps\"]) summary(i$n.overlaps - lengths(i$origins)) #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0 0 0 0 0 0 # A helper function that erases all of y from x: st_erase = function(x, y) st_difference(x, st_union(st_combine(y))) poly = st_polygon(list(cbind(c(0, 0, 1, 1, 0), c(0, 1, 1, 0, 0)))) lines = st_multilinestring(list( cbind(c(0, 1), c(1, 1.05)), cbind(c(0, 1), c(0, -.05)), cbind(c(1, .95, 1), c(1.05, .5, -.05)) )) snapped = st_snap(poly, lines, tolerance=.1) plot(snapped, col='red') plot(poly, border='green', add=TRUE) plot(lines, lwd=2, col='blue', add=TRUE)"},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_pred.html","id":null,"dir":"Reference","previous_headings":"","what":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","title":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","text":"Geometric binary predicates pairs simple feature geometry sets","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_pred.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","text":"","code":"st_intersects(x, y, sparse = TRUE, ...) st_disjoint(x, y = x, sparse = TRUE, prepared = TRUE, ...) st_touches(x, y, sparse = TRUE, prepared = TRUE, ...) st_crosses(x, y, sparse = TRUE, prepared = TRUE, ...) st_within(x, y, sparse = TRUE, prepared = TRUE, ...) st_contains(x, y, sparse = TRUE, prepared = TRUE, ..., model = \"open\") st_contains_properly(x, y, sparse = TRUE, prepared = TRUE, ...) st_overlaps(x, y, sparse = TRUE, prepared = TRUE, ...) st_equals( x, y, sparse = TRUE, prepared = FALSE, ..., retain_unique = FALSE, remove_self = FALSE ) st_covers(x, y, sparse = TRUE, prepared = TRUE, ..., model = \"closed\") st_covered_by(x, y = x, sparse = TRUE, prepared = TRUE, ..., model = \"closed\") st_equals_exact(x, y, par, sparse = TRUE, prepared = FALSE, ...) st_is_within_distance(x, y = x, dist, sparse = TRUE, ..., remove_self = FALSE)"},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_pred.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","text":"x object class sf, sfc sfg y object class sf, sfc sfg; missing, x used sparse logical; sparse index list returned (TRUE) dense logical matrix? See . ... Arguments passed s2::s2_options snap Use s2_snap_identity(), s2_snap_distance(), s2_snap_level(), s2_snap_precision() specify coordinate rounding occur. snap_radius opposed snap function, specifies maximum distance vertex move, snap radius (radians) sets minimum distance vertices output cause vertices move distance specified snap function. can used simplify result boolean operation. Use -1 specify minimum distance acceptable. duplicate_edges Use TRUE keep duplicate edges (e.g., duplicate points). edge_type One 'directed' (default) 'undirected'. validate Use TRUE validate result builder. polyline_type One 'path' (default) 'walk'. 'walk', polylines backtrack preserved. polyline_sibling_pairs One 'discard' (default) 'keep'. simplify_edge_chains Use TRUE remove vertices within snap_radius original vertex. split_crossing_edges Use TRUE split crossing polyline edges creating geometries. idempotent Use FALSE apply snap even snapping necessary satisfy vertex constraints. dimensions combination 'point', 'polyline', /'polygon' can used constrain output s2_rebuild() boolean operation. prepared logical; prepare geometry x, looping y? See Details. model character; polygon/polyline model; one \"open\", \"semi-open\" \"closed\"; see Details. retain_unique logical; TRUE (y missing) return indexes points larger current index; can used select unique geometries, see examples. argument can used geometry predicates; see also distinct.sf find records geometries attributes distinct. remove_self logical; TRUE (y missing) return indexes geometries different current index; can used omit self-intersections; see examples. argument can used geometry predicates par numeric; parameter used \"equals_exact\" (margin); dist distance threshold; geometry indexes distances smaller equal value returned; numeric value units value distance units.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_pred.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","text":"sparse=FALSE, st_predicate (predicate e.g. \"intersects\") returns dense logical matrix element ,j equal TRUE predicate(x[], y[j]) (e.g., geometry feature j intersect); sparse=TRUE, object class sgbp returned, sparse list representation matrix, list element integer vector indices j predicate(x[],y[j]) TRUE (hence zero-length integer vector none TRUE). dense matrix, one can find one elements intersect apply(mat, 1, ), sparse list lengths(lst) > 0, see examples .","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_pred.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","text":"prepared TRUE, x contains POINT geometries y contains polygons, polygon geometries prepared, rather points. predicates, spatial index built argument x; see https://r-spatial.org/r/2017/06/22/spatial-index.html. Specifically, st_intersects, st_disjoint, st_touches st_crosses, st_within, st_contains, st_contains_properly, st_overlaps, st_equals, st_covers st_covered_by build spatial indexes efficient geometry calculations. st_relate, st_equals_exact, ; st_is_within_distance uses spatial index geographic coordinates sf_use_s2() true. y missing, st_predicate(x, x) effectively called, square matrix returned diagonal elements st_predicate(x[], x[]). Sparse geometry binary predicate (sgbp) lists following attributes: region.id row.names x (, else 1:n), ncol number features y, predicate name predicate used. model, see https://github.com/r-spatial/s2/issues/32 st_contains_properly(,B) true intersects B's interior, edges exterior; contains , properly contain . See also st_relate https://en.wikipedia.org/wiki/DE-9IM detailed description underlying algorithms. st_equals_exact returns true two geometries type vertices corresponding index equal specified tolerance.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_pred.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","text":"intersection pairs simple feature geometries, use function st_intersection instead st_intersects.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_binary_pred.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Geometric binary predicates on pairs of simple feature geometry sets — geos_binary_pred","text":"","code":"pts = st_sfc(st_point(c(.5,.5)), st_point(c(1.5, 1.5)), st_point(c(2.5, 2.5))) pol = st_polygon(list(rbind(c(0,0), c(2,0), c(2,2), c(0,2), c(0,0)))) (lst = st_intersects(pts, pol)) #> Sparse geometry binary predicate list of length 3, where the predicate #> was `intersects' #> 1: 1 #> 2: 1 #> 3: (empty) (mat = st_intersects(pts, pol, sparse = FALSE)) #> [,1] #> [1,] TRUE #> [2,] TRUE #> [3,] FALSE # which points fall inside a polygon? apply(mat, 1, any) #> [1] TRUE TRUE FALSE lengths(lst) > 0 #> [1] TRUE TRUE FALSE # which points fall inside the first polygon? st_intersects(pol, pts)[[1]] #> [1] 1 2 # remove duplicate geometries: p1 = st_point(0:1) p2 = st_point(2:1) p = st_sf(a = letters[1:8], geom = st_sfc(p1, p1, p2, p1, p1, p2, p2, p1)) st_equals(p) #> Sparse geometry binary predicate list of length 8, where the predicate #> was `equals' #> 1: 1, 2, 4, 5, 8 #> 2: 1, 2, 4, 5, 8 #> 3: 3, 6, 7 #> 4: 1, 2, 4, 5, 8 #> 5: 1, 2, 4, 5, 8 #> 6: 3, 6, 7 #> 7: 3, 6, 7 #> 8: 1, 2, 4, 5, 8 st_equals(p, remove_self = TRUE) #> Sparse geometry binary predicate list of length 8, where the predicate #> was `equals', with remove_self = TRUE #> 1: 2, 4, 5, 8 #> 2: 1, 4, 5, 8 #> 3: 6, 7 #> 4: 1, 2, 5, 8 #> 5: 1, 2, 4, 8 #> 6: 3, 7 #> 7: 3, 6 #> 8: 1, 2, 4, 5 (u = st_equals(p, retain_unique = TRUE)) #> Sparse geometry binary predicate list of length 8, where the predicate #> was `equals', with retain_unique = TRUE #> 1: 2, 4, 5, 8 #> 2: 4, 5, 8 #> 3: 6, 7 #> 4: 5, 8 #> 5: 8 #> 6: 7 #> 7: (empty) #> 8: (empty) # retain the records with unique geometries: p[-unlist(u),] #> Simple feature collection with 2 features and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 2 ymax: 1 #> CRS: NA #> a geom #> 1 a POINT (0 1) #> 3 c POINT (2 1)"},{"path":"https://r-spatial.github.io/sf/reference/geos_combine.html","id":null,"dir":"Reference","previous_headings":"","what":"Combine or union feature geometries — geos_combine","title":"Combine or union feature geometries — geos_combine","text":"Combine several feature geometries one, without unioning resolving internal boundaries","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_combine.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Combine or union feature geometries — geos_combine","text":"","code":"st_combine(x) st_union(x, y, ..., by_feature = FALSE, is_coverage = FALSE)"},{"path":"https://r-spatial.github.io/sf/reference/geos_combine.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Combine or union feature geometries — geos_combine","text":"x object class sf, sfc sfg y object class sf, sfc sfg (optional) ... ignored by_feature logical; TRUE, union feature y missing else pair features; FALSE return single feature geometric union set features x y missing, else unions elements Cartesian product sets is_coverage logical; TRUE, use optimized algorithm features form polygonal coverage (overlaps)","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_combine.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Combine or union feature geometries — geos_combine","text":"st_combine returns single, combined geometry, resolved boundaries; returned geometries may well invalid. y missing, st_union(x) returns single geometry resolved boundaries, else geometries unioned pairs x[] y[j].","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_combine.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Combine or union feature geometries — geos_combine","text":"st_combine combines geometries without resolving borders, using c.sfg (analogous c ordinary vectors). st_union called single argument, x, (y missing) by_feature FALSE geometries unioned together sfg single-geometry sfc object returned. by_feature TRUE feature geometry unioned individually. can instance used resolve internal boundaries polygons combined using st_combine. y provided, elements x y unioned, pairwise by_feature TRUE, else Cartesian product sets. Unioning set overlapping polygons effect merging areas (.e. effect iteratively unioning individual polygons together). Unioning set LineStrings effect fully noding dissolving input linework. context \"fully noded\" means node endpoint output every endpoint line segment crossing input. \"Dissolved\" means duplicate (e.g. coincident) line segments portions line segments reduced single line segment output.\tUnioning set Points effect merging identical points (producing set duplicates).","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/geos_combine.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Combine or union feature geometries — geos_combine","text":"","code":"nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 st_combine(nc) #> Geometry set for 1 feature #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 #> MULTIPOLYGON (((-81.47276 36.23436, -81.54084 3... plot(st_union(nc))"},{"path":"https://r-spatial.github.io/sf/reference/geos_measures.html","id":null,"dir":"Reference","previous_headings":"","what":"Compute geometric measurements — geos_measures","title":"Compute geometric measurements — geos_measures","text":"Compute Euclidean great circle distance pairs geometries; compute, area length set geometries.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_measures.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compute geometric measurements — geos_measures","text":"","code":"st_area(x, ...) # S3 method for class 'sfc' st_area(x, ...) st_length(x, ...) st_perimeter(x, ...) st_distance( x, y, ..., dist_fun, by_element = FALSE, which = ifelse(isTRUE(st_is_longlat(x)), \"Great Circle\", \"Euclidean\"), par = 0, tolerance = 0 )"},{"path":"https://r-spatial.github.io/sf/reference/geos_measures.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compute geometric measurements — geos_measures","text":"x object class sf, sfc sfg ... passed s2_distance, s2_distance_matrix, s2_perimeter y object class sf, sfc sfg, defaults x dist_fun deprecated by_element logical; TRUE, return vector distance first elements x y, second, etc; error raised x y length. FALSE, return dense matrix pairwise distances. character; Cartesian coordinates : one Euclidean, Hausdorff Frechet; geodetic coordinates, great circle distances computed; see details par equal Hausdorff Frechet, optionally use value 0 1 densify geometry tolerance ignored st_is_longlat(x) FALSE; otherwise, set positive value, first distance smaller tolerance returned, true distance may smaller; may speed computation. meters, units object convertible meters.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_measures.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compute geometric measurements — geos_measures","text":"coordinate reference system x set, functions return values unit measurement; see set_units. st_area returns area geometry, coordinate reference system used; case x degrees longitude/latitude, st_geod_area used area calculation. st_length returns length LINESTRING MULTILINESTRING geometry, using coordinate reference system. POINT, MULTIPOINT, POLYGON MULTIPOLYGON geometries return zero. by_element FALSE st_distance returns dense numeric matrix dimension length(x) length(y); otherwise returns numeric vector length x y error raised lengths x y unequal. Distances involving empty geometries NA.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_measures.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Compute geometric measurements — geos_measures","text":"great circle distance calculations use default spherical distances (s2_distance s2_distance_matrix); sf_use_s2() FALSE, ellipsoidal distances computed using st_geod_distance uses function geod_inverse GeographicLib (part PROJ); see Karney, Charles FF, 2013, Algorithms geodesics, Journal Geodesy 87(1), 43–55","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/geos_measures.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Compute geometric measurements — geos_measures","text":"","code":"b0 = st_polygon(list(rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1)))) b1 = b0 + 2 b2 = b0 + c(-0.2, 2) x = st_sfc(b0, b1, b2) st_area(x) #> [1] 4 4 4 line = st_sfc(st_linestring(rbind(c(30,30), c(40,40))), crs = 4326) st_length(line) #> 1435335 [m] 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) poly = st_polygon(list(outer, hole1, hole2)) mpoly = st_multipolygon(list( list(outer, hole1, hole2), list(outer + 12, hole1 + 12) )) st_length(st_sfc(poly, mpoly)) #> [1] 0 0 st_perimeter(poly) #> [1] 48 st_perimeter(mpoly) #> [1] 92 p = st_sfc(st_point(c(0,0)), st_point(c(0,1)), st_point(c(0,2))) st_distance(p, p) #> [,1] [,2] [,3] #> [1,] 0 1 2 #> [2,] 1 0 1 #> [3,] 2 1 0 st_distance(p, p, by_element = TRUE) #> [1] 0 0 0"},{"path":"https://r-spatial.github.io/sf/reference/geos_query.html","id":null,"dir":"Reference","previous_headings":"","what":"Dimension, simplicity, validity or is_empty queries on simple feature geometries — geos_query","title":"Dimension, simplicity, validity or is_empty queries on simple feature geometries — geos_query","text":"Dimension, simplicity, validity is_empty queries simple feature geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_query.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Dimension, simplicity, validity or is_empty queries on simple feature geometries — geos_query","text":"","code":"st_dimension(x, NA_if_empty = TRUE) st_is_simple(x) st_is_empty(x)"},{"path":"https://r-spatial.github.io/sf/reference/geos_query.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Dimension, simplicity, validity or is_empty queries on simple feature geometries — geos_query","text":"x object class sf, sfc sfg NA_if_empty logical; TRUE, return NA empty geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_query.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Dimension, simplicity, validity or is_empty queries on simple feature geometries — geos_query","text":"st_dimension returns numeric vector 0 points, 1 lines, 2 surfaces, , NA_if_empty TRUE, NA empty geometries. st_is_simple returns logical vector, indicating geometry whether simple (e.g., self-intersecting) st_is_empty returns geometry whether empty","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_query.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Dimension, simplicity, validity or is_empty queries on simple feature geometries — geos_query","text":"","code":"x = st_sfc( st_point(0:1), st_linestring(rbind(c(0,0),c(1,1))), st_polygon(list(rbind(c(0,0),c(1,0),c(0,1),c(0,0)))), st_multipoint(), st_linestring(), st_geometrycollection()) st_dimension(x) #> [1] 0 1 2 NA NA NA st_dimension(x, FALSE) #> [1] 0 1 2 0 1 0 ls = st_linestring(rbind(c(0,0), c(1,1), c(1,0), c(0,1))) st_is_simple(st_sfc(ls, st_point(c(0,0)))) #> [1] FALSE TRUE ls = st_linestring(rbind(c(0,0), c(1,1), c(1,0), c(0,1))) st_is_empty(st_sfc(ls, st_point(), st_linestring())) #> [1] FALSE TRUE TRUE"},{"path":"https://r-spatial.github.io/sf/reference/geos_unary.html","id":null,"dir":"Reference","previous_headings":"","what":"Geometric unary operations on simple feature geometry sets — geos_unary","title":"Geometric unary operations on simple feature geometry sets — geos_unary","text":"Geometric unary operations simple feature geometries. generics, methods sfg, sfc sf objects, returning object class. operations work per-feature basis, ignoring features.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_unary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Geometric unary operations on simple feature geometry sets — geos_unary","text":"","code":"st_buffer( x, dist, nQuadSegs = 30, endCapStyle = \"ROUND\", joinStyle = \"ROUND\", mitreLimit = 1, singleSide = FALSE, ... ) st_boundary(x) st_convex_hull(x) st_concave_hull(x, ratio, ..., allow_holes) st_simplify(x, preserveTopology, dTolerance = 0) st_triangulate(x, dTolerance = 0, bOnlyEdges = FALSE) st_triangulate_constrained(x) st_inscribed_circle(x, dTolerance, ...) st_minimum_rotated_rectangle(x, ...) st_voronoi(x, envelope, dTolerance = 0, bOnlyEdges = FALSE) st_polygonize(x) st_line_merge(x, ..., directed = FALSE) st_centroid(x, ..., of_largest_polygon = FALSE) st_point_on_surface(x) st_reverse(x) st_node(x) st_segmentize(x, dfMaxLength, ...) st_exterior_ring(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/geos_unary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Geometric unary operations on simple feature geometry sets — geos_unary","text":"x object class sfg, sfc sf dist numeric object class units; buffer distance , elements x. case x geodetic coordinates (lon/lat) sf_use_s2() TRUE, numeric dist taken distance meters units object dist converted meters. case x geodetic coordinates (lon/lat) sf_use_s2() FALSE, numeric dist taken degrees, units object dist converted arc_degree (warnings issued). case x geodetic coordinates (projected) numeric dist assumed units coordinates, units dist converted st_crs(x) NA. nQuadSegs integer; number segments per quadrant (fourth circle), per-feature; see details endCapStyle character; style line ends, one 'ROUND', 'FLAT', 'SQUARE'; see details joinStyle character; style line joins, one 'ROUND', 'MITRE', 'BEVEL'; see details mitreLimit numeric; limit extension join joinStyle 'MITRE' used (default 1.0, minimum 0.0); see details singleSide logical; TRUE, single-sided buffers returned linear geometries, case negative dist values give buffers right-hand side, positive left; see details ... st_buffer passed s2::s2_buffer_cells(), otherwise ignored ratio numeric; fraction convex: 1 returns convex hulls, 0 maximally concave hulls allow_holes logical; TRUE, resulting concave hull may holes preserveTopology logical; carry topology preserving simplification? May specified , feature geometries. Note topology preserved single feature geometries, sets . specified (.e. default), internally set equal FALSE input data specified projected coordinates sf_use_s2() returns FALSE. Ignored cases (warning set equal FALSE) since function implicitly calls s2::s2_simplify always preserve topological relationships (per single feature). dTolerance numeric; tolerance parameter, specified feature geometry. run st_simplify, input data specified long-lat coordinates sf_use_s2() returns TRUE, value dTolerance must specified meters. bOnlyEdges logical; TRUE, return lines, else return polygons envelope object class sfc sfg containing POLYGON envelope voronoi diagram; takes effect larger default envelope, chosen envelope empty polygon directed logical; TRUE, lines opposite directions merged of_largest_polygon logical; st_centroid: TRUE, return centroid largest (sub)polygon MULTIPOLYGON rather whole MULTIPOLYGON dfMaxLength maximum length line segment. x geographical coordinates (long/lat), dfMaxLength either numeric expressed meter, object class units length units rad degree; segmentation long/lat case takes place along great circle, using st_geod_segmentize.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_unary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Geometric unary operations on simple feature geometry sets — geos_unary","text":"object class x, manipulated geometry.","code":""},{"path":"https://r-spatial.github.io/sf/reference/geos_unary.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Geometric unary operations on simple feature geometry sets — geos_unary","text":"st_buffer computes buffer around geometry/geometry. Depending spatial coordinate system, different engine (GEOS S2) can used, different function arguments. nQuadSegs, endCapsStyle, joinStyle, mitreLimit singleSide parameters work GEOS engine used (.e. projected coordinates sf_use_s2() set FALSE). See postgis.net/docs/ST_Buffer.html details. max_cells min_level parameters (s2::s2_buffer_cells()) work S2 engine (.e. geographic coordinates) can used change buffer shape (e.g. smoothing). negative buffer returns empty polygons instead shrinking, set sf_use_s2() FALSE. st_boundary returns boundary geometry st_convex_hull creates convex hull set points st_concave_hull creates concave hull geometry st_simplify simplifies lines removing vertices. st_triangulate triangulates set points (constrained). st_triangulate requires GEOS version 3.4 st_triangulate_constrained returns constrained delaunay triangulation polygons; requires GEOS version 3.10 st_inscribed_circle returns maximum inscribed circle polygon geometries. st_inscribed_circle, nQuadSegs 0 2-point LINESTRING returned center point boundary point every circle, otherwise circle (buffer) returned nQuadSegs controls number points per quadrant approximate circle. st_inscribed_circle requires GEOS version 3.9 st_minimum_rotated_rectangle returns minimum rotated rectangular POLYGON encloses input geometry. rectangle width equal minimum diameter, longer length. convex hill input degenerate (line point) linestring point returned. st_voronoi creates voronoi tessellation. st_voronoi requires GEOS version 3.5 st_polygonize creates polygon lines form closed ring. case st_polygonize, x must object class LINESTRING MULTILINESTRING, sfc geometry list-column object containing st_line_merge merges lines. case st_line_merge, x must object class MULTILINESTRING, sfc geometry list-column object containing st_centroid gives centroid geometry st_point_on_surface returns point guaranteed (multi)surface. st_reverse reverses nodes line st_node adds nodes linear geometries intersections without node, works individual linear geometries st_segmentize adds points straight lines","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/geos_unary.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Geometric unary operations on simple feature geometry sets — geos_unary","text":"","code":"## st_buffer, style options (taken from rgeos gBuffer) l1 = st_as_sfc(\"LINESTRING(0 0,1 5,4 5,5 2,8 2,9 4,4 6.5)\") op = par(mfrow=c(2,3)) plot(st_buffer(l1, dist = 1, endCapStyle=\"ROUND\"), reset = FALSE, main = \"endCapStyle: ROUND\") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, endCapStyle=\"FLAT\"), reset = FALSE, main = \"endCapStyle: FLAT\") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, endCapStyle=\"SQUARE\"), reset = FALSE, main = \"endCapStyle: SQUARE\") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, nQuadSegs=1), reset = FALSE, main = \"nQuadSegs: 1\") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, nQuadSegs=2), reset = FALSE, main = \"nQuadSegs: 2\") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, nQuadSegs= 5), reset = FALSE, main = \"nQuadSegs: 5\") plot(l1,col='blue',add=TRUE) par(op) l2 = st_as_sfc(\"LINESTRING(0 0,1 5,3 2)\") op = par(mfrow = c(2, 3)) plot(st_buffer(l2, dist = 1, joinStyle=\"ROUND\"), reset = FALSE, main = \"joinStyle: ROUND\") plot(l2, col = 'blue', add = TRUE) plot(st_buffer(l2, dist = 1, joinStyle=\"MITRE\"), reset = FALSE, main = \"joinStyle: MITRE\") plot(l2, col= 'blue', add = TRUE) plot(st_buffer(l2, dist = 1, joinStyle=\"BEVEL\"), reset = FALSE, main = \"joinStyle: BEVEL\") plot(l2, col= 'blue', add=TRUE) plot(st_buffer(l2, dist = 1, joinStyle=\"MITRE\" , mitreLimit=0.5), reset = FALSE, main = \"mitreLimit: 0.5\") plot(l2, col = 'blue', add = TRUE) plot(st_buffer(l2, dist = 1, joinStyle=\"MITRE\",mitreLimit=1), reset = FALSE, main = \"mitreLimit: 1\") plot(l2, col = 'blue', add = TRUE) plot(st_buffer(l2, dist = 1, joinStyle=\"MITRE\",mitreLimit=3), reset = FALSE, main = \"mitreLimit: 3\") plot(l2, col = 'blue', add = TRUE) par(op) nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 nc_g = st_geometry(nc) plot(st_convex_hull(nc_g)) plot(nc_g, border = grey(.5), add = TRUE) pt = st_combine(st_sfc(st_point(c(0,80)), st_point(c(120,80)), st_point(c(240,80)))) st_convex_hull(pt) # R2 #> Geometry set for 1 feature #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 0 ymin: 80 xmax: 240 ymax: 80 #> CRS: NA #> LINESTRING (0 80, 240 80) st_convex_hull(st_set_crs(pt, 'OGC:CRS84')) # S2 #> Geometry set for 1 feature #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: -120 ymin: 80 xmax: 120 ymax: 80 #> Geodetic CRS: WGS 84 #> POLYGON ((-120 80, 0 80, 120 80, -120 80)) set.seed(131) if (compareVersion(sf_extSoftVersion()[[\"GEOS\"]], \"3.11.0\") > -1) { pts = cbind(runif(100), runif(100)) m = st_multipoint(pts) co = sf:::st_concave_hull(m, 0.3) coh = sf:::st_concave_hull(m, 0.3, allow_holes = TRUE) plot(co, col = 'grey') plot(coh, add = TRUE, border = 'red') plot(m, add = TRUE) } # st_simplify examples: op = par(mfrow = c(2, 3), mar = rep(0, 4)) plot(nc_g[1]) plot(st_simplify(nc_g[1], dTolerance = 1e3)) # 1000m plot(st_simplify(nc_g[1], dTolerance = 5e3)) # 5000m nc_g_planar = st_transform(nc_g, 2264) # planar coordinates, US foot plot(nc_g_planar[1]) plot(st_simplify(nc_g_planar[1], dTolerance = 1e3)) # 1000 foot plot(st_simplify(nc_g_planar[1], dTolerance = 5e3)) # 5000 foot par(op) if (compareVersion(sf_extSoftVersion()[[\"GEOS\"]], \"3.10.0\") > -1) { pts = rbind(c(0,0), c(1,0), c(1,1), c(.5,.5), c(0,1), c(0,0)) po = st_polygon(list(pts)) co = st_triangulate_constrained(po) tr = st_triangulate(po) plot(po, col = NA, border = 'grey', lwd = 15) plot(tr, border = 'green', col = NA, lwd = 5, add = TRUE) plot(co, border = 'red', col = 'NA', add = TRUE) } if (compareVersion(sf_extSoftVersion()[[\"GEOS\"]], \"3.9.0\") > -1) { nc_t = st_transform(nc, 'EPSG:2264') x = st_inscribed_circle(st_geometry(nc_t)) plot(st_geometry(nc_t), asp = 1, col = grey(.9)) plot(x, add = TRUE, col = '#ff9999') } set.seed(1) x = st_multipoint(matrix(runif(10),,2)) box = st_polygon(list(rbind(c(0,0),c(1,0),c(1,1),c(0,1),c(0,0)))) if (compareVersion(sf_extSoftVersion()[[\"GEOS\"]], \"3.5.0\") > -1) { v = st_sfc(st_voronoi(x, st_sfc(box))) plot(v, col = 0, border = 1, axes = TRUE) plot(box, add = TRUE, col = 0, border = 1) # a larger box is returned, as documented plot(x, add = TRUE, col = 'red', cex=2, pch=16) plot(st_intersection(st_cast(v), box)) # clip to smaller box plot(x, add = TRUE, col = 'red', cex=2, pch=16) # matching Voronoi polygons to data points: # https://github.com/r-spatial/sf/issues/1030 # generate 50 random unif points: n = 100 pts = st_as_sf(data.frame(matrix(runif(n), , 2), id = 1:(n/2)), coords = c(\"X1\", \"X2\")) # compute Voronoi polygons: pols = st_collection_extract(st_voronoi(do.call(c, st_geometry(pts)))) # match them to points: pts$pols = pols[unlist(st_intersects(pts, pols))] plot(pts[\"id\"], pch = 16) # ID is color plot(st_set_geometry(pts, \"pols\")[\"id\"], xlim = c(0,1), ylim = c(0,1), reset = FALSE) plot(st_geometry(pts), add = TRUE) layout(matrix(1)) # reset plot layout } mls = st_multilinestring(list(matrix(c(0,0,0,1,1,1,0,0),,2,byrow=TRUE))) st_polygonize(st_sfc(mls)) #> Geometry set for 1 feature #> Geometry type: GEOMETRYCOLLECTION #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> GEOMETRYCOLLECTION (POLYGON ((0 0, 0 1, 1 1, 0 ... mls = st_multilinestring(list(rbind(c(0,0), c(1,1)), rbind(c(2,0), c(1,1)))) st_line_merge(st_sfc(mls)) #> Geometry set for 1 feature #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 1 #> CRS: NA #> LINESTRING (0 0, 1 1, 2 0) plot(nc_g, axes = TRUE) plot(st_centroid(nc_g), add = TRUE, pch = 3, col = 'red') mp = st_combine(st_buffer(st_sfc(lapply(1:3, function(x) st_point(c(x,x)))), 0.2 * 1:3)) plot(mp) plot(st_centroid(mp), add = TRUE, col = 'red') # centroid of combined geometry plot(st_centroid(mp, of_largest_polygon = TRUE), add = TRUE, col = 'blue', pch = 3) plot(nc_g, axes = TRUE) plot(st_point_on_surface(nc_g), add = TRUE, pch = 3, col = 'red') #> Warning: st_point_on_surface may not give correct results for longitude/latitude data if (compareVersion(sf_extSoftVersion()[[\"GEOS\"]], \"3.7.0\") > -1) { st_reverse(st_linestring(rbind(c(1,1), c(2,2), c(3,3)))) } #> LINESTRING (3 3, 2 2, 1 1) (l = st_linestring(rbind(c(0,0), c(1,1), c(0,1), c(1,0), c(0,0)))) #> LINESTRING (0 0, 1 1, 0 1, 1 0, 0 0) st_polygonize(st_node(l)) #> GEOMETRYCOLLECTION (POLYGON ((0 0, 0.5 0.5, 1 0, 0 0)), POLYGON ((0.5 0.5, 0 1, 1 1, 0.5 0.5))) st_node(st_multilinestring(list(rbind(c(0,0), c(1,1), c(0,1), c(1,0), c(0,0))))) #> MULTILINESTRING ((0 0, 0.5 0.5), (0.5 0.5, 1 1, 0 1, 0.5 0.5), (0.5 0.5, 1 0, 0 0)) sf = st_sf(a=1, geom=st_sfc(st_linestring(rbind(c(0,0),c(1,1)))), crs = 4326) if (require(lwgeom, quietly = TRUE)) { seg = st_segmentize(sf, units::set_units(100, km)) seg = st_segmentize(sf, units::set_units(0.01, rad)) nrow(seg$geom[[1]]) } #> Linking to liblwgeom 3.0.0beta1 r16016, GEOS 3.10.2, PROJ 8.2.1 #> #> Attaching package: ‘lwgeom’ #> The following object is masked from ‘package:sf’: #> #> st_perimeter #> [1] 5"},{"path":"https://r-spatial.github.io/sf/reference/interpolate_aw.html","id":null,"dir":"Reference","previous_headings":"","what":"Areal-weighted interpolation of polygon data — interpolate_aw","title":"Areal-weighted interpolation of polygon data — interpolate_aw","text":"Areal-weighted interpolation polygon data","code":""},{"path":"https://r-spatial.github.io/sf/reference/interpolate_aw.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Areal-weighted interpolation of polygon data — interpolate_aw","text":"","code":"st_interpolate_aw(x, to, extensive, ...) # S3 method for class 'sf' st_interpolate_aw(x, to, extensive, ..., keep_NA = FALSE, na.rm = FALSE)"},{"path":"https://r-spatial.github.io/sf/reference/interpolate_aw.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Areal-weighted interpolation of polygon data — interpolate_aw","text":"x object class sf, want aggregate attributes object class sf sfc, target geometries extensive logical; TRUE, attribute variables assumed spatially extensive (like population) sum preserved, otherwise, spatially intensive (like population density) mean preserved. ... ignored keep_NA logical; TRUE, return features , FALSE return non-NA values (row.names index corresponding feature ) na.rm logical; TRUE remove features NA attributes x interpolating","code":""},{"path":"https://r-spatial.github.io/sf/reference/interpolate_aw.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Areal-weighted interpolation of polygon data — interpolate_aw","text":"extensive TRUE na.rm set TRUE, geometries NA effectively treated zero attribute values.","code":""},{"path":"https://r-spatial.github.io/sf/reference/interpolate_aw.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Areal-weighted interpolation of polygon data — interpolate_aw","text":"","code":"nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 g = st_make_grid(nc, n = c(10, 5)) a1 = st_interpolate_aw(nc[\"BIR74\"], g, extensive = FALSE) #> Warning: st_interpolate_aw assumes attributes are constant or uniform over areas of x sum(a1$BIR74) / sum(nc$BIR74) # not close to one: property is assumed spatially intensive #> [1] 0.4026287 a2 = st_interpolate_aw(nc[\"BIR74\"], g, extensive = TRUE) #> Warning: st_interpolate_aw assumes attributes are constant or uniform over areas of x # verify mass preservation (pycnophylactic) property: sum(a2$BIR74) / sum(nc$BIR74) #> [1] 0.9999998 a1$intensive = a1$BIR74 a1$extensive = a2$BIR74 plot(a1[c(\"intensive\", \"extensive\")], key.pos = 4)"},{"path":"https://r-spatial.github.io/sf/reference/is_driver_available.html","id":null,"dir":"Reference","previous_headings":"","what":"Check if driver is available — is_driver_available","title":"Check if driver is available — is_driver_available","text":"Search driver table driver listed","code":""},{"path":"https://r-spatial.github.io/sf/reference/is_driver_available.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check if driver is available — is_driver_available","text":"","code":"is_driver_available(drv, drivers = st_drivers())"},{"path":"https://r-spatial.github.io/sf/reference/is_driver_available.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check if driver is available — is_driver_available","text":"drv character. Name driver drivers data.frame. Table containing driver names support. Default st_drivers","code":""},{"path":"https://r-spatial.github.io/sf/reference/is_driver_can.html","id":null,"dir":"Reference","previous_headings":"","what":"Check if a driver can perform an action — is_driver_can","title":"Check if a driver can perform an action — is_driver_can","text":"Search driver table match driver name action (e.g. \"write\") check action supported.","code":""},{"path":"https://r-spatial.github.io/sf/reference/is_driver_can.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check if a driver can perform an action — is_driver_can","text":"","code":"is_driver_can(drv, drivers = st_drivers(), operation = \"write\")"},{"path":"https://r-spatial.github.io/sf/reference/is_driver_can.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check if a driver can perform an action — is_driver_can","text":"drv character. Name driver drivers data.frame. Table containing driver names support. Default st_drivers operation character. action check","code":""},{"path":"https://r-spatial.github.io/sf/reference/is_geometry_column.html","id":null,"dir":"Reference","previous_headings":"","what":"Check if the columns could be of a coercable type for sf — is_geometry_column","title":"Check if the columns could be of a coercable type for sf — is_geometry_column","text":"Check columns coercable type sf","code":""},{"path":"https://r-spatial.github.io/sf/reference/is_geometry_column.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check if the columns could be of a coercable type for sf — is_geometry_column","text":"","code":"is_geometry_column(con, x, classes = \"\")"},{"path":"https://r-spatial.github.io/sf/reference/is_geometry_column.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check if the columns could be of a coercable type for sf — is_geometry_column","text":"con database connection x inherits data.frame classes classes inherited","code":""},{"path":"https://r-spatial.github.io/sf/reference/merge.sf.html","id":null,"dir":"Reference","previous_headings":"","what":"merge method for sf and data.frame object — merge.sf","title":"merge method for sf and data.frame object — merge.sf","text":"merge method sf data.frame object","code":""},{"path":"https://r-spatial.github.io/sf/reference/merge.sf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"merge method for sf and data.frame object — merge.sf","text":"","code":"# S3 method for class 'sf' merge(x, y, ...)"},{"path":"https://r-spatial.github.io/sf/reference/merge.sf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"merge method for sf and data.frame object — merge.sf","text":"x object class sf y object class data.frame ... arguments passed merge.data.frame","code":""},{"path":"https://r-spatial.github.io/sf/reference/merge.sf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"merge method for sf and data.frame object — merge.sf","text":"","code":"a = data.frame(a = 1:3, b = 5:7) st_geometry(a) = st_sfc(st_point(c(0,0)), st_point(c(1,1)), st_point(c(2,2))) b = data.frame(x = c(\"a\", \"b\", \"c\"), b = c(2,5,6)) merge(a, b) #> Simple feature collection with 2 features and 3 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> b a x geometry #> 1 5 1 b POINT (0 0) #> 2 6 2 c POINT (1 1) merge(a, b, all = TRUE) #> Simple feature collection with 4 features and 3 fields (with 1 geometry empty) #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 2 #> CRS: NA #> b a x geometry #> 1 2 NA a GEOMETRYCOLLECTION EMPTY #> 2 5 1 b POINT (0 0) #> 3 6 2 c POINT (1 1) #> 4 7 3 POINT (2 2)"},{"path":"https://r-spatial.github.io/sf/reference/nc.html","id":null,"dir":"Reference","previous_headings":"","what":"North Carolina SIDS data — nc","title":"North Carolina SIDS data — nc","text":"Sudden Infant Death Syndrome (SIDS) sample data North Carolina counties, two time periods (1974-78 1979-84). details columns can found spdep package vignette. Please note , though basically nc.sids dataset spData package, nc contains subset variables. differences also discussed vignette.","code":""},{"path":"https://r-spatial.github.io/sf/reference/nc.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"North Carolina SIDS data — nc","text":"sf object","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/nc.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"North Carolina SIDS data — nc","text":"","code":"# \\donttest{ nc <- st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 # }"},{"path":"https://r-spatial.github.io/sf/reference/plot.html","id":null,"dir":"Reference","previous_headings":"","what":"plot sf object — plot","title":"plot sf object — plot","text":"plot one attributes sf object map Plot sf object","code":""},{"path":"https://r-spatial.github.io/sf/reference/plot.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"plot sf object — plot","text":"","code":"# S3 method for class 'sf' plot( x, y, ..., main, pal = NULL, nbreaks = 10, breaks = \"pretty\", max.plot = getOption(\"sf_max.plot\", default = 9), key.pos = get_key_pos(x, ...), key.length = 0.618, key.width = kw_dflt(x, key.pos), reset = TRUE, logz = FALSE, extent = x, xlim = st_bbox(extent)[c(1, 3)], ylim = st_bbox(extent)[c(2, 4)], compact = FALSE ) get_key_pos(x, ...) # S3 method for class 'sfc_POINT' plot( x, y, ..., pch = 1, cex = 1, col = 1, bg = 0, lwd = 1, lty = 1, type = \"p\", add = FALSE ) # S3 method for class 'sfc_MULTIPOINT' plot( x, y, ..., pch = 1, cex = 1, col = 1, bg = 0, lwd = 1, lty = 1, type = \"p\", add = FALSE ) # S3 method for class 'sfc_LINESTRING' plot(x, y, ..., lty = 1, lwd = 1, col = 1, pch = 1, type = \"l\", add = FALSE) # S3 method for class 'sfc_CIRCULARSTRING' plot(x, y, ...) # S3 method for class 'sfc_MULTILINESTRING' plot(x, y, ..., lty = 1, lwd = 1, col = 1, pch = 1, type = \"l\", add = FALSE) # S3 method for class 'sfc_POLYGON' plot( x, y, ..., lty = 1, lwd = 1, col = NA, cex = 1, pch = NA, border = 1, add = FALSE, rule = \"evenodd\", xpd = par(\"xpd\") ) # S3 method for class 'sfc_MULTIPOLYGON' plot( x, y, ..., lty = 1, lwd = 1, col = NA, border = 1, add = FALSE, rule = \"evenodd\", xpd = par(\"xpd\") ) # S3 method for class 'sfc_GEOMETRYCOLLECTION' plot( x, y, ..., pch = 1, cex = 1, bg = 0, lty = 1, lwd = 1, col = 1, border = 1, add = FALSE ) # S3 method for class 'sfc_GEOMETRY' plot( x, y, ..., pch = 1, cex = 1, bg = 0, lty = 1, lwd = 1, col = ifelse(st_dimension(x) == 2, NA, 1), border = 1, add = FALSE ) # S3 method for class 'sfg' plot(x, ...) plot_sf( x, xlim = NULL, ylim = NULL, asp = NA, axes = FALSE, bgc = par(\"bg\"), ..., xaxs, yaxs, lab, setParUsrBB = FALSE, bgMap = NULL, expandBB = c(0, 0, 0, 0), graticule = NA_crs_, col_graticule = \"grey\", border, extent = x ) sf.colors(n = 10, cutoff.tails = c(0.35, 0.2), alpha = 1, categorical = FALSE) # S3 method for class 'sf' text(x, labels = row.names(x), ...) # S3 method for class 'sfc' text(x, labels = seq_along(x), ..., of_largest_polygon = FALSE) # S3 method for class 'sf' points(x, ...) # S3 method for class 'sfc' points(x, ..., of_largest_polygon = FALSE)"},{"path":"https://r-spatial.github.io/sf/reference/plot.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"plot sf object — plot","text":"x object class sf y ignored ... specifications, see plot_sf plot details. main title plot (NULL remove) pal palette function, similar rainbow, palette values; omitted, sf.colors used nbreaks number colors breaks (ignored factor character variables) breaks either numeric vector actual breaks, name method accepted style argument classIntervals max.plot integer; lower boundary maximum number attributes plot; default value (9) can overridden setting global option sf_max.plot, e.g. options(sf_max.plot=2) key.pos numeric; side plot color key: 1 bottom, 2 left, 3 top, 4 right; set NULL omit key completely, 0 plot key, -1 select automatically. multiple columns plotted single function call default key plotted every submap stretched individually; key requested (col missing) maps colored according single key. Auto select depends plot size, map aspect, , set, parameter asp. lenght 2, second value, ranging 0 1, determines key placed available space (default: 0.5, center). key.length amount space reserved key along axis, length scale bar key.width amount space reserved key (incl. labels), thickness/width scale bar reset logical; FALSE, keep plot mode allows adding map elements; TRUE restore original mode plotting sf objects attributes; see details. logz logical; TRUE, use log10-scale attribute variable. case, breaks need given log10-values; see examples. extent object st_bbox method define plot extent; defaults x xlim see plot.window ylim see plot.window compact logical; compact sub-plots plotting space? pch plotting symbol cex symbol size col color plotting features; length(col) equal 1 nrow(x), warning emitted colors recycled. Specifying col suppresses plotting legend key. bg symbol background color lwd line width lty line type type plot type: 'p' points, 'l' lines, 'b' add logical; add current plot? Note using add=TRUE, may set reset=FALSE first plot command. border color polygon border(s); using NA hides rule see polypath; winding, exterior ring direction opposite holes; evenodd, plotting robust misspecified ring directions xpd see par; sets polygon clipping strategy; implemented POLYGON MULTIPOLYGON asp see , see par axes logical; axes plotted? (default FALSE) bgc background color xaxs see par yaxs see par lab see par setParUsrBB default FALSE; set par “usr” bounding box; see bgMap object class ggmap, returned function RgoogleMaps::GetMap expandBB numeric; fractional values expand bounding box , direction (bottom, left, top, right) graticule logical, object class crs (e.g., st_crs(4326) WGS84 graticule), object created st_graticule; TRUE give WGS84 graticule object returned st_graticule col_graticule color used graticule (present) n integer; number colors cutoff.tails numeric, [0,0.5] start end values alpha numeric, [0,1], transparency categorical logical; want colors categorical variable? (see details) labels character, text draw (one per row input) of_largest_polygon logical, passed st_centroid","code":""},{"path":"https://r-spatial.github.io/sf/reference/plot.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"plot sf object — plot","text":"plot.sf maximally plots max.plot maps colors following attribute columns, one map per attribute. uses sf.colors default colors. control placement individual maps, set parameter mfrow par prior plotting, plot single maps one one; note works combination setting parameters key.pos=NULL (legend) reset=FALSE. plot.sfc plots geometry, additional parameters can passed control color, lines symbols. setting reset FALSE, original device parameters lost, device must reset using dev.() order reset . parameter can set specify labels placed along key; see examples. features plotted order apppear sf object. See examples different plotting order wanted. plot_sf sets plotting area, axes, graticule, webmap background; called plot methods anything drawn. argument setParUsrBB may used pass logical value TRUE functions within plot.Spatial. set TRUE, par(“usr”) overwritten c(xlim, ylim), defaults bounding box spatial object. needed particular context graphic output specified device given width height, matched spatial object, using par(“xaxs”) par(“yaxs”) addition par(mar=c(0,0,0,0)). default aspect map plots 1; however data projected (coordinates long/lat), aspect default set 1/cos(* pi/180) y coordinate middle map (mean ylim, defaults y range bounding box). implies Equirectangular projection. non-categorical colors sf.colors taken bpy.colors, modified cutoff.tails defaults categorical TRUE, default colors https://colorbrewer2.org/ (n < 9, Set2, else Set3). text.sf adds text existing base graphic. Text placed centroid feature x. Provide POINT features control placement. points.sf adds point symbols existing base graphic. points text shown correctly, try setting argument reset FALSE plot() call.","code":""},{"path":"https://r-spatial.github.io/sf/reference/plot.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"plot sf object — plot","text":"","code":"nc = st_read(system.file(\"gpkg/nc.gpkg\", package=\"sf\"), quiet = TRUE) # plot single attribute, auto-legend: plot(nc[\"SID74\"]) # plot multiple: plot(nc[c(\"SID74\", \"SID79\")]) # better use ggplot2::geom_sf to facet and get a single legend! # adding to a plot of an sf object only works when using reset=FALSE in the first plot: plot(nc[\"SID74\"], reset = FALSE) plot(st_centroid(st_geometry(nc)), add = TRUE) # log10 z-scale: plot(nc[\"SID74\"], logz = TRUE, breaks = c(0,.5,1,1.5,2), at = c(0,.5,1,1.5,2)) # and we need to reset the plotting device after that, e.g. by layout(1) # when plotting only geometries, the reset=FALSE is not needed: plot(st_geometry(nc)) plot(st_geometry(nc)[1], col = 'red', add = TRUE) # add a custom legend to an arbitray plot: layout(matrix(1:2, ncol = 2), widths = c(1, lcm(2))) plot(1) .image_scale(1:10, col = sf.colors(9), key.length = lcm(8), key.pos = 4, at = 1:10) # manipulate plotting order, plot largest polygons first: p = st_polygon(list(rbind(c(0,0), c(1,0), c(1,1), c(0,1), c(0,0)))) x = st_sf(a=1:4, st_sfc(p, p * 2, p * 3, p * 4)) # plot(x, col=2:5) only shows the largest polygon! plot(x[order(st_area(x), decreasing = TRUE),], col = 2:5) # plot largest polygons first sf.colors(10) #> [1] \"#0000B3FF\" \"#0400FFFF\" \"#4500FFFF\" \"#8500FFFF\" \"#C527D8FF\" \"#FF50AFFF\" #> [7] \"#FF7A85FF\" \"#FFA35CFF\" \"#FFCC33FF\" \"#FFF50AFF\" text(nc, labels = substring(nc$NAME,1,1))"},{"path":"https://r-spatial.github.io/sf/reference/prefix_map.html","id":null,"dir":"Reference","previous_headings":"","what":"Map prefix to driver — prefix_map","title":"Map prefix to driver — prefix_map","text":"Map prefix driver","code":""},{"path":"https://r-spatial.github.io/sf/reference/prefix_map.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Map prefix to driver — prefix_map","text":"","code":"prefix_map"},{"path":"https://r-spatial.github.io/sf/reference/prefix_map.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Map prefix to driver — prefix_map","text":"object class list length 10.","code":""},{"path":"https://r-spatial.github.io/sf/reference/proj_tools.html","id":null,"dir":"Reference","previous_headings":"","what":"Manage PROJ settings — proj_tools","title":"Manage PROJ settings — proj_tools","text":"Query manage PROJ search path network settings","code":""},{"path":"https://r-spatial.github.io/sf/reference/proj_tools.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Manage PROJ settings — proj_tools","text":"","code":"sf_proj_search_paths(paths = character(0), with_proj = NA) sf_proj_network(enable = FALSE, url = character(0)) sf_proj_pipelines( source_crs, target_crs, authority = character(0), AOI = numeric(0), Use = \"NONE\", grid_availability = \"USED\", desired_accuracy = -1, strict_containment = FALSE, axis_order_authority_compliant = st_axis_order() )"},{"path":"https://r-spatial.github.io/sf/reference/proj_tools.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Manage PROJ settings — proj_tools","text":"paths search path set; omit paths need queried with_proj logical; NA set GDAL PROJ, otherwise set either PROJ (TRUE) GDAL (FALSE) enable logical; set enable (TRUE) disable (FALSE) proj network search facility url character; use specify override default proj network CDN source_crs, target_crs object class crs character authority character; constrain output pipelines authority AOI length four numeric; desired area interest resulting coordinate transformations (west, south, east, north, degrees). area interest crossing anti-meridian, west greater east. Use one \"NONE\", \"\", \"INTERSECTION\", \"SMALLEST\", indicating AOI's source_crs target_crs used grid_availability character; one \"USED\" (Grid availability used sorting results. Operations grids missing sorted last), \"DISCARD\" (Completely discard operation required grid missing) , \"IGNORED\" (Ignore grid availability . Results presented grids available.), \"AVAILABLE\" (Results presented grids known PROJ (registered grid_alternatives table database) available. Used typically networking enabled.) desired_accuracy numeric; return pipelines least accuracy strict_containment logical; default FALSE; permit partial matching area interest; TRUE strictly contain area interest. area interest either given AOI, implied source/target coordinate reference systems axis_order_authority_compliant logical; FALSE always choose ‘x’ longitude first axis; TRUE, follow axis orders given coordinate reference systems constructing first axis; FALSE, follow axis orders given ","code":""},{"path":"https://r-spatial.github.io/sf/reference/proj_tools.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Manage PROJ settings — proj_tools","text":"sf_proj_search_paths() returns search path (possibly setting ) sf_proj_network called without arguments returns logical indicating whether network search datum grids enabled, called arguments returns character vector URL CDN used (specified url). sf_proj_pipelines() returns table candidate coordinate transformation pipelines along accuracy; NA accuracy indicates ballpark accuracy.","code":""},{"path":"https://r-spatial.github.io/sf/reference/rawToHex.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert raw vector(s) into hexadecimal character string(s) — rawToHex","title":"Convert raw vector(s) into hexadecimal character string(s) — rawToHex","text":"Convert raw vector(s) hexadecimal character string(s)","code":""},{"path":"https://r-spatial.github.io/sf/reference/rawToHex.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert raw vector(s) into hexadecimal character string(s) — rawToHex","text":"","code":"rawToHex(x)"},{"path":"https://r-spatial.github.io/sf/reference/rawToHex.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert raw vector(s) into hexadecimal character string(s) — rawToHex","text":"x raw vector, list raw vectors","code":""},{"path":"https://r-spatial.github.io/sf/reference/reexports.html","id":null,"dir":"Reference","previous_headings":"","what":"Objects exported from other packages — reexports","title":"Objects exported from other packages — reexports","text":"objects imported packages. Follow links see documentation. magrittr %>%","code":""},{"path":"https://r-spatial.github.io/sf/reference/s2.html","id":null,"dir":"Reference","previous_headings":"","what":"functions for spherical geometry, using s2 package — s2","title":"functions for spherical geometry, using s2 package — s2","text":"functions spherical geometry, using s2 package based google s2geometry.io library","code":""},{"path":"https://r-spatial.github.io/sf/reference/s2.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"functions for spherical geometry, using s2 package — s2","text":"","code":"sf_use_s2(use_s2) st_as_s2(x, ...) # S3 method for class 'sf' st_as_s2(x, ...) # S3 method for class 'sfc' st_as_s2( x, ..., oriented = getOption(\"s2_oriented\", FALSE) || isTRUE(attr(x, \"oriented\")), rebuild = FALSE )"},{"path":"https://r-spatial.github.io/sf/reference/s2.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"functions for spherical geometry, using s2 package — s2","text":"use_s2 logical; TRUE, use s2 spherical geometry package geographical coordinate operations x object class sf, sfc sfg ... passed oriented logical; FALSE, polygons cover half globe inverted; TRUE, reversal takes place assumed inside polygon left polygon's path. rebuild logical; call s2_rebuild geometry (think st_make_valid sphere)","code":""},{"path":"https://r-spatial.github.io/sf/reference/s2.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"functions for spherical geometry, using s2 package — s2","text":"sf_use_s2 returns value variable (re)setting , invisibly use_s2 missing.","code":""},{"path":"https://r-spatial.github.io/sf/reference/s2.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"functions for spherical geometry, using s2 package — s2","text":"st_as_s2 converts sf POLYGON object form readable s2.","code":""},{"path":"https://r-spatial.github.io/sf/reference/s2.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"functions for spherical geometry, using s2 package — s2","text":"","code":"m = rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1)) m1 = rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,0), c(-1,-1)) m0 = m[5:1,] mp = st_multipolygon(list( list(m, 0.8 * m0, 0.01 * m1 + 0.9), list(0.7* m, 0.6*m0), list(0.5 * m0), list(m+2), list(m+4,(.9*m0)+4) )) sf = st_sfc(mp, mp, crs = 'EPSG:4326') s2 = st_as_s2(sf)"},{"path":"https://r-spatial.github.io/sf/reference/sf-defunct.html","id":null,"dir":"Reference","previous_headings":"","what":"Deprecated functions in sf — sf-defunct","title":"Deprecated functions in sf — sf-defunct","text":"functions provided compatibility older version sf. eventually completely removed. Use st_read() instead st_read_db(). Use st_write() instead_of st_write_db()","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf-defunct.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Deprecated functions in sf — sf-defunct","text":"","code":"st_read_db( conn = NULL, table = NULL, query = NULL, geom_column = NULL, EWKB = TRUE, ... ) st_write_db( conn = NULL, obj, table = deparse(substitute(obj)), ..., drop = FALSE, append = FALSE )"},{"path":"https://r-spatial.github.io/sf/reference/sf-defunct.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Deprecated functions in sf — sf-defunct","text":"conn open database connection table table name query SQL query select records; see details geom_column deprecated. Geometry column name EWKB logical; WKB type EWKB? missing, defaults TRUE ... parameter(s) passed st_as_sf","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf-defunct.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Deprecated functions in sf — sf-defunct","text":"geom_column argument deprecated. function automatically find geometry type columns. RPostgreSQL drivers try cast character columns, can long wide tables.","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf-package.html","id":null,"dir":"Reference","previous_headings":"","what":"sf: Simple Features for R — sf-package","title":"sf: Simple Features for R — sf-package","text":"Support simple features, standardized way encode spatial vector data. Binds 'GDAL' reading writing data, 'GEOS' geometrical operations, 'PROJ' projection conversions datum transformations. Uses default 's2' package spherical geometry operations ellipsoidal (long/lat) coordinates.","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf-package.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"sf: Simple Features for R — sf-package","text":"Pebesma, E. Bivand, R. (2023). Spatial Data Science: Applications R. Chapman Hall/CRC. doi:10.1201/9780429459016 also found freely online https://r-spatial.org/book/ Pebesma, E., 2018. Simple Features R: Standardized Support Spatial Vector Data. R Journal 10 (1), 439-446, doi:10.32614/RJ-2018-009 (open access)","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/sf-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"sf: Simple Features for R — sf-package","text":"Maintainer: Edzer Pebesma edzer.pebesma@uni-muenster.de (ORCID) contributors: Roger Bivand (ORCID) [contributor] Etienne Racine [contributor] Michael Sumner [contributor] Ian Cook [contributor] Tim Keitt [contributor] Robin Lovelace [contributor] Hadley Wickham [contributor] Jeroen Ooms (ORCID) [contributor] Kirill Müller [contributor] Thomas Lin Pedersen [contributor] Dan Baston [contributor] Dewey Dunnington (ORCID) [contributor]","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf.html","id":null,"dir":"Reference","previous_headings":"","what":"Create sf object — sf","title":"Create sf object — sf","text":"Create sf, extends data.frame-like objects simple feature list column. convert data frame object sf, use st_as_sf()","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create sf object — sf","text":"","code":"st_sf( ..., agr = NA_agr_, row.names, stringsAsFactors = sf_stringsAsFactors(), crs, precision, sf_column_name = NULL, check_ring_dir = FALSE, sfc_last = TRUE ) # S3 method for class 'sf' x[i, j, ..., drop = FALSE, op = st_intersects] # S3 method for class 'sf' print(x, ..., n = getOption(\"sf_max_print\", default = 10))"},{"path":"https://r-spatial.github.io/sf/reference/sf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create sf object — sf","text":"... column elements binded sf object single list data.frame columns; least one columns shall geometry list-column class sfc list-column can converted sfc st_as_sfc. agr character vector; see details . row.names row.names created sf object stringsAsFactors logical; see st_read crs coordinate reference system, something suitable input st_crs precision numeric; see st_as_binary sf_column_name character; name active list-column simple feature geometries; case one sf_column_name NULL, first one taken. check_ring_dir see st_read sfc_last logical; TRUE, sfc columns always put last, otherwise column order left unmodified. x object class sf record selection, see [.data.frame, sf object work op argument j variable selection, see [.data.frame drop logical, default FALSE; TRUE drop geometry column return data.frame, else make geometry sticky return sf object. op function; geometrical binary predicate function apply simple feature object n maximum number features print; can set globally options(sf_max_print=...)","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create sf object — sf","text":"agr, attribute-geometry-relationship, specifies non-geometry attribute column relates geometry, can one following values: \"constant\", \"aggregate\", \"identity\". \"constant\" used attributes constant throughout geometry (e.g. land use), \"aggregate\" attribute aggregate value geometry (e.g. population density population count), \"identity\" attributes uniquely identifies geometry particular \"thing\", building ID city name. default value, NA_agr_, implies know. single value provided agr, cascaded across input columns; otherwise, named vector like c(feature1='constant', ...) set agr value 'constant' input column named feature1. See demo(nc) worked example . confronted data.frame-like object, st_sf try find geometry column class sfc, otherwise try convert list-columns available geometry column, using st_as_sfc. [.sf return data.frame vector geometry column (class sfc) dropped (drop=TRUE), sfc object geometry column selected, otherwise return sf object; see also [.data.frame; [.sf ... arguments passed op.","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create sf object — sf","text":"","code":"g = st_sfc(st_point(1:2)) st_sf(a=3,g) #> Simple feature collection with 1 feature and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2 #> CRS: NA #> a g #> 1 3 POINT (1 2) st_sf(g, a=3) #> Simple feature collection with 1 feature and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2 #> CRS: NA #> a g #> 1 3 POINT (1 2) st_sf(a=3, st_sfc(st_point(1:2))) # better to name it! #> Simple feature collection with 1 feature and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2 #> CRS: NA #> a st_sfc.st_point.1.2.. #> 1 3 POINT (1 2) # create empty structure with preallocated empty geometries: nrows <- 10 geometry = st_sfc(lapply(1:nrows, function(x) st_geometrycollection())) df <- st_sf(id = 1:nrows, geometry = geometry) g = st_sfc(st_point(1:2), st_point(3:4)) s = st_sf(a=3:4, g) s[1,] #> Simple feature collection with 1 feature and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2 #> CRS: NA #> a g #> 1 3 POINT (1 2) class(s[1,]) #> [1] \"sf\" \"data.frame\" s[,1] #> Simple feature collection with 2 features and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 3 ymax: 4 #> CRS: NA #> a g #> 1 3 POINT (1 2) #> 2 4 POINT (3 4) class(s[,1]) #> [1] \"sf\" \"data.frame\" s[,2] #> Simple feature collection with 2 features and 0 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 3 ymax: 4 #> CRS: NA #> g #> 1 POINT (1 2) #> 2 POINT (3 4) class(s[,2]) #> [1] \"sf\" \"data.frame\" g = st_sf(a=2:3, g) pol = st_sfc(st_polygon(list(cbind(c(0,3,3,0,0),c(0,0,3,3,0))))) h = st_sf(r = 5, pol) g[h,] #> Simple feature collection with 1 feature and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2 #> CRS: NA #> a g #> 1 2 POINT (1 2) h[g,] #> Simple feature collection with 1 feature and 1 field #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 3 ymax: 3 #> CRS: NA #> r pol #> 1 5 POLYGON ((0 0, 3 0, 3 3, 0 ..."},{"path":"https://r-spatial.github.io/sf/reference/sf_extSoftVersion.html","id":null,"dir":"Reference","previous_headings":"","what":"Provide the external dependencies versions of the libraries linked to sf — sf_extSoftVersion","title":"Provide the external dependencies versions of the libraries linked to sf — sf_extSoftVersion","text":"Provide external dependencies versions libraries linked sf","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf_extSoftVersion.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Provide the external dependencies versions of the libraries linked to sf — sf_extSoftVersion","text":"","code":"sf_extSoftVersion()"},{"path":"https://r-spatial.github.io/sf/reference/sf_project.html","id":null,"dir":"Reference","previous_headings":"","what":"directly transform a set of coordinates — sf_project","title":"directly transform a set of coordinates — sf_project","text":"directly transform set coordinates","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf_project.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"directly transform a set of coordinates — sf_project","text":"","code":"sf_add_proj_units() sf_project( from = character(0), to = character(0), pts, keep = FALSE, warn = TRUE, authority_compliant = st_axis_order() )"},{"path":"https://r-spatial.github.io/sf/reference/sf_project.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"directly transform a set of coordinates — sf_project","text":"character description source CRS, object class crs, pipeline describing transformation character description target CRS, object class crs pts two-, three- four-column numeric matrix, object can coerced matrix; columns 3 4 contain z t values. keep logical value controlling handling unprojectable points. keep TRUE, points yield Inf -Inf return value; otherwise error reported nothing returned. warn logical; TRUE, warn non-finite values generated authority_compliant logical; TRUE means handle axis order authority compliant (e.g. EPSG:4326 implying x=lat, y=lon), FALSE means use visualisation order (.e. always x=lon, y=lat)","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf_project.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"directly transform a set of coordinates — sf_project","text":"two-column numeric matrix transformed/converted coordinates, returning invalid values Inf","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf_project.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"directly transform a set of coordinates — sf_project","text":"sf_add_proj_units loads PROJ units link, us_in, ind_yd, ind_ft, ind_ch udunits database, returns TRUE invisibly success.","code":""},{"path":"https://r-spatial.github.io/sf/reference/sf_project.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"directly transform a set of coordinates — sf_project","text":"","code":"sf_add_proj_units()"},{"path":"https://r-spatial.github.io/sf/reference/sfc.html","id":null,"dir":"Reference","previous_headings":"","what":"Create simple feature geometry list column — sfc","title":"Create simple feature geometry list column — sfc","text":"Create simple feature geometry list column, set class, add coordinate reference system precision. data.frame alternatives see st_sf(). convert foreign object sfc, see st_as_sfc()","code":""},{"path":"https://r-spatial.github.io/sf/reference/sfc.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create simple feature geometry list column — sfc","text":"","code":"st_sfc( ..., crs = NA_crs_, precision = 0, check_ring_dir = FALSE, dim, recompute_bbox = FALSE, oriented = NA ) # S3 method for class 'sfc' x[i, j, ..., op = st_intersects]"},{"path":"https://r-spatial.github.io/sf/reference/sfc.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create simple feature geometry list column — sfc","text":"... zero simple feature geometries (objects class sfg), single list objects; NULL values get replaced empty geometries. crs coordinate reference system: integer EPSG code, character proj4string precision numeric; see st_as_binary check_ring_dir see st_read dim character; function called without valid geometries, argument may carry right dimension set empty geometries recompute_bbox logical; use TRUE force recomputation bounding box oriented logical; TRUE, ring oriented left edges inside polygon; needed convering polygons larger half globe s2 x object class sfc record selection. Might also sfc/sf object work op argument j ignored op specified op function, geometrical binary predicate function apply sf/sfc object. Additional arguments can specified using ..., see examples.","code":""},{"path":"https://r-spatial.github.io/sf/reference/sfc.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create simple feature geometry list column — sfc","text":"object class sfc, classed list-column simple feature geometries.","code":""},{"path":"https://r-spatial.github.io/sf/reference/sfc.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create simple feature geometry list column — sfc","text":"simple feature geometry list-column list class c(\"stc_TYPE\", \"sfc\") often contains objects identical type; case mix types empty set, TYPE set superclass GEOMETRY. x dim attribute (.e. array matrix) op used.","code":""},{"path":"https://r-spatial.github.io/sf/reference/sfc.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create simple feature geometry list column — sfc","text":"","code":"pt1 = st_point(c(0,1)) pt2 = st_point(c(1,1)) (sfc = st_sfc(pt1, pt2)) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 1 ymax: 1 #> CRS: NA #> POINT (0 1) #> POINT (1 1) sfc[sfc[1], op = st_is_within_distance, dist = 0.5] #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 0 ymax: 1 #> CRS: NA #> POINT (0 1) d = st_sf(data.frame(a=1:2, geom=sfc))"},{"path":"https://r-spatial.github.io/sf/reference/sgbp.html","id":null,"dir":"Reference","previous_headings":"","what":"Methods for dealing with sparse geometry binary predicate lists — sgbp","title":"Methods for dealing with sparse geometry binary predicate lists — sgbp","text":"Methods dealing sparse geometry binary predicate lists","code":""},{"path":"https://r-spatial.github.io/sf/reference/sgbp.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Methods for dealing with sparse geometry binary predicate lists — sgbp","text":"","code":"# S3 method for class 'sgbp' print(x, ..., n = 10, max_nb = 10) # S3 method for class 'sgbp' t(x) # S3 method for class 'sgbp' as.matrix(x, ...) # S3 method for class 'sgbp' dim(x) # S3 method for class 'sgbp' Ops(e1, e2) # S3 method for class 'sgbp' as.data.frame(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/sgbp.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Methods for dealing with sparse geometry binary predicate lists — sgbp","text":"x object class sgbp ... ignored n integer; maximum number items print max_nb integer; maximum number neighbours print item e1 object class sgbp e2 object class sgbp","code":""},{"path":"https://r-spatial.github.io/sf/reference/sgbp.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Methods for dealing with sparse geometry binary predicate lists — sgbp","text":"sgbp sparse matrices, stored list integer vectors holding ordered TRUE indices row. means dense, \\(m \\times n\\) matrix Q list L, Q[,j] TRUE \\(j\\) element L[[]]. Reversed: \\(k\\) value L[[]][j], Q[,k] TRUE. == compares dimension index values, attributes two sgbp object; use identical check equality everything.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st.html","id":null,"dir":"Reference","previous_headings":"","what":"Create simple feature from a numeric vector, matrix or list — st","title":"Create simple feature from a numeric vector, matrix or list — st","text":"Create simple feature numeric vector, matrix list","code":""},{"path":"https://r-spatial.github.io/sf/reference/st.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create simple feature from a numeric vector, matrix or list — st","text":"","code":"st_point(x = c(NA_real_, NA_real_), dim = \"XYZ\") st_multipoint(x = matrix(numeric(0), 0, 2), dim = \"XYZ\") st_linestring(x = matrix(numeric(0), 0, 2), dim = \"XYZ\") st_polygon(x = list(), dim = if (length(x)) \"XYZ\" else \"XY\") st_multilinestring(x = list(), dim = if (length(x)) \"XYZ\" else \"XY\") st_multipolygon(x = list(), dim = if (length(x)) \"XYZ\" else \"XY\") st_geometrycollection(x = list(), dims = \"XY\") # S3 method for class 'sfg' print(x, ..., width = 0) # S3 method for class 'sfg' head(x, n = 10L, ...) # S3 method for class 'sfg' format(x, ..., width = 30) # S3 method for class 'sfg' c(..., recursive = FALSE, flatten = TRUE) # S3 method for class 'sfg' as.matrix(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create simple feature from a numeric vector, matrix or list — st","text":"x st_point, numeric vector (one-row-matrix) length 2, 3 4; st_linestring st_multipoint, numeric matrix points rows; st_polygon st_multilinestring, list numeric matrices points rows; st_multipolygon, list lists numeric matrices; st_geometrycollection list (non-geometrycollection) simple feature geometry (sfg) objects; see examples dim character, indicating dimensions: \"XY\", \"XYZ\", \"XYM\", \"XYZM\"; really needed three-dimensional points (can either XYZ XYM) empty geometries; see details dims character; specify dimensionality case empty (NULL) geometrycollection, case x empty list(). ... objects pasted together single simple feature width integer; number characters printed (max 30; 0 means print everything) n integer; number elements selected recursive logical; ignored flatten logical; TRUE, try simplify results; FALSE, return geometrycollection containing objects","code":""},{"path":"https://r-spatial.github.io/sf/reference/st.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create simple feature from a numeric vector, matrix or list — st","text":"object nature x, appropriate class attribute set .matrix returns set points form geometry single matrix, point row; use unlist(x, recursive = FALSE) get sets matrices.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create simple feature from a numeric vector, matrix or list — st","text":"\"XYZ\" refers coordinates third dimension represents altitude, \"XYM\" refers three-dimensional coordinates third dimension refers something else (\"M\" measure); checking sanity x may partial. flatten=TRUE, method may merge points multipoint structure, may preserve order, hence reverted. given fish, returns fish soup.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create simple feature from a numeric vector, matrix or list — st","text":"","code":"(p1 = st_point(c(1,2))) #> POINT (1 2) class(p1) #> [1] \"XY\" \"POINT\" \"sfg\" st_bbox(p1) #> xmin ymin xmax ymax #> 1 2 1 2 (p2 = st_point(c(1,2,3))) #> POINT Z (1 2 3) class(p2) #> [1] \"XYZ\" \"POINT\" \"sfg\" (p3 = st_point(c(1,2,3), \"XYM\")) #> POINT M (1 2 3) pts = matrix(1:10, , 2) (mp1 = st_multipoint(pts)) #> MULTIPOINT ((1 6), (2 7), (3 8), (4 9), (5 10)) pts = matrix(1:15, , 3) (mp2 = st_multipoint(pts)) #> MULTIPOINT Z ((1 6 11), (2 7 12), (3 8 13), (4 9 14), (5 10 15)) (mp3 = st_multipoint(pts, \"XYM\")) #> MULTIPOINT M ((1 6 11), (2 7 12), (3 8 13), (4 9 14), (5 10 15)) pts = matrix(1:20, , 4) (mp4 = st_multipoint(pts)) #> MULTIPOINT ZM ((1 6 11 16), (2 7 12 17), (3 8 13 18), (4 9 14 19), (5 10 15 20)) pts = matrix(1:10, , 2) (ls1 = st_linestring(pts)) #> LINESTRING (1 6, 2 7, 3 8, 4 9, 5 10) pts = matrix(1:15, , 3) (ls2 = st_linestring(pts)) #> LINESTRING Z (1 6 11, 2 7 12, 3 8 13, 4 9 14, 5 10 15) (ls3 = st_linestring(pts, \"XYM\")) #> LINESTRING M (1 6 11, 2 7 12, 3 8 13, 4 9 14, 5 10 15) pts = matrix(1:20, , 4) (ls4 = st_linestring(pts)) #> LINESTRING ZM (1 6 11 16, 2 7 12 17, 3 8 13 18, 4 9 14 19, 5 10 15 20) 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)) #> 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)) pts3 = lapply(pts, function(x) cbind(x, 0)) (ml2 = st_multilinestring(pts3)) #> 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)) (ml3 = st_multilinestring(pts3, \"XYM\")) #> 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)) pts4 = lapply(pts3, function(x) cbind(x, 0)) (ml4 = st_multilinestring(pts4)) #> 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)) 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) (pl1 = st_polygon(pts)) #> 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)) pts3 = lapply(pts, function(x) cbind(x, 0)) (pl2 = st_polygon(pts3)) #> 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)) (pl3 = st_polygon(pts3, \"XYM\")) #> 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)) pts4 = lapply(pts3, function(x) cbind(x, 0)) (pl4 = st_polygon(pts4)) #> 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)) pol1 = list(outer, hole1, hole2) pol2 = list(outer + 12, hole1 + 12) pol3 = list(outer + 24) mp = list(pol1,pol2,pol3) (mp1 = st_multipolygon(mp)) #> 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))) pts3 = lapply(mp, function(x) lapply(x, function(y) cbind(y, 0))) (mp2 = st_multipolygon(pts3)) #> 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))) (mp3 = st_multipolygon(pts3, \"XYM\")) #> 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))) pts4 = lapply(mp2, function(x) lapply(x, function(y) cbind(y, 0))) (mp4 = st_multipolygon(pts4)) #> 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))) (gc = st_geometrycollection(list(p1, ls1, pl1, mp1))) #> GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (1 6, 2 7, 3 8, 4 9, 5 10), 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)), 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)))) st_geometrycollection() # empty geometry #> GEOMETRYCOLLECTION EMPTY c(st_point(1:2), st_point(5:6)) #> MULTIPOINT ((1 2), (5 6)) c(st_point(1:2), st_multipoint(matrix(5:8,2))) #> MULTIPOINT ((1 2), (5 7), (6 8)) c(st_multipoint(matrix(1:4,2)), st_multipoint(matrix(5:8,2))) #> MULTIPOINT ((1 3), (2 4), (5 7), (6 8)) c(st_linestring(matrix(1:6,3)), st_linestring(matrix(11:16,3))) #> MULTILINESTRING ((1 4, 2 5, 3 6), (11 14, 12 15, 13 16)) c(st_multilinestring(list(matrix(1:6,3))), st_multilinestring(list(matrix(11:16,3)))) #> MULTILINESTRING ((1 4, 2 5, 3 6), (11 14, 12 15, 13 16)) pl = list(rbind(c(0,0), c(1,0), c(1,1), c(0,1), c(0,0))) c(st_polygon(pl), st_polygon(pl)) #> MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((0 0, 1 0, 1 1, 0 1, 0 0))) c(st_polygon(pl), st_multipolygon(list(pl))) #> MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((0 0, 1 0, 1 1, 0 1, 0 0))) c(st_linestring(matrix(1:6,3)), st_point(1:2)) #> GEOMETRYCOLLECTION (LINESTRING (1 4, 2 5, 3 6), POINT (1 2)) c(st_geometrycollection(list(st_point(1:2), st_linestring(matrix(1:6,3)))), st_geometrycollection(list(st_multilinestring(list(matrix(11:16,3)))))) #> GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (1 4, 2 5, 3 6), MULTILINESTRING ((11 14, 12 15, 13 16))) c(st_geometrycollection(list(st_point(1:2), st_linestring(matrix(1:6,3)))), st_multilinestring(list(matrix(11:16,3))), st_point(5:6), st_geometrycollection(list(st_point(10:11)))) #> GEOMETRYCOLLECTION (MULTILINESTRING ((11 14, 12 15, 13 16)), POINT (5 6), POINT (1 2), LINESTRING (1 4, 2 5, 3 6), POINT (10 11))"},{"path":"https://r-spatial.github.io/sf/reference/st_agr.html","id":null,"dir":"Reference","previous_headings":"","what":"get or set relation_to_geometry attribute of an sf object — st_agr","title":"get or set relation_to_geometry attribute of an sf object — st_agr","text":"get set relation_to_geometry attribute sf object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_agr.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"get or set relation_to_geometry attribute of an sf object — st_agr","text":"","code":"NA_agr_ st_agr(x, ...) st_agr(x) <- value st_set_agr(x, value)"},{"path":"https://r-spatial.github.io/sf/reference/st_agr.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"get or set relation_to_geometry attribute of an sf object — st_agr","text":"object class factor length 1.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_agr.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"get or set relation_to_geometry attribute of an sf object — st_agr","text":"x object class sf ... ignored value character, factor appropriate levels; named, names correspond non-geometry list-column columns x","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_agr.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"get or set relation_to_geometry attribute of an sf object — st_agr","text":"NA_agr_ agr object missing value.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_binary.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert sfc object to an WKB object — st_as_binary","title":"Convert sfc object to an WKB object — st_as_binary","text":"Convert sfc object WKB object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_binary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert sfc object to an WKB object — st_as_binary","text":"","code":"st_as_binary(x, ...) # S3 method for class 'sfc' st_as_binary( x, ..., EWKB = FALSE, endian = .Platform$endian, pureR = FALSE, precision = attr(x, \"precision\"), hex = FALSE ) # S3 method for class 'sfg' st_as_binary( x, ..., endian = .Platform$endian, EWKB = FALSE, pureR = FALSE, hex = FALSE, srid = 0 )"},{"path":"https://r-spatial.github.io/sf/reference/st_as_binary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert sfc object to an WKB object — st_as_binary","text":"x object convert ... ignored EWKB logical; use EWKB (PostGIS), (default) ISO-WKB? endian character; either \"big\" \"little\"; default: use platform pureR logical; use pure R solution, C++? precision numeric; zero, modify; reduce precision: negative values convert float (4-byte real); positive values convert round(x*precision)/precision. See details. hex logical; return (unclassed) hexadecimal encoded character vector? srid integer; override srid (can used srid unavailable locally).","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_binary.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Convert sfc object to an WKB object — st_as_binary","text":"st_as_binary called sfc objects way GDAL GEOS libraries, hence rounding (requested) fly e.g. computing spatial predicates like st_intersects. examples show round-trip sfc binary. precision model used, see also https://locationtech.github.io/jts/javadoc/org/locationtech/jts/geom/PrecisionModel.html. , written : “... specify 3 decimal places precision, use scale factor 1000. specify -3 decimal places precision (.e. rounding nearest 1000), use scale factor 0.001.”. Note coordinates, also Z M values (present) affected.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_binary.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert sfc object to an WKB object — st_as_binary","text":"","code":"# examples of setting precision: st_point(c(1/3, 1/6)) %>% st_sfc(precision = 1000) %>% st_as_binary %>% st_as_sfc #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0.333 ymin: 0.167 xmax: 0.333 ymax: 0.167 #> CRS: NA #> POINT (0.333 0.167) st_point(c(1/3, 1/6)) %>% st_sfc(precision = 100) %>% st_as_binary %>% st_as_sfc #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0.33 ymin: 0.17 xmax: 0.33 ymax: 0.17 #> CRS: NA #> POINT (0.33 0.17) st_point(1e6 * c(1/3, 1/6)) %>% st_sfc(precision = 0.01) %>% st_as_binary %>% st_as_sfc #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 333300 ymin: 166700 xmax: 333300 ymax: 166700 #> CRS: NA #> POINT (333300 166700) st_point(1e6 * c(1/3, 1/6)) %>% st_sfc(precision = 0.001) %>% st_as_binary %>% st_as_sfc #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 333000 ymin: 167000 xmax: 333000 ymax: 167000 #> CRS: NA #> POINT (333000 167000)"},{"path":"https://r-spatial.github.io/sf/reference/st_as_grob.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert sf* object to a grob — st_as_grob","title":"Convert sf* object to a grob — st_as_grob","text":"Convert sf* object grid graphics object (grob)","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_grob.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert sf* object to a grob — st_as_grob","text":"","code":"st_as_grob(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_as_grob.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert sf* object to a grob — st_as_grob","text":"x object converted object class grob ... passed xxxGrob function, e.g. gp = gpar(col = 'red')","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_sf.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert foreign object to an sf object — st_as_sf","title":"Convert foreign object to an sf object — st_as_sf","text":"Convert foreign object sf object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_sf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert foreign object to an sf object — st_as_sf","text":"","code":"st_as_sf(x, ...) # S3 method for class 'data.frame' st_as_sf( x, ..., agr = NA_agr_, coords, wkt, dim = \"XYZ\", remove = TRUE, na.fail = TRUE, sf_column_name = NULL ) # S3 method for class 'sf' st_as_sf(x, ...) # S3 method for class 'sfc' st_as_sf(x, ...) # S3 method for class 'Spatial' st_as_sf(x, ...) # S3 method for class 'map' st_as_sf(x, ..., fill = TRUE, group = TRUE) # S3 method for class 'ppp' st_as_sf(x, ...) # S3 method for class 'psp' st_as_sf(x, ...) # S3 method for class 'lpp' st_as_sf(x, ...) # S3 method for class 's2_geography' st_as_sf(x, ..., crs = st_crs(4326))"},{"path":"https://r-spatial.github.io/sf/reference/st_as_sf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert foreign object to an sf object — st_as_sf","text":"x object converted object class sf ... passed st_sf, might included named arguments crs precision agr character vector; see details section st_sf coords case point data: names numbers numeric columns holding coordinates wkt name number character column holds WKT encoded geometries dim specify 3- 4-dimensional points reflect: passed st_point (argument coords given) remove logical; coords wkt given, remove columns data.frame? na.fail logical; TRUE, raise error coordinates contain missing values sf_column_name character; name active list-column simple feature geometries; case one sf_column_name NULL, first one taken. fill logical; value fill used call map. group logical; TRUE, group id labels map prefix : crs coordinate reference system assigned; object class crs","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_sf.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Convert foreign object to an sf object — st_as_sf","text":"setting argument wkt annihilates use argument coords. x contains column called \"geometry\", coords result overwriting column sfc geometry list-column. Setting wkt replace column geometry list-column, unless remove FALSE. coords length 4, dim XYZM, four columns taken xmin, ymin, xmax, ymax corner coordinates rectangle, polygons returned.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_sf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert foreign object to an sf object — st_as_sf","text":"","code":"pt1 = st_point(c(0,1)) pt2 = st_point(c(1,1)) st_sfc(pt1, pt2) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 1 ymax: 1 #> CRS: NA #> POINT (0 1) #> POINT (1 1) d = data.frame(a = 1:2) d$geom = st_sfc(pt1, pt2) df = st_as_sf(d) d$geom = c(\"POINT(0 0)\", \"POINT(0 1)\") df = st_as_sf(d, wkt = \"geom\") d$geom2 = st_sfc(pt1, pt2) st_as_sf(d) # should warn #> Simple feature collection with 2 features and 2 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 1 ymax: 1 #> CRS: NA #> a geom geom2 #> 1 1 POINT(0 0) POINT (0 1) #> 2 2 POINT(0 1) POINT (1 1) if (require(sp, quietly = TRUE)) { data(meuse, package = \"sp\") meuse_sf = st_as_sf(meuse, coords = c(\"x\", \"y\"), crs = 28992, agr = \"constant\") meuse_sf[1:3,] summary(meuse_sf) } #> cadmium copper lead zinc #> Min. : 0.200 Min. : 14.00 Min. : 37.0 Min. : 113.0 #> 1st Qu.: 0.800 1st Qu.: 23.00 1st Qu.: 72.5 1st Qu.: 198.0 #> Median : 2.100 Median : 31.00 Median :123.0 Median : 326.0 #> Mean : 3.246 Mean : 40.32 Mean :153.4 Mean : 469.7 #> 3rd Qu.: 3.850 3rd Qu.: 49.50 3rd Qu.:207.0 3rd Qu.: 674.5 #> Max. :18.100 Max. :128.00 Max. :654.0 Max. :1839.0 #> #> elev dist om ffreq soil lime #> Min. : 5.180 Min. :0.00000 Min. : 1.000 1:84 1:97 0:111 #> 1st Qu.: 7.546 1st Qu.:0.07569 1st Qu.: 5.300 2:48 2:46 1: 44 #> Median : 8.180 Median :0.21184 Median : 6.900 3:23 3:12 #> Mean : 8.165 Mean :0.24002 Mean : 7.478 #> 3rd Qu.: 8.955 3rd Qu.:0.36407 3rd Qu.: 9.000 #> Max. :10.520 Max. :0.88039 Max. :17.000 #> NA's :2 #> landuse dist.m geometry #> W :50 Min. : 10.0 POINT :155 #> Ah :39 1st Qu.: 80.0 epsg:28992 : 0 #> Am :22 Median : 270.0 +proj=ster...: 0 #> Fw :10 Mean : 290.3 #> Ab : 8 3rd Qu.: 450.0 #> (Other):25 Max. :1000.0 #> NA's : 1 if (require(sp, quietly = TRUE)) { x = rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1)) x1 = 0.1 * x + 0.1 x2 = 0.1 * x + 0.4 x3 = 0.1 * x + 0.7 y = x + 3 y1 = x1 + 3 y3 = x3 + 3 m = matrix(c(3, 0), 5, 2, byrow = TRUE) z = x + m z1 = x1 + m z2 = x2 + m z3 = x3 + m p1 = Polygons(list( Polygon(x[5:1,]), Polygon(x2), Polygon(x3), Polygon(y[5:1,]), Polygon(y1), Polygon(x1), Polygon(y3)), \"ID1\") p2 = Polygons(list( Polygon(z[5:1,]), Polygon(z2), Polygon(z3), Polygon(z1)), \"ID2\") r = SpatialPolygons(list(p1,p2)) a = suppressWarnings(st_as_sf(r)) summary(a) demo(meuse, ask = FALSE, echo = FALSE) summary(st_as_sf(meuse)) summary(st_as_sf(meuse.grid)) summary(st_as_sf(meuse.area)) summary(st_as_sf(meuse.riv)) summary(st_as_sf(as(meuse.riv, \"SpatialLines\"))) pol.grd = as(meuse.grid, \"SpatialPolygonsDataFrame\") # summary(st_as_sf(pol.grd)) # summary(st_as_sf(as(pol.grd, \"SpatialLinesDataFrame\"))) } if (require(spatstat.geom)) { g = st_as_sf(gorillas) # select only the points: g[st_is(g, \"POINT\"),] } #> Loading required package: spatstat.geom #> Loading required package: spatstat.data #> Loading required package: spatstat.univar #> spatstat.univar 3.0-1 #> spatstat.geom 3.3-3 #> Simple feature collection with 647 features and 4 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 580797.3 ymin: 675238.7 xmax: 584945.3 ymax: 678313.5 #> CRS: NA #> First 10 features: #> group season date label geom #> 1 major dry 2006-01-06 point POINT (582518.4 676886.2) #> 2 major dry 2006-01-10 point POINT (581823 677422.7) #> 3 major dry 2006-01-15 point POINT (582131 676937.9) #> 4 major dry 2006-01-24 point POINT (582111.9 677420) #> 5 minor dry 2006-01-27 point POINT (582585.1 677509.7) #> 6 major dry 2006-01-28 point POINT (582302.3 677521.6) #> 7 major dry 2006-02-01 point POINT (583167.2 676730.5) #> 8 major dry 2006-02-03 point POINT (583584.5 677207.1) #> 9 major dry 2006-02-13 point POINT (583117.8 676850.3) #> 10 major dry 2006-02-15 point POINT (582902.8 676724.1) if (require(spatstat.linnet)) { data(chicago) plot(st_as_sf(chicago)[\"label\"]) plot(st_as_sf(chicago)[-1,\"label\"]) } #> Loading required package: spatstat.linnet #> Loading required package: spatstat.random #> spatstat.random 3.3-2 #> Loading required package: spatstat.explore #> Loading required package: nlme #> #> Attaching package: ‘nlme’ #> The following object is masked from ‘package:dplyr’: #> #> collapse #> spatstat.explore 3.3-3 #> Loading required package: spatstat.model #> Loading required package: rpart #> spatstat.model 3.3-2 #> spatstat.linnet 3.2-2"},{"path":"https://r-spatial.github.io/sf/reference/st_as_sfc.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert foreign geometry object to an sfc object — st_as_sfc","title":"Convert foreign geometry object to an sfc object — st_as_sfc","text":"Convert foreign geometry object sfc object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_sfc.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert foreign geometry object to an sfc object — st_as_sfc","text":"","code":"# S3 method for class 'pq_geometry' st_as_sfc( x, ..., EWKB = TRUE, spatialite = FALSE, pureR = FALSE, crs = NA_crs_ ) # S3 method for class 'list' st_as_sfc(x, ..., crs = NA_crs_) # S3 method for class 'blob' st_as_sfc(x, ...) # S3 method for class 'bbox' st_as_sfc(x, ...) # S3 method for class 'WKB' st_as_sfc( x, ..., EWKB = FALSE, spatialite = FALSE, pureR = FALSE, crs = NA_crs_ ) # S3 method for class 'raw' st_as_sfc(x, ...) # S3 method for class 'character' st_as_sfc(x, crs = NA_integer_, ..., GeoJSON = FALSE) # S3 method for class 'factor' st_as_sfc(x, ...) st_as_sfc(x, ...) # S3 method for class 'SpatialPoints' st_as_sfc(x, ..., precision = 0) # S3 method for class 'SpatialPixels' st_as_sfc(x, ..., precision = 0) # S3 method for class 'SpatialMultiPoints' st_as_sfc(x, ..., precision = 0) # S3 method for class 'SpatialLines' st_as_sfc(x, ..., precision = 0, forceMulti = FALSE) # S3 method for class 'SpatialPolygons' st_as_sfc(x, ..., precision = 0, forceMulti = FALSE) # S3 method for class 'map' st_as_sfc(x, ...) # S3 method for class 's2_geography' st_as_sfc( x, ..., crs = st_crs(4326), endian = match(.Platform$endian, c(\"big\", \"little\")) - 1L )"},{"path":"https://r-spatial.github.io/sf/reference/st_as_sfc.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert foreign geometry object to an sfc object — st_as_sfc","text":"x object convert ... arguments EWKB logical; TRUE, parse EWKB (extended WKB; PostGIS: ST_AsEWKB), otherwise ISO WKB (PostGIS: ST_AsBinary) spatialite logical; TRUE, WKB assumed spatialite dialect, see https://www.gaia-gis./gaia-sins/BLOB-Geometry.html; supported native endian-ness (.e., files written system endian-ness read). pureR logical; TRUE, use R code, FALSE, use compiled (C++) code; use TRUE endian-ness binary differs host machine (.Platform$endian). crs coordinate reference system assigned; object class crs GeoJSON logical; TRUE, try read geometries GeoJSON text strings geometry, see st_crs() precision precision value; see st_as_binary forceMulti logical; TRUE, force coercion MULTIPOLYGON MULTILINE objects, else autodetect endian integer; 0 1: defaults endian native machine","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_sfc.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Convert foreign geometry object to an sfc object — st_as_sfc","text":"converting WKB, object x either character vector typically obtained PostGIS (either leading \"0x\" without), list raw vectors representing features binary (raw) form. x character vector, vector containing well-known-text, Postgis EWKT GeoJSON representations single geometry vector element. x factor, converted character.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_sfc.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert foreign geometry object to an sfc object — st_as_sfc","text":"","code":"wkb = structure(list(\"01010000204071000000000000801A064100000000AC5C1441\"), class = \"WKB\") st_as_sfc(wkb, EWKB = TRUE) #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 181072 ymin: 333611 xmax: 181072 ymax: 333611 #> Projected CRS: Amersfoort / RD New #> POINT (181072 333611) wkb = structure(list(\"0x01010000204071000000000000801A064100000000AC5C1441\"), class = \"WKB\") st_as_sfc(wkb, EWKB = TRUE) #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 181072 ymin: 333611 xmax: 181072 ymax: 333611 #> Projected CRS: Amersfoort / RD New #> POINT (181072 333611) st_as_sfc(st_as_binary(st_sfc(st_point(0:1)))[[1]], crs = 4326) #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 0 ymax: 1 #> Geodetic CRS: WGS 84 #> POINT (0 1) st_as_sfc(\"SRID=3978;LINESTRING(1663106 -105415,1664320 -104617)\") #> Geometry set for 1 feature #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 1663106 ymin: -105415 xmax: 1664320 ymax: -104617 #> Projected CRS: NAD83 / Canada Atlas Lambert #> LINESTRING (1663106 -105415, 1664320 -104617)"},{"path":"https://r-spatial.github.io/sf/reference/st_as_text.html","id":null,"dir":"Reference","previous_headings":"","what":"Return Well-known Text representation of simple feature geometry or coordinate reference system — st_as_text","title":"Return Well-known Text representation of simple feature geometry or coordinate reference system — st_as_text","text":"Return Well-known Text representation simple feature geometry coordinate reference system","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_text.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return Well-known Text representation of simple feature geometry or coordinate reference system — st_as_text","text":"","code":"# S3 method for class 'crs' st_as_text(x, ..., projjson = FALSE, pretty = FALSE) st_as_text(x, ...) # S3 method for class 'sfg' st_as_text(x, ...) # S3 method for class 'sfc' st_as_text(x, ..., EWKT = FALSE)"},{"path":"https://r-spatial.github.io/sf/reference/st_as_text.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Return Well-known Text representation of simple feature geometry or coordinate reference system — st_as_text","text":"x object class sfg, sfc crs ... modifiers; particular digits can passed control number digits used projjson logical; TRUE, return projjson form (requires GDAL 3.1 PROJ 6.2), else return well-known-text form pretty logical; TRUE, print human-readable well-known-text representation coordinate reference system EWKT logical; TRUE, print SRID=xxx; WKT string epsg available","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_text.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Return Well-known Text representation of simple feature geometry or coordinate reference system — st_as_text","text":"returned WKT representation simple feature geometry conforms simple features access specification extensions (known EWKT, supported PostGIS simple features implementations addition SRID WKT string).","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_text.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Return Well-known Text representation of simple feature geometry or coordinate reference system — st_as_text","text":"improve conversion performance, lwgeom package can used (must installed beforehand) set Sys.setenv(\"LWGEOM_WKT\" = \"true\") environment variable. also result faster printing complex geometries. Note representation WKT different sf package may cause reproducibility problems. alternative solution use lwgeom::st_astext() wk::as_wkt() functions.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_as_text.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Return Well-known Text representation of simple feature geometry or coordinate reference system — st_as_text","text":"","code":"st_as_text(st_point(1:2)) #> [1] \"POINT (1 2)\" st_as_text(st_sfc(st_point(c(-90,40)), crs = 4326), EWKT = TRUE) #> [1] \"SRID=4326;POINT (-90 40)\""},{"path":"https://r-spatial.github.io/sf/reference/st_bbox.html","id":null,"dir":"Reference","previous_headings":"","what":"Return bounding of a simple feature or simple feature set — st_bbox","title":"Return bounding of a simple feature or simple feature set — st_bbox","text":"Return bounding simple feature simple feature set","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_bbox.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return bounding of a simple feature or simple feature set — st_bbox","text":"","code":"# S3 method for class 'bbox' is.na(x) st_bbox(obj, ...) # S3 method for class 'POINT' st_bbox(obj, ...) # S3 method for class 'MULTIPOINT' st_bbox(obj, ...) # S3 method for class 'LINESTRING' st_bbox(obj, ...) # S3 method for class 'POLYGON' st_bbox(obj, ...) # S3 method for class 'MULTILINESTRING' st_bbox(obj, ...) # S3 method for class 'MULTIPOLYGON' st_bbox(obj, ...) # S3 method for class 'GEOMETRYCOLLECTION' st_bbox(obj, ...) # S3 method for class 'MULTISURFACE' st_bbox(obj, ...) # S3 method for class 'MULTICURVE' st_bbox(obj, ...) # S3 method for class 'CURVEPOLYGON' st_bbox(obj, ...) # S3 method for class 'COMPOUNDCURVE' st_bbox(obj, ...) # S3 method for class 'POLYHEDRALSURFACE' st_bbox(obj, ...) # S3 method for class 'TIN' st_bbox(obj, ...) # S3 method for class 'TRIANGLE' st_bbox(obj, ...) # S3 method for class 'CIRCULARSTRING' st_bbox(obj, ...) # S3 method for class 'sfc' st_bbox(obj, ...) # S3 method for class 'sf' st_bbox(obj, ...) # S3 method for class 'Spatial' st_bbox(obj, ...) # S3 method for class 'Raster' st_bbox(obj, ...) # S3 method for class 'Extent' st_bbox(obj, ..., crs = NA_crs_) # S3 method for class 'numeric' st_bbox(obj, ..., crs = NA_crs_) NA_bbox_ FULL_bbox_ # S3 method for class 'bbox' format(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_bbox.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Return bounding of a simple feature or simple feature set — st_bbox","text":"object class bbox length 4. object class bbox length 4.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_bbox.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Return bounding of a simple feature or simple feature set — st_bbox","text":"x object class bbox obj object compute bounding box ... format.bbox, passed format format individual numbers crs object class crs, argument st_crs, specifying CRS bounding box.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_bbox.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Return bounding of a simple feature or simple feature set — st_bbox","text":"numeric vector length four, xmin, ymin, xmax ymax values; obj class sf, sfc, Spatial Raster, object returned class bbox, attribute crs method print bbox st_crs method retrieve coordinate reference system corresponding obj (hence bounding box). st_as_sfc methods bbox objects generate polygon around four bounding box points.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_bbox.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Return bounding of a simple feature or simple feature set — st_bbox","text":"NA_bbox_ represents missing value bbox object NA_bbox_ represents missing value bbox object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_bbox.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Return bounding of a simple feature or simple feature set — st_bbox","text":"","code":"a = st_sf(a = 1:2, geom = st_sfc(st_point(0:1), st_point(1:2)), crs = 4326) st_bbox(a) #> xmin ymin xmax ymax #> 0 1 1 2 st_as_sfc(st_bbox(a)) #> Geometry set for 1 feature #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 1 ymax: 2 #> Geodetic CRS: WGS 84 #> POLYGON ((0 1, 1 1, 1 2, 0 2, 0 1)) st_bbox(c(xmin = 16.1, xmax = 16.6, ymax = 48.6, ymin = 47.9), crs = st_crs(4326)) #> xmin ymin xmax ymax #> 16.1 47.9 16.6 48.6"},{"path":"https://r-spatial.github.io/sf/reference/st_break_antimeridian.html","id":null,"dir":"Reference","previous_headings":"","what":"Break antimeridian for plotting not centred on Greenwich — st_break_antimeridian","title":"Break antimeridian for plotting not centred on Greenwich — st_break_antimeridian","text":"Longitudes can broken antimeridian target central longitude permit plotting (usually world) line polygon objects centred chosen central longitude. method may used non-projected, geographical coordinates linestring polygon objects. s2 turned internally permit use rectangular bounding box. input geometries go outside [-180, 180] degrees longitude, protruding geometries also split using tol= values; case empty geometries dropped first.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_break_antimeridian.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Break antimeridian for plotting not centred on Greenwich — st_break_antimeridian","text":"","code":"st_break_antimeridian(x, lon_0 = 0, tol = 1e-04, ...) # S3 method for class 'sf' st_break_antimeridian(x, lon_0 = 0, tol = 1e-04, ...) # S3 method for class 'sfc' st_break_antimeridian(x, lon_0 = 0, tol = 1e-04, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_break_antimeridian.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Break antimeridian for plotting not centred on Greenwich — st_break_antimeridian","text":"x object class sf sfc lon_0 target central longitude (degrees) tol half break width (degrees, default 0.0001) ... ignored ","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_break_antimeridian.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Break antimeridian for plotting not centred on Greenwich — st_break_antimeridian","text":"","code":"# \\donttest{ if (require(\"maps\", quietly=TRUE)) { opar = par(mfrow=c(3, 2)) wld = st_as_sf(map(fill=FALSE, interior=FALSE, plot=FALSE), fill=FALSE) for (lon_0 in c(-170, -90, -10, 10, 90, 170)) { wld |> st_break_antimeridian(lon_0=lon_0) |> st_transform(paste0(\"+proj=natearth +lon_0=\", lon_0)) |> st_geometry() |> plot(main=lon_0) } par(opar) } #> Warning: st_break_antimeridian: longitude coordinates outside [-180, 180] #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Warning: st_break_antimeridian: longitude coordinates outside [-180, 180] #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Warning: st_break_antimeridian: longitude coordinates outside [-180, 180] #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Warning: st_break_antimeridian: longitude coordinates outside [-180, 180] #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Warning: st_break_antimeridian: longitude coordinates outside [-180, 180] #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Warning: st_break_antimeridian: longitude coordinates outside [-180, 180] #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on #> Spherical geometry (s2) switched off #> although coordinates are longitude/latitude, st_intersection assumes that they #> are planar #> Warning: attribute variables are assumed to be spatially constant throughout all geometries #> Spherical geometry (s2) switched on # }"},{"path":"https://r-spatial.github.io/sf/reference/st_cast.html","id":null,"dir":"Reference","previous_headings":"","what":"Cast geometry to another type: either simplify, or cast explicitly — st_cast","title":"Cast geometry to another type: either simplify, or cast explicitly — st_cast","text":"Cast geometry another type: either simplify, cast explicitly","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_cast.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Cast geometry to another type: either simplify, or cast explicitly — st_cast","text":"","code":"# S3 method for class 'MULTIPOLYGON' st_cast(x, to, ...) # S3 method for class 'MULTILINESTRING' st_cast(x, to, ...) # S3 method for class 'MULTIPOINT' st_cast(x, to, ...) # S3 method for class 'POLYGON' st_cast(x, to, ...) # S3 method for class 'LINESTRING' st_cast(x, to, ...) # S3 method for class 'POINT' st_cast(x, to, ...) # S3 method for class 'GEOMETRYCOLLECTION' st_cast(x, to, ...) # S3 method for class 'CIRCULARSTRING' st_cast(x, to, ...) # S3 method for class 'MULTISURFACE' st_cast(x, to, ...) # S3 method for class 'COMPOUNDCURVE' st_cast(x, to, ...) # S3 method for class 'MULTICURVE' st_cast(x, to, ...) # S3 method for class 'CURVE' st_cast(x, to, ...) st_cast(x, to, ...) # S3 method for class 'sfc' st_cast(x, to, ..., ids = seq_along(x), group_or_split = TRUE) # S3 method for class 'sf' st_cast(x, to, ..., warn = TRUE, do_split = TRUE) # S3 method for class 'sfc_CIRCULARSTRING' st_cast(x, to, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_cast.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Cast geometry to another type: either simplify, or cast explicitly — st_cast","text":"x object class sfg, sfc sf character; target type, missing, simplification tried; x type sfg (.e., single geometry) needs specified. ... ignored ids integer vector, denoting geometries grouped (default: grouping) group_or_split logical; TRUE, group split geometries; FALSE, carry 1-1 per-geometry conversion. warn logical; TRUE, warn attributes assigned sub-geometries do_split logical; TRUE, allow splitting geometries sub-geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_cast.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Cast geometry to another type: either simplify, or cast explicitly — st_cast","text":"object class successful, unmodified object unsuccessful. information gets lost type casting, warning raised. case missing, st_cast.sfc coerce combinations \"POINT\" \"MULTIPOINT\", \"LINESTRING\" \"MULTILINESTRING\", \"POLYGON\" \"MULTIPOLYGON\" \"MULTI...\" form, case geometries \"GEOMETRYCOLLECTION\" return list contents \"GEOMETRYCOLLECTION\" objects, else nothing. case specified, \"GEOMETRY\", geometries converted, else, st_cast try coerce elements ; ids may specified group e.g. \"POINT\" objects \"MULTIPOINT\", specified grouping takes place. e.g. \"sfc_MULTIPOINT\" cast \"sfc_POINT\", objects split, information gets lost, unless group_or_split FALSE.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_cast.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Cast geometry to another type: either simplify, or cast explicitly — st_cast","text":"converting GEOMETRYCOLLECTION COMPOUNDCURVE, MULTISURFACE CURVEPOLYGON, user responsible validity resulting object: checks carried software. converting mixed, GEOMETRY sets, may help first convert MULTI-type, see examples st_cast method sf objects can split geometries, e.g. cast MULTIPOINT multiple POINT features. case splitting, attributes repeated warning issued non-constant attributes assigned sub-geometries. merge feature geometries attribute values, use aggregate summarise.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_cast.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Cast geometry to another type: either simplify, or cast explicitly — st_cast","text":"","code":"# example(st_read) nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 mpl <- st_geometry(nc)[[4]] #st_cast(x) ## error 'argument \"to\" is missing, with no default' cast_all <- function(xg) { lapply(c(\"MULTIPOLYGON\", \"MULTILINESTRING\", \"MULTIPOINT\", \"POLYGON\", \"LINESTRING\", \"POINT\"), function(x) st_cast(xg, x)) } st_sfc(cast_all(mpl)) #> Warning: polygon from first part only #> Warning: line from first ring only #> Warning: point from first coordinate only #> Geometry set for 6 features #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: -76.33025 ymin: 36.07282 xmax: -75.77316 ymax: 36.55716 #> CRS: NA #> First 5 geometries: #> MULTIPOLYGON (((-76.00897 36.3196, -76.01735 36... #> MULTILINESTRING ((-76.00897 36.3196, -76.01735 ... #> MULTIPOINT ((-76.00897 36.3196), (-76.01735 36.... #> POLYGON ((-76.00897 36.3196, -76.01735 36.33773... #> LINESTRING (-76.00897 36.3196, -76.01735 36.337... ## no closing coordinates should remain for multipoint any(duplicated(unclass(st_cast(mpl, \"MULTIPOINT\")))) ## should be FALSE #> [1] FALSE ## number of duplicated coordinates in the linestrings should equal the number of polygon rings ## (... in this case, won't always be true) sum(duplicated(do.call(rbind, unclass(st_cast(mpl, \"MULTILINESTRING\")))) ) == sum(unlist(lapply(mpl, length))) ## should be TRUE #> [1] TRUE p1 <- structure(c(0, 1, 3, 2, 1, 0, 0, 0, 2, 4, 4, 0), .Dim = c(6L, 2L)) p2 <- structure(c(1, 1, 2, 1, 1, 2, 2, 1), .Dim = c(4L, 2L)) st_polygon(list(p1, p2)) #> POLYGON ((0 0, 1 0, 3 2, 2 4, 1 4, 0 0), (1 1, 1 2, 2 2, 1 1)) mls <- st_cast(st_geometry(nc)[[4]], \"MULTILINESTRING\") st_sfc(cast_all(mls)) #> Warning: keeping first linestring only #> Warning: keeping first coordinate only #> Geometry set for 6 features #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: -76.33025 ymin: 36.07282 xmax: -75.77316 ymax: 36.55716 #> CRS: NA #> First 5 geometries: #> MULTIPOLYGON (((-76.00897 36.3196, -76.01735 36... #> MULTILINESTRING ((-76.00897 36.3196, -76.01735 ... #> MULTIPOINT ((-76.00897 36.3196), (-76.01735 36.... #> POLYGON ((-76.00897 36.3196, -76.01735 36.33773... #> LINESTRING (-76.00897 36.3196, -76.01735 36.337... mpt <- st_cast(st_geometry(nc)[[4]], \"MULTIPOINT\") st_sfc(cast_all(mpt)) #> Warning: point from first coordinate only #> Geometry set for 6 features #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: -76.33025 ymin: 36.07282 xmax: -75.77316 ymax: 36.55716 #> CRS: NA #> First 5 geometries: #> MULTIPOLYGON (((-76.00897 36.3196, -76.01735 36... #> MULTILINESTRING ((-76.00897 36.3196, -76.01735 ... #> MULTIPOINT ((-76.00897 36.3196), (-76.01735 36.... #> POLYGON ((-76.00897 36.3196, -76.01735 36.33773... #> LINESTRING (-76.00897 36.3196, -76.01735 36.337... pl <- st_cast(st_geometry(nc)[[4]], \"POLYGON\") #> Warning: polygon from first part only st_sfc(cast_all(pl)) #> Warning: point from first coordinate only #> Geometry set for 6 features #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: -76.33025 ymin: 36.07282 xmax: -75.79885 ymax: 36.55716 #> CRS: NA #> First 5 geometries: #> MULTIPOLYGON (((-76.00897 36.3196, -76.01735 36... #> MULTILINESTRING ((-76.00897 36.3196, -76.01735 ... #> MULTIPOINT ((-76.00897 36.3196), (-76.01735 36.... #> POLYGON ((-76.00897 36.3196, -76.01735 36.33773... #> LINESTRING (-76.00897 36.3196, -76.01735 36.337... ls <- st_cast(st_geometry(nc)[[4]], \"LINESTRING\") #> Warning: line from first ring only st_sfc(cast_all(ls)) #> Warning: point from first coordinate only #> Geometry set for 6 features #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: -76.33025 ymin: 36.07282 xmax: -75.79885 ymax: 36.55716 #> CRS: NA #> First 5 geometries: #> MULTIPOLYGON (((-76.00897 36.3196, -76.01735 36... #> MULTILINESTRING ((-76.00897 36.3196, -76.01735 ... #> MULTIPOINT ((-76.00897 36.3196), (-76.01735 36.... #> POLYGON ((-76.00897 36.3196, -76.01735 36.33773... #> LINESTRING (-76.00897 36.3196, -76.01735 36.337... pt <- st_cast(st_geometry(nc)[[4]], \"POINT\") #> Warning: point from first coordinate only ## st_sfc(cast_all(pt)) ## Error: cannot create MULTIPOLYGON from POINT st_sfc(lapply(c(\"POINT\", \"MULTIPOINT\"), function(x) st_cast(pt, x))) #> Geometry set for 2 features #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: -76.00897 ymin: 36.3196 xmax: -76.00897 ymax: 36.3196 #> CRS: NA #> POINT (-76.00897 36.3196) #> MULTIPOINT ((-76.00897 36.3196)) s = st_multipoint(rbind(c(1,0))) st_cast(s, \"POINT\") #> Warning: point from first coordinate only #> POINT (1 0) # https://github.com/r-spatial/sf/issues/1930: pt1 <- st_point(c(0,1)) pt23 <- st_multipoint(matrix(c(1,2,3,4), ncol = 2, byrow = TRUE)) d <- st_sf(geom = st_sfc(pt1, pt23)) st_cast(d, \"POINT\") # will not convert the entire MULTIPOINT, and warns #> Warning: point from first coordinate only #> Simple feature collection with 2 features and 0 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 1 ymax: 2 #> CRS: NA #> geom #> 1 POINT (0 1) #> 2 POINT (1 2) st_cast(d, \"MULTIPOINT\") %>% st_cast(\"POINT\") #> Simple feature collection with 3 features and 0 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 1 xmax: 3 ymax: 4 #> CRS: NA #> geom #> 1 POINT (0 1) #> 2 POINT (1 2) #> 3 POINT (3 4)"},{"path":"https://r-spatial.github.io/sf/reference/st_cast_sfc_default.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerce geometry to MULTI* geometry — st_cast_sfc_default","title":"Coerce geometry to MULTI* geometry — st_cast_sfc_default","text":"Mixes POINTS MULTIPOINTS, LINESTRING MULTILINESTRING, POLYGON MULTIPOLYGON returned MULTIPOINTS, MULTILINESTRING MULTIPOLYGONS respectively","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_cast_sfc_default.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerce geometry to MULTI* geometry — st_cast_sfc_default","text":"","code":"st_cast_sfc_default(x)"},{"path":"https://r-spatial.github.io/sf/reference/st_cast_sfc_default.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerce geometry to MULTI* geometry — st_cast_sfc_default","text":"x list geometries simple features","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_cast_sfc_default.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Coerce geometry to MULTI* geometry — st_cast_sfc_default","text":"Geometries already MULTI* left unchanged. Features cast single MULTI* geometry return GEOMETRYCOLLECTION","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_collection_extract.html","id":null,"dir":"Reference","previous_headings":"","what":"Given an object with geometries of type GEOMETRY or GEOMETRYCOLLECTION, return an object consisting only of elements of the specified type. — st_collection_extract","title":"Given an object with geometries of type GEOMETRY or GEOMETRYCOLLECTION, return an object consisting only of elements of the specified type. — st_collection_extract","text":"Similar ST_CollectionExtract PostGIS. sub-geometries specified type, empty geometry returned.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_collection_extract.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Given an object with geometries of type GEOMETRY or GEOMETRYCOLLECTION, return an object consisting only of elements of the specified type. — st_collection_extract","text":"","code":"st_collection_extract( x, type = c(\"POLYGON\", \"POINT\", \"LINESTRING\"), warn = FALSE ) # S3 method for class 'sfg' st_collection_extract( x, type = c(\"POLYGON\", \"POINT\", \"LINESTRING\"), warn = FALSE ) # S3 method for class 'sfc' st_collection_extract( x, type = c(\"POLYGON\", \"POINT\", \"LINESTRING\"), warn = FALSE ) # S3 method for class 'sf' st_collection_extract( x, type = c(\"POLYGON\", \"POINT\", \"LINESTRING\"), warn = FALSE )"},{"path":"https://r-spatial.github.io/sf/reference/st_collection_extract.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Given an object with geometries of type GEOMETRY or GEOMETRYCOLLECTION, return an object consisting only of elements of the specified type. — st_collection_extract","text":"x object class sf, sfc sfg mixed geometry (GEOMETRY GEOMETRYCOLLECTION). type character; one \"POLYGON\", \"POINT\", \"LINESTRING\" warn logical; TRUE, warn attributes assigned sub-geometries casting (see st_cast)","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_collection_extract.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Given an object with geometries of type GEOMETRY or GEOMETRYCOLLECTION, return an object consisting only of elements of the specified type. — st_collection_extract","text":"object class x, geometries consisting elements specified type. sfg objects, sfg object returned one geometry specified type, otherwise geometries combined sfc object relevant type. subgeometries input MULTI, subgeometries output MULTI.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_collection_extract.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Given an object with geometries of type GEOMETRY or GEOMETRYCOLLECTION, return an object consisting only of elements of the specified type. — st_collection_extract","text":"","code":"pt <- st_point(c(1, 0)) ls <- st_linestring(matrix(c(4, 3, 0, 0), ncol = 2)) poly1 <- st_polygon(list(matrix(c(5.5, 7, 7, 6, 5.5, 0, 0, -0.5, -0.5, 0), ncol = 2))) poly2 <- st_polygon(list(matrix(c(6.6, 8, 8, 7, 6.6, 1, 1, 1.5, 1.5, 1), ncol = 2))) multipoly <- st_multipolygon(list(poly1, poly2)) i <- st_geometrycollection(list(pt, ls, poly1, poly2)) j <- st_geometrycollection(list(pt, ls, poly1, poly2, multipoly)) st_collection_extract(i, \"POLYGON\") #> Geometry set for 2 features #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 5.5 ymin: -0.5 xmax: 8 ymax: 1.5 #> CRS: NA #> POLYGON ((5.5 0, 7 0, 7 -0.5, 6 -0.5, 5.5 0)) #> POLYGON ((6.6 1, 8 1, 8 1.5, 7 1.5, 6.6 1)) st_collection_extract(i, \"POINT\") #> POINT (1 0) st_collection_extract(i, \"LINESTRING\") #> LINESTRING (4 0, 3 0) ## A GEOMETRYCOLLECTION aa <- rbind(st_sf(a=1, geom = st_sfc(i)), st_sf(a=2, geom = st_sfc(j))) ## With sf objects st_collection_extract(aa, \"POLYGON\") #> Simple feature collection with 5 features and 1 field #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: 5.5 ymin: -0.5 xmax: 8 ymax: 1.5 #> CRS: NA #> a geom #> 1.2 1 MULTIPOLYGON (((5.5 0, 7 0,... #> 1.3 1 MULTIPOLYGON (((6.6 1, 8 1,... #> 2.2 2 MULTIPOLYGON (((5.5 0, 7 0,... #> 2.3 2 MULTIPOLYGON (((6.6 1, 8 1,... #> 2.4 2 MULTIPOLYGON (((5.5 0, 7 0,... st_collection_extract(aa, \"LINESTRING\") #> Simple feature collection with 2 features and 1 field #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 3 ymin: 0 xmax: 4 ymax: 0 #> CRS: NA #> a geom #> 1.1 1 LINESTRING (4 0, 3 0) #> 2.1 2 LINESTRING (4 0, 3 0) st_collection_extract(aa, \"POINT\") #> Simple feature collection with 2 features and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 0 xmax: 1 ymax: 0 #> CRS: NA #> a geom #> 1 1 POINT (1 0) #> 2 2 POINT (1 0) ## With sfc objects st_collection_extract(st_geometry(aa), \"POLYGON\") #> Geometry set for 5 features #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: 5.5 ymin: -0.5 xmax: 8 ymax: 1.5 #> CRS: NA #> MULTIPOLYGON (((5.5 0, 7 0, 7 -0.5, 6 -0.5, 5.5... #> MULTIPOLYGON (((6.6 1, 8 1, 8 1.5, 7 1.5, 6.6 1))) #> MULTIPOLYGON (((5.5 0, 7 0, 7 -0.5, 6 -0.5, 5.5... #> MULTIPOLYGON (((6.6 1, 8 1, 8 1.5, 7 1.5, 6.6 1))) #> MULTIPOLYGON (((5.5 0, 7 0, 7 -0.5, 6 -0.5, 5.5... st_collection_extract(st_geometry(aa), \"LINESTRING\") #> Geometry set for 2 features #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 3 ymin: 0 xmax: 4 ymax: 0 #> CRS: NA #> LINESTRING (4 0, 3 0) #> LINESTRING (4 0, 3 0) st_collection_extract(st_geometry(aa), \"POINT\") #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 0 xmax: 1 ymax: 0 #> CRS: NA #> POINT (1 0) #> POINT (1 0) ## A GEOMETRY of single types bb <- rbind( st_sf(a = 1, geom = st_sfc(pt)), st_sf(a = 2, geom = st_sfc(ls)), st_sf(a = 3, geom = st_sfc(poly1)), st_sf(a = 4, geom = st_sfc(multipoly)) ) st_collection_extract(bb, \"POLYGON\") #> Simple feature collection with 2 features and 1 field #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: 5.5 ymin: -0.5 xmax: 8 ymax: 1.5 #> CRS: NA #> a geom #> 3 3 MULTIPOLYGON (((5.5 0, 7 0,... #> 4 4 MULTIPOLYGON (((5.5 0, 7 0,... ## A GEOMETRY of mixed single types and GEOMETRYCOLLECTIONS cc <- rbind(aa, bb) st_collection_extract(cc, \"POLYGON\") #> Simple feature collection with 7 features and 1 field #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: 5.5 ymin: -0.5 xmax: 8 ymax: 1.5 #> CRS: NA #> a geom #> 1.2 1 MULTIPOLYGON (((5.5 0, 7 0,... #> 1.3 1 MULTIPOLYGON (((6.6 1, 8 1,... #> 2.2 2 MULTIPOLYGON (((5.5 0, 7 0,... #> 2.3 2 MULTIPOLYGON (((6.6 1, 8 1,... #> 2.4 2 MULTIPOLYGON (((5.5 0, 7 0,... #> 5 3 MULTIPOLYGON (((5.5 0, 7 0,... #> 6 4 MULTIPOLYGON (((5.5 0, 7 0,..."},{"path":"https://r-spatial.github.io/sf/reference/st_coordinates.html","id":null,"dir":"Reference","previous_headings":"","what":"retrieve coordinates in matrix form — st_coordinates","title":"retrieve coordinates in matrix form — st_coordinates","text":"retrieve coordinates matrix form","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_coordinates.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"retrieve coordinates in matrix form — st_coordinates","text":"","code":"st_coordinates(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_coordinates.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"retrieve coordinates in matrix form — st_coordinates","text":"x object class sf, sfc sfg ... ignored","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_coordinates.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"retrieve coordinates in matrix form — st_coordinates","text":"matrix coordinates (X, Y, possibly Z /M) rows, possibly followed integer indicators L1,...,L3 point structure coordinate belongs; POINT absent (coordinate feature), LINESTRING L1 refers feature, MULTILINESTRING L1 refers part L2 simple feature, POLYGON L1 refers main ring holes L2 simple feature, MULTIPOLYGON L1 refers main ring holes, L2 ring id MULTIPOLYGON, L3 simple feature. POLYGONS, L1 can used identify exterior rings inner holes. exterior ring L1 equal 1. Interior rings identified L1 greater 1. L2 can used differentiate feature. Whereas MULTIPOLYGON, L3 refers MULTIPOLYGON feature L2 refers component POLYGON.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crop.html","id":null,"dir":"Reference","previous_headings":"","what":"crop an sf object to a specific rectangle — st_crop","title":"crop an sf object to a specific rectangle — st_crop","text":"crop sf object specific rectangle","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crop.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"crop an sf object to a specific rectangle — st_crop","text":"","code":"st_crop(x, y, ...) # S3 method for class 'sfc' st_crop(x, y, ..., xmin, ymin, xmax, ymax) # S3 method for class 'sf' st_crop(x, y, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_crop.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"crop an sf object to a specific rectangle — st_crop","text":"x object class sf sfc y numeric vector named elements xmin, ymin, xmax ymax, object class bbox, object st_bbox method convert bbox object ... ignored xmin minimum x extent cropping area ymin minimum y extent cropping area xmax maximum x extent cropping area ymax maximum y extent cropping area","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crop.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"crop an sf object to a specific rectangle — st_crop","text":"setting arguments xmin, ymin, xmax ymax implies argument y gets ignored.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crop.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"crop an sf object to a specific rectangle — st_crop","text":"","code":"box = c(xmin = 0, ymin = 0, xmax = 1, ymax = 1) pol = st_sfc(st_buffer(st_point(c(.5, .5)), .6)) pol_sf = st_sf(a=1, geom=pol) plot(st_crop(pol, box)) plot(st_crop(pol_sf, st_bbox(box))) #> Warning: attribute variables are assumed to be spatially constant throughout all geometries # alternative: plot(st_crop(pol, xmin = 0, ymin = 0, xmax = 1, ymax = 1))"},{"path":"https://r-spatial.github.io/sf/reference/st_crs.html","id":null,"dir":"Reference","previous_headings":"","what":"Retrieve coordinate reference system from object — st_crs","title":"Retrieve coordinate reference system from object — st_crs","text":"Retrieve coordinate reference system sf sfc object Set replace retrieve coordinate reference system object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crs.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Retrieve coordinate reference system from object — st_crs","text":"","code":"st_crs(x, ...) # S3 method for class 'sf' st_crs(x, ...) # S3 method for class 'numeric' st_crs(x, ...) # S3 method for class 'character' st_crs(x, ...) # S3 method for class 'sfc' st_crs(x, ..., parameters = FALSE) # S3 method for class 'bbox' st_crs(x, ...) # S3 method for class 'CRS' st_crs(x, ...) # S3 method for class 'crs' st_crs(x, ...) st_crs(x) <- value # S3 method for class 'sf' st_crs(x) <- value # S3 method for class 'sfc' st_crs(x) <- value st_set_crs(x, value) NA_crs_ # S3 method for class 'crs' is.na(x) # S3 method for class 'crs' x$name # S3 method for class 'crs' format(x, ...) st_axis_order(authority_compliant = logical(0))"},{"path":"https://r-spatial.github.io/sf/reference/st_crs.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Retrieve coordinate reference system from object — st_crs","text":"object class crs length 2.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crs.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Retrieve coordinate reference system from object — st_crs","text":"x numeric, character, object class sf sfc ... ignored parameters logical; FALSE default; TRUE return list coordinate reference system parameters, named elements SemiMajor, InvFlattening, units_gdal, IsVertical, WktPretty, Wkt value one () character: string accepted GDAL, (ii) integer, valid EPSG value (numeric), (iii) object class crs. name element name authority_compliant logical; specify whether axis order handled compliant authority; omitted, current value printed.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crs.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Retrieve coordinate reference system from object — st_crs","text":"x numeric, return crs object EPSG:x; x character, return crs object x; x class sf sfc, return crs object. Object class crs, list elements input (length-1 character) wkt (length-1 character). Elements may NA valued; elements NA CRS missing valued, coordinates assumed relate arbitrary Cartesian coordinate system. st_axis_order returns (logical) current value called without argument, (invisibly) previous value set.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crs.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Retrieve coordinate reference system from object — st_crs","text":"*crs functions create, get, set replace crs attribute simple feature geometry list-column. attribute class crs, list consisting input (user input, e.g. \"EPSG:4326\" \"WGS84\" proj4string), wkt, automatically generated wkt2 representation crs. x identical wkt2 representation, CRS name, name used input field. Comparison two objects class crs uses GDAL function OGRSpatialReference::IsSame. case coordinate reference system replaced, transformation takes place warning raised stress . NA_crs_ crs object missing values input wkt. $ method crs objects retrieves named elements using GDAL interface; named elements include SemiMajor, SemiMinor, InvFlattening, IsGeographic, units_gdal, IsVertical, WktPretty, Wkt, Name, proj4string, epsg, yx, ud_unit, axes (may subject changes future GDAL versions). Note valid CRS corresponding proj4string. ud_unit returns valid units object NULL units missing. format.crs returns NA crs missing valued, else name crs different \"unknown\", else user input set, else \"proj4string\" representation; st_axis_order can used get set axis order: TRUE indicates axes order according authority (e.g. EPSG:4326 defining coordinates latitude,longitude pairs), FALSE indicates usual GIS (display) order (longitude,latitude). can useful data read, written, coordinates authority compliant order. return value current state (FALSE, default).","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_crs.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Retrieve coordinate reference system from object — st_crs","text":"","code":"sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1))) sf = st_sf(a = 1:2, geom = sfc) st_crs(sf) = 4326 st_geometry(sf) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> Geodetic CRS: WGS 84 #> POINT (0 0) #> POINT (1 1) sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1))) st_crs(sfc) = 4326 sfc #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> Geodetic CRS: WGS 84 #> POINT (0 0) #> POINT (1 1) sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1))) sfc %>% st_set_crs(4326) %>% st_transform(3857) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 111319.5 ymax: 111325.1 #> Projected CRS: WGS 84 / Pseudo-Mercator #> POINT (0 0) #> POINT (111319.5 111325.1) st_crs(\"EPSG:3857\")$input #> [1] \"EPSG:3857\" st_crs(3857)$proj4string #> [1] \"+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs\" pt = st_sfc(st_point(c(0, 60)), crs = 4326) # st_axis_order() only has effect in GDAL >= 2.5.0: st_axis_order() # query default: FALSE means interpret pt as (longitude latitude) #> [1] FALSE st_transform(pt, 3857)[[1]] #> POINT (0 8399738) old_value = FALSE if (sf_extSoftVersion()[\"GDAL\"] >= \"2.5.0\") (old_value = st_axis_order(TRUE)) #> [1] FALSE # now interpret pt as (latitude longitude), as EPSG:4326 prescribes: st_axis_order() # query current value #> [1] TRUE st_transform(pt, 3857)[[1]] #> POINT (6679169 0) st_axis_order(old_value) # set back to old value"},{"path":"https://r-spatial.github.io/sf/reference/st_drivers.html","id":null,"dir":"Reference","previous_headings":"","what":"Get GDAL drivers — st_drivers","title":"Get GDAL drivers — st_drivers","text":"Get list available GDAL drivers","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_drivers.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get GDAL drivers — st_drivers","text":"","code":"st_drivers(what = \"vector\", regex)"},{"path":"https://r-spatial.github.io/sf/reference/st_drivers.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get GDAL drivers — st_drivers","text":"character: \"vector\" \"raster\", anything else return drivers. regex character; regular expression filter name long_name fields ","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_drivers.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get GDAL drivers — st_drivers","text":"data.frame driver metadata.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_drivers.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Get GDAL drivers — st_drivers","text":"drivers available depend installation GDAL/OGR, can vary; st_drivers() function shows drivers readable, may written. field vsi refers driver's capability read/create datasets VSI*L API. See GDAL website additional details driver support","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_drivers.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get GDAL drivers — st_drivers","text":"","code":"# The following driver lists depend on the GDAL setup and platform used: st_drivers() #> name #> ESRIC ESRIC #> FITS FITS #> PCIDSK PCIDSK #> netCDF netCDF #> PDS4 PDS4 #> VICAR VICAR #> JP2OpenJPEG JP2OpenJPEG #> PDF PDF #> MBTiles MBTiles #> BAG BAG #> EEDA EEDA #> OGCAPI OGCAPI #> ESRI Shapefile ESRI Shapefile #> MapInfo File MapInfo File #> UK .NTF UK .NTF #> LVBAG LVBAG #> OGR_SDTS OGR_SDTS #> S57 S57 #> DGN DGN #> OGR_VRT OGR_VRT #> REC REC #> Memory Memory #> CSV CSV #> NAS NAS #> GML GML #> GPX GPX #> LIBKML LIBKML #> KML KML #> GeoJSON GeoJSON #> GeoJSONSeq GeoJSONSeq #> ESRIJSON ESRIJSON #> TopoJSON TopoJSON #> Interlis 1 Interlis 1 #> Interlis 2 Interlis 2 #> OGR_GMT OGR_GMT #> GPKG GPKG #> SQLite SQLite #> ODBC ODBC #> WAsP WAsP #> PGeo PGeo #> MSSQLSpatial MSSQLSpatial #> OGR_OGDI OGR_OGDI #> PostgreSQL PostgreSQL #> MySQL MySQL #> OpenFileGDB OpenFileGDB #> DXF DXF #> CAD CAD #> FlatGeobuf FlatGeobuf #> Geoconcept Geoconcept #> GeoRSS GeoRSS #> GPSTrackMaker GPSTrackMaker #> VFK VFK #> PGDUMP PGDUMP #> OSM OSM #> GPSBabel GPSBabel #> OGR_PDS OGR_PDS #> WFS WFS #> OAPIF OAPIF #> SOSI SOSI #> Geomedia Geomedia #> EDIGEO EDIGEO #> SVG SVG #> CouchDB CouchDB #> Cloudant Cloudant #> Idrisi Idrisi #> ARCGEN ARCGEN #> XLS XLS #> ODS ODS #> XLSX XLSX #> Elasticsearch Elasticsearch #> Walk Walk #> Carto Carto #> AmigoCloud AmigoCloud #> SXF SXF #> Selafin Selafin #> JML JML #> PLSCENES PLSCENES #> CSW CSW #> VDV VDV #> GMLAS GMLAS #> MVT MVT #> NGW NGW #> MapML MapML #> TIGER TIGER #> AVCBin AVCBin #> AVCE00 AVCE00 #> HTTP HTTP #> long_name #> ESRIC Esri Compact Cache #> FITS Flexible Image Transport System #> PCIDSK PCIDSK Database File #> netCDF Network Common Data Format #> PDS4 NASA Planetary Data System 4 #> VICAR MIPL VICAR file #> JP2OpenJPEG JPEG-2000 driver based on OpenJPEG library #> PDF Geospatial PDF #> MBTiles MBTiles #> BAG Bathymetry Attributed Grid #> EEDA Earth Engine Data API #> OGCAPI OGCAPI #> ESRI Shapefile ESRI Shapefile #> MapInfo File MapInfo File #> UK .NTF UK .NTF #> LVBAG Kadaster LV BAG Extract 2.0 #> OGR_SDTS SDTS #> S57 IHO S-57 (ENC) #> DGN Microstation DGN #> OGR_VRT VRT - Virtual Datasource #> REC EPIInfo .REC #> Memory Memory #> CSV Comma Separated Value (.csv) #> NAS NAS - ALKIS #> GML Geography Markup Language (GML) #> GPX GPX #> LIBKML Keyhole Markup Language (LIBKML) #> KML Keyhole Markup Language (KML) #> GeoJSON GeoJSON #> GeoJSONSeq GeoJSON Sequence #> ESRIJSON ESRIJSON #> TopoJSON TopoJSON #> Interlis 1 Interlis 1 #> Interlis 2 Interlis 2 #> OGR_GMT GMT ASCII Vectors (.gmt) #> GPKG GeoPackage #> SQLite SQLite / Spatialite #> ODBC #> WAsP WAsP .map format #> PGeo ESRI Personal GeoDatabase #> MSSQLSpatial Microsoft SQL Server Spatial Database #> OGR_OGDI OGDI Vectors (VPF, VMAP, DCW) #> PostgreSQL PostgreSQL/PostGIS #> MySQL MySQL #> OpenFileGDB ESRI FileGDB #> DXF AutoCAD DXF #> CAD AutoCAD Driver #> FlatGeobuf FlatGeobuf #> Geoconcept Geoconcept #> GeoRSS GeoRSS #> GPSTrackMaker GPSTrackMaker #> VFK Czech Cadastral Exchange Data Format #> PGDUMP PostgreSQL SQL dump #> OSM OpenStreetMap XML and PBF #> GPSBabel GPSBabel #> OGR_PDS Planetary Data Systems TABLE #> WFS OGC WFS (Web Feature Service) #> OAPIF OGC API - Features #> SOSI Norwegian SOSI Standard #> Geomedia Geomedia .mdb #> EDIGEO French EDIGEO exchange format #> SVG Scalable Vector Graphics #> CouchDB CouchDB / GeoCouch #> Cloudant Cloudant / CouchDB #> Idrisi Idrisi Vector (.vct) #> ARCGEN Arc/Info Generate #> XLS MS Excel format #> ODS Open Document/ LibreOffice / OpenOffice Spreadsheet #> XLSX MS Office Open XML spreadsheet #> Elasticsearch Elastic Search #> Walk #> Carto Carto #> AmigoCloud AmigoCloud #> SXF Storage and eXchange Format #> Selafin Selafin #> JML OpenJUMP JML #> PLSCENES Planet Labs Scenes API #> CSW OGC CSW (Catalog Service for the Web) #> VDV VDV-451/VDV-452/INTREST Data Format #> GMLAS Geography Markup Language (GML) driven by application schemas #> MVT Mapbox Vector Tiles #> NGW NextGIS Web #> MapML MapML #> TIGER U.S. Census TIGER/Line #> AVCBin Arc/Info Binary Coverage #> AVCE00 Arc/Info E00 (ASCII) Coverage #> HTTP HTTP Fetching Wrapper #> write copy is_raster is_vector vsi #> ESRIC FALSE FALSE TRUE TRUE TRUE #> FITS TRUE FALSE TRUE TRUE FALSE #> PCIDSK TRUE FALSE TRUE TRUE TRUE #> netCDF TRUE TRUE TRUE TRUE TRUE #> PDS4 TRUE TRUE TRUE TRUE TRUE #> VICAR TRUE TRUE TRUE TRUE TRUE #> JP2OpenJPEG FALSE TRUE TRUE TRUE TRUE #> PDF TRUE TRUE TRUE TRUE TRUE #> MBTiles TRUE TRUE TRUE TRUE TRUE #> BAG TRUE TRUE TRUE TRUE TRUE #> EEDA FALSE FALSE FALSE TRUE FALSE #> OGCAPI FALSE FALSE TRUE TRUE TRUE #> ESRI Shapefile TRUE FALSE FALSE TRUE TRUE #> MapInfo File TRUE FALSE FALSE TRUE TRUE #> UK .NTF FALSE FALSE FALSE TRUE TRUE #> LVBAG FALSE FALSE FALSE TRUE TRUE #> OGR_SDTS FALSE FALSE FALSE TRUE TRUE #> S57 TRUE FALSE FALSE TRUE TRUE #> DGN TRUE FALSE FALSE TRUE TRUE #> OGR_VRT FALSE FALSE FALSE TRUE TRUE #> REC FALSE FALSE FALSE TRUE FALSE #> Memory TRUE FALSE FALSE TRUE FALSE #> CSV TRUE FALSE FALSE TRUE TRUE #> NAS FALSE FALSE FALSE TRUE TRUE #> GML TRUE FALSE FALSE TRUE TRUE #> GPX TRUE FALSE FALSE TRUE TRUE #> LIBKML TRUE FALSE FALSE TRUE TRUE #> KML TRUE FALSE FALSE TRUE TRUE #> GeoJSON TRUE FALSE FALSE TRUE TRUE #> GeoJSONSeq TRUE FALSE FALSE TRUE TRUE #> ESRIJSON FALSE FALSE FALSE TRUE TRUE #> TopoJSON FALSE FALSE FALSE TRUE TRUE #> Interlis 1 TRUE FALSE FALSE TRUE TRUE #> Interlis 2 TRUE FALSE FALSE TRUE TRUE #> OGR_GMT TRUE FALSE FALSE TRUE TRUE #> GPKG TRUE TRUE TRUE TRUE TRUE #> SQLite TRUE FALSE FALSE TRUE TRUE #> ODBC FALSE FALSE FALSE TRUE FALSE #> WAsP TRUE FALSE FALSE TRUE TRUE #> PGeo FALSE FALSE FALSE TRUE FALSE #> MSSQLSpatial TRUE FALSE FALSE TRUE FALSE #> OGR_OGDI FALSE FALSE FALSE TRUE FALSE #> PostgreSQL TRUE FALSE FALSE TRUE FALSE #> MySQL TRUE FALSE FALSE TRUE FALSE #> OpenFileGDB FALSE FALSE FALSE TRUE TRUE #> DXF TRUE FALSE FALSE TRUE TRUE #> CAD FALSE FALSE TRUE TRUE TRUE #> FlatGeobuf TRUE FALSE FALSE TRUE TRUE #> Geoconcept TRUE FALSE FALSE TRUE TRUE #> GeoRSS TRUE FALSE FALSE TRUE TRUE #> GPSTrackMaker TRUE FALSE FALSE TRUE TRUE #> VFK FALSE FALSE FALSE TRUE FALSE #> PGDUMP TRUE FALSE FALSE TRUE TRUE #> OSM FALSE FALSE FALSE TRUE TRUE #> GPSBabel TRUE FALSE FALSE TRUE FALSE #> OGR_PDS FALSE FALSE FALSE TRUE TRUE #> WFS FALSE FALSE FALSE TRUE TRUE #> OAPIF FALSE FALSE FALSE TRUE FALSE #> SOSI FALSE FALSE FALSE TRUE FALSE #> Geomedia FALSE FALSE FALSE TRUE FALSE #> EDIGEO FALSE FALSE FALSE TRUE TRUE #> SVG FALSE FALSE FALSE TRUE TRUE #> CouchDB TRUE FALSE FALSE TRUE FALSE #> Cloudant TRUE FALSE FALSE TRUE FALSE #> Idrisi FALSE FALSE FALSE TRUE TRUE #> ARCGEN FALSE FALSE FALSE TRUE TRUE #> XLS FALSE FALSE FALSE TRUE FALSE #> ODS TRUE FALSE FALSE TRUE TRUE #> XLSX TRUE FALSE FALSE TRUE TRUE #> Elasticsearch TRUE FALSE FALSE TRUE FALSE #> Walk FALSE FALSE FALSE TRUE FALSE #> Carto TRUE FALSE FALSE TRUE FALSE #> AmigoCloud TRUE FALSE FALSE TRUE FALSE #> SXF FALSE FALSE FALSE TRUE TRUE #> Selafin TRUE FALSE FALSE TRUE TRUE #> JML TRUE FALSE FALSE TRUE TRUE #> PLSCENES FALSE FALSE TRUE TRUE FALSE #> CSW FALSE FALSE FALSE TRUE FALSE #> VDV TRUE FALSE FALSE TRUE TRUE #> GMLAS FALSE TRUE FALSE TRUE TRUE #> MVT TRUE FALSE FALSE TRUE TRUE #> NGW TRUE TRUE TRUE TRUE FALSE #> MapML TRUE FALSE FALSE TRUE TRUE #> TIGER TRUE FALSE FALSE TRUE TRUE #> AVCBin FALSE FALSE FALSE TRUE TRUE #> AVCE00 FALSE FALSE FALSE TRUE TRUE #> HTTP FALSE FALSE TRUE TRUE FALSE st_drivers(\"raster\", \"GeoT\") #> name long_name write copy is_raster is_vector #> GTiff GTiff GeoTIFF TRUE TRUE TRUE FALSE #> COG COG Cloud optimized GeoTIFF generator FALSE TRUE TRUE FALSE #> vsi #> GTiff TRUE #> COG TRUE"},{"path":"https://r-spatial.github.io/sf/reference/st_geometry.html","id":null,"dir":"Reference","previous_headings":"","what":"Get, set, replace or rename geometry from an sf object — st_geometry","title":"Get, set, replace or rename geometry from an sf object — st_geometry","text":"Get, set, replace rename geometry sf object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_geometry.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get, set, replace or rename geometry from an sf object — st_geometry","text":"","code":"# S3 method for class 'sfc' st_geometry(obj, ...) st_geometry(obj, ...) # S3 method for class 'sf' st_geometry(obj, ...) # S3 method for class 'sfc' st_geometry(obj, ...) # S3 method for class 'sfg' st_geometry(obj, ...) st_geometry(x) <- value st_set_geometry(x, value) st_drop_geometry(x, ...) # S3 method for class 'sf' st_drop_geometry(x, ...) # Default S3 method st_drop_geometry(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_geometry.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get, set, replace or rename geometry from an sf object — st_geometry","text":"obj object class sf sfc ... ignored x object class data.frame sf value object class sfc, character set, replace, rename geometry x","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_geometry.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get, set, replace or rename geometry from an sf object — st_geometry","text":"st_geometry returns object class sfc, list-column geometries st_geometry returns object class sfc. Assigning geometry data.frame creates sf object, assigning sf object replaces geometry list-column.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_geometry.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Get, set, replace or rename geometry from an sf object — st_geometry","text":"applied data.frame value object class sfc, st_set_geometry st_geometry<- first check existence attribute sf_column overwrite , else look list-columns class sfc overwrite first , else write geometry list-column column named geometry. case value character x class sf, \"active\" geometry column set x[[value]]. replacement function applied sf objects overwrite geometry list-column, value NULL, remove coerce x data.frame. x class sf, st_drop_geometry drops geometry argument, reclasses accordingly; otherwise returns x unmodified.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_geometry.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get, set, replace or rename geometry from an sf object — st_geometry","text":"","code":"df = data.frame(a = 1:2) sfc = st_sfc(st_point(c(3,4)), st_point(c(10,11))) st_geometry(sfc) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 3 ymin: 4 xmax: 10 ymax: 11 #> CRS: NA #> POINT (3 4) #> POINT (10 11) st_geometry(df) <- sfc class(df) #> [1] \"sf\" \"data.frame\" st_geometry(df) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 3 ymin: 4 xmax: 10 ymax: 11 #> CRS: NA #> POINT (3 4) #> POINT (10 11) st_geometry(df) <- sfc # replaces st_geometry(df) <- NULL # remove geometry, coerce to data.frame sf <- st_set_geometry(df, sfc) # set geometry, return sf st_set_geometry(sf, NULL) # remove geometry, coerce to data.frame #> a #> 1 1 #> 2 2"},{"path":"https://r-spatial.github.io/sf/reference/st_geometry_type.html","id":null,"dir":"Reference","previous_headings":"","what":"Return geometry type of an object — st_geometry_type","title":"Return geometry type of an object — st_geometry_type","text":"Return geometry type object, factor","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_geometry_type.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return geometry type of an object — st_geometry_type","text":"","code":"st_geometry_type(x, by_geometry = TRUE)"},{"path":"https://r-spatial.github.io/sf/reference/st_geometry_type.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Return geometry type of an object — st_geometry_type","text":"x object class sf sfc by_geometry logical; TRUE, return geometry type geometry, else return geometry type set","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_geometry_type.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Return geometry type of an object — st_geometry_type","text":"factor geometry type simple feature geometry x, whole set","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_graticule.html","id":null,"dir":"Reference","previous_headings":"","what":"Compute graticules and their parameters — st_graticule","title":"Compute graticules and their parameters — st_graticule","text":"Compute graticules parameters","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_graticule.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compute graticules and their parameters — st_graticule","text":"","code":"st_graticule( x = c(-180, -90, 180, 90), crs = st_crs(x), datum = st_crs(4326), ..., lon = NULL, lat = NULL, ndiscr = 100, margin = 0.001 )"},{"path":"https://r-spatial.github.io/sf/reference/st_graticule.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compute graticules and their parameters — st_graticule","text":"x object class sf, sfc sfg numeric vector bounding box given (minx, miny, maxx, maxy). crs object class crs, display coordinate reference system datum either object class crs coordinate reference system graticules, NULL case grid coordinate system x drawn, NA, case empty sf object returned. ... ignored lon numeric; values degrees East meridians, associated datum lat numeric; values degrees North parallels, associated datum ndiscr integer; number points discretize parallel meridian margin numeric; small number trim longlat bounding box touches crosses +/-180 long +/-90 latitude.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_graticule.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compute graticules and their parameters — st_graticule","text":"object class sf additional attributes describing type (E: meridian, N: parallel) degree value, label, start end coordinates angle; see example.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_graticule.html","id":"use-of-graticules","dir":"Reference","previous_headings":"","what":"Use of graticules","title":"Compute graticules and their parameters — st_graticule","text":"cartographic visualization, use graticules advised, unless graphical output used measurement navigation, direction North important interpretation content, content intended display distortions artifacts created projection. Unnecessary use graticules adds visual clutter little relevant information. Use coastlines, administrative boundaries place names permits viewers output orient better graticule.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_graticule.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Compute graticules and their parameters — st_graticule","text":"","code":"library(sf) if (require(maps, quietly = TRUE)) { usa = st_as_sf(map('usa', plot = FALSE, fill = TRUE)) laea = st_crs(\"+proj=laea +lat_0=30 +lon_0=-95\") # Lambert equal area usa <- st_transform(usa, laea) bb = st_bbox(usa) bbox = st_linestring(rbind(c( bb[1],bb[2]),c( bb[3],bb[2]), c( bb[3],bb[4]),c( bb[1],bb[4]),c( bb[1],bb[2]))) g = st_graticule(usa) plot(usa, xlim = 1.2 * c(-2450853.4, 2186391.9), reset = FALSE) plot(g[1], add = TRUE, col = 'grey') plot(bbox, add = TRUE) points(g$x_start, g$y_start, col = 'red') points(g$x_end, g$y_end, col = 'blue') invisible(lapply(seq_len(nrow(g)), function(i) { if (g$type[i] == \"N\" && g$x_start[i] - min(g$x_start) < 1000) text(g$x_start[i], g$y_start[i], labels = parse(text = g$degree_label[i]), srt = g$angle_start[i], pos = 2, cex = .7) if (g$type[i] == \"E\" && g$y_start[i] - min(g$y_start) < 1000) text(g$x_start[i], g$y_start[i], labels = parse(text = g$degree_label[i]), srt = g$angle_start[i] - 90, pos = 1, cex = .7) if (g$type[i] == \"N\" && g$x_end[i] - max(g$x_end) > -1000) text(g$x_end[i], g$y_end[i], labels = parse(text = g$degree_label[i]), srt = g$angle_end[i], pos = 4, cex = .7) if (g$type[i] == \"E\" && g$y_end[i] - max(g$y_end) > -1000) text(g$x_end[i], g$y_end[i], labels = parse(text = g$degree_label[i]), srt = g$angle_end[i] - 90, pos = 3, cex = .7) })) plot(usa, graticule = st_crs(4326), axes = TRUE, lon = seq(-60,-130,by=-10)) }"},{"path":"https://r-spatial.github.io/sf/reference/st_is.html","id":null,"dir":"Reference","previous_headings":"","what":"test equality between the geometry type and a class or set of classes — st_is","title":"test equality between the geometry type and a class or set of classes — st_is","text":"test equality geometry type class set classes","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_is.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"test equality between the geometry type and a class or set of classes — st_is","text":"","code":"st_is(x, type)"},{"path":"https://r-spatial.github.io/sf/reference/st_is.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"test equality between the geometry type and a class or set of classes — st_is","text":"x object class sf, sfc sfg type character; class, set classes, test ","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_is.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"test equality between the geometry type and a class or set of classes — st_is","text":"","code":"st_is(st_point(0:1), \"POINT\") #> [1] TRUE sfc = st_sfc(st_point(0:1), st_linestring(matrix(1:6,,2))) st_is(sfc, \"POINT\") #> [1] TRUE FALSE st_is(sfc, \"POLYGON\") #> [1] FALSE FALSE st_is(sfc, \"LINESTRING\") #> [1] FALSE TRUE st_is(st_sf(a = 1:2, sfc), \"LINESTRING\") #> [1] FALSE TRUE st_is(sfc, c(\"POINT\", \"LINESTRING\")) #> [1] TRUE TRUE"},{"path":"https://r-spatial.github.io/sf/reference/st_is_full.html","id":null,"dir":"Reference","previous_headings":"","what":"predicate whether a geometry is equal to a POLYGON FULL — st_is_full","title":"predicate whether a geometry is equal to a POLYGON FULL — st_is_full","text":"predicate whether geometry equal POLYGON FULL","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_is_full.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"predicate whether a geometry is equal to a POLYGON FULL — st_is_full","text":"","code":"st_is_full(x, ...) # S3 method for class 'sfg' st_is_full(x, ..., is_longlat = NULL) # S3 method for class 'sfc' st_is_full(x, ...) # S3 method for class 'sf' st_is_full(x, ...) # S3 method for class 'bbox' st_is_full(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_is_full.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"predicate whether a geometry is equal to a POLYGON FULL — st_is_full","text":"x object class sfg, sfc sf ... ignored, except contains crs argument inform unspecified is_longlat is_longlat logical; output st_is_longlat parent sfc object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_is_full.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"predicate whether a geometry is equal to a POLYGON FULL — st_is_full","text":"logical, indicating whether geometries POLYGON FULL (spherical polygon covering entire sphere)","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_is_longlat.html","id":null,"dir":"Reference","previous_headings":"","what":"Assert whether simple feature coordinates are longlat degrees — st_is_longlat","title":"Assert whether simple feature coordinates are longlat degrees — st_is_longlat","text":"Assert whether simple feature coordinates longlat degrees","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_is_longlat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Assert whether simple feature coordinates are longlat degrees — st_is_longlat","text":"","code":"st_is_longlat(x)"},{"path":"https://r-spatial.github.io/sf/reference/st_is_longlat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Assert whether simple feature coordinates are longlat degrees — st_is_longlat","text":"x object class sf sfc, otherwise object class st_crs method returning crs object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_is_longlat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Assert whether simple feature coordinates are longlat degrees — st_is_longlat","text":"TRUE x geographic coordinates, FALSE projected coordinates, NA .na(st_crs(x)).","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_jitter.html","id":null,"dir":"Reference","previous_headings":"","what":"jitter geometries — st_jitter","title":"jitter geometries — st_jitter","text":"jitter geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_jitter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"jitter geometries — st_jitter","text":"","code":"st_jitter(x, amount, factor = 0.002)"},{"path":"https://r-spatial.github.io/sf/reference/st_jitter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"jitter geometries — st_jitter","text":"x object class sf sfc amount numeric; amount jittering applied; missing, amount set factor * bounding box diagonal; units coordinates. factor numeric; fractional amount jittering applied","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_jitter.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"jitter geometries — st_jitter","text":"jitters coordinates amount runif(1, -amount, amount) added coordinates. x- y-coordinates jittered independently coordinates single geometry jittered amount, meaning geometry shape change. longlat data, latitude correction made jittering East North directions identical distance center bounding box x.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_jitter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"jitter geometries — st_jitter","text":"","code":"nc = st_read(system.file(\"gpkg/nc.gpkg\", package=\"sf\")) #> Reading layer `nc.gpkg' from data source #> `/home/runner/work/_temp/Library/sf/gpkg/nc.gpkg' using driver `GPKG' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 pts = st_centroid(st_geometry(nc)) plot(pts) plot(st_jitter(pts, .05), add = TRUE, col = 'red') plot(st_geometry(nc)) plot(st_jitter(st_geometry(nc), factor = .01), add = TRUE, col = '#ff8888')"},{"path":"https://r-spatial.github.io/sf/reference/st_join.html","id":null,"dir":"Reference","previous_headings":"","what":"spatial join, spatial filter — st_join","title":"spatial join, spatial filter — st_join","text":"spatial join, spatial filter","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_join.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"spatial join, spatial filter — st_join","text":"","code":"st_join(x, y, join, ...) # S3 method for class 'sf' st_join( x, y, join = st_intersects, ..., suffix = c(\".x\", \".y\"), left = TRUE, largest = FALSE ) st_filter(x, y, ...) # S3 method for class 'sf' st_filter(x, y, ..., .predicate = st_intersects)"},{"path":"https://r-spatial.github.io/sf/reference/st_join.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"spatial join, spatial filter — st_join","text":"x object class sf y object class sf join geometry predicate function profile st_intersects; see details ... st_join: arguments passed join function st_intersection largest TRUE; st_filter arguments passed .predicate function, e.g. prepared, pattern st_relate suffix length 2 character vector; see merge left logical; TRUE return left join, otherwise inner join; see details. see also left_join largest logical; TRUE, return x features augmented fields y largest overlap features x; see https://github.com/r-spatial/sf/issues/578 .predicate geometry predicate function profile st_intersects; see details","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_join.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"spatial join, spatial filter — st_join","text":"object class sf, joined based geometry","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_join.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"spatial join, spatial filter — st_join","text":"alternative values argument join : st_contains_properly, st_contains, st_covered_by, st_covers, st_crosses, st_disjoint, st_equals_exact, st_equals, st_is_within_distance, st_nearest_feature, st_overlaps, st_touches, st_within, st_relate (require pattern set), user-defined function profile left join returns records x object y fields non-matched records filled NA values; inner join returns records spatially match. replicate results st_within(x, y) need use st_join(x, y, join = \"st_within\", left = FALSE).","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_join.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"spatial join, spatial filter — st_join","text":"","code":"a = st_sf(a = 1:3, geom = st_sfc(st_point(c(1,1)), st_point(c(2,2)), st_point(c(3,3)))) b = st_sf(a = 11:14, geom = st_sfc(st_point(c(10,10)), st_point(c(2,2)), st_point(c(2,2)), st_point(c(3,3)))) st_join(a, b) #> Simple feature collection with 4 features and 2 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 1 xmax: 3 ymax: 3 #> CRS: NA #> a.x a.y geom #> 1 1 NA POINT (1 1) #> 2 2 12 POINT (2 2) #> 2.1 2 13 POINT (2 2) #> 3 3 14 POINT (3 3) st_join(a, b, left = FALSE) #> Simple feature collection with 3 features and 2 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 2 ymin: 2 xmax: 3 ymax: 3 #> CRS: NA #> a.x a.y geom #> 2 2 12 POINT (2 2) #> 2.1 2 13 POINT (2 2) #> 3 3 14 POINT (3 3) # two ways to aggregate y's attribute values outcome over x's geometries: st_join(a, b) %>% aggregate(list(.$a.x), mean) #> Simple feature collection with 3 features and 3 fields #> Attribute-geometry relationships: aggregate (2), identity (1) #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 1 xmax: 3 ymax: 3 #> CRS: NA #> Group.1 a.x a.y geometry #> 1 1 1 NA POINT (1 1) #> 2 2 2 12.5 POINT (2 2) #> 3 3 3 14.0 POINT (3 3) if (require(dplyr, quietly = TRUE)) { st_join(a, b) %>% group_by(a.x) %>% summarise(mean(a.y)) } #> Simple feature collection with 3 features and 2 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 1 xmax: 3 ymax: 3 #> CRS: NA #> # A tibble: 3 × 3 #> a.x `mean(a.y)` geom #> #> 1 1 NA (1 1) #> 2 2 12.5 (2 2) #> 3 3 14 (3 3) # example of largest = TRUE: nc <- st_transform(st_read(system.file(\"shape/nc.shp\", package=\"sf\")), 2264) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 gr = st_sf( label = apply(expand.grid(1:10, LETTERS[10:1])[,2:1], 1, paste0, collapse = \" \"), geom = st_make_grid(st_as_sfc(st_bbox(nc)))) gr$col = sf.colors(10, categorical = TRUE, alpha = .3) # cut, to check, NA's work out: gr = gr[-(1:30),] nc_j <- st_join(nc, gr, largest = TRUE) #> Warning: attribute variables are assumed to be spatially constant throughout all geometries # the two datasets: opar = par(mfrow = c(2,1), mar = rep(0,4)) plot(st_geometry(nc_j)) plot(st_geometry(gr), add = TRUE, col = gr$col) text(st_coordinates(st_centroid(gr)), labels = gr$label) #> Warning: st_centroid assumes attributes are constant over geometries # the joined dataset: plot(st_geometry(nc_j), border = 'black', col = nc_j$col) text(st_coordinates(st_centroid(nc_j)), labels = nc_j$label, cex = .8) #> Warning: st_centroid assumes attributes are constant over geometries plot(st_geometry(gr), border = 'green', add = TRUE) par(opar) # st_filter keeps the geometries in x where .predicate(x,y) returns any match in y for x st_filter(a, b) #> Simple feature collection with 2 features and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 2 ymin: 2 xmax: 3 ymax: 3 #> CRS: NA #> a geom #> 1 2 POINT (2 2) #> 2 3 POINT (3 3) # for an anti-join, use the union of y st_filter(a, st_union(b), .predicate = st_disjoint) #> Simple feature collection with 1 feature and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 1 xmax: 1 ymax: 1 #> CRS: NA #> a geom #> 1 1 POINT (1 1)"},{"path":"https://r-spatial.github.io/sf/reference/st_layers.html","id":null,"dir":"Reference","previous_headings":"","what":"Return properties of layers in a datasource — st_layers","title":"Return properties of layers in a datasource — st_layers","text":"Return properties layers datasource","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_layers.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return properties of layers in a datasource — st_layers","text":"","code":"st_layers(dsn, options = character(0), do_count = FALSE)"},{"path":"https://r-spatial.github.io/sf/reference/st_layers.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Return properties of layers in a datasource — st_layers","text":"dsn data source name (interpretation varies driver - drivers, dsn file name, may also folder, contain name access credentials database) options character; driver dependent dataset open options, multiple options supported. do_count logical; TRUE, count features reading , even count reported driver","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_layers.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Return properties of layers in a datasource — st_layers","text":"list object class sf_layers elements name name layer geomtype list layer geometry types features number features (reported; see do_count) fields number fields crs list layer crs object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_line_project_point.html","id":null,"dir":"Reference","previous_headings":"","what":"Project point on linestring, interpolate along a linestring — st_line_project_point","title":"Project point on linestring, interpolate along a linestring — st_line_project_point","text":"Project point linestring, interpolate along linestring","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_line_project_point.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Project point on linestring, interpolate along a linestring — st_line_project_point","text":"","code":"st_line_project(line, point, normalized = FALSE) st_line_interpolate(line, dist, normalized = FALSE)"},{"path":"https://r-spatial.github.io/sf/reference/st_line_project_point.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Project point on linestring, interpolate along a linestring — st_line_project_point","text":"line object class sfc LINESTRING geometry point object class sfc POINT geometry normalized logical; TRUE, use return distance normalised 0-1 dist numeric, vector distance value(s)","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_line_project_point.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Project point on linestring, interpolate along a linestring — st_line_project_point","text":"st_line_project returns distance(s) point(s) along line(s), projected line(s) st_line_interpolate returns point(s) dist(s), measured along (interpolated ) line(s)","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_line_project_point.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Project point on linestring, interpolate along a linestring — st_line_project_point","text":"arguments line, point dist recycled common length needed","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_line_project_point.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Project point on linestring, interpolate along a linestring — st_line_project_point","text":"","code":"st_line_project(st_as_sfc(\"LINESTRING (0 0, 10 10)\"), st_as_sfc(c(\"POINT (0 0)\", \"POINT (5 5)\"))) #> [1] 0.000000 7.071068 st_line_project(st_as_sfc(\"LINESTRING (0 0, 10 10)\"), st_as_sfc(\"POINT (5 5)\"), TRUE) #> [1] 0.5 st_line_interpolate(st_as_sfc(\"LINESTRING (0 0, 1 1)\"), 1) #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0.7071068 ymin: 0.7071068 xmax: 0.7071068 ymax: 0.7071068 #> CRS: NA #> POINT (0.7071068 0.7071068) st_line_interpolate(st_as_sfc(\"LINESTRING (0 0, 1 1)\"), 1, TRUE) #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 1 xmax: 1 ymax: 1 #> CRS: NA #> POINT (1 1)"},{"path":"https://r-spatial.github.io/sf/reference/st_line_sample.html","id":null,"dir":"Reference","previous_headings":"","what":"Sample points on a linear geometry — st_line_sample","title":"Sample points on a linear geometry — st_line_sample","text":"Sample points linear geometry","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_line_sample.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Sample points on a linear geometry — st_line_sample","text":"","code":"st_line_sample(x, n, density, type = \"regular\", sample = NULL)"},{"path":"https://r-spatial.github.io/sf/reference/st_line_sample.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Sample points on a linear geometry — st_line_sample","text":"x object class sf, sfc sfg n integer; number points choose per geometry; missing, n computed round(density * st_length(geom)). density numeric; density (points per distance unit) sampling, possibly vector length equal number features (otherwise recycled); density may class units. type character; indicate sampling type, either \"regular\" \"random\" sample numeric; vector numbers 0 1 indicating points sample - defined sample overrules n, density type.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_line_sample.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Sample points on a linear geometry — st_line_sample","text":"","code":"ls = st_sfc(st_linestring(rbind(c(0,0),c(0,1))), st_linestring(rbind(c(0,0),c(10,0)))) st_line_sample(ls, density = 1) #> Geometry set for 2 features #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 9.5 ymax: 0.5 #> CRS: NA #> MULTIPOINT ((0 0.5)) #> MULTIPOINT ((0.5 0), (1.5 0), (2.5 0), (3.5 0),... ls = st_sfc(st_linestring(rbind(c(0,0),c(0,1))), st_linestring(rbind(c(0,0),c(.1,0))), crs = 4326) try(st_line_sample(ls, density = 1/1000)) # error #> Error in st_line_sample(ls, density = 1/1000) : #> st_line_sample for longitude/latitude not supported; use st_segmentize? st_line_sample(st_transform(ls, 3857), n = 5) # five points for each line #> Geometry set for 2 features #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 10018.75 ymax: 100192.6 #> Projected CRS: WGS 84 / Pseudo-Mercator #> MULTIPOINT ((0 11132.51), (0 33397.54), (0 5566... #> MULTIPOINT ((1113.195 0), (3339.585 0), (5565.9... st_line_sample(st_transform(ls, 3857), n = c(1, 3)) # one and three points #> Geometry set for 2 features #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 9276.624 ymax: 55662.57 #> Projected CRS: WGS 84 / Pseudo-Mercator #> MULTIPOINT ((0 55662.57)) #> MULTIPOINT ((1855.325 0), (5565.975 0), (9276.6... st_line_sample(st_transform(ls, 3857), density = 1/1000) # one per km #> Geometry set for 2 features #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 10625.95 ymax: 110823.7 #> Projected CRS: WGS 84 / Pseudo-Mercator #> MULTIPOINT ((0 501.4646), (0 1504.394), (0 2507... #> MULTIPOINT ((505.9977 0), (1517.993 0), (2529.9... st_line_sample(st_transform(ls, 3857), density = c(1/1000, 1/10000)) # one per km, one per 10 km #> Geometry set for 2 features #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 5565.975 ymax: 110823.7 #> Projected CRS: WGS 84 / Pseudo-Mercator #> MULTIPOINT ((0 501.4646), (0 1504.394), (0 2507... #> MULTIPOINT ((5565.975 0)) st_line_sample(st_transform(ls, 3857), density = units::set_units(1, 1/km)) # one per km #> Geometry set for 2 features #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 10625.95 ymax: 110823.7 #> Projected CRS: WGS 84 / Pseudo-Mercator #> MULTIPOINT ((0 501.4646), (0 1504.394), (0 2507... #> MULTIPOINT ((505.9977 0), (1517.993 0), (2529.9... # five equidistant points including start and end: st_line_sample(st_transform(ls, 3857), sample = c(0, 0.25, 0.5, 0.75, 1)) #> Geometry set for 2 features #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 11131.95 ymax: 111325.1 #> Projected CRS: WGS 84 / Pseudo-Mercator #> MULTIPOINT ((0 0), (0 27831.29), (0 55662.57), ... #> MULTIPOINT ((0 0), (2782.987 0), (5565.975 0), ..."},{"path":"https://r-spatial.github.io/sf/reference/st_m_range.html","id":null,"dir":"Reference","previous_headings":"","what":"Return 'm' range of a simple feature or simple feature set — st_m_range","title":"Return 'm' range of a simple feature or simple feature set — st_m_range","text":"Return 'm' range simple feature simple feature set","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_m_range.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return 'm' range of a simple feature or simple feature set — st_m_range","text":"","code":"# S3 method for class 'm_range' is.na(x) st_m_range(obj, ...) # S3 method for class 'POINT' st_m_range(obj, ...) # S3 method for class 'MULTIPOINT' st_m_range(obj, ...) # S3 method for class 'LINESTRING' st_m_range(obj, ...) # S3 method for class 'POLYGON' st_m_range(obj, ...) # S3 method for class 'MULTILINESTRING' st_m_range(obj, ...) # S3 method for class 'MULTIPOLYGON' st_m_range(obj, ...) # S3 method for class 'GEOMETRYCOLLECTION' st_m_range(obj, ...) # S3 method for class 'MULTISURFACE' st_m_range(obj, ...) # S3 method for class 'MULTICURVE' st_m_range(obj, ...) # S3 method for class 'CURVEPOLYGON' st_m_range(obj, ...) # S3 method for class 'COMPOUNDCURVE' st_m_range(obj, ...) # S3 method for class 'POLYHEDRALSURFACE' st_m_range(obj, ...) # S3 method for class 'TIN' st_m_range(obj, ...) # S3 method for class 'TRIANGLE' st_m_range(obj, ...) # S3 method for class 'CIRCULARSTRING' st_m_range(obj, ...) # S3 method for class 'sfc' st_m_range(obj, ...) # S3 method for class 'sf' st_m_range(obj, ...) # S3 method for class 'numeric' st_m_range(obj, ..., crs = NA_crs_) NA_m_range_"},{"path":"https://r-spatial.github.io/sf/reference/st_m_range.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Return 'm' range of a simple feature or simple feature set — st_m_range","text":"object class m_range length 2.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_m_range.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Return 'm' range of a simple feature or simple feature set — st_m_range","text":"x object class m_range obj object compute m range ... ignored crs object class crs, argument st_crs, specifying CRS bounding box.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_m_range.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Return 'm' range of a simple feature or simple feature set — st_m_range","text":"numeric vector length two, mmin mmax values; obj class sf sfc object obj class sf sfc object returned class m_range","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_m_range.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Return 'm' range of a simple feature or simple feature set — st_m_range","text":"NA_m_range_ represents missing value m_range object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_m_range.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Return 'm' range of a simple feature or simple feature set — st_m_range","text":"","code":"a = st_sf(a = 1:2, geom = st_sfc(st_point(0:3), st_point(1:4)), crs = 4326) st_m_range(a) #> mmin mmax #> 3 4 st_m_range(c(mmin = 16.1, mmax = 16.6), crs = st_crs(4326)) #> mmin mmax #> 16.1 16.6"},{"path":"https://r-spatial.github.io/sf/reference/st_make_grid.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a regular tesselation over the bounding box of an sf or sfc object — st_make_grid","title":"Create a regular tesselation over the bounding box of an sf or sfc object — st_make_grid","text":"Create square hexagonal grid covering bounding box geometry sf sfc object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_make_grid.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a regular tesselation over the bounding box of an sf or sfc object — st_make_grid","text":"","code":"st_make_grid( x, cellsize = c(diff(st_bbox(x)[c(1, 3)]), diff(st_bbox(x)[c(2, 4)]))/n, offset = st_bbox(x)[c(\"xmin\", \"ymin\")], n = c(10, 10), crs = if (missing(x)) NA_crs_ else st_crs(x), what = \"polygons\", square = TRUE, flat_topped = FALSE )"},{"path":"https://r-spatial.github.io/sf/reference/st_make_grid.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a regular tesselation over the bounding box of an sf or sfc object — st_make_grid","text":"x object class sf sfc cellsize numeric length 1 2 target cellsize: square rectangular cells width height, hexagonal cells distance opposite edges (edge length cellsize/sqrt(3)). length units object can passed, area unit object area size square hexagonal cell. offset numeric length 2; lower left corner coordinates (x, y) grid n integer length 1 2, number grid cells x y direction (columns, rows) crs object class crs; coordinate reference system target grid case argument x missing, x missing, crs inherited. character; one : \"polygons\", \"corners\", \"centers\" square logical; FALSE, create hexagonal grid flat_topped logical; TRUE generate flat topped hexagons, else generate pointy topped","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_make_grid.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a regular tesselation over the bounding box of an sf or sfc object — st_make_grid","text":"Object class sfc (simple feature geometry list column) , depending square, square hexagonal polygons, corner points polygons, center points polygons.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_make_grid.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a regular tesselation over the bounding box of an sf or sfc object — st_make_grid","text":"","code":"plot(st_make_grid(what = \"centers\"), axes = TRUE) plot(st_make_grid(what = \"corners\"), add = TRUE, col = 'green', pch=3) sfc = st_sfc(st_polygon(list(rbind(c(0,0), c(1,0), c(1,1), c(0,0))))) plot(st_make_grid(sfc, cellsize = .1, square = FALSE)) plot(sfc, add = TRUE) # non-default offset: plot(st_make_grid(sfc, cellsize = .1, square = FALSE, offset = c(0, .05 / (sqrt(3)/2)))) plot(sfc, add = TRUE) nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 g = st_make_grid(nc) plot(g) plot(st_geometry(nc), add = TRUE) # g[nc] selects cells that intersect with nc: plot(g[nc], col = '#ff000088', add = TRUE)"},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_feature.html","id":null,"dir":"Reference","previous_headings":"","what":"get index of nearest feature — st_nearest_feature","title":"get index of nearest feature — st_nearest_feature","text":"get index nearest feature","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_feature.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"get index of nearest feature — st_nearest_feature","text":"","code":"st_nearest_feature( x, y, ..., check_crs = TRUE, longlat = isTRUE(st_is_longlat(x)) )"},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_feature.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"get index of nearest feature — st_nearest_feature","text":"x object class sfg, sfc sf y object class sfg, sfc sf; missing, features x compared remaining features x. ... ignored check_crs logical; x y checked CRS equality? longlat logical; x ellipsoidal coordinates?","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_feature.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"get index of nearest feature — st_nearest_feature","text":"feature (geometry) x index nearest feature (geometry) set y, remaining set x y missing; empty geometries result NA indexes","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_feature.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"get index of nearest feature — st_nearest_feature","text":"","code":"ls1 = st_linestring(rbind(c(0,0), c(1,0))) ls2 = st_linestring(rbind(c(0,0.1), c(1,0.1))) ls3 = st_linestring(rbind(c(0,1), c(1,1))) (l = st_sfc(ls1, ls2, ls3)) #> Geometry set for 3 features #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> LINESTRING (0 0, 1 0) #> LINESTRING (0 0.1, 1 0.1) #> LINESTRING (0 1, 1 1) p1 = st_point(c(0.1, -0.1)) p2 = st_point(c(0.1, 0.11)) p3 = st_point(c(0.1, 0.09)) p4 = st_point(c(0.1, 0.9)) (p = st_sfc(p1, p2, p3, p4)) #> Geometry set for 4 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0.1 ymin: -0.1 xmax: 0.1 ymax: 0.9 #> CRS: NA #> POINT (0.1 -0.1) #> POINT (0.1 0.11) #> POINT (0.1 0.09) #> POINT (0.1 0.9) try(st_nearest_feature(p, l)) #> [1] 1 2 2 3 try(st_nearest_points(p, l[st_nearest_feature(p,l)], pairwise = TRUE)) #> Geometry set for 4 features #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 0.1 ymin: -0.1 xmax: 0.1 ymax: 1 #> CRS: NA #> LINESTRING (0.1 -0.1, 0.1 0) #> LINESTRING (0.1 0.11, 0.1 0.1) #> LINESTRING (0.1 0.09, 0.1 0.1) #> LINESTRING (0.1 0.9, 0.1 1) r = sqrt(2)/10 b1 = st_buffer(st_point(c(.1,.1)), r) b2 = st_buffer(st_point(c(.9,.9)), r) b3 = st_buffer(st_point(c(.9,.1)), r) circles = st_sfc(b1, b2, b3) plot(circles, col = NA, border = 2:4) pts = st_sfc(st_point(c(.3,.1)), st_point(c(.6,.2)), st_point(c(.6,.6)), st_point(c(.4,.8))) plot(pts, add = TRUE, col = 1) # draw points to nearest circle: nearest = try(st_nearest_feature(pts, circles)) if (inherits(nearest, \"try-error\")) # GEOS 3.6.1 not available nearest = c(1, 3, 2, 2) ls = st_nearest_points(pts, circles[nearest], pairwise = TRUE) plot(ls, col = 5:8, add = TRUE) # compute distance between pairs of nearest features: st_distance(pts, circles[nearest], by_element = TRUE) #> [1] 0.05857864 0.17481378 0.28284271 0.36849479"},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_points.html","id":null,"dir":"Reference","previous_headings":"","what":"get nearest points between pairs of geometries — st_nearest_points","title":"get nearest points between pairs of geometries — st_nearest_points","text":"get nearest points pairs geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_points.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"get nearest points between pairs of geometries — st_nearest_points","text":"","code":"st_nearest_points(x, y, ...) # S3 method for class 'sfc' st_nearest_points(x, y, ..., pairwise = FALSE) # S3 method for class 'sfg' st_nearest_points(x, y, ...) # S3 method for class 'sf' st_nearest_points(x, y, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_points.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"get nearest points between pairs of geometries — st_nearest_points","text":"x object class sfg, sfc sf y object class sfg, sfc sf ... ignored pairwise logical; FALSE (default) return nearest points pairs, TRUE, return nearest points subsequent pairs.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_points.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"get nearest points between pairs of geometries — st_nearest_points","text":"sfc object two-point LINESTRING geometries point pairs first second geometry, length x * y, y cycling fastest. See examples ideas convert POINT geometries.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_points.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"get nearest points between pairs of geometries — st_nearest_points","text":"case x lies inside y, using S2, end points polygon boundaries, using GEOS end point identical x.","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/st_nearest_points.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"get nearest points between pairs of geometries — st_nearest_points","text":"","code":"r = sqrt(2)/10 pt1 = st_point(c(.1,.1)) pt2 = st_point(c(.9,.9)) pt3 = st_point(c(.9,.1)) b1 = st_buffer(pt1, r) b2 = st_buffer(pt2, r) b3 = st_buffer(pt3, r) (ls0 = st_nearest_points(b1, b2)) # sfg #> Geometry set for 1 feature #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 0.2 ymin: 0.2 xmax: 0.8 ymax: 0.8 #> CRS: NA #> LINESTRING (0.2 0.2, 0.8 0.8) (ls = st_nearest_points(st_sfc(b1), st_sfc(b2, b3))) # sfc #> Geometry set for 2 features #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 0.2 ymin: 0.1 xmax: 0.8 ymax: 0.8 #> CRS: NA #> LINESTRING (0.2 0.2, 0.8 0.8) #> LINESTRING (0.2414214 0.1, 0.7585786 0.1) plot(b1, xlim = c(-.2,1.2), ylim = c(-.2,1.2), col = NA, border = 'green') plot(st_sfc(b2, b3), add = TRUE, col = NA, border = 'blue') plot(ls, add = TRUE, col = 'red') nc = st_read(system.file(\"gpkg/nc.gpkg\", package=\"sf\")) #> Reading layer `nc.gpkg' from data source #> `/home/runner/work/_temp/Library/sf/gpkg/nc.gpkg' using driver `GPKG' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 plot(st_geometry(nc)) ls = st_nearest_points(nc[1,], nc) plot(ls, col = 'red', add = TRUE) pts = st_cast(ls, \"POINT\") # gives all start & end points #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only #> Warning: point from first coordinate only # starting, \"from\" points, corresponding to x: plot(pts[seq(1, 200, 2)], add = TRUE, col = 'blue') # ending, \"to\" points, corresponding to y: plot(pts[seq(2, 200, 2)], add = TRUE, col = 'green')"},{"path":"https://r-spatial.github.io/sf/reference/st_normalize.html","id":null,"dir":"Reference","previous_headings":"","what":"Normalize simple features — st_normalize","title":"Normalize simple features — st_normalize","text":"st_normalize transforms coordinates input feature fall 0 1. default current domain set bounding box input, domains can used well","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_normalize.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Normalize simple features — st_normalize","text":"","code":"st_normalize(x, domain = st_bbox(x), ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_normalize.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Normalize simple features — st_normalize","text":"x object class sf, sfc sfg domain domain x normalized length 4 vector form c(xmin, ymin, xmax, ymax). Defaults bounding box x ... ignored","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_normalize.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Normalize simple features — st_normalize","text":"","code":"p1 = st_point(c(7,52)) st_normalize(p1, domain = c(0, 0, 10, 100)) #> POINT (0.7 0.52) p2 = st_point(c(-30,20)) sfc = st_sfc(p1, p2, crs = 4326) sfc #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -30 ymin: 20 xmax: 7 ymax: 52 #> Geodetic CRS: WGS 84 #> POINT (7 52) #> POINT (-30 20) sfc_norm <- st_normalize(sfc) st_bbox(sfc_norm) #> xmin ymin xmax ymax #> 0 0 1 1"},{"path":"https://r-spatial.github.io/sf/reference/st_precision.html","id":null,"dir":"Reference","previous_headings":"","what":"Get precision — st_precision","title":"Get precision — st_precision","text":"Get precision Set precision","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_precision.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get precision — st_precision","text":"","code":"st_precision(x) st_set_precision(x, precision) st_precision(x) <- value"},{"path":"https://r-spatial.github.io/sf/reference/st_precision.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get precision — st_precision","text":"x object class sfc sf precision numeric, object class units distance units (see details); see st_as_binary . value precision value","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_precision.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Get precision — st_precision","text":"precision units object, object set precision must coordinate reference system compatible distance units. Setting precision direct effect coordinates geometries, merely set attribute tag sfc object. effect takes place st_as_binary , precise, C++ function CPL_write_wkb, simple feature geometries serialized well-known-binary (WKB). happens always routines called GEOS library (geometrical operations predicates), writing geometries using st_write write_sf, st_make_valid package lwgeom; also aggregate summarise default union geometries, calls GEOS library function. Routines libraries receive rounded coordinates, possibly return results based . st_as_binary contains example roundtrip sfc geometries WKB, order see rounding happening R data. reason support precision geometrical operations GEOS liblwgeom may work better reduced precision. writing data R external resources harder think good reason limiting precision.","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/st_precision.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get precision — st_precision","text":"","code":"x <- st_sfc(st_point(c(pi, pi))) st_precision(x) #> [1] 0 st_precision(x) <- 0.01 st_precision(x) #> [1] 0.01"},{"path":"https://r-spatial.github.io/sf/reference/st_read.html","id":null,"dir":"Reference","previous_headings":"","what":"Read simple features or layers from file or database — st_read","title":"Read simple features or layers from file or database — st_read","text":"Read simple features file database, retrieve layer names geometry type(s) Read PostGIS table directly DBI RPostgreSQL interface, converting Well-Know Binary geometries sfc","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_read.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Read simple features or layers from file or database — st_read","text":"","code":"st_read(dsn, layer, ...) # S3 method for class 'character' st_read( dsn, layer, ..., query = NA, options = NULL, quiet = FALSE, geometry_column = 1L, type = 0, promote_to_multi = TRUE, stringsAsFactors = sf_stringsAsFactors(), int64_as_string = FALSE, check_ring_dir = FALSE, fid_column_name = character(0), drivers = character(0), wkt_filter = character(0), optional = FALSE, use_stream = default_st_read_use_stream() ) read_sf(..., quiet = TRUE, stringsAsFactors = FALSE, as_tibble = TRUE) # S3 method for class 'DBIObject' st_read( dsn = NULL, layer = NULL, query = NULL, EWKB = TRUE, quiet = TRUE, as_tibble = FALSE, geometry_column = NULL, ... )"},{"path":"https://r-spatial.github.io/sf/reference/st_read.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Read simple features or layers from file or database — st_read","text":"dsn data source name (interpretation varies driver - drivers, dsn file name, may also folder, contain name access credentials database); case GeoJSON, dsn may character string holding geojson data. can also open database connection. layer layer name (varies driver, may file name without extension); case layer missing, st_read read first layer dsn, give warning (unless quiet = TRUE) print message multiple layers, give error layers dsn. dsn database connection, layer can table name database identifier (see Id). also possible omit layer rather use query argument. ... parameter(s) passed st_as_sf query SQL query select records; see details options character; driver dependent dataset open options, multiple options supported. possible values, see \"Open options\" section GDAL documentation corresponding driver, https://github.com/r-spatial/sf/issues/1157 example. quiet logical; suppress info name, driver, size spatial reference, signaling multiple layers geometry_column integer character; case multiple geometry fields, one take? type integer; ISO number desired simple feature type; see details. left zero, promote_to_multi TRUE, case mixed feature geometry types, conversion highest numeric type value found attempted. vector different values geometry column can given. promote_to_multi logical; case mix Point MultiPoint, LineString MultiLineString, Polygon MultiPolygon, convert Multi variety; defaults TRUE stringsAsFactors logical; logical: character vectors converted factors? Default read_sf R version >= 4.1.0 FALSE, st_read R version < 4.1.0 equal default.stringsAsFactors() int64_as_string logical; TRUE, Int64 attributes returned string; FALSE, returned double warning given precision lost (.e., values larger 2^53). check_ring_dir logical; TRUE, polygon ring directions checked necessary corrected (seen : exterior ring counter clockwise, holes clockwise) fid_column_name character; name column write feature IDs ; defaults drivers character; limited set driver short names tried (default: try ) wkt_filter character; WKT representation spatial filter (may used bounding box, selecting overlapping geometries); see examples optional logical; passed .data.frame; always TRUE as_tibble TRUE use_stream Use TRUE use experimental columnar interface introduced GDAL 3.6. as_tibble logical; returned table class tibble data.frame? EWKB logical; WKB type EWKB? missing, defaults TRUE","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_read.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Read simple features or layers from file or database — st_read","text":"object class sf layer successfully read; case argument layer missing data source dsn contain single layer, object class sf_layers returned layer names, geometry type(s). Note number layers may also zero.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_read.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Read simple features or layers from file or database — st_read","text":"geometry_column, see also https://gdal.org/en/latest/development/rfc/rfc41_multiple_geometry_fields.html values type see https://en.wikipedia.org/wiki/Well-known_text#Well-known_binary, note every target value may lead successful conversion. typical conversion POLYGON (3) MULTIPOLYGON (6) work; way around (type=3), secondary rings MULTIPOLYGONS may dropped without warnings. promote_to_multi handled per-geometry column basis; type may specified geometry column. Note stray files data source directories (*.dbf) may lead spurious errors accompanying *.shp missing. case problems reading shapefiles USB drives OSX, please see https://github.com/r-spatial/sf/issues/252. Reading shapefiles (data sources) directly zip files can done prepending path /vsizip/. part GDAL Virtual File Systems interface also supports .gz, curl, operations, including chaining; see https://gdal.org/en/latest/user/virtual_file_systems.html complete description examples. query character dsn query text handed 'ExecuteSQL' GDAL/OGR data set result creation new layer (layer ignored). See 'OGRSQL' https://gdal.org/en/latest/user/ogr_sql_dialect.html details. Please note 'FID' special field driver-dependent, may either 0-based (e.g. ESRI Shapefile), 1-based (e.g. MapInfo) arbitrary (e.g. OSM). features OGRSQL also likely driver dependent. available layer names may obtained st_layers. Care required properly escape use layer names. read_sf write_sf aliases st_read st_write, respectively, modified default arguments. read_sf write_sf quiet default: print information data source. read_sf returns sf-tibble rather sf-data.frame. write_sf delete layers default: overwrites existing files without asking warning. table given query , spatial reference system (crs) table queried available case stored geometry record (e.g., PostGIS, using EWKB) function automatically find geometry type columns drivers support . drivers, try cast character columns, can slow wide tables.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_read.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Read simple features or layers from file or database — st_read","text":"use system.file examples make sure examples run regardless R installed: typical users use system.file give file name directly, either full path relative current working directory (see getwd). \"Shapefiles\" consist several files basename reside directory, one extension .shp.","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/st_read.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Read simple features or layers from file or database — st_read","text":"","code":"nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 summary(nc) # note that AREA was computed using Euclidian area on lon/lat degrees #> AREA PERIMETER CNTY_ CNTY_ID #> Min. :0.0420 Min. :0.999 Min. :1825 Min. :1825 #> 1st Qu.:0.0910 1st Qu.:1.324 1st Qu.:1902 1st Qu.:1902 #> Median :0.1205 Median :1.609 Median :1982 Median :1982 #> Mean :0.1263 Mean :1.673 Mean :1986 Mean :1986 #> 3rd Qu.:0.1542 3rd Qu.:1.859 3rd Qu.:2067 3rd Qu.:2067 #> Max. :0.2410 Max. :3.640 Max. :2241 Max. :2241 #> NAME FIPS FIPSNO CRESS_ID #> Length:100 Length:100 Min. :37001 Min. : 1.00 #> Class :character Class :character 1st Qu.:37050 1st Qu.: 25.75 #> Mode :character Mode :character Median :37100 Median : 50.50 #> Mean :37100 Mean : 50.50 #> 3rd Qu.:37150 3rd Qu.: 75.25 #> Max. :37199 Max. :100.00 #> BIR74 SID74 NWBIR74 BIR79 #> Min. : 248 Min. : 0.00 Min. : 1.0 Min. : 319 #> 1st Qu.: 1077 1st Qu.: 2.00 1st Qu.: 190.0 1st Qu.: 1336 #> Median : 2180 Median : 4.00 Median : 697.5 Median : 2636 #> Mean : 3300 Mean : 6.67 Mean :1050.8 Mean : 4224 #> 3rd Qu.: 3936 3rd Qu.: 8.25 3rd Qu.:1168.5 3rd Qu.: 4889 #> Max. :21588 Max. :44.00 Max. :8027.0 Max. :30757 #> SID79 NWBIR79 geometry #> Min. : 0.00 Min. : 3.0 MULTIPOLYGON :100 #> 1st Qu.: 2.00 1st Qu.: 250.5 epsg:4267 : 0 #> Median : 5.00 Median : 874.5 +proj=long...: 0 #> Mean : 8.36 Mean : 1352.8 #> 3rd Qu.:10.25 3rd Qu.: 1406.8 #> Max. :57.00 Max. :11631.0 ## only three fields by select clause ## only two features by where clause nc_sql = st_read(system.file(\"shape/nc.shp\", package=\"sf\"), query = \"SELECT NAME, SID74, FIPS FROM \\\"nc\\\" WHERE BIR74 > 20000\") #> Reading query `SELECT NAME, SID74, FIPS FROM \"nc\" WHERE BIR74 > 20000' #> from data source `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 2 features and 3 fields #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: -81.06555 ymin: 34.82742 xmax: -78.49929 ymax: 35.50912 #> Geodetic CRS: NAD27 if (FALSE) { # \\dontrun{ library(sp) example(meuse, ask = FALSE, echo = FALSE) try(st_write(st_as_sf(meuse), \"PG:dbname=postgis\", \"meuse\", layer_options = \"OVERWRITE=true\")) try(st_meuse <- st_read(\"PG:dbname=postgis\", \"meuse\")) if (exists(\"st_meuse\")) summary(st_meuse) } # } if (FALSE) { # \\dontrun{ ## note that we need special escaping of layer within single quotes (nc.gpkg) ## and that geom needs to be included in the select, otherwise we don't detect it layer <- st_layers(system.file(\"gpkg/nc.gpkg\", package = \"sf\"))$name[1] nc_gpkg_sql = st_read(system.file(\"gpkg/nc.gpkg\", package = \"sf\"), query = sprintf(\"SELECT NAME, SID74, FIPS, geom FROM \\\"%s\\\" WHERE BIR74 > 20000\", layer)) } # } # spatial filter, as wkt: wkt = st_as_text(st_geometry(nc[1,])) # filter by (bbox overlaps of) first feature geometry: st_read(system.file(\"gpkg/nc.gpkg\", package=\"sf\"), wkt_filter = wkt) #> Reading layer `nc.gpkg' from data source #> `/home/runner/work/_temp/Library/sf/gpkg/nc.gpkg' using driver `GPKG' #> Simple feature collection with 4 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -81.91116 ymin: 35.98933 xmax: -80.87086 ymax: 36.58965 #> Geodetic CRS: NAD27 # read geojson from string: geojson_txt <- paste(\"{\\\"type\\\":\\\"MultiPoint\\\",\\\"coordinates\\\":\", \"[[3.2,4],[3,4.6],[3.8,4.4],[3.5,3.8],[3.4,3.6],[3.9,4.5]]}\") x = st_read(geojson_txt) #> Reading layer `OGRGeoJSON' from data source #> `{\"type\":\"MultiPoint\",\"coordinates\": [[3.2,4],[3,4.6],[3.8,4.4],[3.5,3.8],[3.4,3.6],[3.9,4.5]]}' #> using driver `GeoJSON' #> Simple feature collection with 1 feature and 0 fields #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 3 ymin: 3.6 xmax: 3.9 ymax: 4.6 #> Geodetic CRS: WGS 84 x #> Simple feature collection with 1 feature and 0 fields #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 3 ymin: 3.6 xmax: 3.9 ymax: 4.6 #> Geodetic CRS: WGS 84 #> geometry #> 1 MULTIPOINT ((3.2 4), (3 4.6... if (FALSE) { # \\dontrun{ library(RPostgreSQL) try(conn <- dbConnect(PostgreSQL(), dbname = \"postgis\")) if (exists(\"conn\") && !inherits(conn, \"try-error\")) { x = st_read(conn, \"meuse\", query = \"select * from meuse limit 3;\") x = st_read(conn, table = \"public.meuse\") print(st_crs(x)) # SRID resolved by the database, not by GDAL! dbDisconnect(conn) } } # }"},{"path":"https://r-spatial.github.io/sf/reference/st_relate.html","id":null,"dir":"Reference","previous_headings":"","what":"Compute DE9-IM relation between pairs of geometries, or match it to a given pattern — st_relate","title":"Compute DE9-IM relation between pairs of geometries, or match it to a given pattern — st_relate","text":"Compute DE9-IM relation pairs geometries, match given pattern","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_relate.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compute DE9-IM relation between pairs of geometries, or match it to a given pattern — st_relate","text":"","code":"st_relate(x, y, pattern = NA_character_, sparse = !is.na(pattern))"},{"path":"https://r-spatial.github.io/sf/reference/st_relate.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compute DE9-IM relation between pairs of geometries, or match it to a given pattern — st_relate","text":"x object class sf, sfc sfg y object class sf, sfc sfg pattern character; define pattern match , see details. sparse logical; sparse matrix returned (TRUE) dense matrix?","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_relate.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compute DE9-IM relation between pairs of geometries, or match it to a given pattern — st_relate","text":"case pattern given, st_relate returns dense character matrix; element [,j] nine characters, referring DE9-IM relationship x[] y[j], encoded IxIy,IxBy,IxEy,BxIy,BxBy,BxEy,ExIy,ExBy,ExEy refers interior, B boundary, E exterior, e.g. BxIy dimensionality intersection boundary x[] interior y[j], one : 0, 1, 2, F; digits denoting dimensionality intersection, F denoting intersection. pattern given, dense logical matrix sparse index list returned matches given pattern; see st_intersects description returned matrix list. See also https://en.wikipedia.org/wiki/DE-9IM explanation.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_relate.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Compute DE9-IM relation between pairs of geometries, or match it to a given pattern — st_relate","text":"","code":"p1 = st_point(c(0,0)) p2 = st_point(c(2,2)) pol1 = st_polygon(list(rbind(c(0,0),c(1,0),c(1,1),c(0,1),c(0,0)))) - 0.5 pol2 = pol1 + 1 pol3 = pol1 + 2 st_relate(st_sfc(p1, p2), st_sfc(pol1, pol2, pol3)) #> [,1] [,2] [,3] #> [1,] \"0FFFFF212\" \"FF0FFF212\" \"FF0FFF212\" #> [2,] \"FF0FFF212\" \"FF0FFF212\" \"0FFFFF212\" sfc = st_sfc(st_point(c(0,0)), st_point(c(3,3))) grd = st_make_grid(sfc, n = c(3,3)) st_intersects(grd) #> Sparse geometry binary predicate list of length 9, where the predicate #> was `intersects' #> 1: 1, 2, 4, 5 #> 2: 1, 2, 3, 4, 5, 6 #> 3: 2, 3, 5, 6 #> 4: 1, 2, 4, 5, 7, 8 #> 5: 1, 2, 3, 4, 5, 6, 7, 8, 9 #> 6: 2, 3, 5, 6, 8, 9 #> 7: 4, 5, 7, 8 #> 8: 4, 5, 6, 7, 8, 9 #> 9: 5, 6, 8, 9 st_relate(grd, pattern = \"****1****\") # sides, not corners, internals #> Sparse geometry binary predicate list of length 9, where the predicate #> was `relate_pattern' #> 1: 1, 2, 4 #> 2: 1, 2, 3, 5 #> 3: 2, 3, 6 #> 4: 1, 4, 5, 7 #> 5: 2, 4, 5, 6, 8 #> 6: 3, 5, 6, 9 #> 7: 4, 7, 8 #> 8: 5, 7, 8, 9 #> 9: 6, 8, 9 st_relate(grd, pattern = \"****0****\") # only corners touch #> Sparse geometry binary predicate list of length 9, where the predicate #> was `relate_pattern' #> 1: 5 #> 2: 4, 6 #> 3: 5 #> 4: 2, 8 #> 5: 1, 3, 7, 9 #> 6: 2, 8 #> 7: 5 #> 8: 4, 6 #> 9: 5 st_rook = function(a, b = a) st_relate(a, b, pattern = \"F***1****\") st_rook(grd) #> Sparse geometry binary predicate list of length 9, where the predicate #> was `relate_pattern' #> 1: 2, 4 #> 2: 1, 3, 5 #> 3: 2, 6 #> 4: 1, 5, 7 #> 5: 2, 4, 6, 8 #> 6: 3, 5, 9 #> 7: 4, 8 #> 8: 5, 7, 9 #> 9: 6, 8 # queen neighbours, see \\url{https://github.com/r-spatial/sf/issues/234#issuecomment-300511129} st_queen <- function(a, b = a) st_relate(a, b, pattern = \"F***T****\")"},{"path":"https://r-spatial.github.io/sf/reference/st_sample.html","id":null,"dir":"Reference","previous_headings":"","what":"sample points on or in (sets of) spatial features — st_sample","title":"sample points on or in (sets of) spatial features — st_sample","text":"Sample points (sets ) spatial features. default, returns pre-specified number points equal size (type = \"random\" exact = TRUE) approximation size otherwise. spatstat methods interfaced use size argument, see examples.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_sample.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"sample points on or in (sets of) spatial features — st_sample","text":"","code":"st_sample(x, size, ...) # S3 method for class 'sf' st_sample(x, size, ...) # S3 method for class 'sfc' st_sample( x, size, ..., type = \"random\", exact = TRUE, warn_if_not_integer = TRUE, by_polygon = FALSE, progress = FALSE, force = FALSE ) # S3 method for class 'sfg' st_sample(x, size, ...) # S3 method for class 'bbox' st_sample( x, size, ..., great_circles = FALSE, segments = units::set_units(2, \"degree\", mode = \"standard\") )"},{"path":"https://r-spatial.github.io/sf/reference/st_sample.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"sample points on or in (sets of) spatial features — st_sample","text":"x object class sf sfc size sample size(s) requested; either total size, numeric vector sample sizes feature geometry. sampling polygons, returned sampling size may differ requested size, bounding box sampled, sampled points intersecting polygon returned. ... passed sample multipoint sampling, spatstat functions spatstat sampling types (see details) type character; indicates spatial sampling type; one random, hexagonal (triangular really), regular, Fibonacci, one spatstat methods Thomas calling spatstat.random::rThomas (see Details). exact logical; length output exactly warn_if_not_integer logical; FALSE warning emitted size integer by_polygon logical; MULTIPOLYGON geometries, effort split POLYGON? See https://github.com/r-spatial/sf/issues/1480 specified size? TRUE default. applies polygons, type = \"random\". progress logical; TRUE show progress bar (size vector). force logical; TRUE continue sampled bounding box area 1e4 times area interest, else (default) stop error. error justified, try setting oriented=TRUE, see details. great_circles logical; TRUE, great circle arcs used connect bounding box vertices, FALSE parallels (graticules) segments units, numeric (degrees); segment sizes segmenting bounding box polygon great_circles FALSE","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_sample.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"sample points on or in (sets of) spatial features — st_sample","text":"sfc object containing sampled POINT geometries","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_sample.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"sample points on or in (sets of) spatial features — st_sample","text":"function vectorised: samples size points across geometries object size single number, specified number points feature size vector integers equal length geometry x. x dimension 2 (polygons) geographical coordinates (long/lat), uniform random sampling sphere applied, see e.g. https://mathworld.wolfram.com/SpherePointPicking.html. regular hexagonal sampling polygons, resulting size approximation. parameter called offset can passed control (\"fix\") regular hexagonal sampling: polygons length 2 numeric vector (default: random point st_bbox(x)); lines use number like runif(1). Fibonacci sampling see: Alvaro Gonzalez, 2010. Measurement Areas Sphere Using Fibonacci Latitude-Longitude Lattices. Mathematical Geosciences 42(1), p. 49-64 regular sampling sphere, see also geosphere::regularCoordinates. Sampling methods package spatstat interfaced (see examples), need parameters set. instance, use spatstat.random::rThomas(), set type = \"Thomas\". sampling polygons one can specify oriented=TRUE make sure polygons larger half globe reverted, e.g. specifying polygon bounding box global dataset. st_sample method bbox default.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_sample.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"sample points on or in (sets of) spatial features — st_sample","text":"","code":"nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 p1 = st_sample(nc[1:3, ], 6) p2 = st_sample(nc[1:3, ], 1:3) plot(st_geometry(nc)[1:3]) plot(p1, add = TRUE) plot(p2, add = TRUE, pch = 2) x = st_sfc(st_polygon(list(rbind(c(0,0),c(90,0),c(90,90),c(0,90),c(0,0)))), crs = st_crs(4326)) plot(x, axes = TRUE, graticule = TRUE) if (sf_extSoftVersion()[\"proj.4\"] >= \"4.9.0\") plot(p <- st_sample(x, 1000), add = TRUE) if (require(lwgeom, quietly = TRUE)) { # for st_segmentize() x2 = st_transform(st_segmentize(x, 1e4), st_crs(\"+proj=ortho +lat_0=30 +lon_0=45\")) g = st_transform(st_graticule(), st_crs(\"+proj=ortho +lat_0=30 +lon_0=45\")) plot(x2, graticule = g) if (sf_extSoftVersion()[\"proj.4\"] >= \"4.9.0\") { p2 = st_transform(p, st_crs(\"+proj=ortho +lat_0=30 +lon_0=45\")) plot(p2, add = TRUE) } } x = st_sfc(st_polygon(list(rbind(c(0,0),c(90,0),c(90,10),c(0,90),c(0,0))))) # NOT long/lat: plot(x) p_exact = st_sample(x, 1000, exact = TRUE) p_not_exact = st_sample(x, 1000, exact = FALSE) length(p_exact); length(p_not_exact) #> [1] 1000 #> [1] 1000 plot(st_sample(x, 1000), add = TRUE) x = st_sfc(st_polygon(list(rbind(c(-180,-90),c(180,-90),c(180,90),c(-180,90),c(-180,-90)))), crs=st_crs(4326)) # FIXME: #if (sf_extSoftVersion()[\"proj.4\"] >= \"4.9.0\") { # p = st_sample(x, 1000) # st_sample(p, 3) #} # hexagonal: sfc = st_sfc(st_polygon(list(rbind(c(0,0), c(1,0), c(1,1), c(0,0))))) plot(sfc) h = st_sample(sfc, 100, type = \"hexagonal\") h1 = st_sample(sfc, 100, type = \"hexagonal\") plot(h, add = TRUE) plot(h1, col = 'red', add = TRUE) c(length(h), length(h1)) # approximate! #> [1] 97 99 pt = st_multipoint(matrix(1:20,,2)) ls = st_sfc(st_linestring(rbind(c(0,0),c(0,1))), st_linestring(rbind(c(0,0),c(.1,0))), st_linestring(rbind(c(0,1),c(.1,1))), st_linestring(rbind(c(2,2),c(2,2.00001)))) st_sample(ls, 80) #> Geometry set for 4 features (with 1 geometry empty) #> Geometry type: MULTIPOINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 0.08531849 ymax: 1 #> CRS: NA #> MULTIPOINT ((0 0.01737041), (0 0.8441574), (0 0... #> MULTIPOINT ((0.03337024 0), (0.03010541 0), (0.... #> MULTIPOINT ((0.04159846 1), (0.06942899 1), (0.... #> MULTIPOINT EMPTY plot(st_sample(ls, 80)) # spatstat example: if (require(spatstat.random)) { x <- sf::st_sfc(sf::st_polygon(list(rbind(c(0, 0), c(10, 0), c(10, 10), c(0, 0))))) # for spatstat.random::rThomas(), set type = \"Thomas\": pts <- st_sample(x, kappa = 1, mu = 10, scale = 0.1, type = \"Thomas\") } bbox = st_bbox( c(xmin = 0, xmax = 40, ymax = 70, ymin = 60), crs = st_crs('OGC:CRS84') ) set.seed(13531) s1 = st_sample(bbox, 400) st_bbox(s1) # within bbox #> xmin ymin xmax ymax #> 0.1809029 60.0231214 39.9875925 69.9900375 s2 = st_sample(bbox, 400, great_circles = TRUE) st_bbox(s2) # outside bbox #> xmin ymin xmax ymax #> 0.2031083 60.2048778 39.9612431 69.9107718"},{"path":"https://r-spatial.github.io/sf/reference/st_shift_longitude.html","id":null,"dir":"Reference","previous_headings":"","what":"Shift or re-center geographical coordinates for a Pacific view — st_shift_longitude","title":"Shift or re-center geographical coordinates for a Pacific view — st_shift_longitude","text":"longitudes < 0 added 360, avoid instance parts Alaska represented far left right plot values straddling 180 degrees. general, using projected coordinate reference system preferred, method permits geographical coordinate reference system used. sf equivalent recenter sp package ST_ShiftLongitude PostGIS.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_shift_longitude.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Shift or re-center geographical coordinates for a Pacific view — st_shift_longitude","text":"","code":"st_shift_longitude(x) # S3 method for class 'sfc' st_shift_longitude(x, ...) # S3 method for class 'sf' st_shift_longitude(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/st_shift_longitude.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Shift or re-center geographical coordinates for a Pacific view — st_shift_longitude","text":"x object class sf sfc ... ignored","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_shift_longitude.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Shift or re-center geographical coordinates for a Pacific view — st_shift_longitude","text":"","code":"## sfc pt1 = st_point(c(-170, 50)) pt2 = st_point(c(170, 50)) (sfc = st_sfc(pt1, pt2)) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -170 ymin: 50 xmax: 170 ymax: 50 #> CRS: NA #> POINT (-170 50) #> POINT (170 50) sfc = st_set_crs(sfc, 4326) st_shift_longitude(sfc) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 170 ymin: 50 xmax: 190 ymax: 50 #> Geodetic CRS: WGS 84 #> POINT (190 50) #> POINT (170 50) ## sf d = st_as_sf(data.frame(id = 1:2, geometry = sfc)) st_shift_longitude(d) #> Simple feature collection with 2 features and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 170 ymin: 50 xmax: 190 ymax: 50 #> Geodetic CRS: WGS 84 #> id geometry #> 1 1 POINT (190 50) #> 2 2 POINT (170 50)"},{"path":"https://r-spatial.github.io/sf/reference/st_transform.html","id":null,"dir":"Reference","previous_headings":"","what":"Transform or convert coordinates of simple feature — st_transform","title":"Transform or convert coordinates of simple feature — st_transform","text":"Transform convert coordinates simple feature","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_transform.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Transform or convert coordinates of simple feature — st_transform","text":"","code":"st_can_transform(src, dst) st_transform(x, crs, ...) # S3 method for class 'sfc' st_transform( x, crs = st_crs(x), ..., aoi = numeric(0), pipeline = character(0), reverse = FALSE, desired_accuracy = -1, allow_ballpark = TRUE, partial = TRUE, check = FALSE ) # S3 method for class 'sf' st_transform(x, crs = st_crs(x), ...) # S3 method for class 'sfg' st_transform(x, crs = st_crs(x), ...) # S3 method for class 'bbox' st_transform(x, crs, ..., densify = 21) st_wrap_dateline(x, options, quiet) # S3 method for class 'sfc' st_wrap_dateline(x, options = \"WRAPDATELINE=YES\", quiet = TRUE) # S3 method for class 'sf' st_wrap_dateline(x, options = \"WRAPDATELINE=YES\", quiet = TRUE) # S3 method for class 'sfg' st_wrap_dateline(x, options = \"WRAPDATELINE=YES\", quiet = TRUE) sf_proj_info(type = \"proj\", path)"},{"path":"https://r-spatial.github.io/sf/reference/st_transform.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Transform or convert coordinates of simple feature — st_transform","text":"src source crs dst destination crs x object class sf, sfc sfg crs target coordinate reference system: object class crs, input string st_crs ... ignored aoi area interest, degrees: WestLongitude, SouthLatitude, EastLongitude, NorthLatitude pipeline character; coordinate operation pipeline, overriding default operation reverse boolean; effect pipeline defined: TRUE, inverse operation pipeline applied desired_accuracy numeric; coordinate operations offer accuracy least one specified considered; negative value disables feature (requires GDAL >= 3.3) allow_ballpark logical; ballpark (low accuracy) transformations allowed? (requires GDAL >= 3.3) partial logical; allow partial projection, points geometry can projected (corresponds setting environment variable OGR_ENABLE_PARTIAL_REPROJECTION TRUE) check logical; TRUE, perform sanity check resulting polygons densify integer, number points discretizing lines bounding box corner points; see Details options character; \"WRAPDATELINE=YES\" function; another parameter used \"DATELINEOFFSET=10\" (10 default value) quiet logical; print options parsed? type character; one have_datum_files, proj, ellps, datum, units, path, prime_meridians; see Details. path character; PROJ search path set","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_transform.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Transform or convert coordinates of simple feature — st_transform","text":"st_can_transform returns boolean indicating whether coordinates CRS src can transformed CRS dst Transforms coordinates object new projection. Features transformed returned empty geometries. Transforms using pipeline= argument may fail ambiguity axis order specified coordinate reference system; need traditional GIS order, use \"OGC:CRS84\", \"EPSG:4326\". Extra care needed ESRI Shapefile format, WKT1 store axis order unambiguously. st_transform method sfg objects assumes CRS object available attribute name. method bbox objects densifies lines geographic coordinates along Cartesian lines, great circle arcs discussion using options, see https://github.com/r-spatial/sf/issues/280 https://github.com/r-spatial/sf/issues/1983 sf_proj_info lists available projections, ellipses, datums, units, data search path PROJ library type equal proj, ellps, datum, units path; type equals have_datum_files boolean returned indicating whether datum files installed accessible (checking conus). path returns PROJ_INFO.searchpath field directly, single string path separaters (: ;). PROJ >= 6, sf_proj_info provide option type = \"datums\". PROJ < 6 provide option type = \"prime_meridians\". PROJ >= 7.1.0, \"units\" query sf_proj_info returns to_meter variable numeric, previous versions return character vector containing numeric expression.","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/st_transform.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Transform or convert coordinates of simple feature — st_transform","text":"","code":"p1 = st_point(c(7,52)) p2 = st_point(c(-30,20)) sfc = st_sfc(p1, p2, crs = 4326) sfc #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -30 ymin: 20 xmax: 7 ymax: 52 #> Geodetic CRS: WGS 84 #> POINT (7 52) #> POINT (-30 20) st_transform(sfc, 3857) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -3339585 ymin: 2273031 xmax: 779236.4 ymax: 6800125 #> Projected CRS: WGS 84 / Pseudo-Mercator #> POINT (779236.4 6800125) #> POINT (-3339585 2273031) st_transform(st_sf(a=2:1, geom=sfc), \"EPSG:3857\") #> Simple feature collection with 2 features and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -3339585 ymin: 2273031 xmax: 779236.4 ymax: 6800125 #> Projected CRS: WGS 84 / Pseudo-Mercator #> a geom #> 1 2 POINT (779236.4 6800125) #> 2 1 POINT (-3339585 2273031) if (sf_extSoftVersion()[\"GDAL\"] >= \"3.0.0\") { st_transform(sfc, pipeline = \"+proj=pipeline +step +proj=axisswap +order=2,1\") # reverse axes st_transform(sfc, pipeline = \"+proj=pipeline +step +proj=axisswap +order=2,1\", reverse = TRUE) # also reverse axes } #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -30 ymin: 20 xmax: 7 ymax: 52 #> CRS: NA #> POINT (7 52) #> POINT (-30 20) nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 st_area(nc[1,]) # area from long/lat #> 1137107793 [m^2] st_area(st_transform(nc[1,], 32119)) # NC state plane, m #> 1137598162 [m^2] st_area(st_transform(nc[1,], 2264)) # NC state plane, US foot #> 12244955726 [US_survey_foot^2] library(units) #> udunits database from /usr/share/xml/udunits/udunits2.xml set_units(st_area(st_transform(nc[1,], 2264)), m^2) #> 1137598162 [m^2] st_transform(structure(p1, proj4string = \"EPSG:4326\"), \"EPSG:3857\") #> POINT (779236.4 6800125) st_wrap_dateline(st_sfc(st_linestring(rbind(c(-179,0),c(179,0))), crs = 4326)) #> Geometry set for 1 feature #> Geometry type: MULTILINESTRING #> Dimension: XY #> Bounding box: xmin: -180 ymin: 0 xmax: 180 ymax: 0 #> Geodetic CRS: WGS 84 #> MULTILINESTRING ((-179 0, -180 0), (180 0, 179 0)) sf_proj_info(\"datum\") #> data frame with 0 columns and 0 rows"},{"path":"https://r-spatial.github.io/sf/reference/st_viewport.html","id":null,"dir":"Reference","previous_headings":"","what":"Create viewport from sf, sfc or sfg object — st_viewport","title":"Create viewport from sf, sfc or sfg object — st_viewport","text":"Create viewport sf, sfc sfg object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_viewport.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create viewport from sf, sfc or sfg object — st_viewport","text":"","code":"st_viewport(x, ..., bbox = st_bbox(x), asp)"},{"path":"https://r-spatial.github.io/sf/reference/st_viewport.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create viewport from sf, sfc or sfg object — st_viewport","text":"x object class sf, sfc sfg object ... parameters passed viewport bbox bounding box used aspect ratio asp numeric; target aspect ratio (y/x), see Details","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_viewport.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create viewport from sf, sfc or sfg object — st_viewport","text":"output call viewport","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_viewport.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create viewport from sf, sfc or sfg object — st_viewport","text":"parameters width, height, xscale yscale set aspect ratio honoured plot size maximized current viewport; others can passed ... asp missing, taken 1, except isTRUE(st_is_longlat(x)), case set 1.0 /cos(y), y middle latitude bounding box.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_viewport.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create viewport from sf, sfc or sfg object — st_viewport","text":"","code":"library(grid) #> #> Attaching package: ‘grid’ #> The following object is masked from ‘package:spatstat.geom’: #> #> as.mask nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 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')))))"},{"path":"https://r-spatial.github.io/sf/reference/st_write.html","id":null,"dir":"Reference","previous_headings":"","what":"Write simple features object to file or database — st_write","title":"Write simple features object to file or database — st_write","text":"Write simple features object file database","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_write.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Write simple features object to file or database — st_write","text":"","code":"st_write(obj, dsn, layer, ...) # S3 method for class 'sfc' st_write(obj, dsn, layer, ...) # S3 method for class 'sf' st_write( obj, dsn, layer = NULL, ..., driver = guess_driver_can_write(dsn), dataset_options = NULL, layer_options = NULL, quiet = FALSE, factorsAsCharacter = TRUE, append = NA, delete_dsn = FALSE, delete_layer = !is.na(append) && !append, fid_column_name = NULL, config_options = character(0) ) # S3 method for class 'data.frame' st_write(obj, dsn, layer = NULL, ...) write_sf(..., quiet = TRUE, append = FALSE, delete_layer = !append) st_delete( dsn, layer = character(0), driver = guess_driver_can_write(dsn), quiet = FALSE )"},{"path":"https://r-spatial.github.io/sf/reference/st_write.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Write simple features object to file or database — st_write","text":"obj object class sf sfc dsn data source name. Interpretation varies driver: can filename, folder, database name, Database Connection (officially test support RPostgres::Postgres() connections). layer layer name. Varies driver, may file name without extension; database connection, name table. layer missing, basename dsn taken. ... arguments passed dbWriteTable dsn Database Connection driver character; name driver used; missing dsn Database Connection, driver name guessed dsn; st_drivers() returns drivers available properties; links full driver documentation found https://gdal.org/en/latest/drivers/vector/index.html dataset_options character; driver dependent dataset creation options; multiple options supported. layer_options character; driver dependent layer creation options; multiple options supported. quiet logical; suppress info name, driver, size spatial reference factorsAsCharacter logical; convert factor levels character strings (TRUE, default), otherwise numbers factorsAsCharacter FALSE. database connections, factorsAsCharacter always TRUE. append logical; append existing layer, replace ? TRUE append, FALSE replace. default st_write NA raises error layer exists. default write_sf FALSE, overwrites existing data. See also next two arguments control overwrite behavior. delete_dsn logical; delete data source dsn attempting write? delete_layer logical; delete layer layer attempting write? default st_write FALSE raises error layer exists. default write_sf TRUE. fid_column_name character, name column feature IDs; specified, column longer written feature attribute. config_options character, named vector GDAL config options","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_write.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Write simple features object to file or database — st_write","text":"obj, invisibly","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_write.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Write simple features object to file or database — st_write","text":"Columns (variables) class supported dropped warning. updating existing layer, records appended updating object right variable names types. names match error raised. types match, behaviour undefined: GDAL may raise warnings errors fail silently. deleting layers data sources successful, error emitted. delete_dsn delete_layer handled care; former may erase complete directories databases. st_delete() deletes layer(s) data source, data source layers omitted; returns TRUE success, FALSE failure, invisibly.","code":""},{"path":[]},{"path":"https://r-spatial.github.io/sf/reference/st_write.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Write simple features object to file or database — st_write","text":"","code":"nc = st_read(system.file(\"shape/nc.shp\", package=\"sf\")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 st_write(nc, paste0(tempdir(), \"/\", \"nc.shp\")) #> Writing layer `nc' to data source #> `/tmp/RtmpokzaW8/nc.shp' using driver `ESRI Shapefile' #> Writing 100 features with 14 fields and geometry type Multi Polygon. st_write(nc, paste0(tempdir(), \"/\", \"nc.shp\"), delete_layer = TRUE) # overwrites #> Deleting layer `nc' using driver `ESRI Shapefile' #> Writing layer `nc' to data source #> `/tmp/RtmpokzaW8/nc.shp' using driver `ESRI Shapefile' #> Writing 100 features with 14 fields and geometry type Multi Polygon. if (require(sp, quietly = TRUE)) { data(meuse, package = \"sp\") # loads data.frame from sp meuse_sf = st_as_sf(meuse, coords = c(\"x\", \"y\"), crs = 28992) # writes X and Y as columns: st_write(meuse_sf, paste0(tempdir(), \"/\", \"meuse.csv\"), layer_options = \"GEOMETRY=AS_XY\") st_write(meuse_sf, paste0(tempdir(), \"/\", \"meuse.csv\"), layer_options = \"GEOMETRY=AS_WKT\", delete_dsn=TRUE) # overwrites if (FALSE) { # \\dontrun{ library(sp) example(meuse, ask = FALSE, echo = FALSE) try(st_write(st_as_sf(meuse), \"PG:dbname=postgis\", \"meuse_sf\", layer_options = c(\"OVERWRITE=yes\", \"LAUNDER=true\"))) demo(nc, ask = FALSE) try(st_write(nc, \"PG:dbname=postgis\", \"sids\", layer_options = \"OVERWRITE=true\")) } # } } #> Writing layer `meuse' to data source `/tmp/RtmpokzaW8/meuse.csv' using driver `CSV' #> options: GEOMETRY=AS_XY #> Writing 155 features with 12 fields and geometry type Point. #> Deleting source `/tmp/RtmpokzaW8/meuse.csv' using driver `CSV' #> Writing layer `meuse' to data source `/tmp/RtmpokzaW8/meuse.csv' using driver `CSV' #> options: GEOMETRY=AS_WKT #> Writing 155 features with 12 fields and geometry type Point."},{"path":"https://r-spatial.github.io/sf/reference/st_z_range.html","id":null,"dir":"Reference","previous_headings":"","what":"Return 'z' range of a simple feature or simple feature set — st_z_range","title":"Return 'z' range of a simple feature or simple feature set — st_z_range","text":"Return 'z' range simple feature simple feature set","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_z_range.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return 'z' range of a simple feature or simple feature set — st_z_range","text":"","code":"# S3 method for class 'z_range' is.na(x) st_z_range(obj, ...) # S3 method for class 'POINT' st_z_range(obj, ...) # S3 method for class 'MULTIPOINT' st_z_range(obj, ...) # S3 method for class 'LINESTRING' st_z_range(obj, ...) # S3 method for class 'POLYGON' st_z_range(obj, ...) # S3 method for class 'MULTILINESTRING' st_z_range(obj, ...) # S3 method for class 'MULTIPOLYGON' st_z_range(obj, ...) # S3 method for class 'GEOMETRYCOLLECTION' st_z_range(obj, ...) # S3 method for class 'MULTISURFACE' st_z_range(obj, ...) # S3 method for class 'MULTICURVE' st_z_range(obj, ...) # S3 method for class 'CURVEPOLYGON' st_z_range(obj, ...) # S3 method for class 'COMPOUNDCURVE' st_z_range(obj, ...) # S3 method for class 'POLYHEDRALSURFACE' st_z_range(obj, ...) # S3 method for class 'TIN' st_z_range(obj, ...) # S3 method for class 'TRIANGLE' st_z_range(obj, ...) # S3 method for class 'CIRCULARSTRING' st_z_range(obj, ...) # S3 method for class 'sfc' st_z_range(obj, ...) # S3 method for class 'sf' st_z_range(obj, ...) # S3 method for class 'numeric' st_z_range(obj, ..., crs = NA_crs_) NA_z_range_"},{"path":"https://r-spatial.github.io/sf/reference/st_z_range.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Return 'z' range of a simple feature or simple feature set — st_z_range","text":"object class z_range length 2.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_z_range.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Return 'z' range of a simple feature or simple feature set — st_z_range","text":"x object class z_range obj object compute z range ... ignored crs object class crs, argument st_crs, specifying CRS bounding box.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_z_range.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Return 'z' range of a simple feature or simple feature set — st_z_range","text":"numeric vector length two, zmin zmax values; obj class sf sfc object returned class z_range","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_z_range.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Return 'z' range of a simple feature or simple feature set — st_z_range","text":"NA_z_range_ represents missing value z_range object","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_z_range.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Return 'z' range of a simple feature or simple feature set — st_z_range","text":"","code":"a = st_sf(a = 1:2, geom = st_sfc(st_point(0:2), st_point(1:3)), crs = 4326) st_z_range(a) #> zmin zmax #> 2 3 st_z_range(c(zmin = 16.1, zmax = 16.6), crs = st_crs(4326)) #> zmin zmax #> 16.1 16.6"},{"path":"https://r-spatial.github.io/sf/reference/st_zm.html","id":null,"dir":"Reference","previous_headings":"","what":"Drop or add Z and/or M dimensions from feature geometries — st_zm","title":"Drop or add Z and/or M dimensions from feature geometries — st_zm","text":"Drop Z /M dimensions feature geometries, resetting classes appropriately","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_zm.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Drop or add Z and/or M dimensions from feature geometries — st_zm","text":"","code":"st_zm(x, ..., drop = TRUE, what = \"ZM\")"},{"path":"https://r-spatial.github.io/sf/reference/st_zm.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Drop or add Z and/or M dimensions from feature geometries — st_zm","text":"x object class sfg, sfc sf ... ignored drop logical; drop, (FALSE) add? character dimensions drop add","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_zm.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Drop or add Z and/or M dimensions from feature geometries — st_zm","text":"combinations drop=TRUE, = \"ZM\", drop=FALSE, =\"Z\" supported far. latter case, x XY geometry, zero values added Z dimension.","code":""},{"path":"https://r-spatial.github.io/sf/reference/st_zm.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Drop or add Z and/or M dimensions from feature geometries — st_zm","text":"","code":"st_zm(st_linestring(matrix(1:32,8))) #> LINESTRING (1 9, 2 10, 3 11, 4 12, 5 13, 6 14, 7 15, 8 16) x = st_sfc(st_linestring(matrix(1:32,8)), st_linestring(matrix(1:8,2))) st_zm(x) #> Geometry set for 2 features #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 1 ymin: 3 xmax: 8 ymax: 16 #> CRS: NA #> LINESTRING (1 9, 2 10, 3 11, 4 12, 5 13, 6 14, ... #> LINESTRING (1 3, 2 4) a = st_sf(a = 1:2, geom=x) st_zm(a) #> Simple feature collection with 2 features and 1 field #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 1 ymin: 3 xmax: 8 ymax: 16 #> CRS: NA #> a geom #> 1 1 LINESTRING (1 9, 2 10, 3 11... #> 2 2 LINESTRING (1 3, 2 4)"},{"path":"https://r-spatial.github.io/sf/reference/stars.html","id":null,"dir":"Reference","previous_headings":"","what":"functions only exported to be used internally by stars — stars","title":"functions only exported to be used internally by stars — stars","text":"functions exported used internally stars","code":""},{"path":"https://r-spatial.github.io/sf/reference/stars.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"functions only exported to be used internally by stars — stars","text":"","code":".get_layout(bb, n, total_size, key.pos, key.width, mfrow = NULL, main = NULL) .degAxis(side, at, labels, ..., lon, lat, ndiscr, reset) .image_scale( z, col, breaks = NULL, key.pos, add.axis = TRUE, at = NULL, ..., axes = FALSE, key.length, logz = FALSE, lab = \"\", cex.axis = par(\"cex.axis\") ) .image_scale_factor( z, col, key.pos, add.axis = TRUE, ..., axes = FALSE, key.width, key.length, cex.axis = par(\"cex.axis\") )"},{"path":"https://r-spatial.github.io/sf/reference/stars.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"functions only exported to be used internally by stars — stars","text":"bb ignore n ignore total_size ignore key.pos ignore key.width ignore mfrow length-2 integer vector number rows, columns main main sub title side ignore ignore labels ignore ... ignore lon ignore lat ignore ndiscr ignore reset ignore z ignore col ignore breaks ignore add.axis ignore axes ignore key.length ignore logz ignore lab ignore cex.axis see par","code":""},{"path":"https://r-spatial.github.io/sf/reference/summary.sfc.html","id":null,"dir":"Reference","previous_headings":"","what":"Summarize simple feature column — summary.sfc","title":"Summarize simple feature column — summary.sfc","text":"Summarize simple feature column","code":""},{"path":"https://r-spatial.github.io/sf/reference/summary.sfc.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Summarize simple feature column — summary.sfc","text":"","code":"# S3 method for class 'sfc' summary(object, ..., maxsum = 7L, maxp4s = 10L)"},{"path":"https://r-spatial.github.io/sf/reference/summary.sfc.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Summarize simple feature column — summary.sfc","text":"object object class sfc ... ignored maxsum maximum number classes summarize simple feature column maxp4s maximum number characters print PROJ string","code":""},{"path":"https://r-spatial.github.io/sf/reference/tibble.html","id":null,"dir":"Reference","previous_headings":"","what":"Summarize simple feature type for tibble — tibble","title":"Summarize simple feature type for tibble — tibble","text":"Summarize simple feature type / item tibble","code":""},{"path":"https://r-spatial.github.io/sf/reference/tibble.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Summarize simple feature type for tibble — tibble","text":"","code":"type_sum.sfc(x, ...) obj_sum.sfc(x) pillar_shaft.sfc(x, ...)"},{"path":"https://r-spatial.github.io/sf/reference/tibble.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Summarize simple feature type for tibble — tibble","text":"x object class sfc ... ignored","code":""},{"path":"https://r-spatial.github.io/sf/reference/tibble.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Summarize simple feature type for tibble — tibble","text":"see type_sum","code":""},{"path":"https://r-spatial.github.io/sf/reference/tidyverse.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidyverse methods for sf objects — tidyverse","title":"Tidyverse methods for sf objects — tidyverse","text":"Tidyverse methods sf objects. Geometries sticky, use .data.frame let dplyr's methods drop . Use methods loading tidyverse package generic (loading package tidyverse).","code":""},{"path":"https://r-spatial.github.io/sf/reference/tidyverse.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidyverse methods for sf objects — tidyverse","text":"","code":"filter.sf(.data, ..., .dots) arrange.sf(.data, ..., .dots) group_by.sf(.data, ..., add = FALSE) ungroup.sf(x, ...) rowwise.sf(x, ...) mutate.sf(.data, ..., .dots) transmute.sf(.data, ..., .dots) select.sf(.data, ...) rename.sf(.data, ...) rename_with.sf(.data, .fn, .cols, ...) slice.sf(.data, ..., .dots) summarise.sf(.data, ..., .dots, do_union = TRUE, is_coverage = FALSE) distinct.sf(.data, ..., .keep_all = FALSE) gather.sf( data, key, value, ..., na.rm = FALSE, convert = FALSE, factor_key = FALSE ) pivot_longer.sf( data, cols, names_to = \"name\", names_prefix = NULL, names_sep = NULL, names_pattern = NULL, names_ptypes = NULL, names_transform = NULL, names_repair = \"check_unique\", values_to = \"value\", values_drop_na = FALSE, values_ptypes = NULL, values_transform = NULL, ... ) pivot_wider.sf( data, ..., id_cols = NULL, id_expand = FALSE, names_from = name, names_prefix = \"\", names_sep = \"_\", names_glue = NULL, names_sort = FALSE, names_vary = \"fastest\", names_expand = FALSE, names_repair = \"check_unique\", values_from = value, values_fill = NULL, values_fn = NULL, unused_fn = NULL ) spread.sf( data, key, value, fill = NA, convert = FALSE, drop = TRUE, sep = NULL ) sample_n.sf(tbl, size, replace = FALSE, weight = NULL, .env = parent.frame()) sample_frac.sf( tbl, size = 1, replace = FALSE, weight = NULL, .env = parent.frame() ) group_split.sf(.tbl, ..., .keep = TRUE) nest.sf(.data, ...) separate.sf( data, col, into, sep = \"[^[:alnum:]]+\", remove = TRUE, convert = FALSE, extra = \"warn\", fill = \"warn\", ... ) separate_rows.sf(data, ..., sep = \"[^[:alnum:]]+\", convert = FALSE) unite.sf(data, col, ..., sep = \"_\", remove = TRUE) unnest.sf(data, ..., .preserve = NULL) drop_na.sf(x, ...) inner_join.sf(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ...) left_join.sf(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ...) right_join.sf(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ...) full_join.sf(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ...) semi_join.sf(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ...) anti_join.sf(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ...)"},{"path":"https://r-spatial.github.io/sf/reference/tidyverse.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidyverse methods for sf objects — tidyverse","text":".data data object class sf ... arguments .dots see corresponding function package dplyr add see corresponding function dplyr x, y pair data frames, data frame extensions (e.g. tibble), lazy data frames (e.g. dbplyr dtplyr). See Methods, , details. .fn, .cols see original docs do_union logical; case summary create geometry column, geometries created unioning using st_union, simply combining using st_combine? Using st_union resolves internal boundaries, case unioning points, likely change order points; see Details. is_coverage logical; do_union TRUE, use optimized algorithm features form polygonal coverage (overlaps) .keep_all see corresponding function dplyr data see original function docs key see original function docs value see original function docs na.rm see original function docs convert see separate_rows factor_key see original function docs cols see original function docs names_to, names_pattern, names_ptypes, names_transform see tidyr::pivot_longer() names_prefix, names_sep, names_repair see original function docs. values_to, values_drop_na, values_ptypes, values_transform See tidyr::pivot_longer() id_cols, id_expand, names_from, names_sort, names_glue, names_vary, names_expand see tidyr::pivot_wider() values_from, values_fill, values_fn, unused_fn see tidyr::pivot_wider() fill see original function docs drop see original function docs sep see separate_rows tbl see original function docs size see original function docs replace see original function docs weight see original function docs .env see original function docs .tbl see original function docs .keep see original function docs col see separate see separate remove see separate extra see separate .preserve see unnest join specification created join_by(), character vector variables join . NULL, default, *_join() perform natural join, using variables common across x y. message lists variables can check correct; suppress message supplying explicitly. join different variables x y, use join_by() specification. example, join_by(== b) match x$y$b. join multiple variables, use join_by() specification multiple expressions. example, join_by(== b, c == d) match x$y$b x$c y$d. column names x y, can shorten listing variable names, like join_by(, c). join_by() can also used perform inequality, rolling, overlap joins. See documentation ?join_by details types joins. simple equality joins, can alternatively specify character vector variable names join . example, = c(\"\", \"b\") joins x$y$x$b y$b. variable names differ x y, use named character vector like = c(\"x_a\" = \"y_a\", \"x_b\" = \"y_b\"). perform cross-join, generating combinations x y, see cross_join(). copy x y data source, copy TRUE, y copied src x. allows join tables across srcs, potentially expensive operation must opt . suffix non-joined duplicate variables x y, suffixes added output disambiguate . character vector length 2.","code":""},{"path":"https://r-spatial.github.io/sf/reference/tidyverse.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidyverse methods for sf objects — tidyverse","text":"object class sf","code":""},{"path":"https://r-spatial.github.io/sf/reference/tidyverse.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Tidyverse methods for sf objects — tidyverse","text":"select keeps geometry regardless whether selected ; deselect , first pipe .data.frame let dplyr's select drop . case one arguments (expressions) summarise call creates geometry list-column, first (active) geometry returned object. case, geometry column created, depending value do_union. case do_union FALSE, summarise simply combine geometries using c.sfg. polygons sharing boundary combined, leads geometries invalid; see instance https://github.com/r-spatial/sf/issues/681. distinct gives distinct records attributes geometries distinct; st_equals used find geometries distinct. nest assumes simple feature geometry list-column among columns nested.","code":""},{"path":"https://r-spatial.github.io/sf/reference/tidyverse.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidyverse methods for sf objects — tidyverse","text":"","code":"if (require(dplyr, quietly = TRUE)) { nc = read_sf(system.file(\"shape/nc.shp\", package=\"sf\")) nc %>% filter(AREA > .1) %>% plot() # plot 10 smallest counties in grey: st_geometry(nc) %>% plot() nc %>% select(AREA) %>% arrange(AREA) %>% slice(1:10) %>% plot(add = TRUE, col = 'grey') title(\"the ten counties with smallest area\") nc2 <- nc %>% mutate(area10 = AREA/10) nc %>% slice(1:2) } #> Warning: plotting the first 10 out of 14 attributes; use max.plot = 14 to plot all #> Simple feature collection with 2 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -81.74107 ymin: 36.23436 xmax: -80.90344 ymax: 36.58965 #> Geodetic CRS: NAD27 #> # A tibble: 2 × 15 #> AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 NWBIR74 #> #> 1 0.114 1.44 1825 1825 Ashe 37009 37009 5 1091 1 10 #> 2 0.061 1.23 1827 1827 Alleg… 37005 37005 3 487 0 10 #> # ℹ 4 more variables: BIR79 , SID79 , NWBIR79 , #> # geometry # plot 10 smallest counties in grey: if (require(dplyr, quietly = TRUE)) { st_geometry(nc) %>% plot() nc %>% select(AREA) %>% arrange(AREA) %>% slice(1:10) %>% plot(add = TRUE, col = 'grey') title(\"the ten counties with smallest area\") } if (require(dplyr, quietly = TRUE)) { nc$area_cl = cut(nc$AREA, c(0, .1, .12, .15, .25)) nc %>% group_by(area_cl) %>% class() } #> [1] \"sf\" \"grouped_df\" \"tbl_df\" \"tbl\" \"data.frame\" if (require(dplyr, quietly = TRUE)) { nc2 <- nc %>% mutate(area10 = AREA/10) } if (require(dplyr, quietly = TRUE)) { nc %>% transmute(AREA = AREA/10) %>% class() } #> [1] \"sf\" \"tbl_df\" \"tbl\" \"data.frame\" if (require(dplyr, quietly = TRUE)) { nc %>% select(SID74, SID79) %>% names() nc %>% select(SID74, SID79) %>% class() } #> [1] \"sf\" \"tbl_df\" \"tbl\" \"data.frame\" if (require(dplyr, quietly = TRUE)) { nc2 <- nc %>% rename(area = AREA) } if (require(dplyr, quietly = TRUE)) { nc %>% slice(1:2) } #> Simple feature collection with 2 features and 15 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -81.74107 ymin: 36.23436 xmax: -80.90344 ymax: 36.58965 #> Geodetic CRS: NAD27 #> # A tibble: 2 × 16 #> AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 NWBIR74 #> #> 1 0.114 1.44 1825 1825 Ashe 37009 37009 5 1091 1 10 #> 2 0.061 1.23 1827 1827 Alleg… 37005 37005 3 487 0 10 #> # ℹ 5 more variables: BIR79 , SID79 , NWBIR79 , #> # geometry , area_cl if (require(dplyr, quietly = TRUE)) { nc$area_cl = cut(nc$AREA, c(0, .1, .12, .15, .25)) nc.g <- nc %>% group_by(area_cl) nc.g %>% summarise(mean(AREA)) nc.g %>% summarise(mean(AREA)) %>% plot(col = grey(3:6 / 7)) nc %>% as.data.frame %>% summarise(mean(AREA)) } #> mean(AREA) #> 1 0.12626 if (require(dplyr, quietly = TRUE)) { nc[c(1:100, 1:10), ] %>% distinct() %>% nrow() } #> [1] 100 if (require(tidyr, quietly = TRUE) && require(dplyr, quietly = TRUE) && \"geometry\" %in% names(nc)) { nc %>% select(SID74, SID79) %>% gather(\"VAR\", \"SID\", -geometry) %>% summary() } #> geometry VAR SID #> MULTIPOLYGON :200 Length:200 Min. : 0.000 #> epsg:4267 : 0 Class :character 1st Qu.: 2.000 #> +proj=long...: 0 Mode :character Median : 5.000 #> Mean : 7.515 #> 3rd Qu.: 9.000 #> Max. :57.000 if (require(tidyr, quietly = TRUE) && require(dplyr, quietly = TRUE) && \"geometry\" %in% names(nc)) { nc$row = 1:100 # needed for spread to work nc %>% select(SID74, SID79, geometry, row) %>% gather(\"VAR\", \"SID\", -geometry, -row) %>% spread(VAR, SID) %>% head() } #> Simple feature collection with 6 features and 3 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -81.74107 ymin: 36.07282 xmax: -75.77316 ymax: 36.58965 #> Geodetic CRS: NAD27 #> # A tibble: 6 × 4 #> geometry row SID74 SID79 #> #> 1 (((-81.47276 36.23436, -81.54084 36.27251, -81.56198 36.273… 1 1 0 #> 2 (((-81.23989 36.36536, -81.24069 36.37942, -81.26284 36.405… 2 0 3 #> 3 (((-80.45634 36.24256, -80.47639 36.25473, -80.53688 36.256… 3 5 6 #> 4 (((-76.00897 36.3196, -76.01735 36.33773, -76.03288 36.3359… 4 1 2 #> 5 (((-77.21767 36.24098, -77.23461 36.2146, -77.29861 36.2115… 5 9 3 #> 6 (((-76.74506 36.23392, -76.98069 36.23024, -76.99475 36.235… 6 7 5 if (require(tidyr, quietly = TRUE) && require(dplyr, quietly = TRUE)) { storms.sf = st_as_sf(storms, coords = c(\"long\", \"lat\"), crs = 4326) x <- storms.sf %>% group_by(name, year) %>% nest trs = lapply(x$data, function(tr) st_cast(st_combine(tr), \"LINESTRING\")[[1]]) %>% st_sfc(crs = 4326) trs.sf = st_sf(x[,1:2], trs) plot(trs.sf[\"year\"], axes = TRUE) }"},{"path":"https://r-spatial.github.io/sf/reference/transform.sf.html","id":null,"dir":"Reference","previous_headings":"","what":"transform method for sf objects — transform.sf","title":"transform method for sf objects — transform.sf","text":"Can used create modify attribute variables; transforming geometries see st_transform, functions starting st_.","code":""},{"path":"https://r-spatial.github.io/sf/reference/transform.sf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"transform method for sf objects — transform.sf","text":"","code":"# S3 method for class 'sf' transform(`_data`, ...)"},{"path":"https://r-spatial.github.io/sf/reference/transform.sf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"transform method for sf objects — transform.sf","text":"_data object class sf ... arguments form new_variable = expression","code":""},{"path":"https://r-spatial.github.io/sf/reference/transform.sf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"transform method for sf objects — transform.sf","text":"","code":"a = data.frame(x1 = 1:3, x2 = 5:7) st_geometry(a) = st_sfc(st_point(c(0,0)), st_point(c(1,1)), st_point(c(2,2))) transform(a, x1_sq = x1^2) #> Simple feature collection with 3 features and 3 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 2 #> CRS: NA #> x1 x2 x1_sq geometry #> 1 1 5 1 POINT (0 0) #> 2 2 6 4 POINT (1 1) #> 3 3 7 9 POINT (2 2) transform(a, x1_x2 = x1*x2) #> Simple feature collection with 3 features and 3 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 2 #> CRS: NA #> x1 x2 x1_x2 geometry #> 1 1 5 5 POINT (0 0) #> 2 2 6 12 POINT (1 1) #> 3 3 7 21 POINT (2 2)"},{"path":"https://r-spatial.github.io/sf/reference/valid.html","id":null,"dir":"Reference","previous_headings":"","what":"Check validity or make an invalid geometry valid — valid","title":"Check validity or make an invalid geometry valid — valid","text":"Checks whether geometry valid, makes invalid geometry valid","code":""},{"path":"https://r-spatial.github.io/sf/reference/valid.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check validity or make an invalid geometry valid — valid","text":"","code":"st_is_valid(x, ...) # S3 method for class 'sfc' st_is_valid(x, ..., NA_on_exception = TRUE, reason = FALSE) # S3 method for class 'sf' st_is_valid(x, ...) # S3 method for class 'sfg' st_is_valid(x, ...) st_make_valid(x, ...) # S3 method for class 'sfg' st_make_valid(x, ...) # S3 method for class 'sfc' st_make_valid( x, ..., oriented = FALSE, s2_options = s2::s2_options(snap = s2::s2_snap_precision(1e+07), ...), geos_method = \"valid_structure\", geos_keep_collapsed = TRUE )"},{"path":"https://r-spatial.github.io/sf/reference/valid.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check validity or make an invalid geometry valid — valid","text":"x object class sfg, sfc sf ... passed s2_options NA_on_exception logical; TRUE, polygons otherwise raise GEOS error (exception, e.g. POLYGON zero less 4 points, LINESTRING one point) return NA rather raising error, suppress warning messages (e.g. self-intersection); FALSE, regular GEOS errors warnings emitted. reason logical; TRUE, return character , geometry, reason invalidity, NA exception, \"Valid Geometry\" otherwise. oriented logical; relevant st_is_longlat(x) TRUE; see s2 s2_options relevant st_is_longlat(x) TRUE; options s2_rebuild, see s2_options Details. geos_method character; either \"valid_linework\" (Original method, combines rings set noded lines extracts valid polygons linework) \"valid_structure\" (Structured method, first makes rings valid merges shells subtracts holes shells generate valid result. Assumes holes shells correctly categorized.) (requires GEOS >= 3.10.1) geos_keep_collapsed logical; parameter set FALSE, \"valid_structure\" method keep component collapsed lower dimensionality. example, ring collapsing line, line collapsing point (requires GEOS >= 3.10.1)","code":""},{"path":"https://r-spatial.github.io/sf/reference/valid.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Check validity or make an invalid geometry valid — valid","text":"st_is_valid returns logical vector indicating geometries x whether valid. st_make_valid returns object topologically valid geometry. Object class x","code":""},{"path":"https://r-spatial.github.io/sf/reference/valid.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Check validity or make an invalid geometry valid — valid","text":"projected geometries, st_make_valid uses lwgeom_makevalid method also used PostGIS command ST_makevalid GEOS version linked smaller 3.8.0, otherwise version shipped GEOS; geometries ellipsoidal coordinates s2::s2_rebuild used. s2_options specified x non-zero precision set, precision value used value s2_snap_precision, passed s2_options, rather 1e7 default.","code":""},{"path":"https://r-spatial.github.io/sf/reference/valid.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check validity or make an invalid geometry valid — valid","text":"","code":"p1 = st_as_sfc(\"POLYGON((0 0, 0 10, 10 0, 10 10, 0 0))\") st_is_valid(p1) #> [1] FALSE st_is_valid(st_sfc(st_point(0:1), p1[[1]]), reason = TRUE) #> [1] \"Valid Geometry\" \"Self-intersection[5 5]\" library(sf) x = st_sfc(st_polygon(list(rbind(c(0,0),c(0.5,0),c(0.5,0.5),c(0.5,0),c(1,0),c(1,1),c(0,1),c(0,0))))) suppressWarnings(st_is_valid(x)) #> [1] FALSE y = st_make_valid(x) st_is_valid(y) #> [1] TRUE y %>% st_cast() #> Geometry set for 1 feature #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 #> CRS: NA #> POLYGON ((0 0, 0 1, 1 1, 1 0, 0.5 0, 0 0))"},{"path":"https://r-spatial.github.io/sf/reference/vctrs.html","id":null,"dir":"Reference","previous_headings":"","what":"vctrs methods for sf objects — vctrs","title":"vctrs methods for sf objects — vctrs","text":"vctrs methods sf objects","code":""},{"path":"https://r-spatial.github.io/sf/reference/vctrs.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"vctrs methods for sf objects — vctrs","text":"","code":"vec_ptype2.sfc(x, y, ...) # Default S3 method vec_ptype2.sfc(x, y, ..., x_arg = \"x\", y_arg = \"y\") # S3 method for class 'sfc' vec_ptype2.sfc(x, y, ...) vec_cast.sfc(x, to, ...) # S3 method for class 'sfc' vec_cast.sfc(x, to, ...) # Default S3 method vec_cast.sfc(x, to, ...)"},{"path":"https://r-spatial.github.io/sf/reference/vctrs.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"vctrs methods for sf objects — vctrs","text":"x, y Vector types. ... dots future extensions must empty. x_arg, y_arg Argument names x y. Type cast . NULL, x returned .","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-19","dir":"Changelog","previous_headings":"","what":"version 1.0-19","title":"version 1.0-19","text":"fix type checks C++ GDAL area length computation functions, anticipating GDAL 3.10.0; #2466, #2468, #2469 @rsbivand @rouault improve test empty geometries, changed 1.0-18; #2463 gdal_utils() ogrinfo argument read_only , TRUE (options includes \"-ro\"), opens datasource read-mode (#2460; sf 1.0-17); default datasource opened update (read-write) mode (since sf 1.0-17; #2420) sf -> ppp conversion .ppp.sf() accepts data.frame marks instead just 1 column #2450, @agila5","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-18","dir":"Changelog","previous_headings":"","what":"version 1.0-18","title":"version 1.0-18","text":"CRAN release: 2024-10-11 support POLYGON FULL simple feature geometry, representing entire Earth surface, used s2geometry; #2441 st_sfc() argument oriented , set TRUE, adds attribute oriented=TRUE sfc object, indicating object reoriented conversion s2_geography (avoiding using global option s2_oriented); st_as_sfc.bbox() sets TRUE; #2441 fix build failure GDAL < 3.4.0 #2436 st_simplify() now accepts feature-wise tolerance values s2 switched #2442","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-17","dir":"Changelog","previous_headings":"","what":"version 1.0-17","title":"version 1.0-17","text":"CRAN release: 2024-09-06 add st_transform() method bbox objects; uses OGRCoordinateTransformation::TransformBounds(), densifying first antemeridian proof; #2415 st_filter.sf() correctly scopes x y arguments using !! operator; #2416 [.sfc [<-.sfc use matrix/array type subsetting sfc objects dim attribute add st_exterior_ring() extract exterior rings (remove holes); #2406 add text.sf(), text.sfc(), points.sf(), points.sfc() annotate base plots geometry centroids; #2399 st_sf() longer strips tbl tbl_df class labels; #2378 st_layers() returns object class c(\"sf_layers\", \"data.frame\"), dedicated print method. dim XYZM, sf_as_sf.data.frame() interprets length 4 coords argument specify corners rectangular polygon; #2357 st_interpolate_aw() gains na.rm argument, removing features NA attributes interpolating; #830 merge.sf() longer renames geometry column; #2334","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-16","dir":"Changelog","previous_headings":"","what":"version 1.0-16","title":"version 1.0-16","text":"CRAN release: 2024-03-24 st_join() longer renames geometry column; #2327 st_sample() works unprojected polygon geometry crosses antemeridian; #2331 clean modernization S3 registration methods tests; #2285, #2288, #2316, #2341, #2342, @olivroy [.sfc works setting argument op; #2320 st_sample() polygons sensitive setting oriented = TRUE prevent wrongly correcting ring directions; #2308 add support GDAL footprint utility (requiring GDAL >= 3.8.0) gdal_utils; #2305, @goergen95 existing environment variables PROJ_LIB PROJ_DATA () ignored sf binary CRAN installations (win + macos), effectively overwriting R session restoring exit; happen environment variable R_SF_USE_PROJ_DATA set true. #2298 add st_line_project() find far point projected line; #2291 add st_line_interpolate() obtain point certain distance along line; #2291","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-15","dir":"Changelog","previous_headings":"","what":"version 1.0-15","title":"version 1.0-15","text":"CRAN release: 2023-12-18 add st_perimeter() generic cover geographic projected coordinates; #268, #2279, @JosiahParry add st_sample() method bbox, special provisions ellipsoidal coordinates; #2283 documentation clean-@olivroy; #2266, #2285 st_convex_hull() uses s2::s2_convex_hull() geodetic coordinates; #2250 add directed argument st_line_merge(); #2264 st_union.sfc() given x y works consistently across geodetic projected objects; #2262 st_union.sf() given x y unions pairwise by_feature = TRUE; #2259 st_read() work around issue GPKG driver wkt_filter set; #2248 st_read() uses GDAL’s stream reading use_stream = TRUE; #2238 @paleolimbot st_transform() responds -session changes sf_proj_network(); #2166 plot.sf(): key.width sensitive pointsize graphics parameter par(\"ps\"); keys factor levels suggest proper size won’t fit. plot.sf(): key.pos can hold second value [0, 1] determining relative position key available space [<-.sf fixes agr attribute broken; #2211 env. variable ADD_SF_NAMESPACE set true, sf objects get new attribute, .sf_namespace, forces loading sf namespace loaded far, e.g. proper printing plotting sf object; #2212 Mike Mahoney distinct.sf() type-safe sf objects zero rows; #2204 summarise.sf() raises error .given across() geometry; #2207 st_write() matches fields name first, position; matters formats pre-defined names, GPX; #2202","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-14","dir":"Changelog","previous_headings":"","what":"version 1.0-14","title":"version 1.0-14","text":"CRAN release: 2023-07-11 fix plot.sf() using key multiple factor variables; #2196, #2195 fix use .numeric_version test, upcoming change r-devel code tidy-ing: fix many lintr suggestions, thanks Michael Chirico (#2181 - #2191)","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-13","dir":"Changelog","previous_headings":"","what":"version 1.0-13","title":"version 1.0-13","text":"CRAN release: 2023-05-24 gdal_utils() adds \"ogrinfo\" utility (requires GDAL >= 3.7.0); #2160 st_as_sf() catches errors setting invalid crs values, raised Jon Skøien add rename_with.sf() method; #1472 use GEOS’ overlayNG routines (GEOS) Intersection, Difference, Union SymDifference; #2143 added duplicated.sf(); #2138, #2140, thanks @bart1 select.sf() allows selecting column twice different names; #1886 st_as_sf.ppplist() deprecated; #1926 st_cast() handles empty geometries; #1961 don’t repeat longlat messages summarise.sf(); #1519 fix random sampling sphere; #2133","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-12","dir":"Changelog","previous_headings":"","what":"version 1.0-12","title":"version 1.0-12","text":"CRAN release: 2023-03-19 update NAMESPACE useDynLib(sf, .registration=TRUE); #2127 thanks @eddelbuettel fix call gdal_addo(); #2124 fix issues came older GDAL version, use GDAL_VERSION_NUM consistently; #2123 #2121 #2119","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-11","dir":"Changelog","previous_headings":"","what":"version 1.0-11","title":"version 1.0-11","text":"CRAN release: 2023-03-15 st_make_grid() also accepts area units cellsize, square hexagonal grids; #1505 add st_concave_hull(), concave hulls, GEOS >= 3.11.0; #1964 add st_triangulate_constrained(), constrained Delaunay triangulation, GEOS >= 3.10.0; #1964 clean retrieval length angle units WKT representations; https://lists.osgeo.org/pipermail/gdal-dev/2023-March/056994.html conversion GEOS uses GEOS_PREC_VALID_OUTPUT flag, makes sure “[o]utput always valid. Collapsed geometry elements (including polygons lines) removed.”","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-10","dir":"Changelog","previous_headings":"","what":"version 1.0-10","title":"version 1.0-10","text":"CRAN release: 2023-03-12 gdal_utils() config_options argument set GDAL options, just like st_write(); #2003 fix slow writing logical vectors st_write(); #1409; #1689 st_drivers() argument regex filter driver (long) name; #2090 drop C++11 system requirement c.sfc() (, consequently, dplyr::bind_rows()) gives error components different CRS; #1884 data imported maps associated Clark 1866 ellipsoid; #2080 fix importing legacy SpatialPolygon objects without comments; #2063, #2069, https://github.com/rstudio/leaflet/issues/833 st_read() longer errors mixes XY XYZ geometries; #2046 #1592 plot.sf(), numeric breaks given legend key always plotted; #2065 st_crs()$axes returns data.frame axes properties (name, orientation, conversion factor) GDAL >= 3.0.0 clean unit handling geometry measures (length, area, distance) crs; st_crs(x)$ud_unit returns NULL units unknown; #2049 st_write() substitutes NA crs ENGCRS[\"Undefined Cartesian SRS unknown unit\"]; #2049, #2054 st_can_transform() checks whether transformation two crs exists; see https://github.com/dieghernan/tidyterra/issues/64; #2049 matrix returned st_coordinates() row names, reduce output size","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-9","dir":"Changelog","previous_headings":"","what":"version 1.0-9","title":"version 1.0-9","text":"CRAN release: 2022-11-08 adjust changes R-devel handles POSIXlt; #2028 add st_break_antimeridian(); #1983, #1991 Roger Bivand add Fibonacci spatial sampling type st_sample() use global options(\"sf_use_s2\") determine whether use s2, rather value local environment; #1977 fix utils mdiminfo mdimtranslate gdal_utils() extend arguments gdal_read_mdim() needed stars::read_mdim() stars >= 0.5-7; add gdal_write_mdim() add drop_na() method sf objects; #1975","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-8","dir":"Changelog","previous_headings":"","what":"version 1.0-8","title":"version 1.0-8","text":"CRAN release: 2022-07-14 st_drop_geometry.default() returns x unmodified; sf_project() accepts 3- 4-column matrices, containing z t values; optimization st_sfc() @paleolimbot; #1938, #1925 [<-.sfc() recomputes bounding box; st_sfc() gets parameter compute_bbox; #1965 add new algorithm drop option st_make_valid() using GEOS GEOS >= 3.10.1; #1655 add st_minimum_rotated_rectangle(), available GEOS >= 3.9.0; #1953 fix st_sample() type = \"hexagonal\" corner case (n=1), add progress argument progress bar; #1945 add package pbapply Suggests; #1945 add pdf driver windows build; #1942 clarify pipeline argument st_transform() axis order ambiguous; #1934 handle argument xpd calls plot.sfc_POLYGON() plot.sfc_MULTIPOLYGON() add pivot_wider() method, Henning Teickner; #1915 add gdal_addo() add remove overviews raster images; #1921 st_layers() returns crs layer crs list crs objects restore st_graticule() behaviour pre-sf 1.0-0; https://github.com/tidyverse/ggplot2/issues/4571 gdal_metadata() sets metadata item names properly st_read() gains argument optional passed .data.frame avoid changing column names; #1916 GPX files autodetected st_read(); #1917 unnecessary coordinate names returned st_sample(), making output size smaller; #1879","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-7","dir":"Changelog","previous_headings":"","what":"version 1.0-7","title":"version 1.0-7","text":"CRAN release: 2022-03-07 st_drop_geometry() generic; #1914 st_crs(x)$ud_unit returns unit coordinate reference system x geometric predicates return sgbp objects omitting self-intersections etc. passing remove_self = TRUE unique symmetric relationship passing retain_unique = TRUE (... needed); simplifies identifying (removing) duplicated geometries; duplicates identified e.g. st_equals(x, retain_unique = TRUE) |> unlist() |> unique(); #1893 fix compile issue GDAL < 2.5.0 introduced 1.0-6; #1899","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-6","dir":"Changelog","previous_headings":"","what":"version 1.0-6","title":"version 1.0-6","text":"CRAN release: 2022-02-04 adapt new spatstat.random package; #1892 st_geometry<-() also allows rename geometry column sf object; #1890 sf objects, st_as_sfc() method alias st_geometry(); #1882 st_make_grid() speeded ; #1579 thanks Krzysztof Dyba remove direct indirect dependencies rgeos rgdal; #1869 use stats::dist rather GEOS symmetric point-point Euclidian distance computation; #1874","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-5","dir":"Changelog","previous_headings":"","what":"version 1.0-5","title":"version 1.0-5","text":"CRAN release: 2021-12-17 package startup message reports status sf_use_s2(); #1782 sf_use_s2() uses message() report change; #1782 st_sample() using regular sampling ellipsoidal coordinates “works” coordinates Cartesian; #1837","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-4","dir":"Changelog","previous_headings":"","what":"version 1.0-4","title":"version 1.0-4","text":"CRAN release: 2021-11-14 new function st_delete() deletes data source, layer(s) within data source; #1828 fix memory leak WKT1_ESRI retrieval; #1690","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-3","dir":"Changelog","previous_headings":"","what":"version 1.0-3","title":"version 1.0-3","text":"CRAN release: 2021-10-07 cope GEOS >= 3.10.0 handles illegal geometries (e.g., non-closed rings); #1807 crs objects $srid method extract SRID (authority “name:code”); #1804 st_as_grob() methods sfc_* objects correctly handle empty geometries; #1789 help Hiroaki Yutani writing objects NA CRS GeoPackage, assign “Unknown Cartesian CRS” first - line using Cartesian geometry operations objects NA CRS; #1776 add coerce method sgbp sparseMatrix; #1750 fix st_cast() GEOMETRYCOLLECTIONS containing empty geometries; #1767 fix st_is_valid() bogus polygons projected coordinates; #1666, #1760; #1761","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-2","dir":"Changelog","previous_headings":"","what":"version 1.0-2","title":"version 1.0-2","text":"CRAN release: 2021-07-26 st_read() st_write() using GDAL handle binary attributes (OFTBinary fields) ; #1721 pivot_longer method added sf objects (data.frame method works, raises warning) rbind.sf preserves primary geometry column; #1717 configure constrains using --static Darwin platform; #1702, #1712, #1713 old-style crs objects created sf < 0.9-0 generate message, cause warning future. st_crs() called WKT2 text input, input field replaced CRS name (one). GEOS (>= 3.9.0) operations use GEOSGeom_setPrecision_r set precision geometries; #1535 st_read() specified query ignores argument layers, warns given; #1444","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-1","dir":"Changelog","previous_headings":"","what":"version 1.0-1","title":"version 1.0-1","text":"CRAN release: 2021-06-29 fix regression st_intersection(): using s2 attributes assigned wrongly; #1704 crs (sf) CRS (sp) conversion longer needs validation rgdal; https://github.com/edzer/sp/issues/107 retrieve ESRI’s WKT version CRS st_crs(id)$WKT1_ESRI; #1690","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-10-0","dir":"Changelog","previous_headings":"","what":"version 1.0-0","title":"version 1.0-0","text":"CRAN release: 2021-06-09 add s2 Imports: add Dewey Dunnington contributors sf_use_s2() prints message using s2 switched . use s2 spherical geometry default coordinates ellipsoidal. can switched (defaulting planar geometry, using GEOS, sf < 1.0-0) setting environment variable _SF_USE_S2 false package sf loaded, sf_use_s2(FALSE); #1649 st_nearest_feature() missing y returns nearest features remaining set x; https://github.com/r-spatial/s2/issues/111 st_write() gains argument config_options set GDAL config options; #1618 fix regression sf_project(..., keep = TRUE); #1635","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-8","dir":"Changelog","previous_headings":"","what":"version 0.9-8","title":"version 0.9-8","text":"CRAN release: 2021-03-17 add st_as_sf() method terra’s SpatVector class; #1567 distinct.sf() works default variables, keeps active geometry active; #1613 improve (fix?) polygonize/contour code; #1608 sf_proj_network() reports whether PROJ uses network (CDN) grids, can switch , can set CDN url. st_write() returns obj, invisibly; #1597 fix regression n-ary st_intersection(), #1595, introduced #1549 st_inscribed_circle() computes maximum inscribed circle polygons (requires GEOS >= 3.9.0) allow st_cast() COMPOUNDCURVE, MULTISURFACE CURVEPOLYGON GEOMETRYCOLLECTION, back; #1573 Fixed bug st_as_grob() plotting mix MULTI non-MULTI geometries base type","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-7","dir":"Changelog","previous_headings":"","what":"version 0.9-7","title":"version 0.9-7","text":"CRAN release: 2021-01-06 n-ary st_intersection() skips failing geometries, rather returning error; #1549 use s2_centroid() geographical coordinates sf_use_s2() TRUE. st_as_text() method crs objects can return projjson (GDAL >= 3.1.0 PROJ > 6.2.0) st_transform() longer warns conversions like \"+proj=ob_tran +o_proj=longlat +o_lat_p=45 +o_lon_p=30\" st_as_wkb() takes srid wkt field crs input field doesn’t contain ; #1490 plot.sf() adds key.pos=0 option run logic behind key without plotting ; #1487 fix bug select.sf() selected variables renamed; #1483 st_as_sf.stars(..., merge = TRUE) now works CRS NA; #1389 add (dynamically loaded) as_wkb() methods sf, sfc sfg, making st_as_s2() unnecessary st_as_s2() transforms non-longlat objects EPSG:4326 first","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-6","dir":"Changelog","previous_headings":"","what":"version 0.9-6","title":"version 0.9-6","text":"CRAN release: 2020-09-13 gdal_utils() print (GDAL-style) progress bar quiet = FALSE (except info mdiminfo) fix CPL_gdal_warper multi bands; https://github.com/r-spatial/stars/issues/320 sf_proj_search_paths() retrieves sets proj search path (GDAL > 3.0.3) loading sf, sf_use_s2() set FALSE unless environment variable _SF_USE_S2 equals true (changes TRUE sf 1.0-0) resolve GDAL/PROJ version vulnerabilities CRS-crs conversion; #1479 st_sample() gains argument, by_polygon, clevery sample MULTIPOLYGON geometries; #1480 st_sample() accepts non-integer sample sizes, (suppressable) warning handles values sizes round zero; #1480 gdal_utils() adds utils mdiminfo mdimtranslate (requires GDAL >= 3.1) st_union() gains argument is_coverage, , set TRUE, leads much faster unioning case features form coverage (polygons don’t overlap); #1462 Don Baston fix gdal_utils(\"translate\") locking input file; #1452 st_make_grid() longer selects cells intersecting x; #1447 use s2::s2_dwithin_matrix() st_is_within_distance(); #1367","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-5","dir":"Changelog","previous_headings":"","what":"version 0.9-5","title":"version 0.9-5","text":"CRAN release: 2020-07-14 package s2 >= 1.0.1 available: support spherical geometry operators (predicates, transformers, measures, nearest point/feature) geographic coordinates package s2 now default switched , can switched sf_use_s2(TRUE); see https://www.r-spatial.org/r/2020/06/17/s2.html vignette sf7. planned switched default sf 1.0-0. drop Z /M coordinate st_as_s2(), message geometry predicates transformers gain … argument pass s2::s2_options() dplyr::select() now ensures geometry column sticks back rather front data frame; #1425 dplyr::rename() now preserves active geometry column even renamed; #1431 proj units query adjusted PROJ 7.1.0 release; #1434","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-4","dir":"Changelog","previous_headings":"","what":"version 0.9-4","title":"version 0.9-4","text":"CRAN release: 2020-06-12 empty geom generators take care XYZ etc dim; #1400 write_sf() read_sf() longer warn reading tables without geometries st_write() writes non-spatial tables given plain data.frame tbl_df; #1345 default stringsAsFactors st_read st_sf FALSE R version >= 4.1.0 sf method dplyr::select() supports renaming geometry column; #1415","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-3","dir":"Changelog","previous_headings":"","what":"version 0.9-3","title":"version 0.9-3","text":"CRAN release: 2020-05-04 st_is_valid() generic Windows CRAN binaries use GDAL 3.0.4, PROJ 6.3.1 GEOS 3.8.0, thanks Jeroen Ooms’ rwinlib work; #1275 plot.sf() gains extent argument set extent (xlim, ylim) plot; extent must object st_bbox() method, sf stars object; #1193","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-2","dir":"Changelog","previous_headings":"","what":"version 0.9-2","title":"version 0.9-2","text":"CRAN release: 2020-04-14 st_axis_order(TRUE) gives error GDAL version < 2.5.0 loading PROJ units link, us_in, ind_yd, ind_ft, ind_ch udunits database longer done package load time, function sf_add_proj_units() called. fix line sampling small densities; #1365 sf_project() handles crs objects PROJ version 6 using proj.4 string representations. avoid using isFALSE st_write(); #1342 fix regression gdal_utils(\"translate\", ...); #1339","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-1","dir":"Changelog","previous_headings":"","what":"version 0.9-1","title":"version 0.9-1","text":"CRAN release: 2020-04-06 fix invalid read bug st_m_range(); #1332 st_crs(4326) == st_crs(\"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs\") returns TRUE GDAL >= 3.0, irrespective authority compliance axis order; see #1331 https://github.com/ropensci/scrubr/issues/34 sf_project() parameter authority_compliant return coordinates “visualisation order”; TRUE returns coordinates authority compliant axis order (e.g. EPSG:4326 latitude longitude); default st_axis_order(). fix test Solaris certain GDAL/PROJ versions fix error reading category table GDAL; https://github.com/r-spatial/stars/issues/245","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-09-0","dir":"Changelog","previous_headings":"","what":"version 0.9-0","title":"version 0.9-0","text":"CRAN release: 2020-03-24 see r-spatial blog post: https://www.r-spatial.org/r/2020/03/17/wkt.html modify crs objects reflect post-proj4string world (#1146; #1225): crs objects contain two fields, input user input (), wkt well-known-text (WKT2) representation coordinate reference system. crs objects $ method dynamically retrieve epsg (integer) proj4string representation, using e.g. x$epsg. support PostGIS 3 using WKT new-style crs objects; #1234, #1303, #1308 @etiennebr st_write_db() st_read_db() defunct. Use st_write st_read instead. st_write() uses append, replacing (deprecating) argument update; st_write fails layer already exists append set explicitly TRUE (append) FALSE (overwrite); #1266 st_proj_info() renamed sf_proj_info; sf_proj_info can get set PROJ data search path use CDN; #1277 adapt new dplyr version; https://github.com/tidyverse/dplyr/issues/4917 st_sample() generic write stars rasters wkt info, rather proj4strings GEOS >= 3.8.0, st_make_valid provided sf rather lwgeom #989 allow single-sided buffers linear geometries; #1001 add st_reverse() methods reverse points linestring (requires GEOS >= 3.7.0); #1246 st_make_grid() returns grid cells points intersect target geometry, bounding box; #1260 allow PROJ >= 7; #1254 st_geometry_type() accepts by_geometry argument; #1264","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-08-1","dir":"Changelog","previous_headings":"","what":"version 0.8-1","title":"version 0.8-1","text":"CRAN release: 2020-01-28 st_as_sf.map() longer requires maptools sp; dropped dependency maptools. work around bug 6.0.0 <= PROJ < 6.3.1: replace +init=epsg:XXXX ... strings XXXX EPSG integer, work around bug PROJ; see https://github.com/OSGeo/PROJ/pull/1875 links therein. ... arguments present, raise warning ignored. st_as_sf.map() longer requires maptools sp; drop dependency maptools. conversion spatstat classes owin, ppp psp sf classes longer use maptools; #1204 gdal_utils() processes open options -oo -doo properly; https://github.com/ITSLeeds/geofabric/issues/12 st_sample() directly interfaces spatstat sampling methods, e.g. type = \"Thomas\" calls spatstat::rThomas converting input arguments (window) converts returned ppp object sf’s POINT geometries; #1204 help Ege Rubak Jakub Nowosad sf_project() gains option keep = TRUE return Inf values points projectable; #1228 support vctrs methods geometry list columns; makes unnest work (#1172); #1196 Lionel Henry st_as_sf.pq_geometry() converts binary geom columns RPostgres::dbGetQuery; #1195 st_cast() can convert MULTICURVE MULTILINESTRING; #1194 st_read() gains parameter wkt_filter spatially filtering features read; #1192 st_area() st_length() handle +to_meter argument PROJ strings; #1170 add st_filter() generic filtering spatial features ; #1148 new UBSAN error wkb_read() resolved; #1154, #1152 new method st_shift_longitude() re-center data Pacific view. #1218 output st_as_text() MULTIPOINT nested parentheses around points. E.g., MULTIPOINT ((0 0), (1 1)) instead MULTIPOINT (0 0, 1 1); #1219, #1221","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-08-0","dir":"Changelog","previous_headings":"","what":"version 0.8-0","title":"version 0.8-0","text":"CRAN release: 2019-09-17 fix tests PROJ 6.2.0 accepting +units= fixes tidyr 1.0-0 release; attempt port nest.sf() unnest.sf(); #1068, #1145 gdal_utils() better closes connections use; #1143 st_write() gains drivers options, limit drivers attempted; #1142 rather replacing, st_write() write_sf() append existing layer update=TRUE; #1126 improve plotting POSIXct Date attributes (Date requiring classInt >= 0.4-2) NULL geometries read GDAL returned empty geometries; #1119 gdal_utils('rasterize', ...) accepts non-existing destinations, defined e.g. resolution extent options (see #1116 example), overwrites needed (see #1136 example) add Dan Baston contributor; #1120 many others addition NULL, st_sfc() also converts NA values empty geometries; #1114. st_join() generic","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-7","dir":"Changelog","previous_headings":"","what":"version 0.7-7","title":"version 0.7-7","text":"CRAN release: 2019-07-24 plot() handles POSIXct values legend constructor functions like st_linestring() check break NA coordinates; #1101, #1102","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-6","dir":"Changelog","previous_headings":"","what":"version 0.7-6","title":"version 0.7-6","text":"CRAN release: 2019-07-05 examples st_write write temporary R session directory","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-5","dir":"Changelog","previous_headings":"","what":"version 0.7-5","title":"version 0.7-5","text":"CRAN release: 2019-07-03 (x, \"Spatial\") gives proper error message empty geometries; #1093 st_cast() takes care empty polygons; #1094 st_nearest_* functions warn case used geographic coordinates; #1081 st_union() longer segfaults zero row sf objects; #1077 st_transform() longer breaks zero row sf objects; #1075 PROJ >= 6.1.0 available sf comes datum files (case statically linked Windows OSX CRAN binaries), PROJ_LIB longer temporarily overwritten, PROJ C api used set datum path; #1074, suggested Jeroen Ooms sf compiles GDAL 3.x PROJ 6.1.0, using new proj.h interface; #1070 st_distance() returns NA empty geometries, rather 0; #1055","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-4","dir":"Changelog","previous_headings":"","what":"version 0.7-4","title":"version 0.7-4","text":"CRAN release: 2019-04-25 add example voronoi polygons can tied back points contain; #1030 st_difference(x, y), x sfc zero feature geometries, returns x; #1024 don’t reset (base) plot device add = TRUE == != return NA one operands empty geometry; #1013 st_intersects() generic drop requiring proj_api.h favor proj.h, enables compatibility PROJ 6.0.0 GDAL 2.5.0-dev; #988 fix regression binary predicates introduced #855; #999 reported Barry Rowlingson fix bug gdal_utils util warper certain GDAL/OS combinations; https://github.com/r-spatial/stars/issues/117 c.sfc() ignores type (class) empty sfc objects choosing result type; #985, #982 rename default value distance \"Euclidean\", rather \"distance\" st_distance()","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-3","dir":"Changelog","previous_headings":"","what":"version 0.7-3","title":"version 0.7-3","text":"CRAN release: 2019-02-21 add argument exact st_sample(), defaulting FALSE; #896 fixed n-ary st_difference() cases geometries entirely contained others; #975, Jonathan Marshall faster Ops.sfc(), added st_normalize(); #973 Thomas Lin Pedersen new grob constructor sfc objects; #971 Thomas Lin Pedersen; add Thomas contributor add group_split() group_map() methods sf objects (experimental); #969 make st_interpolate_aw() generic; argument col plot GEOMETRY sfc’s NA (open) (multi) polygon geometries","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-2","dir":"Changelog","previous_headings":"","what":"version 0.7-2","title":"version 0.7-2","text":"CRAN release: 2018-12-20 feature IDs longer returned names geometry list column, optionally returned st_read attribute column; #812 plotting multiple attributes, plot.sf adds (single, common) key key.pos set precision can specified distance units; #901 support log-scale color legend setting logz TRUE plot.sf st_intersects() etc. prepare y y polygons x points; #885 Dan Baston st_write() (write_sf()) returns first argument, invisibly; #889","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-1","dir":"Changelog","previous_headings":"","what":"version 0.7-1","title":"version 0.7-1","text":"CRAN release: 2018-10-24 fix bug broke n-ary st_intersection() platforms using clang; #867","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-07-0","dir":"Changelog","previous_headings":"","what":"version 0.7-0","title":"version 0.7-0","text":"CRAN release: 2018-10-17 adds several interfaces GDAL functions, meant used package stars st_read() receives query argument can run queries OGR datasets; #834, Barry Rowlingson Michael Sumner read_sf() longer first creates tibbles data.frames, creates directly; #853, db propagation Etienne Racine check difference compile-time run-time GEOS versions; #844 GEOS routines () robust memory leaks, using unique pointers; #822, #845, Dan Baston st_buffer() receives buffer styles endCapStyle, joinStyle mitreLimit; #833, #842 Michael Sumner","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-06-4","dir":"Changelog","previous_headings":"","what":"version 0.6-4","title":"version 0.6-4","text":"st_area() generic; https://github.com/r-spatial/stars/issues/32 st_write() resolves ~ correctly; #456 read write feature IDs sfc list column names; #812 st_centroid() works empty geometries, returning empty point #769 add st_nearest_points(), obtain (LINESTRING connecting ) two nearest points pairs geometries; #788 add hexagonal tiling st_make_grid() add regular hexagonal sampling st_sample() fixes PROJ 5.0.1; #545 fixes GDAL 2.3.0; #759 st_sample() supports regular sampling LINESTRING; #725 @statnmap Support reading writing database Pool objects; #756 fix plotting sf objects without attributes; #755 add reference R Journal article CITATION","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-06-3","dir":"Changelog","previous_headings":"","what":"version 0.6-3","title":"version 0.6-3","text":"CRAN release: 2018-05-17 move dependency RPostgreSQL Imports: back Suggests: st_centroid.sf() st_point_on_surface.sf also warn attributes constant geometries. summarise() allows user define geometries summaries; #714, Kirill Mueller plot.sf() emits warning col length 1 nrow(x), requires pal (rather col) set palette factors. plot.sf() provides control legend keys using key.length key.width, decrease default key length; #731 sgbp objects receive .data.frame method; #715","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-06-2","dir":"Changelog","previous_headings":"","what":"version 0.6-2","title":"version 0.6-2","text":"CRAN release: 2018-04-25 GDAL read/write supports logical variables; #722 add st_crop() simplify cropping objects rectangular area; #720 fix bug [<- columns added sf object; #718 use dynamic registration S3 methods, similar hms ; #710 Kirill Mueller (partially) address writing GPKG network drive, writing temp file first; #628 add Kirill Mueller contributor st_make_grid() faster; #708, Dan Baston st_read() st_write() generic, methods directly reading writing database connections; st_read_db st_write_db deprecated; #558, thanks Etienne Racine @etiennebr Package RPostgreSQL moved Suggests Imports restore compatibility GDAL 2.0.x versions (won’t gdal_utils); #686 read_sf() can also read tables without geometry; #684, Andy Teucher","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-06-1","dir":"Changelog","previous_headings":"","what":"version 0.6-1","title":"version 0.6-1","text":"CRAN release: 2018-03-22 method distinct() works; #669, #672 +, -, * / pairs geometries (sfg, sfc) return geometric union, difference, intersection symmetric difference, respectively. st_cast() MULTIPOLYGON MULTILINESTRING work properly; #660 Rcpp interfaces needed package stars moved sf; pkg stars R-, sf needs linking GDAL. gdal_utils() interfaces 9 gdal utils using C++ API improve resetting (base) plots; add reset = FALSE call plot enable adding plots legend st_read() returns data.frame table contains geometries, rather giving error; emit warning case. See https://stat.ethz.ch/pipermail/r-sig-geo/2018-February/026344.html move pillar Imports: Suggests: update new rwinlib distribution gdal (adds JPG2000); #639 speed computation centroids largest polygon; #623 add st_as_sfc.raw method Bugfix: binary operations (st_intersection, st_difference, etc) longer fail operating data frames class \"tbl_df\" common column names; #644","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-06-0","dir":"Changelog","previous_headings":"","what":"version 0.6-0","title":"version 0.6-0","text":"CRAN release: 2018-01-06 add pillar Imports: provide method printing WKT geometries tibbles st_as_text, subsequently format print, use argument digits (options(digits = n)) control number digits used printing coordinates; default options(\"digits\"), typically 7. st_is_within_distance works geographic coordinates st_cast MULTIPOLYGON MULTILINESTRING longer changes number features/feature geometries, conversion MULTIPOLYGON LINESTRING (typically) ; #596 st_distance long/lat geographic coordinates uses lwgeom, accepting geometry types; argument dist_fun deprecated consequence, distance calculations different sf versions 0.5-5 earlier; #593 add package lwgeom Suggests; st_area, st_length, st_distance, st_segmentize long/lat CRS use package lwgeom instead geosphere; #593 st_length returns zero polygon-type geometries; #593 present, add units attribute default plot title; #591 add unnest method, depends tidyr > 0.7-2; #570 PR @karldw add largest option st_join get largest intersection match ; #547, @tiernanmartin change default maximum number feature print 10, controllable options(sf_max_print); #556 add Hausdorff (Frechet GEOS 3.7.0) options st_distance; add par densified versions add st_snap, snapping geometries geometries, within tolerance make st_wrap_dateline generic, methods sf, sfc sfg; #541 plot.sf st_as_grob (used ggplot2) robust misspecified ring directions (holes direction exterior rings), using rule = \"evenodd\"; #540 functions depending liblwgeom (st_make_valid, st_geohash, st_plit) moved package, https://github.com/r-spatial/lwgeom; argument use_gdal st_transform deprecated, instead one can use lwgeom::st_transform_proj; sf longer tries link liblwgeom; #509, #537, #487 st_read, st_sf st_sfc gain parameter check_ring_dir (default: FALSE) checks ring directions corrects : exterior counter clockwise, holes clockwise, seen . get rid classInt::classIntervals warning number unique values smaller number breaks asked ","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-05-5","dir":"Changelog","previous_headings":"","what":"version 0.5-5","title":"version 0.5-5","text":"CRAN release: 2017-10-31 classInt Imports:, break package checks add vignettes 5: plotting sf objects 6: miscellaneous; #324 add (default) color key plot.sf single map plotted, contributed @hughjonesd; #528 st_as_sfc can read EWKT; #530 argument max.plot takes default options(sf_max.plot=n), present; #516 plot.sf gets arguments pal specify color palette function; #526 plot.sf gets arguments breaks nbreaks; add support classInt::classIntervals styles finding class intervals (using breaks) add st_as_sf methods ppp, lpp psp objects spatstat. allow direct route proj.4 ignoring GDAL (requiring liblwgeom); #509, #511 add print method crs objects; #517 sf_extSoftVersion reveals whether GDAL linked GEOS; #510 better check input st_polygon; #514 add st_node, similar rgeos::gNode support reading OFTInteger64List fields; #508 sparse geometric binary predicate lists class, sgbp, attributes region.id predicate; #234, #524 prevent st_split stopping R session; #492 st_intersection, st_union also print message used directly long/lat coordinates; #496 add rep method sfc objects comparing two crs objects uses GDAL function IsSame; #180 add st_collection_extract, , given object geometries type GEOMETRY GEOMETRYCOLLECTION, returns object consisting elements specified type; Andy Teucher, #482 st_write exports GeoJSON UTF-8 encoding Windows; #444 move package methods Imports: Depends: ; #478 deal better precision setting propagation; #476 fix bug st_layers case layers geometry; #334 clarify argument envelope st_voronoi; #474 change aggregate make return geometry ‘’, padding attributes NA needed; #453","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-05-4","dir":"Changelog","previous_headings":"","what":"version 0.5-4","title":"version 0.5-4","text":"CRAN release: 2017-08-28 fix compatibility problems introduced tidyr 0.7-0 using rlang magic convert path names UTF-8 st_read, st_write st_layers; #471 st_sfc converts NULL values empty geometries, correctly identifies empty POINTs; #466, #463 st_write abbreviates column names driver ESRI Shapefile; #464 add of_largest_polygon argument st_centroid, get centroid largest polygon; #450 fix use st_relate join predicate st_join; #454 fix bug st_intersects empty second argument crash; #458 produce better WKT; #463 fix bug st_cast.sf; #461, #462 change st_read SRS assignment logic; corrects reading projected geojson gdal 2.2.0; #449 st_intersection etc. tbl also return tbl; #448 [.sf preserves class, e.g. tbl; #448","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-05-3","dir":"Changelog","previous_headings":"","what":"version 0.5-3","title":"version 0.5-3","text":"CRAN release: 2017-07-30 support propagate Proj.4 +units=xx length units; #446 allow arith ops empty sfc objects st_graticule return empty graticule object argument datum NA; export as_Spatial, make easier packages convert sfc objects without importing sf st_distance gains parameter by_element obtain pairwise distances; #437 add ability aggregate using simple feature argument; #429 make op argument [.sf work speed st_coordinates POINT geometries; #433 fix performance regression st_bbox; #418 correct bug st_union, st_difference st_sym_difference introduced 0.5-2; #431 inform gdal CRS always proj4string, never epsg; see #424 properly deal kilometre units; #424 (fixed Karl Dunkle Werner) add st_is_within_distance, return sparse index matrix; #419 st_graticule work world2 (0,360); #421, #422, fixed Ben Best st_graticule return graticules native crs; https://github.com/tidyverse/ggplot2/issues/2200 (WIP) st_graticule support data NA_crs_; https://github.com/tidyverse/ggplot2/issues/2199 fix bug joining sf-tibble tibble; #414 read gdal StringList, RealList, IntegerList fields list-column; #416","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-05-2","dir":"Changelog","previous_headings":"","what":"version 0.5-2","title":"version 0.5-2","text":"CRAN release: 2017-07-12 made ready rwinlib/gdal2; #408 make [.sf selections including NA values like x[c(1,NA,2)]; #403 add [<- method sfc objects; automatically replaces NULL empty geometry; #411 add st_point_on_surface() return point guaranteed surface (standard compliance) read_sf returns sf-tibble, object class c(\"sf\", \"tbl_df\", \"tbl\", \"data.frame\") work around dplyr::filter dispatching geometry column subsetting sf::[.sfc allow units object dist argument st_buffer; must convertable arc_degree geographic, length unit non-geographic data; #399 prevent gdal crashing trying st_transform empty geometry; #398 add st_as_sfc method bbox, returning bbox polygon; #377 strip file name extension default layer name st_write; #392 st_sf replace NULL values sfc list-column appropriate empty geometry; #372 allow setting ndiscr ggplot2::coords_sf improve graticule plotting geom_sf; #396","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-05-1","dir":"Changelog","previous_headings":"","what":"version 0.5-1","title":"version 0.5-1","text":"CRAN release: 2017-06-23 add spatial indexes binary geometry operations; #394 http://r-spatial.org/r/2017/06/22/spatial-index.html drastically reduce memory footprint st_intersection similar; #394 support RSQLite 2.0 providing st_as_sfc method list columns class blob drop dependency dbplyr","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-05-0","dir":"Changelog","previous_headings":"","what":"version 0.5-0","title":"version 0.5-0","text":"CRAN release: 2017-06-15 better handle empty/NULL geometries shapefiles; #351 add unite_.sf method deprecate FUN argument st_join; #376 improve graticule tic label placement ggplot2; #375 https://github.com/tidyverse/ggplot2/issues/2119 improve configure logic deal libraries installed custom locations; #335 fix bug geom_sf wouldn’t deal Z /M geoms; #373 return conveniently typed empty geoms; #372 fix subsetting [ sf using drop = TRUE, #370 addition m, allow rad units st_segmentize add example st_read GeoJSON string; #185 add separate_.sf method add st_split split geometries (available compiled liblwgeom), #359 fix bug reading writing dates (months 1 ): #358 [.sf [.sfc also select sfg object, accept geometric predicate function optional arguments; #352 reading GDAL, empty (NULL) geometries longer result error; creation, longer automatically give GEOMETRY object; #351 plotting ggplot2::geom_sf, empty geometries longer break; grid functions return nullGrob() ; #351 arith operations empty geometries longer break give warnings; #351 st_as_sf.data.frame default break NA values coordinates; #342 st_join accept arguments, passed join function (e.g. pattern st_relate) WKB reader throw error () malformed inputs, check buffer bounds","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-04-3","dir":"Changelog","previous_headings":"","what":"version 0.4-3","title":"version 0.4-3","text":"CRAN release: 2017-05-15 back-port do_union argument dplyr <= 0.5.0, using lazyeval strings returned OGR/GDAL get encoding set UTF-8, making work non-UTF-8 platforms; #5 $.crs retrieves proj4string components, st_crs(4326)$datum addition epsg proj4string let st_geohash return geohash (average) points (sf linked liblwgeom)","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-04-2","dir":"Changelog","previous_headings":"","what":"version 0.4-2","title":"version 0.4-2","text":"CRAN release: 2017-05-05 summarise.sf always returns sf object, also global (non-grouped) summaries. summarise.sf gains argument do_union determines whether union geometries summary given, st_combine (resolving boundaries); #331 rename argument union aggregate.sf do_union, consistency summarise; #331 add nest_ method sf objects st_relate gets pattern parameter, rgeos::gRelate; add examples get rook queen neighbour lists using ; #234 support direct reading spatialite sqlite geometry wkb blobs build proper support cbind rbind methods sf, work (documented) arguments class sf; dplyr::bind_cols st_sf(data.frame(sf, df)) work binding data.frames sf object. st_segmentize() st_line_sample() accept units arguments document problem reading shapefiles USB drives OSX; #252 improve docs st_is_valid st_make_valid; #296 coercing sf data.frame works better; #298 st_line_sample gains argument sample specify points t.b. sampled; #299 #300 thanks @joethorley add compatibility upcoming dplyr 0.6.0; #304 #42 write GDAL fields name, number, fixing KML problem #308 st_write gains arguments delete_layer delete_dsn allow overwrite capability #307 #274 write_sf defaults delete_layer=TRUE, silently overwriting layers ’re already present compatibility GDAL 2.2beta0; #303; #309 replace st_write_db version fast large datasets (#285), thanks Josh London take memory leaking examples tests aggregate method sf objects assumes argument identical stats::aggregate st_wrap_dateline wraps (cuts ) geometries crossing antimeridian, longer cross .","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-04-1","dir":"Changelog","previous_headings":"","what":"version 0.4-1","title":"version 0.4-1","text":"CRAN release: 2017-03-28 restore 3.3.0 c++11 requirement st_read respects time read UTC st_write writes time always UTC, since GDAL mechanism define local timezones “unknown” “local” st_length works POINT MULTIPOINT (returning 0); POLYGON MULTIPOLYGON converted MULTILINESTRING computing length, thus giving polygon perimeter (#268) st_write update depend driver; databases, default TRUE, otherwise FALSE (refers update database, overwriting table database, default succeed); #274 st_read supports reading objects multiple geometry columns #257 #255 support writing (exporting) objects non-standard columns, units POSIXlt #264 catch dependencies GEOS 3.3.5 (hence 0.4-0 CRAN binary MacOSX) #260","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-04-0","dir":"Changelog","previous_headings":"","what":"version 0.4-0","title":"version 0.4-0","text":"CRAN release: 2017-03-21 st_is_valid catch corrupt geometries , returning NA case (requiring GEOS 3.5.0) add st_make_valid, available sf linked liblwgeom add st_coordinates method, returning coordinates matrix indexes remove unlist.sfg add .matrix.sfg; .matrix.sfg add indexes coordinates add st_bind_cols method improve handling features can’t projected support uniform sampling polygons sphere add st_sample, sampling points multipoints, linestrings, polygons add c method sfc objects import export magrittr::%>% support ggplot’ing geometrycollections drop C++11 requirement, allowing build older R versions add st_proj_info, modelled rgdal::projInfo overwriting datasets st_write() longer allowed; update=TRUE appends , permitted driver supports appending. st_write gains argument, update, TRUE try append existing datasets (#204) added list corresponding function migration sp, rgdal rgeos sf https://github.com/edzer/sfr/wiki/migrating remove deprecated st_list rename st_makegrid st_make_grid, st_linemerge st_line_merge add NEWS.md file (#207) faster conversion data.frame POINT sf object, using st_as_sf (Michael Sumner) rbind method sf objects keeps coordinate reference system","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-03-4-feb-6-2017","dir":"Changelog","previous_headings":"","what":"version 0.3-4, Feb 6, 2017","title":"version 0.3-4, Feb 6, 2017","text":"CRAN release: 2017-02-06 add st_contains_properly spatial predicate GEOS functions (geometry operations) accept XYZ geometries (ignore Z) make prepared = TRUE default geometry binary operations","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-03-2-feb-4-2017","dir":"Changelog","previous_headings":"","what":"version 0.3-2, Feb 4, 2017","title":"version 0.3-2, Feb 4, 2017","text":"CRAN release: 2017-02-04 add user interrupt checks GEOS geometry operations make st_graticule something useful polar projections make st_graticule return NA labels labels useless add merge.sf methods merge sf object data.frame (#193) add st_join table joins based (user-defined) spatial predicates add dplyr-style non-spatial joins sf objects (left_join, full_join etc.) (#193) allow multiple non-gathered variables (#196) add missing meridian st_graticule (#198)","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-03-1-jan-31-2017","dir":"Changelog","previous_headings":"","what":"version 0.3-1, Jan 31, 2017","title":"version 0.3-1, Jan 31, 2017","text":"CRAN release: 2017-01-31 add merge method (#193) st_graticule laea (#198) allow st_buffer feature-dependent buffer distance (#197) spread return sf object (#196) clarify overwrite = TRUE write docs fix st_as_sf.map (#194) add prepared arg spatial binary predicates, speed large intersections add st_voronoi interface (requires lib GEOS >= 3.5.0) add st_as_sf methods map objects (library maps) add RStudio project file st_bbox return bbox object st_crs method rename st_drop_zm st_zm, general handling Z M allow 3D coordinates returned, +proj=geocent (#172; #103) fix NA_integer_ handling shapefiles /O (#184) add fix st_agr API, set get attribute--geometry relationships","code":""},{"path":"https://r-spatial.github.io/sf/news/index.html","id":"version-02-8-jan-5-2017","dir":"Changelog","previous_headings":"","what":"version 0.2-8, Jan 5, 2017","title":"version 0.2-8, Jan 5, 2017","text":"CRAN release: 2017-01-05","code":""}]