8 Reading, Exploring, and Visualising Spatial Data with sf (Cont. Chapter 6)
8.1 Package
8.2 Data
columbus <- st_read(system.file("shapes/columbus.gpkg", package="spData")[1], quiet=TRUE)
columbusSimple feature collection with 49 features and 20 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 5.874907 ymin: 10.78863 xmax: 11.28742 ymax: 14.74245
Projected CRS: Undefined Cartesian SRS with unknown unit
First 10 features:
AREA PERIMETER COLUMBUS_ COLUMBUS_I POLYID NEIG HOVAL INC CRIME
1 0.309441 2.440629 2 5 1 5 80.467 19.531 15.725980
2 0.259329 2.236939 3 1 2 1 44.567 21.232 18.801754
3 0.192468 2.187547 4 6 3 6 26.350 15.956 30.626781
4 0.083841 1.427635 5 2 4 2 33.200 4.477 32.387760
5 0.488888 2.997133 6 7 5 7 23.225 11.252 50.731510
6 0.283079 2.335634 7 8 6 8 28.750 16.029 26.066658
7 0.257084 2.554577 8 4 7 4 75.000 8.438 0.178269
8 0.204954 2.139524 9 3 8 3 37.125 11.337 38.425858
9 0.500755 3.169707 10 18 9 18 52.600 17.586 30.515917
10 0.246689 2.087235 11 10 10 10 96.400 13.598 34.000835
OPEN PLUMB DISCBD X Y NSA NSB EW CP THOUS NEIGNO
1 2.850747 0.217155 5.03 38.80 44.07 1 1 1 0 1000 1005
2 5.296720 0.320581 4.27 35.62 42.38 1 1 0 0 1000 1001
3 4.534649 0.374404 3.89 39.82 41.18 1 1 1 0 1000 1006
4 0.394427 1.186944 3.70 36.50 40.52 1 1 0 0 1000 1002
5 0.405664 0.624596 2.83 40.01 38.00 1 1 1 0 1000 1007
6 0.563075 0.254130 3.78 43.75 39.28 1 1 1 0 1000 1008
7 0.000000 2.402402 2.74 33.36 38.41 1 1 0 0 1000 1004
8 3.483478 2.739726 2.89 36.71 38.71 1 1 0 0 1000 1003
9 0.527488 0.890736 3.17 43.44 35.92 1 1 1 0 1000 1018
10 1.548348 0.557724 4.33 47.61 36.42 1 1 1 0 1000 1010
geom
1 POLYGON ((8.624129 14.23698...
2 POLYGON ((8.25279 14.23694,...
3 POLYGON ((8.653305 14.00809...
4 POLYGON ((8.459499 13.82035...
5 POLYGON ((8.685274 13.63952...
6 POLYGON ((9.401384 13.5504,...
7 POLYGON ((8.037741 13.60752...
8 POLYGON ((8.247527 13.58651...
9 POLYGON ((9.333297 13.27242...
10 POLYGON ((10.08251 13.03377...
8.3 Explore data structure
st_crs(columbus)Coordinate Reference System:
User input: Undefined Cartesian SRS with unknown unit
wkt:
ENGCRS["Undefined Cartesian SRS with unknown unit",
EDATUM["Unknown engineering datum"],
CS[Cartesian,2],
AXIS["x",unspecified,
ORDER[1],
LENGTHUNIT["unknown",0]],
AXIS["y",unspecified,
ORDER[2],
LENGTHUNIT["unknown",0]]]
sf::st_geometry(columbus)Geometry set for 49 features
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 5.874907 ymin: 10.78863 xmax: 11.28742 ymax: 14.74245
Projected CRS: Undefined Cartesian SRS with unknown unit
First 5 geometries:
8.4 Visualise data
st_geometry() is an sf function that extracts only the geometry from an sf object.
st_geometry(columbus)Geometry set for 49 features
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 5.874907 ymin: 10.78863 xmax: 11.28742 ymax: 14.74245
Projected CRS: Undefined Cartesian SRS with unknown unit
First 5 geometries:
plot(st_geometry(columbus))
Your turn: Use ggplot2 to draw the plot