Computing on geometries with sf
Features: “things” or objects that have a spatial location or extent; they may be physical objects like a building, or social conventions like a political state
Feature geometry: the spatial properties (location or extent) of a feature, and can be described by a point, a point set, a polygon, etc.
Feature attributes: other non-spatial properties measured on the feature (e.g. color, name, landtype)
Shapefile
A bundle of files that describe spatial data. Developed by Esri for its ArcView GIS; the format’s specification is public, so most GIS software can read it.
Google: CA shapefile


Reading layer `CA_State' from data source
`/workspace/24-spatial-2/data/CA_State.shp' using driver `ESRI Shapefile'
Simple feature collection with 1 feature and 18 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -13857270 ymin: 3832931 xmax: -12705030 ymax: 5162406
Projected CRS: Popular Visualisation CRS / Mercator
Simple feature collection with 1 feature and 18 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -13857270 ymin: 3832931 xmax: -12705030 ymax: 5162406
Projected CRS: Popular Visualisation CRS / Mercator
OBJECTID REGION DIVISION STATEFP STATENS GEOID STUSPS NAME LSAD MTFCC
1 56 4 9 06 01779778 06 CA California 00 G4000
FUNCSTAT ALAND AWATER INTPTLAT INTPTLON Shape_Leng
1 A 403467168329 20499799756 +37.1551773 -119.5434183 5258041
Shape_Le_1 Shape_Area geometry
1 5258041 671892661618 MULTIPOLYGON (((-13060109 3...

st_: “spatial type”
sfc: “simple feature (geometry) column”
Geometry set for 3 features
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 7.22 ymin: 52.18 xmax: 7.44 ymax: 52.31
Geodetic CRS: WGS 84 (CRS84)
Simple feature collection with 3 features and 2 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 7.22 ymin: 52.18 xmax: 7.44 ymax: 52.31
Geodetic CRS: WGS 84 (CRS84)
elev marker geom
1 33.2 Id01 POINT (7.35 52.31)
2 52.1 Id02 POINT (7.22 52.18)
3 81.2 Id03 POINT (7.44 52.19)

Simple feature collection with 1 feature and 2 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 7.17 ymin: 52.11 xmax: 7.4 ymax: 52.35
Geodetic CRS: WGS 84 (CRS84)
elev marker geom
1 45 Id04 POLYGON ((7.17 52.11, 7.4 5...


Successive base R plot commands draw on top of one another.
Simple feature collection with 3 features and 2 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 7.22 ymin: 52.18 xmax: 7.44 ymax: 52.31
Geodetic CRS: WGS 84 (CRS84)
elev marker geom
1 33.2 Id01 POINT (7.35 52.31)
2 52.1 Id02 POINT (7.22 52.18)
3 81.2 Id03 POINT (7.44 52.19)
Simple feature collection with 3 features and 2 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 7.22 ymin: 52.18 xmax: 7.44 ymax: 52.31
Geodetic CRS: WGS 84 (CRS84)
elev marker geom
1 81.2 Id03 POINT (7.44 52.19)
2 52.1 Id02 POINT (7.22 52.18)
3 33.2 Id01 POINT (7.35 52.31)
Simple feature collection with 1 feature and 1 field
Geometry type: MULTIPOINT
Dimension: XY
Bounding box: xmin: 7.22 ymin: 52.18 xmax: 7.44 ymax: 52.31
Geodetic CRS: WGS 84 (CRS84)
sum(elev) geom
1 166.5 MULTIPOINT ((7.35 52.31), (...

Simple feature collection with 3 features and 3 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 7.22 ymin: 52.18 xmax: 7.44 ymax: 52.31
Geodetic CRS: WGS 84 (CRS84)
elev marker geom dim
1 33.2 Id01 POINT (7.35 52.31) 0
2 52.1 Id02 POINT (7.22 52.18) 0
3 81.2 Id03 POINT (7.44 52.19) 0
Simple feature collection with 1 feature and 3 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 7.17 ymin: 52.11 xmax: 7.4 ymax: 52.35
Geodetic CRS: WGS 84 (CRS84)
elev marker geom area
1 45 Id04 POLYGON ((7.17 52.11, 7.4 5... 418033285 [m^2]
Simple feature collection with 3 features and 2 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 7.218624 ymin: 52.17505 xmax: 7.432613 ymax: 52.33405
Geodetic CRS: WGS 84 (CRS84)
elev marker geom
1 33.2 Id01 POINT (7.359401 52.33405)
2 52.1 Id02 POINT (7.218624 52.17505)
3 81.2 Id03 POINT (7.432613 52.21221)
Simple feature collection with 1 feature and 2 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 7.137086 ymin: 52.0894 xmax: 7.433105 ymax: 52.37073
Geodetic CRS: WGS 84 (CRS84)
elev marker geom
1 45 Id04 POLYGON ((7.429425 52.1882,...
Table joins:

Table joins:
Spatial joins:

Simple feature collection with 3 features and 2 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 7.22 ymin: 52.18 xmax: 7.44 ymax: 52.31
Geodetic CRS: WGS 84 (CRS84)
elev marker geom
1 33.2 Id01 POINT (7.35 52.31)
2 52.1 Id02 POINT (7.22 52.18)
3 81.2 Id03 POINT (7.44 52.19)
Question: How many rows and columns will st_join(my_point_sf, my_square_sf, join = st_within) return? What goes in the square’s columns for Id03?
01:00
Simple feature collection with 3 features and 4 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 7.22 ymin: 52.18 xmax: 7.44 ymax: 52.31
Geodetic CRS: WGS 84 (CRS84)
elev.x marker.x elev.y marker.y geom
1 33.2 Id01 45 Id04 POINT (7.35 52.31)
2 52.1 Id02 45 Id04 POINT (7.22 52.18)
3 81.2 Id03 NA <NA> POINT (7.44 52.19)
Simple feature collection with 2 features and 4 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 7.22 ymin: 52.18 xmax: 7.35 ymax: 52.31
Geodetic CRS: WGS 84 (CRS84)
elev.x marker.x elev.y marker.y geom
1 33.2 Id01 45 Id04 POINT (7.35 52.31)
2 52.1 Id02 45 Id04 POINT (7.22 52.18)
A spatial join is like the pirate islands: the islands are polygons and the ships are points. To learn whose waters each ship sails in, you match them by location, not by a shared key, and a ship out in open water finds no island at all.
