Skip to content

Commit

Permalink
v0.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
RichDeto committed Jul 5, 2022
1 parent f9eb791 commit 6374dcc
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SystemRequirements: 'unrar' (Linux/macOS) or '7-Zip' (Windows)
6.2.1)
Imports:
rlang,
RCurl, curl,
curl,
dplyr,
glue,
stringr,
Expand Down
15 changes: 3 additions & 12 deletions R/geocode_ide_uy.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,17 @@ geocode_ide_uy <- function(x, details = F) {
x <- x %>% dplyr::mutate(dir = stringr::str_trim(dir)) %>% dplyr::filter(nchar(dir) > 0)
for (i in 1:nrow(x)) {
p <- glue::glue("https://direcciones.ide.uy/api/v0/geocode/BusquedaDireccion?calle={x[i,'dir']}&departamento={x[i,'dpto']}&localidad={x[i,'loc']}.json") %>%
# "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 <- suppressWarnings(rjson::fromJSON(paste(readLines(p), collapse=""))[[1]]) #RCurl::getURL(p[1])
x[i, "x"] <- p$puntoX#suppressWarnings(as.numeric(stringr::str_sub(p, stringr::str_locate(p, "puntoX\":")[2] + 1, stringr::str_locate(p, "puntoX\":")[2] + 10)))
x[i, "y"] <- p$puntoY#suppressWarnings(as.numeric(stringr::str_sub(p, stringr::str_locate(p, "puntoY\":")[2] + 1, stringr::str_locate(p, "puntoY\":")[2] + 10)))
p <- suppressWarnings(rjson::fromJSON(paste(readLines(p), collapse=""))[[1]])
x[i, "x"] <- p$puntoX
x[i, "y"] <- p$puntoY
if (details == T) {
x[i, "idTipoClasificacion"] <- p$idTipoClasificacion
# suppressWarnings(as.numeric(stringr::str_sub(p, stringr::str_locate(p, "idTipoClasificacion\":")[2] + 1,
# stringr::str_locate(p, "idTipoClasificacion\":")[2] + 1)))
x[i, "error"] <- p$error
# suppressWarnings(stringr::str_sub(p, stringr::str_locate(p, "error\":")[2] + 1, stringr::str_locate(p, "error\":")[2] + 50))
}

p <- NULL
Sys.sleep(10)
}
return(x)
}

# @importFrom dplyr mutate filter %>%
# @importFrom stringr str_sub str_locate str_trim str_replace_all
# @importFrom RCurl getURL
# @importFrom glue glue
2 changes: 1 addition & 1 deletion data-raw/metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata <- tibble::tribble(
"Areas administrativas", "SGM", "SGM", 4326, "wfs", 2011, "polnbda_ury", NA, NA, "UTF-8",
"Dptos", "DINAMA", "MVOTMA", 4326, "wfs", 2020, "https://www.ambiente.gub.uy/geoserver/u19600217/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=u19600217:c004","gid", "nombre", "UTF-8",
"Limites departamentales", "IGM", "IGM", 4326, "wfs", 2011, "WFS:https://srvgis.igm.gub.uy/arcgis/services/LimiteDepartamental_wfs_250000/MapServer/WFSServer", "GLOBALID", "DEPTO", "UTF-8",
"Departamentos", "IDE", "MIDES", 32721, "wfs", 2011, "https://mapas.mides.gub.uy/geoserver/IDE/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=IDE:departamentos&outputFormat=GML2", "uruguay_", "nombre", "UTF-8",
"Departamentos", "IDE", "MIDES", 32721, "wfs", 2011, "https://mapas.mides.gub.uy/geoserver/IDE/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=IDE:departamentos", "uruguay_", "nombre", "UTF-8",
"Deptos", "INE", "IDE", 32721, "zip", 2011, "https://mapas.ide.uy/geoserver-vectorial/INE_NO_SEGURO/wfs?service=WFS&request=GetFeature&version=1.0.0&outputFormat=shape-zip&typeName=ine_depto", "depto", "nombre", "UTF-8",
# "Secc", "INE", "MIDES", 32721, "zip", 2011, "https://mapas.ide.uy/geoserver-vectorial/INE_NO_SEGURO/wfs?service=WFS&request=GetFeature&version=1.0.0&outputFormat=shape-zip&typeName=ine_seccen", "codsec","seccion", "UTF-8",
"Secciones", "INE", "MIDES", 32721, "wfs", 2011, "https://mapas.mides.gub.uy:443/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=INECenso:Secciones", "CODSEC","SECCION", "UTF-8",
Expand Down
Binary file modified data-raw/metadata.Rds
Binary file not shown.
Binary file modified data/metadata.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/testthat/test-add_geom.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("add_geom works", {
pobre_x_dpto <- as.data.frame(cbind(nomdpto = c("ARTIGAS", "DURAZNO", "FLORIDA", "LAVALLEJA"),
Pobreza = c(0.26, 0.27, 0.07, 0.10)))
pobre_x_dpto_geo <- add_geom(data = pobre_x_dpto, unit = "Departamentos", variable = "nomdpto")
pobre_x_dpto_geo <- add_geom(data = pobre_x_dpto, unit = "Deptos", variable = "nomdpto")
testthat::expect_equal(ncol(pobre_x_dpto_geo), 3)
})

0 comments on commit 6374dcc

Please sign in to comment.