convWGS2GCJ: Transform WGS-84 (Global) coordinates to GCJ-02 (Google...

Description Usage Arguments Value Note Author(s) References See Also Examples

View source: R/geoCoord.R

Description

WGS-84 coordinates are gloabal coordinates. This function encrypts it into GCJ-02 that is mandated by Chinese Gov't.

Usage

1

Arguments

y
  • A vector c(latitude, longitude)

  • simply latitude number

  • a matrix (row 1-2 or col 1-2). The function will choose how to read the data

  • a data.frame (col 1-2)

...
  • When y is only latitude, you can pass in x (longitude) here.

  • when y is a vector of c(lat, lon), you can pass in the rest vectors as well.

  • when y is a matrix or a data.frame, ... is omitted.

Value

A 2-col data.frame ([lng, lat]) of transformed coordinates.

Note

Latitude is the horizontal line serving as y-axis metric, longitude is the vertical line serving as x-axis metric.

Author(s)

Yiying Wang, wangy@aetna.com

References

https://on4wp7.codeplex.com/SourceControl/changeset/view/21483#353936

See Also

convGCJ2WGS, convCoord.

Examples

 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
## Not run: 
# 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
convWGS2GCJ(c(39.90734, 116.39089))  # or
convWGS2GCJ(39.90734, 116.39089)  # get
#           lat      lng
# [1,] 39.90874 116.3971

## Multiple points
### Vectors
convWGS2GCJ(c(39.90734, 116.39089), c(39.90734, 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
convWGS2GCJ(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))
convWGS2GCJ(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)

madlogos/recharts2 documentation built on May 21, 2019, 11:03 a.m.