sf
packagesf
objects in Rmapview
and sf
to preview spatial datasf
<etherpad.andyteucher.ca/p/r-telemetry-pg>
sf
R package12
sf
objectSimple feature collection with 455 features and 5 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 406543.7 ymin: 367957.6 xmax: 1796645 ymax: 1689146
Projected CRS: NAD83 / BC Albers
# A tibble: 455 × 6
AIRPORT_NAME IATA_CODE LOCALITY ELEVATION NUMBER_OF_RUNWAYS
<chr> <chr> <chr> <dbl> <int>
1 Terrace (Northwest Regional) … <NA> Terrace 217. 2
2 Victoria Harbour (Camel Point… <NA> Victoria 4.57 0
3 Victoria Inner Harbour Airpor… YWH Victoria 0 0
4 Victoria Harbour (Shoal Point… <NA> Victoria 3.05 0
5 Victoria (Royal Jubilee Hospi… <NA> Saanich 15.6 0
6 Victoria (General Hospital) H… <NA> View Ro… 15.8 0
7 Victoria (BC Hydro) Heliport <NA> Saanich 12.2 0
8 San Juan Point (Coast Guard) … <NA> Port Re… 7.62 0
9 Shawnigan Lake Water Aerodrome <NA> Shawnig… 0 0
10 Victoria International Airport YYJ North S… 19.5 3
# ℹ 445 more rows
# ℹ 1 more variable: geom <POINT [m]>
sf
objectPOINT (833323.9 1054950)
POINT (1193727 381604.1)
POINT (1194902 382257.7)
POINT (1193719 382179.3)
POINT (1198292 383563.6)
Coordinate Reference System:
User input: NAD83 / BC Albers
wkt:
PROJCRS["NAD83 / BC Albers",
BASEGEOGCRS["NAD83",
DATUM["North American Datum 1983",
ELLIPSOID["GRS 1980",6378137,298.257222101,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4269]],
CONVERSION["British Columbia Albers",
METHOD["Albers Equal Area",
ID["EPSG",9822]],
PARAMETER["Latitude of false origin",45,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8821]],
PARAMETER["Longitude of false origin",-126,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8822]],
PARAMETER["Latitude of 1st standard parallel",50,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8823]],
PARAMETER["Latitude of 2nd standard parallel",58.5,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8824]],
PARAMETER["Easting at false origin",1000000,
LENGTHUNIT["metre",1],
ID["EPSG",8826]],
PARAMETER["Northing at false origin",0,
LENGTHUNIT["metre",1],
ID["EPSG",8827]]],
CS[Cartesian,2],
AXIS["(E)",east,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["(N)",north,
ORDER[2],
LENGTHUNIT["metre",1]],
USAGE[
SCOPE["Province-wide spatial data management."],
AREA["Canada - British Columbia."],
BBOX[48.25,-139.04,60.01,-114.08]],
ID["EPSG",3005]]
sf
object is a data.frame
[1] "sf" "tbl_df" "tbl" "data.frame"
[1] TRUE
AIRPORT_NAME IATA_CODE LOCALITY ELEVATION
Length:455 Length:455 Length:455 Min. : 0.0
Class :character Class :character Class :character 1st Qu.: 0.0
Mode :character Mode :character Mode :character Median : 6.4
Mean : 194.4
3rd Qu.: 307.1
Max. :1277.4
NUMBER_OF_RUNWAYS geom
Min. :0.0000 POINT :455
1st Qu.:0.0000 epsg:3005 : 0
Median :0.0000 +proj=aea ...: 0
Mean :0.3385
3rd Qu.:1.0000
Max. :3.0000
https://epsg.io/3005
Coordinate Reference System:
User input: EPSG:3005
wkt:
PROJCRS["NAD83 / BC Albers",
BASEGEOGCRS["NAD83",
DATUM["North American Datum 1983",
ELLIPSOID["GRS 1980",6378137,298.257222101,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4269]],
CONVERSION["British Columbia Albers",
METHOD["Albers Equal Area",
ID["EPSG",9822]],
PARAMETER["Latitude of false origin",45,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8821]],
PARAMETER["Longitude of false origin",-126,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8822]],
PARAMETER["Latitude of 1st standard parallel",50,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8823]],
PARAMETER["Latitude of 2nd standard parallel",58.5,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8824]],
PARAMETER["Easting at false origin",1000000,
LENGTHUNIT["metre",1],
ID["EPSG",8826]],
PARAMETER["Northing at false origin",0,
LENGTHUNIT["metre",1],
ID["EPSG",8827]]],
CS[Cartesian,2],
AXIS["(E)",east,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["(N)",north,
ORDER[2],
LENGTHUNIT["metre",1]],
USAGE[
SCOPE["Province-wide spatial data management."],
AREA["Canada - British Columbia."],
BBOX[48.25,-139.04,60.01,-114.08]],
ID["EPSG",3005]]
raw_data
folder:elec_bc <- read_sf("raw_data/bc_electoral_districts.shp")
st_geometry_type(elec_bc, by_geometry = FALSE)
Coordinate Reference System:
User input: WGS 84
wkt:
GEOGCRS["WGS 84",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84",6378137,298.257223563,
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",4326]]
Or, if you have another object in the CRS you want to use:
Coordinate Reference System:
User input: NAD83 / BC Albers
wkt:
PROJCRS["NAD83 / BC Albers",
BASEGEOGCRS["NAD83",
DATUM["North American Datum 1983",
ELLIPSOID["GRS 1980",6378137,298.257222101,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4269]],
CONVERSION["British Columbia Albers",
METHOD["Albers Equal Area",
ID["EPSG",9822]],
PARAMETER["Latitude of false origin",45,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8821]],
PARAMETER["Longitude of false origin",-126,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8822]],
PARAMETER["Latitude of 1st standard parallel",50,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8823]],
PARAMETER["Latitude of 2nd standard parallel",58.5,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8824]],
PARAMETER["Easting at false origin",1000000,
LENGTHUNIT["metre",1],
ID["EPSG",8826]],
PARAMETER["Northing at false origin",0,
LENGTHUNIT["metre",1],
ID["EPSG",8827]]],
CS[Cartesian,2],
AXIS["(E)",east,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["(N)",north,
ORDER[2],
LENGTHUNIT["metre",1]],
USAGE[
SCOPE["Province-wide spatial data management."],
AREA["Canada - British Columbia."],
BBOX[48.25,-139.04,60.01,-114.08]],
ID["EPSG",3005]]
Load "raw_data/ski_resorts.csv"
as an sf
object
facility_name | locality | latitude | longitude | elevation |
---|---|---|---|---|
Wapiti Ski Club | Elkford | 50.02168 | -114.9380 | 1467 |
Summit Lake Ski Area | Nakusp | 50.14546 | -117.6144 | 1132 |
Sasquatch Mountain Resort | Hemlock Valley | 49.38011 | -121.9354 | 1185 |
Apex Mountain Resort | Apex | 49.39042 | -119.9047 | 1852 |
Salmo Ski Hill | Salmo | 49.18640 | -117.3015 | 864 |
Red Mountain Resort | Rossland | 49.10238 | -117.8194 | 1150 |
Load "raw_data/ski_resorts.csv"
as an sf
object
ski_resorts <- read.csv("raw_data/ski_resorts.csv")
ski_resorts <- st_as_sf(ski_resorts,
coords = c("longitude", "latitude"),
crs = 4326)
head(ski_resorts)
Simple feature collection with 6 features and 3 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -121.9354 ymin: 49.10238 xmax: -114.938 ymax: 50.14546
Geodetic CRS: WGS 84
facility_name locality elevation geometry
1 Wapiti Ski Club Elkford 1467 POINT (-114.938 50.02168)
2 Summit Lake Ski Area Nakusp 1132 POINT (-117.6144 50.14546)
3 Sasquatch Mountain Resort Hemlock Valley 1185 POINT (-121.9354 49.38011)
4 Apex Mountain Resort Apex 1852 POINT (-119.9047 49.39042)
5 Salmo Ski Hill Salmo 864 POINT (-117.3015 49.1864)
6 Red Mountain Resort Rossland 1150 POINT (-117.8194 49.10238)
st_area()
st_length()
st_distance()
st_union()
st_intersection()
st_difference()
st_sym_difference()
Use with st_filter()
or st_join()
st_intersects()
:st_disjoint()
:st_touches()
: touchst_crosses()
:st_within()
: withinst_contains()
:st_overlaps()
:st_covers()
: coverst_covered_by()
:st_equals()
: equalsst_line_merge()
st_segmentize()
st_voronoi()
st_centroid()
st_convex_hull()
st_triangulate()
st_polygonize()
st_split()
st_buffer()
st_make_valid()
st_boundary()