diff --git a/docs/04_Processing_Logic.md b/docs/04_Processing_Logic.md index 61474dc1e842e5a835286ef893eae9139c8cf64f..97c0453ec4898df1d684a2505a0b4afafb1c80f8 100644 --- a/docs/04_Processing_Logic.md +++ b/docs/04_Processing_Logic.md @@ -236,22 +236,24 @@ exposure model onto the tiles). 2. **Retrieve completeness of data-unit tiles**: The completeness status of the data-unit tiles is retrieved from the `obm_built_area_assessments` table of the [OBM tiles database](https://git.gfz-potsdam.de/dynamicexposure/openbuildingmap/database-obmtiles) -(entries associated with `source_id=1`, whih corresponds to the Global Human Settlement Layer GHSL, -Corbane et al., 2018). As +(entries associated with `source_id=1` or `source_id=3`, depending on the country, whih +correspond to the Global Human Settlement Layer GHSL, Corbane et al., 2018). As [obmgapanalysis](https://git.gfz-potsdam.de/dynamicexposure/openbuildingmap/obmgapanalysis) does not create entries for tiles for which the built-up area is zero, if a quadkey does not -have an entry for `source_id=1`, it is assumed to be complete. If the entry exists, the -completeness status is retrieved from the database. The table below shows the interpretation of -the contents of `obm_built_area_assessments` depending on whether the GHS (`source_id=1`) and/or +have an entry for `source_id=1`/`source_id=3`, it is assumed to be complete. If the entry +exists, the completeness status is retrieved from the database. If the entry exists but the +value of completeness is NULL, it is assumed to be incomplete (GHS built-up area is non-zero but +OSM built-up area is zero). The table below shows the interpretation of the contents of +`obm_built_area_assessments` depending on whether the GHS (`source_id=1`/`source_id=3`) and/or the OSM (`source_id=0`) entries exist. -| GHS entry | OSM entry | Completeness | -| -------------- | -------------- | -------------------------------------- | -| Exists | Exists | Retrieve from source_id=1 | -| Exists | Does not exist | Retrieve from source_id=1 (incomplete) | -| Does not exist | Exists | OSM/0 --> infinity, assume complete | -| Does not exist | Does not exist | 0/0 --> undefined, assume complete | +| GHS entry | OSM entry | Completeness | +| -------------- | -------------- | ------------------------------------------- | +| Exists | Exists | Retrieve from source_id=1 or 3 | +| Exists | Does not exist | Retrieve from source_id=1 or 3 (incomplete) | +| Does not exist | Exists | OSM/0 --> infinity, assume complete | +| Does not exist | Does not exist | 0/0 --> undefined, assume complete | 3. **Calculate remainder buildings in data-unit tiles**: If the data-unit tile is complete, it is assigned zero remainder buildings (and, as a consequence, the total number of buildings is diff --git a/gdecore/database_queries.py b/gdecore/database_queries.py index 6bbe4eb8e9344f5d941dcddbb57e68d684d9322c..bf4ebcea16ceccba567e64752bd3384a04f7a52c 100644 --- a/gdecore/database_queries.py +++ b/gdecore/database_queries.py @@ -846,7 +846,12 @@ class DatabaseQueries: # If quadkey not found => GHSL built-up area is zero => treat as complete completeness_codes[i] = 1 elif len(exec_result) == 1: - completeness_codes[i] = exec_result[0][0] + if exec_result[0][0] is None: + # Quadkey found but completeness value is NULL => there are no OBM buildings + # but there is GHS built-up area => treat as incomplete + completeness_codes[i] = 0 + else: + completeness_codes[i] = exec_result[0][0] else: # More than one entries found, this is an error # This should not happen, as the database should not allow two entries with the # same primary key diff --git a/tests/data/test_database_set_up.sql b/tests/data/test_database_set_up.sql index 85851f86e6a0238dc6420e16dad03b48a210f61e..2e8bbac2c30efb850960c365e03bbf84020fd2b6 100644 --- a/tests/data/test_database_set_up.sql +++ b/tests/data/test_database_set_up.sql @@ -219,6 +219,8 @@ VALUES ('122010321033023130', 1, 0), ('122010321033023132', 1, 1), ('122010321033023121', 1, 0), ('122010321033023123', 1, 1); +INSERT INTO obm_built_area_assessments(quadkey, source_id) +VALUES ('122010321033023133', 1); CREATE TABLE gde_buildings ( diff --git a/tests/test_database_queries.py b/tests/test_database_queries.py index 76332737ebfeba8b88bdf00926be628c40043e3a..604b833482fe3871a746dedef08805f4e217d16b 100644 --- a/tests/test_database_queries.py +++ b/tests/test_database_queries.py @@ -399,9 +399,10 @@ def test_get_automatic_completeness_of_quadkeys(test_db): "122010321033023120", "122010321033023132", "999999999999999999", # will not be found -> return complete + "122010321033023133", # NULL completeness -> return incomplete ] - expected_completeness = [False, False, True, True] + expected_completeness = [False, False, True, True, False] returned_completeness = DatabaseQueries.get_automatic_completeness_of_quadkeys( quadkeys, config.database_completeness, "obm_built_area_assessments"