@@ -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
5448select
@@ -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' ,
7564 )::text as geom_geojson
7665
7766from 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
0 commit comments