05_Querying_Results.md 11.5 KB
Newer Older
Cecilia Nievas's avatar
Cecilia Nievas committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# Querying Results

Example queries that allow to access data from the GDE model are shown herein. Unless stated
otherwise, all queries refer to the
[GDE Tiles database](https://git.gfz-potsdam.de/dynamicexposure/globaldynamicexposure/database-gdetiles).

## Available aggregated sources

To list all available aggregated sources, that is, aggregated exposure models that have been
imported by the
[gde-importer](https://git.gfz-potsdam.de/dynamicexposure/globaldynamicexposure/gde-importer),
do:

```
gde_tiles=> SELECT aggregated_source_id, name, format FROM aggregated_sources;
```

## Total number of buildings of an exposure entity, grouped by occupancy case

The following example query returns the number of aggregated buildings, OBM buildings and
remainder buildings in Greece (`GRC`), as per `aggregated_source_id=1` (i.e., ESRM20), grouped
by each occupancy case:

```
gde_tiles=> SELECT occupancy_case, SUM(aggregated_buildings), SUM(obm_buildings), SUM(remainder_buildings) FROM data_unit_tiles WHERE exposure_entity='GRC' AND aggregated_source_id=1 GROUP BY occupancy_case;

 occupancy_case |        sum         |  sum   |        sum         
----------------+--------------------+--------+--------------------
 residential    | 3051157.8920203564 | 607409 |  2553080.074310104
 commercial     |  249708.0000000016 |  21811 | 212562.61958915135
 industrial     | 51229.000000000095 |  15952 |  41849.26464570898
(3 rows)
```

The summation of all OBM buildings and all remainder buildings gives the total number of
buildings in Greece for the three occupancy cases. This does not mean that these are all the OBM
buildings that exist in Greece in the
[OBM buildings database](https://git.gfz-potsdam.de/dynamicexposure/openbuildingmap/database-obmbuildings),
as many of those correspond to occupancy cases not covered by ESRM20 (and, thus, by GDE).

## Number of tiles associated with an exposure entity

The following example query returns the number of zoom-level 18 tiles associated with Luxembourg
(`LUX`), as per `aggregated_source_id=1` (i.e., ESRM20):

```
gde_tiles=> SELECT COUNT(DISTINCT(quadkey)) FROM data_unit_tiles WHERE exposure_entity='LUX' AND aggregated_source_id=1;

 count  
--------
 267637
(1 row)

```

Note that the use of `DISTINCT` is relevant because the same tile (identified by its quadkey)
normally has more than one entry associated with the same exposure entity and aggregated source
ID, for different occupancy cases and/or data unit IDs.

## Exposure results associated with a quadkey

The following example query returns the list of entries associated with the zoom-level 18 tile
with quadkey `122100203132021122`, as per `aggregated_source_id=1` (i.e., ESRM20). For each
entry, the data unit ID, occupancy case and numbers of aggregated, OBM and remainder buildings
are requested.

```
gde_tiles=> SELECT data_unit_id, occupancy_case, aggregated_buildings, obm_buildings, remainder_buildings FROM data_unit_tiles WHERE quadkey='122100203132021122' AND aggregated_source_id=1;

       data_unit_id        | occupancy_case | aggregated_buildings | obm_buildings | remainder_buildings 
---------------------------+----------------+----------------------+---------------+---------------------
 GRC_3514508               | residential    |   3.5232385833448014 |             0 |  3.5232385833448014
 GRC_3514608               | residential    |   10.832479557437827 |            38 |                   0
 GRC_3514508               | commercial     |   0.2990195693416231 |             0 |  0.2990195693416231
 GRC_3514608               | commercial     |    1.437904894386666 |             0 |   1.437904894386666
 GRC_industrial_FILLER_205 | industrial     |                    0 |             0 |                   0
(5 rows)
```

This result says that both for residential and commercial exposure this tile is intersected by
the boundary between data units `GRC_3514508` and `GRC_3514608` of Greece (`GRC`), but is fully
contained in the filler data-unit created for industrial exposure by the `gde-importer` to
ensure full geographic coverage (see more details
[here](https://git.gfz-potsdam.de/dynamicexposure/globaldynamicexposure/gde-importer/-/blob/master/docs/06_Ensuring_Full_Geographic_Coverage.md)).

## Building classes associated with a data unit ID

If, following the previous example, one were interested in knowing the residential building
classes associated with `GRC_3514508`, as per `aggregated_source_id=1` (i.e., ESRM20), the
following query could be run:

```
gde_tiles=> SELECT building_class_name, settlement_type, occupancy_subtype, proportions FROM data_units_buildings WHERE data_unit_id='GRC_3514508' AND occupancy_case='residential' AND aggregated_source_id=1;

        building_class_name         | settlement_type | occupancy_subtype |      proportions       
------------------------------------+-----------------+-------------------+------------------------
 CR/LDUAL+CDH+LFC:15.0/H:1          | urban           | ALL               |  0.0014801545326146078
 CR/LDUAL+CDH+LFC:15.0/H:2          | urban           | ALL               |  0.0023115539626318814
 CR/LDUAL+CDH+LFC:15.0/H:2/SOS      | urban           | ALL               |  0.0017060083401791966
 CR/LDUAL+CDH+LFC:15.0/HBET:3-5     | urban           | ALL               |   0.014476105111235434
 CR/LDUAL+CDH+LFC:15.0/HBET:3-5/SOS | urban           | ALL               |   0.007514762230467308
 ... (continues)
```

It is possible to check that all these proportions add up to unity by doing:

```
gde_tiles=> SELECT SUM(proportions) FROM data_units_buildings WHERE data_unit_id='GRC_3514508' AND occupancy_case='residential' AND aggregated_source_id=1;

        sum         
--------------------
 1.0000000000000004
(1 row)
```

## Census people and total replacement cost per building for a specific building class

Taking one of the building classes from the output to the query above, it is possible to
retrieve the census people and total replacement cost per building by doing:

```
gde_tiles=> SELECT census_people_per_building, total_cost_per_building FROM data_units_buildings WHERE building_class_name='CR/LDUAL+CDH+LFC:15.0/HBET:3-5' AND settlement_type='urban' AND occupancy_subtype='ALL' AND occupancy_case='residential' AND data_unit_id='GRC_3514508' AND aggregated_source_id=1;
 census_people_per_building | total_cost_per_building 
----------------------------+-------------------------
          7.905868678536067 |      303187.50000000006
(1 row)
```

Note that not specifying the data unit ID would lead to more than one entry being returned, as
in this other example:

```
gde_tiles=> SELECT data_unit_id, census_people_per_building, total_cost_per_building FROM data_units_buildings WHERE building_class_name='CR/LDUAL+CDH+LFC:15.0/HBET:3-5' AND settlement_type='urban' AND occupancy_subtype='ALL' AND occupancy_case='residential' AND aggregated_source_id=1;

 data_unit_id | census_people_per_building | total_cost_per_building 
--------------+----------------------------+-------------------------
 GRC_1120703  |          5.482850339082017 |                303187.5
 GRC_2312405  |         10.349432913301737 |                303187.5
 GRC_1120709  |          9.110088642942177 |                303187.5
 GRC_1121301  |          7.159655217902061 |      303187.50000000006
 GRC_2322901  |          7.683854928944831 |      303187.50000000006
 GRC_2312403  |          4.688827891144585 |                303187.5
 ... (continues)
```

## People at different times of the day

If for the building class queried above it is desired to distribute the census people onto
different times of the day, one should first retrieve the respective coefficients for the
corresponding exposure entity (`GRC`), occupancy case (`residential`) and aggregated source ID
(`1`):

```
gde_tiles=> SELECT day, night, transit FROM exposure_entities_population_time_distribution WHERE exposure_entity='GRC' AND occupancy_case='residential' AND aggregated_source_id=1;

    day    |  night   | transit  
-----------+----------+----------
 0.2302575 | 0.952945 | 0.527497
(1 row)
```

Then, the number of people in the building at each time of the day is calculated as:
- day time: 0.2302575 x 7.91 = 1.82
- night time: 0.952945 x 7.91 = 7.54
- transit time: 0.527497 x 7.91 = 4.17

## Disaggregation of replacement costs

If for the building class queried above it is desired to disaggregate the total replacement cost
of one building into structural components, non-structural components and contents, one should
first retrieve the respective coefficients for the corresponding exposure entity (`GRC`),
occupancy case (`residential`) and aggregated source ID (`1`):

```
gde_tiles=> SELECT structural, non_structural, contents, currency FROM exposure_entities_costs_assumptions WHERE exposure_entity='GRC' AND occupancy_case='residential' AND aggregated_source_id=1;
 structural | non_structural | contents | currency 
------------+----------------+----------+----------
        0.3 |            0.5 |      0.2 | EUR 2020
(1 row)
```

Then the disaggregated replacement costs are calculated as:
- structural components: 0.3 x 303,187.5 = 90,956.25
- non-structural components: 0.5 x 303,187.5 = 151,593.75
- contents: 0.2 x 303,187.5 = 60,637.5

As indicated in the output from the query, these values correspond to euros of the year 2020.

## Building classes associated with an OBM building (defined by its OSM ID)

In order to retrieve the building classes associated with an OBM building one can query the
`gde_buildings` table by `osm_id` and `aggregated_source_id`, as shown in the example below. The
query is split into three to facilitate the visualisation of the results. The actual OSM ID that
this query corresponds to is anonymised as XXXXXXXXX.

Querying first just for building class names and their probabilities:

```
gde_tiles=> SELECT building_class_names, probabilities FROM gde_buildings WHERE osm_id=XXXXXXXXX AND aggregated_source_id=1;

                                                   building_class_names                                                    |     probabilities     
---------------------------------------------------------------------------------------------------------------------------+-----------------------
 {CR/LDUAL+CDH+LFC:15.0/HBET:6-,CR/LDUAL+CDM+LFC:12.0/HBET:6-,CR/LFINF+CDH+LFC:15.0/HBET:6-,CR/LFINF+CDM+LFC:12.0/HBET:6-} | {0.25,0.25,0.25,0.25}
(1 row)
```

Querying then for their settlement types and occupancy sub-types it is noted that all of the
above are associated with "all" settlement types and the "Hotels" occupancy subtype:

```
gde_tiles=> SELECT settlement_types, occupancy_subtypes FROM gde_buildings WHERE osm_id=XXXXXXXXX AND aggregated_source_id=1;

 settlement_types  |      occupancy_subtypes       
-------------------+-------------------------------
 {all,all,all,all} | {Hotels,Hotels,Hotels,Hotels}
(1 row)
```

Additionaly, one can know the ID of the data unit and the occupancy case this building belongs
to:

```
gde_tiles=> SELECT data_unit_id, occupancy_case FROM gde_buildings WHERE osm_id=XXXXXXXXX AND aggregated_source_id=1;
 data_unit_id | occupancy_case 
--------------+----------------
 GRC_4626901  | commercial
(1 row)
```

Querying the
[OBM buildings](https://git.gfz-potsdam.de/dynamicexposure/openbuildingmap/database-obmbuildings)
database:

```
obm_buildings=> SELECT storeys, occupancy FROM obm_buildings WHERE osm_id=XXXXXXXXX;

 storeys | occupancy 
---------+-----------
       7 | RES3
(1 row)
```

As can be observed, only building classes associated with the occupancy type `RES3` (i.e.
hotels) and compatible with 7 storeys (i.e. `HBET:6-`) have been assigned to this building by
`gde-core`.