Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

identify and download healthsites data in a query #6

Open
andysouth opened this issue Mar 12, 2020 · 2 comments
Open

identify and download healthsites data in a query #6

andysouth opened this issue Mar 12, 2020 · 2 comments

Comments

@andysouth
Copy link

Hi Ahmadou,

I see that hdx has monthly updated healthsites data by country. I wonder if this could be an easier way of getting at the healthsites data.

I've been trying to do something like this to be able to identify the healthsites data but haven't been able to get it to work yet.

library(rhdx)
rhdx::set_rhdx_config()
querytext <- 'Name:"Kenya-healthsites-shp"'
datasets_list <- rhdx::search_datasets(query = querytext)
#so far not returning any results

Any tips appreciated.
Thanks,
Andy

@andysouth
Copy link
Author

Aha, getting there, this returns a single dataset (note lowercase throughout)
querytext <- 'name:"kenya-healthsites"'
Now to see if I can get to the one shp data layer ...
Will close this if I do.

@andysouth
Copy link
Author

The download works but it won't open the shapefile and read into an sf object, i think because the shapefiles are within a subfolder in the zip. Is there a way of coping with that ?

library(rhdx)
rhdx::set_rhdx_config()
querytext <- 'name:"kenya-healthsites"'
datasets_list <- rhdx::search_datasets(query = querytext)

#query needs to return a single dataset (with multiple resources)
ds <- datasets_list[[1]]

    #get list of resources
    list_of_rs <- rhdx::get_resources(ds)
    list_of_rs

    #selecting resource
    ds_id <- which( rhdx::get_formats(ds) %in% c("zipped shapefiles","zipped shapefile"))

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

    # find which layers in file (fails)
    #mlayers <- rhdx::get_resource_layers(rs, download_folder=getwd())
 
   #should read 1st layer by default
    sflayer <- rhdx::read_resource(rs, download_folder=getwd())

#the zip does download but fails to read into R with
#Cannot open data source /vsizip/C:/rsprojects/afriadmin/kenya-shapefiles.zip
#Error in CPL_get_layers(dsn, options, do_count) : Open failed. 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant