Skip to content

Commit

Permalink
Geocode from xml2 to RCurl
Browse files Browse the repository at this point in the history
  • Loading branch information
RichDeto committed Apr 28, 2020
1 parent 9c0be0c commit 3349d3b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions CRAN-RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
This package was submitted to CRAN on 2020-02-26.
Once it is accepted, delete this file and tag the release (commit 531a634a59).
This package was submitted to CRAN on 2020-03-26.
Once it is accepted, delete this file and tag the release (commit cd8f83d528).
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ Depends: R (>= 3.4.0)
Language: en, es
Encoding: UTF-8
LazyData: TRUE
RoxygenNote: 7.0.2
RoxygenNote: 7.1.0
SystemRequirements: GDAL (>= 3.0.2), GEOS (>= 3.8.0), PROJ (>= 6.2.1)
Imports:
rlang,
utils,
xml2,
RCurl,
dplyr,
glue,
stringr,
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export(which_uy)
import(ggplot2)
import(ggthemes)
import(rgdal)
importFrom(RCurl,getURL)
importFrom(dplyr,"%>%")
importFrom(dplyr,distinct)
importFrom(dplyr,filter)
Expand Down Expand Up @@ -42,4 +43,3 @@ importFrom(stringr,str_sub)
importFrom(stringr,str_trim)
importFrom(utils,download.file)
importFrom(utils,unzip)
importFrom(xml2,read_html)
16 changes: 8 additions & 8 deletions R/geocode_ide_uy.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @return The DafaFrame x with the coordinates variables append (x and y)
#' @importFrom dplyr mutate filter %>%
#' @importFrom stringr str_sub str_locate str_trim str_replace_all
#' @importFrom xml2 read_html
#' @importFrom RCurl getURL
#' @importFrom glue glue
#' @export
#' @examples
Expand All @@ -21,13 +21,13 @@ geocode_ide_uy <- function(x) {
stopifnot(is.character(x$dir), "dir" %in% colnames(x))
x <- x %>% mutate(dir = stringr::str_trim(dir)) %>% filter(nchar(dir) > 0)
for (i in 1:nrow(x)) {
p <- glue::glue("http://servicios.ide.gub.uy/servicios/BusquedaDireccion?departamento={x[i,'dpto']}&localidad={x[i,'loc']}&calle={x[i,'dir']}") %>%
str_replace_all(" ", "%20") %>%
xml2::read_html(encoding = "UTF-8", options = c("NOBLANKS", "NOERROR"), n = 256) %>%
suppressWarnings()
x[i,"x"] <- suppressWarnings(as.numeric(stringr::str_sub(p, stringr::str_locate(p, "puntoX\":")[2] + 1, stringr::str_locate(p, "puntoX\":")[2] + 10)))
x[i,"y"] <- suppressWarnings(as.numeric(stringr::str_sub(p, stringr::str_locate(p, "puntoY\":")[2] + 1, stringr::str_locate(p, "puntoY\":")[2] + 10)))
p <- NULL
p <- glue::glue("http://servicios.ide.gub.uy/servicios/BusquedaDireccion?departamento={x[i,'dpto']}&localidad={x[i,'loc']}&calle={x[i,'dir']}.json") %>%
stringr::str_replace_all(" ", "%20")
p <- RCurl::getURL(p[1])
x[i, "x"] <- suppressWarnings(as.numeric(stringr::str_sub(p, stringr::str_locate(p, "puntoX\":")[2] + 1, stringr::str_locate(p, "puntoX\":")[2] + 10)))
x[i, "y"] <- suppressWarnings(as.numeric(stringr::str_sub(p, stringr::str_locate(p, "puntoY\":")[2] + 1, stringr::str_locate(p, "puntoY\":")[2] + 10)))
p <- NULL
Sys.sleep(10)
}
return(x)
}
6 changes: 4 additions & 2 deletions man/metadata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3349d3b

Please sign in to comment.