Learn R Programming

geoChina (version 1.3.0)

conv: Convert coordinates

Description

the general function that converts lat/lon coordintes from one GCS to another GCS including WGS-84, GCJ-02 and BD-09 either locally or by calling Baidu Maps API.

Usage

conv(lat, lon, from = c("WGS-84", "GCJ-02", "BD-09"), to = c("WGS-84",
  "GCJ-02", "BD-09"), api = FALSE)

Arguments

lat
a numeric latitude
lon
a numeric longitude
from
the inputting GCS
to
the outputting GCS
api
use Baidu Maps API. Note that Baidu Maps API only supports the transformations from WGS-84 or GCJ-02 to BD-09. Other coodinate conversions must be done locally. As the conversion result is the same, it's recommended to perform conversions locally.

Value

a data.frame with variables lat/lng

Details

note that the Baidu Maps API limits to 20 lat/lon coordinates per query. Since the coordinate conversion results of Baidu Maps API and local algorithms are the same, it is recommended to use local algorithms.

See Also

wgs2gcj, wgs2bd, gcj2wgs, gcj2bd, bd2wgs, bd2gcj.

Examples

Run this code
## Not run: ------------------------------------
# # latitude/longitude coordinates of Beijing railway station
# # WGS-84: (39.90105, 116.42079)
# # GCJ-02: (39.90245, 116.42703)
# # BD-09:  (39.90851, 116.43351)
# conv(39.90105, 116.42079, from = 'WGS-84', to = 'GCJ-02')
# conv(39.90105, 116.42079, from = 'WGS-84', to = 'GCJ-02', api = TRUE)
# conv(39.90105, 116.42079, from = 'WGS-84', to = 'BD-09')
# conv(39.90105, 116.42079, from = 'WGS-84', to = 'BD-09', api = TRUE)
# conv(39.90245, 116.42703, from = 'GCJ-02', to = 'WGS-84')
# # not supported by baidu map api, return NAs
# conv(39.90245, 116.42703, from = 'GCJ-02', to = 'WGS-84', api = TRUE)
# conv(39.90245, 116.42703, from = 'GCJ-02', to = 'BD-09')
# conv(39.90245, 116.42703, from = 'GCJ-02', to = 'BD-09', api = TRUE)
# conv(39.90851, 116.43351, from = 'BD-09', to = 'GCJ-02')
# # not supported by baidu map api, return NAs
# conv(39.90851, 116.43351, from = 'BD-09', to = 'GCJ-02', api = TRUE)
# conv(39.90851, 116.43351, from = 'BD-09', to = 'WGS-84')
# # not supported by baidu map api, return NAs
# conv(39.90851, 116.43351, from = 'BD-09', to = 'WGS-84', api = TRUE)
# # convert multiple coordinates
# lat = c(39.99837, 39.98565)
# lng = c(116.3203, 116.2998)
# conv(lat, lng, from = 'WGS-84', to = 'GCJ-02')
## ---------------------------------------------

Run the code above in your browser using DataLab