::install_gitlab("dickoa/rhdx") #install hdx
remoteslibrary(rhdx) # load HDX
library(tidyverse)
library(sf)
library(tmap)
Day 8: Humanitarian Data Exchange (HDX)
The Humanitarian Data Exchange (HDX) is an open platform that facilitates data sharing across crises and organisations worldwide. Since its launch in July 2014, HDX has aimed to make humanitarian data accessible and easy to use. It hosts a diverse and growing collection of datasets, which have been accessed by users from over 250 countries and territories. Managed by theUnited Nations Office for the Coordination of Humanitarian Affairs (OCHA) through its Centre for Humanitarian Data in The Hague, HDX plays a vital role in unifying humanitarian efforts by providing a reliable data hub.
In my own work, I am yet to use HDX data, so for Day 7 I will dip into demo mode to show how these can be accessed from within R.
Setup
This code loads the rhdx package which enables connection to HDX. Note that this isn’t on CRAN, so you need to use the remotes package to pull this from github. You can obviously just go to the HDX website and download some data, but I will try to be entirely automated here.
Next we will connect to the HDX servers.
set_rhdx_config(hdx_site = "prod")
Searching for Data
And search for some data. This is perhaps not the best way to find data on their website which is powered by CKAN, but I include it here for completeness.
<- search_datasets("fire", rows = 2) # search for data on HDX
data_returned data_returned
[[1]]
<HDX Dataset> 3096b00b-be4c-4fdf-9c65-020a37cedec4
Title: Fire in Algeria - UNOSAT Live Web Map
Name: fire-in-algeria-unosat-live-web-map
Date range: 2023-07-24 to 2023-07-24
Tags (up to 5): disaster risk reduction-drr, geodata
Locations (up to 5): dza
Resources (up to 5): FR20230724DZA_gdb.zip, FR20230724DZA_SHP.zip
[[2]]
<HDX Dataset> 302060fa-b0b2-41af-8c82-ec12979f8f20
Title: Cox’s Bazar: Fire Affected Area at Rohingya Refugee Camps
Name: cox-s-bazar-fire-incident-area-at-rohingya-refugee-camps-in-march-2021
Date range: 2021-03-22 to 2021-03-22
Tags (up to 5): disaster risk reduction-drr, refugee crisis
Locations (up to 5): bgd
Resources (up to 5): Fire_Extent_shapefile.zip
attr(,"class")
[1] "hdx_datasets_list"
We will then select the second dataset which concerns the March 2021 Rohingya refugee-camp fire.
<- pluck(data_returned, 2)
ds ds
<HDX Dataset> 302060fa-b0b2-41af-8c82-ec12979f8f20
Title: Cox’s Bazar: Fire Affected Area at Rohingya Refugee Camps
Name: cox-s-bazar-fire-incident-area-at-rohingya-refugee-camps-in-march-2021
Date range: 2021-03-22 to 2021-03-22
Tags (up to 5): disaster risk reduction-drr, refugee crisis
Locations (up to 5): bgd
Resources (up to 5): Fire_Extent_shapefile.zip
And list all the resources contained in the data.
get_resources(ds)
[[1]]
<HDX Resource> 834dc826-4a6d-4d72-9498-1d2980531bfb
Name: Fire_Extent_shapefile.zip
Description: The source of the data is IOM Cox's Bazar
Size: 54885
Format: SHP
attr(,"class")
[1] "hdx_resources_list"
And then select the resource that we want to download.
<- get_resource(ds, 1) # Select the resource
fire download_resource(fire,folder = getwd()) # Download
Next we read this into a SF object for plotting.
unzip("fire_extent_shapefile.zip", exdir = "./") # unzip
# Read the file
<- st_read(file.path(getwd(), "Fire_Extent_shapefile", "Fire affcted area.shp")) fire_SF
Reading layer `Fire affcted area' from data source
`/home/rstudio/alexsingleton.github.io/content/blog/2024-11-08-30DMC_HDX/Fire_Extent_shapefile/Fire affcted area.shp'
using driver `ESRI Shapefile'
Simple feature collection with 1 feature and 3 fields
Geometry type: POLYGON
Dimension: XYZ
Bounding box: xmin: 10258610 ymin: 2414147 xmax: 10259620 ymax: 2415538
z_range: zmin: -56.7 zmax: 0
Projected CRS: WGS 84 / Pseudo-Mercator
Creating a Plot
tmap_options(check.and.fix = TRUE) #fix any invalid polygons
# Set tmap to interactive viewing mode
tmap_mode("view")
# Change CRS to WGS 84 (EPSG:4326)
<- st_transform(fire_SF, crs = 4326)
fire_SF
tm_shape(fire_SF) +
tm_polygons(
col = "red", # Fill color
alpha = 0, # Set fill opacity to zero
border.col = "red", # Red border
lty = "dotted", # Dotted line
lwd = 2
+
) tm_basemap("Esri.WorldImagery") +
tm_view(bbox = fire_SF)
The Balukhali camp in Bangladesh is believed to one of the largest refugee settlements in the world. In March 2021, a devastating fire broke out on the afternoon of March 22 and was possibly triggered by exploding gas cylinders used for cooking. The fire spread rapidly through the camp’s densely packed shelters, and burned for around eight hours despite the best efforts of firefighters. Tragically, the fire claimed the lives of at least 15 people, left over 560 injured, and around 400 missing. Approximately 50,000 refugees were displaced.