geocoord: Convert addresses into coordinates

View source: R/geocoord.R

geocoordR Documentation

Convert addresses into coordinates

Description

Convert addresses into coordinates

Usage

geocoord(data, address, city = "", ncore = 999, nquery = 10)

Arguments

data

The dataset, a data.frame or data.table.

address

The column name of address

city

Specify the city to query. This argument supports the city name in Chinese, the city name in pinyin, the administrative code of city or the city code defined by Amap. By default, this argument is empty. For more information, see the Amap official documents at https://lbs.amap.com/api/webservice/guide/api/georegeo.

ncore

The specific number of CPU cores used (ncore = 999 by default, which indicates the maximum of CPU cores minus 1 were used in parallel computing if your CPU is less than 999 cores)

nquery

The number of query in each batch (nquery = 10 by default). This argument is used to avoid the http 413 error when the request url is too long.

Value

a data.table which adds the formatted address, longitude and latitude in the original data set.

Note

(1) According to the official document of AMap Web Service API, the address in the data set should be in Chinese format. If a address is in English or includes special characters (i.e., ?, -, >, _, etc.), the function may return empty result for this address automatically. (2) Task may fail when the network connection between you and Amap API is unstable. To avoid loop break in this function, the result for that task will not be returned. Therefore, the final results returned may be less than the original data. If you want to check where the task failed, I suggest adding an ID column to the original data and comparing the IDs between the final results returned and original data.

References

Amap. Official documents for developers: Web Service API. https://lbs.amap.com/api/webservice/summary

Examples

## Not run: 
library(amapR)
options(amap.key = "xxxxxxxxxxxx")

# Note: The "address" is the column having Chinese addresses, and the data set named "test"
# should be a data.frame or a data.table.
results <- geocoord(data = test, address = "address")

# Set the specific number of CPU cores used and the number of query in each batch
results <- geocoord(data = test, address = "address", ncore = 4, nquery = 5)

# Specify the city to query
results <- geocoord(data = test, address = "address", city = "chengdu")

## End(Not run)


xiaojunlin/amap documentation built on Sept. 29, 2022, 6:35 a.m.