2 402
edições
(reusando Peter) |
|||
Linha 79: | Linha 79: | ||
from doc_UDF_using_a_table('optim.jurisdiction') t order by 1,2,3 | from doc_UDF_using_a_table('optim.jurisdiction') t order by 1,2,3 | ||
; | ; | ||
... | -- R1. Intervalos de CEP das cidades do Brasil | ||
create view optim.vw_jurisdiction76_postal_ranges AS | |||
select isolabel_ext, jurisd_local_id, osm_id, admin_level, name, | |||
('{'|| translate(info->>'postalCode_ranges', '[] ','{},') ||'}')::text[] as postal_ranges, | |||
('{'|| translate(regexp_replace(info->>'postalCode_ranges','\-\d+','','g'), '[] ','{},') ||'}')::int[] as cep5, | |||
(info->'area_km2')::int area_km2 | |||
from optim.jurisdiction | |||
where jurisd_base_id=76 | |||
order by 1 | |||
; | |||
select * from optim.vw_jurisdiction76_postal_ranges where cardinality(postal_ranges)>2; | |||
-- apenas BR-SP-SaoPaulo, BR-DF-Brasilia e BR-RJ-NovaIguacu | |||
-- avalia área por cep, para inferir quantos dígitos mais o CEP5 precisaria para chegar a 1m2 com AFAcode | |||
select *, round(area_km2::float/cep5s::float,2) as area_per_cep | |||
from ( | |||
select isolabel_ext, jurisd_local_id, osm_id, admin_level, name, cardinality(postal_ranges) as num_ceps, cep5, | |||
1 + (cep5[1][2] - cep5[1][1]) + case when cardinality(cep5)>2 then (cep5[2][2] - cep5[2][1]) else 0 end as cep5s, | |||
area_km2 | |||
from optim.vw_jurisdiction76_postal_ranges | |||
) t order by 10 desc, 1 | |||
; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
edições