Description Usage Arguments Value Note Author(s) References See Also Examples
There are three commonly seen coordinate systems:
WGS-84 is the gloabal coordinate system, typcially collected by GPS.
GCJ-02 is the coordinate system mandated by Chinese Gov't.
BD-09 is the coordinates system developed by Baidu Inc. that encrypts GCJ-02 further more.
The functions in this family encrypts coordinates from 'WGS-84' to 'GCJ-02' and 'BD-09', and decrypts them back vice versa. The built-in algorithm called by these functions is open source and comes with absolutely no ganrantee.
1 2 3 4 5 6 7 8 9 10 11 | wgs_to_gcj(y, ..., force = FALSE, accurate_cn_bou = TRUE)
gcj_to_wgs(y, ..., force = FALSE, accurate_cn_bou = TRUE)
gcj_to_bd(y, ..., force = FALSE, accurate_cn_bou = TRUE)
bd_to_gcj(y, ..., force = FALSE, accurate_cn_bou = TRUE)
wgs_to_bd(y, ..., force = FALSE, accurate_cn_bou = TRUE)
bd_to_wgs(y, ..., force = FALSE, accurate_cn_bou = TRUE)
|
y |
one of
|
... |
one of
|
force |
logical, whether convert the coordinates regardless if they locate inside China. Default FALSE, indicating that only coordinates inside China will be converted. |
accurate_cn_bou |
logical, whether to convert the coordinates based on
accurate China boundary. Only effective when |
A 2-col data.frame ([lng, lat]) of transformed coordinates. Note that points out of China will not have the coordinates converted.
Latitude is the horizontal line serving as y-axis metric, longitude is the vertical line serving as x-axis metric.
Yiying Wang, wangy@aetna.com
https://on4wp7.codeplex.com/SourceControl/changeset/view/21483#353936
conv_coord()
is a wrapper of these functions (local mode
transforming functions) and conv_coord_api
(api mode transforming
function).
asesgeo:::get_cn_bou()
: a list of the 'accurate China boundary'
in 'WGS-84', 'GCJ-02' and 'BD-09', which are all sp::SpatialPolygons
objects.
is_out_of_china()
: how points are distinguished as in
or out of China.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | ## Not run:
## ========== wgs_to_gcj ==========
# Tiananmen square's WGS-84 coordinate is c(39.90734, 116.39089)
# http://www.google.cn/maps/place/Tiananmen,+Dongcheng,+Beijing/
# @39.90874,116.39713,16z?hl=en
## Single point
wgs_to_gcj(list(39.90734, 116.39089)) # or
wgs_to_gcj(39.90734, 116.39089) # get
# lat lng
# [1,] 39.90874 116.3971
## Multiple points
### Coordinate pairs or Lat / Lon vectors
wgs_to_gcj(list(39.90734, 116.39089), list(39.90734, 116.39089)) # or
wgs_to_gcj(c(39.90734, 39.90734), c(116.39089, 116.39089)) # get
# lat lng
# [1,] 39.90874 116.3971
# [2,] 39.90874 116.3971
### Matrix
m <- matrix(c(39.90734, 116.39089, 39.90734, 116.39089, 39.90734,
116.39089), nrow=2)
m
# [,1] [,2] [,3]
# [1,] 39.90734 39.90734 39.90734
# [2,] 116.39089 116.39089 116.39089
wgs_to_gcj(m) # get
# lat lng
# [1,] 39.90874 116.3971
# [2,] 39.90874 116.3971
# [3,] 39.90874 116.3971
### data.frame
df <- data.frame(lat=c(39.90734, 39.90734, 39.90734, NA),
lon=c(116.39089, 116.39089, 116.39089, 116.39089))
wgs_to_gcj(df) # get
# lat lng
# [1,] 39.90874 116.3971
# [2,] 39.90874 116.3971
# [3,] 39.90874 116.3971
# [4,] NA NA
## End(Not run)
## Not run:
## ========== gcj_to_wgs ==========
# Tiananmen square's GCJ-02 coordinate is c(39.908746, 116.397131)
# http://www.openstreetmap.org/#map=19/39.90734/116.39089
## Single point
gcj_to_wgs(list(39.908746, 116.397131)) # or
gcj_to_wgs(39.908746, 116.397131) # get
# lat lng
# [1,] 39.90734 116.3909
## Multiple points
### Coordinate pairs or lat / lon vectors
gcj_to_wgs(list(39.908746, 116.397131), list(39.908746, 116.397131)) # or
gcj_to_wgs(c(39.908746, 39.908746), c(116.397131, 116.397131)) # get
# lat lng
# [1,] 39.90734 116.3909
# [2,] 39.90734 116.3909
### Matrix
m <- matrix(c(39.908746, 116.397131, 39.908746, 116.397131, 39.908746,
116.397131), nrow=2)
m
# [,1] [,2] [,3]
# [1,] 39.90875 39.90875 39.90875
# [2,] 116.39713 116.39713 116.39713
gcj_to_wgs(m) # get
# lat lng
# [1,] 39.90734 116.3909
# [2,] 39.90734 116.3909
# [3,] 39.90734 116.3909
### data.frame
df <- data.frame(lat=c(39.908746, 39.908746, 39.908746, NA),
lon=c(116.397131, 116.397131, 116.397131, 116.397131))
gcj_to_wgs(df) # get
# lat lng
# [1,] 39.90734 116.3909
# [2,] 39.90734 116.3909
# [3,] 39.90734 116.3909
# [4,] NA NA
## End(Not run)
## Not run:
## ========== gcj_to_bd ==========
# Tiananmen square's GCJ-02 coordinate is c(39.908746, 116.397131)
#http://api.map.baidu.com/marker?location=39.91509,116.40350&title=Tiananmen&
content=Tiananmen%20square&output=html
## Single point
gcj_to_bd(list(39.908746, 116.397131)) # or
gcj_to_bd(39.908746, 116.397131) # get
# lat lng
# [1,] 39.91509 116.4035
## Multiple points
### Coordiante pairs or lat / lon vectors
gcj_to_bd(list(39.908746, 116.397131), list(39.908746, 116.397131)) # or
gcj_to_bd(c(39.908746, 39.908746), c(116.397131, 116.397131)) # get
# lat lng
# [1,] 39.91509 116.4035
# [2,] 39.91509 116.4035
### Matrix
m <- matrix(c(39.908746, 116.397131, 39.908746, 116.397131, 39.908746,
116.397131), nrow=2)
m
# [,1] [,2] [,3]
# [1,] 39.90875 39.90875 39.90875
# [2,] 116.39713 116.39713 116.39713
gcj_to_bd(m) # get
# lat lng
# [1,] 39.91509 116.4035
# [2,] 39.91509 116.4035
# [3,] 39.91509 116.4035
### data.frame
df <- data.frame(lat=c(39.908746, 39.908746, 39.908746, NA),
lon=c(116.397131, 116.397131, 116.397131, 116.397131))
gcj_to_bd(df) # get
# lat lng
# [1,] 39.91509 116.4035
# [2,] 39.91509 116.4035
# [3,] 39.91509 116.4035
# [4,] NA NA
## End(Not run)
## Not run:
## ========== bd_to_gcj ==========
# Tiananmen square's BD-06 coordinate is c(39.91509, 116.40350)
# http://www.google.cn/maps/place/Tiananmen,+Dongcheng,+Beijing/
# @39.90875,116.39713,16z?hl=en
## Single point
bd_to_gcj(list(39.91509, 116.40350)) # or
bd_to_gcj(39.91509, 116.40350) # get
# lat lng
# [1,] 39.90875 116.3971
## Multiple points
### coordinate pairs or lat / lon vectors
bd_to_gcj(list(39.91509, 116.40350), list(39.91509, 116.40350)) # or
bd_to_gcj(c(39.91509, 39.91509), c(116.40350, 116.40350)) # get
# lat lng
# [1,] 39.90875 116.3971
# [2,] 39.90875 116.3971
### Matrix
m <- matrix(c(39.91509, 116.40350, 39.91509, 116.40350, 39.91509,
116.40350), nrow=2)
m
# [,1] [,2] [,3]
# [1,] 39.91509 39.91509 39.91509
# [2,] 116.40350 116.40350 116.40350
bd_to_gcj(m) # get
# lat lng
# [1,] 39.90875 116.3971
# [2,] 39.90875 116.3971
# [3,] 39.90875 116.3971
### data.frame
df <- data.frame(lat=c(39.91509, 39.91509, 39.91509, NA),
lon=c(116.40350, 116.40350, 116.40350, 116.40350))
bd_to_gcj(df) # get
# lat lng
# [1,] 39.90875 116.3971
# [2,] 39.90875 116.3971
# [3,] 39.90875 116.3971
# [4,] NA NA
## End(Not run)
## Not run:
## ========== wgs_to_bd ==========
# Tiananmen square's WGS-84 coordinate is c(39.90734, 116.39089)
# http://api.map.baidu.com/marker?location=39.91509,116.40350&title=
# Tiananmen&content=Tiananmen%20square&output=html
## Single point
wgs_to_bd(list(39.90734, 116.39089)) # or
wgs_to_bd(39.90734, 116.39089) # get
# lat lng
# [1,] 39.91508 116.4035
## Multiple points
### Coordinate pairs or lat / lon vectors
wgs_to_bd(list(c(39.90734, 116.39089), c(39.90734, 116.39089))) # or
wgs_to_bd(c(39.90734, 39.90734), c(116.39089, 116.39089)) # get
# lat lng
# [1,] 39.91508 116.4035
# [2,] 39.91508 116.4035
### Matrix
m <- matrix(c(39.90734, 116.39089, 39.90734, 116.39089, 39.90734,
116.39089), nrow=2)
m
# [,1] [,2] [,3]
# [1,] 39.90734 39.90734 39.90734
# [2,] 116.39089 116.39089 116.39089
wgs_to_bd(m) # get
# lat lng
# [1,] 39.91508 116.4035
# [2,] 39.91508 116.4035
# [3,] 39.91508 116.4035
### data.frame
df <- data.frame(lat=c(39.90734, 39.90734, 39.90734, NA),
lon=c(116.39089, 116.39089, 116.39089, 116.39089))
wgs_to_bd(df) # get
# lat lng
# [1,] 39.91508 116.4035
# [2,] 39.91508 116.4035
# [3,] 39.91508 116.4035
# [4,] NA NA
## End(Not run)
## Not run:
## ========== bd_to_wgs ==========
# Tiananmen square's BD-06 coordinate is c(39.91509, 116.40350)
# http://www.openstreetmap.org/#map=19/39.90734/116.39089
## Single point
bd_to_wgs(list(39.91509, 116.40350)) # or
bd_to_wgs(39.91509, 116.40350) # get
# lat lng
# [1,] 39.90734 116.3909
## Multiple points
### Coordinate pairs or lat / lon vectors
bd_to_wgs(list(39.91509, 116.40350), list(39.91509, 116.40350)) # or
bd_to_wgs(c(39.91509, 39.91509), c(116.40350, 116.40350)) # get
# lat lng
# [1,] 39.90734 116.3909
# [2,] 39.90734 116.3909
### Matrix
m <- matrix(c(39.91509, 116.40350, 39.91509, 116.40350, 39.91509,
116.40350), nrow=2)
m
# [,1] [,2] [,3]
# [1,] 39.90734 39.90734 39.90734
# [2,] 116.39089 116.39089 116.39089
bd_to_wgs(m) # get
# lat lng
# [1,] 39.90734 116.3909
# [2,] 39.90734 116.3909
# [3,] 39.90734 116.3909
### data.frame
df <- data.frame(lat=c(39.91509, 39.91509, 39.91509, NA),
lon=c(116.40350, 116.40350, 116.40350, 116.40350))
bd_to_wgs(df) # get
# lat lng
# [1,] 39.90734 116.3909
# [2,] 39.90734 116.3909
# [3,] 39.90734 116.3909
# [4,] NA NA
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.