Skip to content

Commit

Permalink
to pass check - remaining warning to document data
Browse files Browse the repository at this point in the history
  • Loading branch information
andysouth committed Feb 19, 2020
1 parent a184da4 commit 7997fa7
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
^afriadmin\.Rproj$
^\.Rproj\.user$
^data-raw$
^doc$
^Meta$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ vignettes/*.pdf
.Renviron
.Rproj.user
inst/doc
doc
Meta
66 changes: 34 additions & 32 deletions R/hdxadmin.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#' hdx admin layers starting to looking at downloading
#' NOT WORKING YET
#'
#' #todo vectorise
#'
Expand All @@ -8,7 +9,7 @@
#'
#' @examples
#'
#' hdxadmin("nigeria")
#' #hdxadmin("nigeria")
#'
#' @return not sure yet
#' @export
Expand Down Expand Up @@ -41,7 +42,8 @@ hdxadmin <- function(country,
#selecting resource
#nigeria "zipped shapefiles"
#mali "zipped shapefile"
ds_id <- which( rhdx::get_formats(ds) == "zipped shapefiles" | "zipped shapefile")
ds_id <- which( rhdx::get_formats(ds) %in% c("zipped shapefiles","zipped shapefile"))


rs <- rhdx::get_resource(ds, ds_id)

Expand Down Expand Up @@ -95,39 +97,39 @@ hdxadmin <- function(country,
# plot(sf::st_geometry(malishp))

# alternative approach using name of resource
# TODO is naming consistent ?
ds <- pull_dataset("administrative-boundaries-cod-mli")
# naming seems not consistent ?
# ds <- pull_dataset("administrative-boundaries-cod-mli")
# these fail, may need to go back to query
#ds <- pull_dataset("administrative-boundaries-cod-uga") #uganda none ?
#ds <- pull_dataset("administrative-boundaries-cod-nga") #nigeria none ?

list_of_rs <- rhdx::get_resources(ds)

# for Mali is 3rd resource
# TODO find better way of selecting from dataset list
re <- get_resource(ds, 3)

# find which layers in file
mlayers <- get_resource_layers(re, download_folder=getwd())

# next can I search for adm1 3 etc. in name field of the result
# to get the layer I want

#mlayers$name[ grep("adm2",mlayers$name) ]
#using paste from admin_level
#level <- 2
level <- 3
layername <- mlayers$name[ grep(paste0("adm",level),mlayers$name) ]
# this relies on all country layers having adm* in their names

# read layer using layername
sflayer <- read_resource(re, layer=layername, download_folder=getwd())


#todo later put these plotting bits into shared function
plot(sf::st_geometry(sflayer))

mapview(sflayer, zcol=paste0("admin",level,"Name"), legend=FALSE)
# list_of_rs <- rhdx::get_resources(ds)
#
# # for Mali is 3rd resource
# # TODO find better way of selecting from dataset list
# re <- get_resource(ds, 3)
#
# # find which layers in file
# mlayers <- get_resource_layers(re, download_folder=getwd())
#
# # next can I search for adm1 3 etc. in name field of the result
# # to get the layer I want
#
# #mlayers$name[ grep("adm2",mlayers$name) ]
# #using paste from admin_level
# #level <- 2
# level <- 3
# layername <- mlayers$name[ grep(paste0("adm",level),mlayers$name) ]
# # this relies on all country layers having adm* in their names
#
# # read layer using layername
# sflayer <- read_resource(re, layer=layername, download_folder=getwd())
#
#
# #todo later put these plotting bits into shared function
# plot(sf::st_geometry(sflayer))
#
# mapview(sflayer, zcol=paste0("admin",level,"Name"), legend=FALSE)

# when I do directly from sf (see below)
# seems to be problem opening a layer from a zipped shapefile by name
Expand All @@ -136,7 +138,7 @@ hdxadmin <- function(country,

# TODO will it work for geodatabase ? not quite
# also geopackage not present for all countries
ds_id <- which( rhdx::get_formats(ds) == "geodatabase" )
#ds_id <- which( rhdx::get_formats(ds) == "geodatabase" )


}
Expand Down
5 changes: 3 additions & 2 deletions man/hdxadmin.Rd

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

1 change: 1 addition & 0 deletions vignettes/afriadmin-atlas.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: "afriadmin-atlas"
output: rmarkdown::html_vignette
#output: rmarkdown::pdf_document
vignette: >
%\VignetteIndexEntry{afriadmin-atlas}
%\VignetteEngine{knitr::rmarkdown}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Document
title:
username:
account: rpubs
server: rpubs.com
hostUrl: rpubs.com
appId: https://api.rpubs.com/api/v1/document/576214/905269ecf163493d907bce94f278aa23
bundleId: https://api.rpubs.com/api/v1/document/576214/905269ecf163493d907bce94f278aa23
url: http://rpubs.com/publish/claim/576214/67562eed668d479d953fd7298f08aac9
when: 1582149853.71513

0 comments on commit 7997fa7

Please sign in to comment.