municipality_pop_geom <-left_join(municipalities_ghs, population_2010, by ="row") |>select(c(shapename,"Population_2010.y", geom)) |>rename("population"="Population_2010.y") |>mutate(n_od_sampling =ceiling(municipality_pop_geom$population/sum(municipality_pop_geom$population) *n_samples_ghs))municipalities_ghs_leaflet <- sf::st_read(connection,Id(schema="agile_gis_2025_rs",table="municipalities_ghs_leaflet"))tabela1378_bairros <-read_csv("/home/ricardors/heigit_data/tabela1378_bairros.csv")library(stringr)filtered_bairros <-data.frame()for (x in1:length(municipalities_ghs$shapename)) {# Select places that are in the municipality of the AoI a= tabela1378_bairros[str_which(tabela1378_bairros$place, municipalities_ghs$shapename[x]),]# Filter places that have code of 7 characters a_filtered <- a[nchar(a$code) ==7, ] |># Remove space and the (RS) that indicates Rio Grande do Sulmutate(place=str_remove(place, " \\(RS\\)"))# Create dataset filtered_bairros <-bind_rows(filtered_bairros, a_filtered)}# Add the population to municipalities_ghsmunicipalities_ghs$Population_2010 <- filtered_bairros$Population_2010# municipalities_ghs <- municipalities_ghs |>mutate(n_od_sampling =ceiling( municipalities_ghs$Population_2010/sum(municipalities_ghs$Population_2010) *n_samples))
8.2 Figures
8.2.1 Using overture building data for the weighted OD figure.
CREATETABLE municipalities_ghs_hospitals ASWITH municipalities_ghs_united AS(SELECT st_union(geom) AS geom_unite FROM municipalities_ghs),---Use the bounding box to select hospitalshospital_rs_porto AS (SELECT h.*FROM hospitals_bed_rs AS h, municipalities_ghs_united geom_ghs_aoiWHERE st_intersects(h.geom, geom_ghs_aoi.geom_unite))SELECTDISTINCTON (h.cd_cnes) cd_cnes, ds_cnes, f.id, f.the_geom <-> h.geom AS distance, h.geom AS geom_hospital, f.the_geom AS geom_nodeFROM hospital_rs_porto h---- Snapping the hospitals to the closest vertices in the networkLEFTJOIN LATERAL(SELECTid, the_geomFROM ghs_aoi_net_largest_vertices_pgr AS netORDERBY net.the_geom <-> h.geomLIMIT1) AS f ONtrue
8.4 Leaflet input:
8.4.1 Hospitals with bed capacity
Show the code
---- Hospitals with ICU and their bed capacity -> ***Input for leaflet map****EXPLAINANALYZECREATETABLE hospital_bed_aux_leaflet ASSELECT h.fid,initcap(h.ds_cnes) AS ds_cnes, h.tp_risco, h.nm_municip, h.ds_bairro, h.addr_ct, h.geom_hospital, h.distance, aux_data."QTLEITP1", aux_data."QTLEITP2", aux_data."QTLEITP3","QTLEITP1"+"QTLEITP2"+"QTLEITP3"AS beds, aux_data."NAT_JUR",CASEWHEN"NAT_JUR"IN (3069,3999)THEN'Private'ELSE'Public'ENDAS nat_jur_cat,initcap(h.nm_razao_s) AS nm_razao_sFROM etlcnes_hospital_selected AS aux_dataJOIN municipalities_ghs_hospitals AS hON h.cd_cnes = aux_data."CNES"; ---- Execution Time: 43.901 ms--- Municipality of the AoI with additonial data from:------- A) IBGR: "https://www.ibge.gov.br/cidades-e-estados/rs/"--------B) DEE-SPGG: "https://mup.rs.gov.br/" --- -> ***Input for leaflet map****EXPLAINANALYZECREATETABLE municipalities_ghs_leaflet ASSELECT shapename, wkb_geometryFROM municipalities_ghs; ---- 8.511 ms--- Add new fields (A,B)ALTERTABLE municipalities_ghs_leafletADDCOLUMN"Pop.Aff" text,ADDCOLUMN"GDP" text ; --- 0.012S execute time--- Populate columnsEXPLAINANALYZEUPDATE municipalities_ghs_leafletSET"Pop.Aff"=data."Pop.Aff","GDP"=data."GDP"FROM (VALUES ('Alvorada', '26K (29%)', '15K'), ('Cachoeirinha', '12K (9%)', '49K'), ('Canoas', '157K (45%)', '63K'), ('Esteio', '20K (26%)', '45K'), ('Gravataí', '6K (2%)', '36K'), ('Nova Santa Rita', '7K (24%)', '81K'), ('Porto Alegre', '125K (9%)', '55K'), ('Sapucaia do Sul', '6K (4%)', '29K'), ('Viamão', '2K (1%)', '17K')) ASdata(shapename, "Pop.Aff", "GDP")WHERE municipalities_ghs_leaflet.shapename =data.shapename; --- Execution Time: 0.596 ms
8.5 Finding urban arterias in ORS using OSM address