Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rabotnik-rules
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Global Dynamic Exposure
rabotnik
rabotnik-rules
Merge requests
!14
Resolve "Add height from GHSL characteristics"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Add height from GHSL characteristics"
18-add-height-from-ghsl-characteristics
into
main
Overview
13
Commits
1
Pipelines
9
Changes
5
Merged
Laurens Oostwegel
requested to merge
18-add-height-from-ghsl-characteristics
into
main
8 months ago
Overview
8
Commits
1
Pipelines
9
Changes
5
Expand
Closes
#18 (closed)
\approve
@ds
@pdlmora
0
0
Merge request reports
Viewing commit
87e61f0b
Show latest version
5 files
+
164
−
3
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
87e61f0b
Add height from the GHSL characteristics type
· 87e61f0b
Laurens Oostwegel
authored
8 months ago
building/01_select/ghsl_characteristics_information/ghsl_characteristics_information.py
0 → 100644
+
64
−
0
Options
#!/usr/bin/env python3
# Copyright (c) 2024:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
class
GHSLCharacteristicsInformation
:
def
__call__
(
self
,
database
,
geometry_wkt
,
*
args
,
**
kwargs
):
"""
Intersect the building geometry with the GHSL characteristics layer and return the type
with the most overlap.
Args:
database (PostGISDatabase):
GHSL source database.
geometry_wkt (string):
The WKT representation of the geometry of the building.
Returns:
A dictionary with the most overlapping GHSL characteristics type.
"""
# Get the total area of the intersection between a GHSL type and the building.
get_area_function
=
f
"""
SUM(
ST_Area(
ST_Intersection(geom, ST_Buffer(ST_GeomFromText(
'
{
geometry_wkt
}
'
, 4326),0)
), True)
) AS area
"""
# Select the type with the largest overlap with the building.
sql_statement
=
f
"""
SELECT type
FROM (
SELECT type,
{
get_area_function
}
FROM ghsl_characteristics
WHERE geom && ST_GeomFromText(
'
{
geometry_wkt
}
'
, 4326)
GROUP BY type
) AS ghsl_area
ORDER BY area DESC
LIMIT 1
"""
database
.
cursor
.
execute
(
sql_statement
)
result
=
database
.
cursor
.
fetchone
()
if
result
:
return
{
"
ghsl_characteristics_type
"
:
result
[
0
]}
else
:
return
{
"
ghsl_characteristics_type
"
:
None
}
Loading