@@ -56,32 +56,34 @@ s2_contains(
56
56
# > [1] TRUE
57
57
```
58
58
59
- The [ sf package] ( https://r-spatial.github.io/sf/ ) will soon support s2
60
- natively, but s2 can also read well-known text and well-known binary:
59
+ The [ sf package] ( https://r-spatial.github.io/sf/ ) uses s2 for geographic
60
+ coordinates with ` sf::sf_use_s2(TRUE) ` , and will become the default
61
+ after sf version 1.0.0. The sf package also supports creating s2 vectors
62
+ using ` as_s2_geography() ` :
61
63
62
64
``` r
63
65
library(dplyr )
64
66
library(sf )
65
67
66
68
nc_s2 <- read_sf(system.file(" shape/nc.shp" , package = " sf" )) %> %
67
- mutate(geometry = s2_geog_from_wkb(st_as_binary( geometry ) )) %> %
69
+ mutate(geometry = as_s2_geography( geometry )) %> %
68
70
as_tibble() %> %
69
71
select(NAME , geometry )
70
72
71
73
nc_s2
72
74
# > # A tibble: 100 x 2
73
75
# > NAME geometry
74
76
# > <chr> <s2_geography>
75
- # > 1 Ashe <POLYGON ((-81.4529 36.2396 , -81.431 36.2607 , -81.4123 36.2673, …
76
- # > 2 Alleghany <POLYGON ((-81.1767 36.4154 , -81.1534 36.4247 , -81.1384 36.4176, …
77
- # > 3 Surry <POLYGON ((-80.453 36.2571 , -80.4353 36.551 , -80.6111 36.5573, - …
78
- # > 4 Currituck <MULTIPOLYGON (((-75.9419 36.2943 , -75.9575 36.2595, -75.9138 36 …
79
- # > 5 Northampton <POLYGON ((-77.142 36.4171 , -77.1393 36.4565 , -77.1273 36.4707, …
80
- # > 6 Hertford <POLYGON ((-76.7075 36.2661 , -76.7413 36.3152 , -76.9241 36.3924, …
81
- # > 7 Camden <POLYGON ((-76.0173 36.3377 , -76.0329 36.336 , -76.044 36.3536, - …
82
- # > 8 Gates <POLYGON ((-76.4604 36.3739 , -76.5025 36.4523 , -76.4983 36.5039, …
83
- # > 9 Warren <POLYGON ((-78.1347 36.2366 , -78.1096 36.2135 , -78.0583 36.2113, …
84
- # > 10 Stokes <POLYGON ((-80.0241 36.545 , -80.0481 36.5471 , -80.4353 36.551, - …
77
+ # > 1 Ashe <POLYGON ((-81.4528885 36.2395859 , -81.4310379 36.2607193 , -81.4 …
78
+ # > 2 Alleghany <POLYGON ((-81.1766739 36.4154434 , -81.1533661 36.4247398 , -81.1 …
79
+ # > 3 Surry <POLYGON ((-80.4530106 36.2570877 , -80.4353104 36.5510445 , -80.6 …
80
+ # > 4 Currituck <MULTIPOLYGON (((-75.9419327 36.2943382 , -75.9575119 36.2594528, …
81
+ # > 5 Northampton <POLYGON ((-77.1419601 36.4170647 , -77.1393204 36.4564781 , -77.1 …
82
+ # > 6 Hertford <POLYGON ((-76.7074966 36.2661324 , -76.7413483 36.3151665 , -76.9 …
83
+ # > 7 Camden <POLYGON ((-76.0173492 36.3377304 , -76.0328751 36.3359756 , -76.0 …
84
+ # > 8 Gates <POLYGON ((-76.46035 36.3738976 , -76.5024643 36.4522858 , -76.498 …
85
+ # > 9 Warren <POLYGON ((-78.1347198 36.2365837 , -78.1096268 36.2135086 , -78.0 …
86
+ # > 10 Stokes <POLYGON ((-80.0240555 36.5450249 , -80.0480957 36.5471344 , -80.4 …
85
87
# > # … with 90 more rows
86
88
```
87
89
@@ -96,16 +98,16 @@ nc_s2 %>%
96
98
# > # A tibble: 100 x 4
97
99
# > NAME geometry area perimeter
98
100
# > <chr> <s2_geography> <dbl> <dbl>
99
- # > 1 Ashe <POLYGON ((-81.4529 36.2396 , -81.431 36.2607, - … 1.14e9 141627.
100
- # > 2 Alleghany <POLYGON ((-81.1767 36.4154 , -81.1534 36.4247, … 6.11e8 119876.
101
- # > 3 Surry <POLYGON ((-80.453 36.2571 , -80.4353 36.551, -8 … 1.42e9 160458.
102
- # > 4 Currituck <MULTIPOLYGON (((-75.9419 36.2943 , -75.9575 36. … 6.94e8 301644.
103
- # > 5 Northamp… <POLYGON ((-77.142 36.4171 , -77.1393 36.4565, - … 1.52e9 211794.
104
- # > 6 Hertford <POLYGON ((-76.7075 36.2661 , -76.7413 36.3152, … 9.68e8 160780.
105
- # > 7 Camden <POLYGON ((-76.0173 36.3377 , -76.0329 36.336, - … 6.16e8 150430.
106
- # > 8 Gates <POLYGON ((-76.4604 36.3739 , -76.5025 36.4523, … 9.03e8 123170.
107
- # > 9 Warren <POLYGON ((-78.1347 36.2366 , -78.1096 36.2135, … 1.18e9 141073.
108
- # > 10 Stokes <POLYGON ((-80.0241 36.545 , -80.0481 36.5471, - … 1.23e9 140583.
101
+ # > 1 Ashe <POLYGON ((-81.4528885 36.2395859 , -81.4310379 … 1.14e9 141627.
102
+ # > 2 Alleghany <POLYGON ((-81.1766739 36.4154434 , -81.1533661 … 6.11e8 119876.
103
+ # > 3 Surry <POLYGON ((-80.4530106 36.2570877 , -80.4353104 … 1.42e9 160458.
104
+ # > 4 Currituck <MULTIPOLYGON (((-75.9419327 36.2943382 , -75.95 … 6.94e8 301644.
105
+ # > 5 Northamp… <POLYGON ((-77.1419601 36.4170647 , -77.1393204 … 1.52e9 211794.
106
+ # > 6 Hertford <POLYGON ((-76.7074966 36.2661324 , -76.7413483 … 9.68e8 160780.
107
+ # > 7 Camden <POLYGON ((-76.0173492 36.3377304 , -76.0328751 … 6.16e8 150430.
108
+ # > 8 Gates <POLYGON ((-76.46035 36.3738976 , -76.5024643 36… 9.03e8 123170.
109
+ # > 9 Warren <POLYGON ((-78.1347198 36.2365837 , -78.1096268 … 1.18e9 141073.
110
+ # > 10 Stokes <POLYGON ((-80.0240555 36.5450249 , -80.0480957 … 1.23e9 140583.
109
111
# > # … with 90 more rows
110
112
```
111
113
@@ -117,7 +119,7 @@ nc_s2 %>%
117
119
# > # A tibble: 1 x 2
118
120
# > NAME geometry
119
121
# > <chr> <s2_geography>
120
- # > 1 Catawba <POLYGON ((-80.9313 35.6196 , -81.0036 35.6971 , -81.0548 35.7134, -81. …
122
+ # > 1 Catawba <POLYGON ((-80.9312744 35.6195908 , -81.0035782 35.6970558 , -81.054779 …
121
123
```
122
124
123
125
Use transformers to create new geometries:
@@ -128,16 +130,16 @@ nc_s2 %>%
128
130
# > # A tibble: 100 x 2
129
131
# > NAME geometry
130
132
# > <chr> <s2_geography>
131
- # > 1 Ashe <LINESTRING (-81.4529 36.2396 , -81.431 36.2607 , -81.4123 36.2673 …
132
- # > 2 Alleghany <LINESTRING (-81.1767 36.4154 , -81.1534 36.4247 , -81.1384 36.417 …
133
- # > 3 Surry <LINESTRING (-80.453 36.2571 , -80.4353 36.551 , -80.6111 36.5573, …
134
- # > 4 Currituck <MULTILINESTRING ((-75.9419 36.2943 , -75.9575 36.2595, -75.9138 …
135
- # > 5 Northampton <LINESTRING (-77.142 36.4171 , -77.1393 36.4565 , -77.1273 36.4707 …
136
- # > 6 Hertford <LINESTRING (-76.7075 36.2661 , -76.7413 36.3152 , -76.9241 36.392 …
137
- # > 7 Camden <LINESTRING (-76.0173 36.3377 , -76.0329 36.336 , -76.044 36.3536, …
138
- # > 8 Gates <LINESTRING (-76.4604 36.3739 , -76.5025 36.4523 , -76.4983 36.503 …
139
- # > 9 Warren <LINESTRING (-78.1347 36.2366 , -78.1096 36.2135 , -78.0583 36.211 …
140
- # > 10 Stokes <LINESTRING (-80.0241 36.545 , -80.0481 36.5471 , -80.4353 36.551, …
133
+ # > 1 Ashe <LINESTRING (-81.4528885 36.2395859 , -81.4310379 36.2607193 , -81…
134
+ # > 2 Alleghany <LINESTRING (-81.1766739 36.4154434 , -81.1533661 36.4247398 , -81…
135
+ # > 3 Surry <LINESTRING (-80.4530106 36.2570877 , -80.4353104 36.5510445 , -80…
136
+ # > 4 Currituck <MULTILINESTRING ((-75.9419327 36.2943382 , -75.9575119 36.259452 …
137
+ # > 5 Northampton <LINESTRING (-77.1419601 36.4170647 , -77.1393204 36.4564781 , -77…
138
+ # > 6 Hertford <LINESTRING (-76.7074966 36.2661324 , -76.7413483 36.3151665 , -76…
139
+ # > 7 Camden <LINESTRING (-76.0173492 36.3377304 , -76.0328751 36.3359756 , -76…
140
+ # > 8 Gates <LINESTRING (-76.46035 36.3738976 , -76.5024643 36.4522858 , -76.4 …
141
+ # > 9 Warren <LINESTRING (-78.1347198 36.2365837 , -78.1096268 36.2135086 , -78…
142
+ # > 10 Stokes <LINESTRING (-80.0240555 36.5450249 , -80.0480957 36.5471344 , -80…
141
143
# > # … with 90 more rows
142
144
```
143
145
@@ -175,5 +177,4 @@ This project gratefully acknowledges financial
175
177
[ support] ( https://www.r-consortium.org/projects ) from the
176
178
177
179
<a href =" https://www.r-consortium.org/projects/awarded-projects " >
178
- <img src =" http://pebesma.staff.ifgi.de/RConsortium_Horizontal_Pantone.png " width =" 300 " >
179
- </a >
180
+ <img src =" man/figures/rc300.png " width =" 300 " /> </a >
0 commit comments