From 16d5c42c751eb016f6e26f23afebc52915fd060f Mon Sep 17 00:00:00 2001 From: seifer08ms Date: Wed, 23 Nov 2016 09:43:29 +0800 Subject: [PATCH] update documents --- DESCRIPTION | 4 ++- NAMESPACE | 2 +- R/getCoordinate.R | 65 ++++++++++++++++++++++++--------------- R/getLocation.R | 73 ++++++++++++++++++++++++++++---------------- man/geoconv.Rd | 2 +- man/getBaiduMap.Rd | 5 +-- man/getCoordinate.Rd | 9 ++++-- man/getLocation.Rd | 19 +++++++----- man/getPlace.Rd | 5 +-- man/getRoute.Rd | 9 +++--- man/url_character.Rd | 3 +- 11 files changed, 122 insertions(+), 74 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 092ad6e..26e4ec6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,6 +13,8 @@ Imports: png, RCurl, rjson, - XML + XML, + parallel License: GPL-2 LazyData: true +RoxygenNote: 5.0.1 diff --git a/NAMESPACE b/NAMESPACE index 5de0755..0a807d8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,4 +1,4 @@ -# Generated by roxygen2 (4.1.1): do not edit by hand +# Generated by roxygen2: do not edit by hand export(geoconv) export(getBaiduMap) diff --git a/R/getCoordinate.R b/R/getCoordinate.R index 22a46df..c373b32 100644 --- a/R/getCoordinate.R +++ b/R/getCoordinate.R @@ -1,28 +1,4 @@ -#' Get coordiante from address -#' Take in address and return the coordinate -#' @param address address -#' @param city the city of the address, optional -#' @param output should be "json" or "xml", the type of the result -#' @param formatted logical value, return the coordinates or the original results -#' @return A vector contains the corresponding coordiante. If "formatted=TRUE", return the numeric coordinates, otherwise return json or xml type result, depents on the argument "output". If the length of address is larger than 1, the result is a matrix. -#' @export getCoordinate -#' @examples -#' -#' \dontrun{ -#' ## json output -#' getCoordinate('beijingdaxue') -#' -#' ## xml output -#' getCoordinate('beijingdaxue', output='xml') -#' -#' ## formatted -#' getCoordinate('beijingdaxue', formatted = T) -#' -#' ## vectorization, return a matrix -#' getCoordinate(c('beijingdaxue', 'qinghuadaxue'), formatted = T) -#' } -#' -getCoordinate = function(address, city=NULL, output='json', formatted = F){ +getCoordinate.core = function(address, city=NULL, output='json', formatted = F){ ### address if (grepl(' |#', address)) warning('address should have blank character!') address = gsub(' |#', '', address) @@ -58,4 +34,43 @@ getCoordinate = function(address, city=NULL, output='json', formatted = F){ ### final return(result) +} +#' Get coordiante from address +#' Take in address and return the coordinate +#' @param address address +#' @param city the city of the address, optional +#' @param output should be "json" or "xml", the type of the result +#' @param formatted logical value, return the coordinates or the original results +#' @param limit integer value.If the length of address exceeded limit, function will run in parallel +#' @return A vector contains the corresponding coordiante. If "formatted=TRUE", return the numeric coordinates, otherwise return json or xml type result, depents on the argument "output". If the length of address is larger than 1, the result is a matrix. +#' @export getCoordinate +#' @examples +#' \dontrun{ +#' ## json output +#' getCoordinate('beijingdaxue') +#' +#' ## xml output +#' getCoordinate('beijingdaxue', output='xml') +#' +#' ## formatted +#' getCoordinate('beijingdaxue', formatted = T) +#' +#' ## vectorization, return a matrix +#' getCoordinate(c('beijingdaxue', 'qinghuadaxue'), formatted = T) +#' } +getCoordinate=function(address, city=NULL, output='json', formatted = F,limit=600){ + if(length(address)(.*?).*", '\\1', result) + } + } + + #### final + return(result) +} #' Get location from coordinate #' Take in coordiantes and return the location #' @param location longtitude and latitude #' @param output should be "json" or "xml", the type of the result #' @param formatted logical. whether to return a nice result -#' @param pois whether to return the PIO around the location +#' @param pois whether to return the POI around the location +#' @param limit integer value.If the number of row exceeded limit, function will run in parallel #' @return the corresponding locations #' @export getLocation #' @importFrom RCurl getURL @@ -32,30 +61,20 @@ map_ak = 'wwZFCIqxIqjRGMVsZ0qgTh7D' #' ## formatted #' location = getLocation(loc, formatted = T) #' } -getLocation = function(location, output='json', formatted = F, pois=0){ - ##### URL - if (!class(location) %in% c('matrix', 'data.frame')){ - location = matrix(location, ncol=2, byrow=T) - } - lon = location[, 1] - lat = location[, 2] - url_head = paste0("http://api.map.baidu.com/geocoder/v2/?ak=", map_ak, "&location=") - url_tail = paste0("&output=", output, "&", "pois=", pois, collapse='') - url = paste0(url_head, lat, ",", lon, url_tail) - - ##### result - result = tryCatch(getURL(url),error = function(e) {getURL(url, timeout = 200)}) - names(result) = paste0("lon=", lon, ";lat=", lat) - - ##### if formatted, return a nice result but loss some information - if (formatted){ - if (output == 'json'){ - result = gsub('.*"formatted_address":"(.*?)".*', '\\1', result) - } else if (output == 'xml') { - result = gsub(".*(.*?).*", '\\1', result) +#' +getLocation= + function (location, output = "json", formatted = F, pois = 0,limit=600) { + if(nrow(location)