Skip to content

Commit 443a2bd

Browse files
committed
feat: improve intersection with aree idonee
1 parent fc3864a commit 443a2bd

2 files changed

Lines changed: 17 additions & 31 deletions

File tree

apps/pv_estimation/dbt/models/gold/pv_building_suitability.sql

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,22 @@ with buildings as (
2727
{% endif %}
2828
),
2929

30-
suitable_hits as (
30+
eligible as (
3131
select distinct b.building_id
3232
from buildings b
3333
join {{ ref('pv_aree_idonee') }} s on ST_Intersects(b.geometry, s.geometry)
34-
),
35-
36-
unsuitable_hits as (
37-
select distinct b.building_id
38-
from buildings b
39-
join {{ ref('pv_aree_non_idonee') }} u on ST_Intersects(b.geometry, u.geometry)
40-
),
41-
42-
direct_hits as (
43-
select distinct b.building_id
44-
from buildings b
45-
join {{ ref('pv_vincoli_diretti') }} cd on ST_Intersects(b.geometry, cd.geometry)
46-
),
47-
48-
indirect_hits as (
49-
select distinct b.building_id
50-
from buildings b
51-
join {{ ref('pv_vincoli_indiretti') }} ci on ST_Intersects(b.geometry, ci.geometry)
34+
where not exists (
35+
select 1 from {{ ref('pv_aree_non_idonee') }} u
36+
where ST_Intersects(b.geometry, u.geometry)
37+
)
38+
and not exists (
39+
select 1 from {{ ref('pv_vincoli_diretti') }} cd
40+
where ST_Intersects(b.geometry, cd.geometry)
41+
)
42+
and not exists (
43+
select 1 from {{ ref('pv_vincoli_indiretti') }} ci
44+
where ST_Intersects(b.geometry, ci.geometry)
45+
)
5246
)
5347

5448
select
@@ -61,11 +55,6 @@ select
6155
b.footprint_area_m2,
6256
b._sdc_extracted_at,
6357

64-
sh.building_id is not null as in_suitable_area,
65-
uh.building_id is not null as in_unsuitable_area,
66-
dh.building_id is not null as has_direct_constraint,
67-
ih.building_id is not null as has_indirect_constraint,
68-
6958
(
7059
jsonb_build_object(
7160
'type', 'Feature',
@@ -75,7 +64,4 @@ select
7564
)::text as geom_geojson
7665

7766
from buildings b
78-
left join suitable_hits sh on sh.building_id = b.building_id
79-
left join unsuitable_hits uh on uh.building_id = b.building_id
80-
left join direct_hits dh on dh.building_id = b.building_id
81-
left join indirect_hits ih on ih.building_id = b.building_id
67+
join eligible e on e.building_id = b.building_id

apps/pv_estimation/governance.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ sources:
256256
datasets.ds_dev_gold.pv_building_suitability:
257257
title: "PV Building Suitability - Trentino (Gold)"
258258
description: >
259-
Overture Maps buildings in Trentino enriched with PV suitability flags:
260-
whether the building falls within a suitable area (L.P. 4/2022),
261-
an unsuitable area (PUP invariants), or is affected by direct/indirect
259+
Overture Maps buildings in Trentino eligible for PV installation:
260+
located within a suitable area (L.P. 4/2022 Allegato B) and not
261+
intersecting unsuitable areas (PUP invariants) or direct/indirect
262262
heritage constraints.
263263
license: ODbL-1.0
264264
access_level: open

0 commit comments

Comments
 (0)