Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bano v3 #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
334 changes: 155 additions & 179 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,210 +58,186 @@ Stylesheet:
- style.mss

Layer:
# points d'adresses BAN
- id: ban
name: ban
status: off
- id: adresses
name: adresses
<<: *extents84
Datasource:
<<: *banodb
table: >-
(
SELECT b.geometrie,
b.nom_voie,
b.numero::numeric as numero,
trim(b.numero||' '||coalesce(b.rep,'')) as num,
coalesce(v.fantoir,'') as fantoir
FROM ban_odbl b
LEFT JOIN cumul_voies v ON (v.insee_com=b.code_insee
AND v.fantoir LIKE
b.code_insee||SUBSTRING(UPPER(b.id_fantoir)||'xxxxxxxxxx',7,4)||'%')
) as ban
SELECT COALESCE(r.nom,o.nom_voie,o.nom_place,b.nom_voie,b.nom_place) as nom,
COALESCE(o.fantoir,b.fantoir,null) as fantoir,
COALESCE(o.numero,b.numero) as numero,
COALESCE(o.geometrie,b.geometrie) as geometrie,
COALESCE(s.id_statut,0) as id_statut,
COALESCE(o.short_source,b.short_source)||
CASE
WHEN o.short_source IS NULL AND NOT r.rapproche THEN 'oo'
WHEN b.short_source IS NOT NULL AND r.rapproche AND o.numero IS NULL THEN 'Oo'
WHEN o.short_source IS NOT NULL AND r.rapproche AND b.numero IS NOT NULL THEN 'FB'
WHEN o.short_source IS NOT NULL AND r.rapproche AND b.numero IS NULL THEN 'Fb'
ELSE 'xx'
END AS cat
FROM (SELECT *,
'B' AS short_source,
TRANSLATE(UPPER(numero),' ','') AS uppernumero
FROM bano_adresses
WHERE source = 'BAN') b
FULL OUTER JOIN (SELECT *,
'O' AS short_source,
TRANSLATE(UPPER(numero),' ','') AS uppernumero
FROM bano_adresses
WHERE source = 'OSM') o
USING (fantoir,uppernumero)
LEFT OUTER JOIN (SELECT uppernumero,fantoir,source,id_statut
FROM (SELECT *,
TRANSLATE(UPPER(numero),' ','') AS uppernumero,
RANK() OVER (PARTITION BY numero,fantoir,source ORDER BY timestamp_statut DESC) rang
FROM statut_numero
) r
WHERE rang = 1) s
USING (uppernumero,fantoir)
LEFT OUTER JOIN (SELECT DISTINCT fantoir,
nom,
1::boolean AS rapproche
FROM nom_fantoir
WHERE source = 'OSM') r
USING (fantoir)
) as adresses
geometry_field: geometrie

- id: addr
name: addr
- id: polygones
name: polygones
<<: *extents84
Datasource:
<<: *banodb
table: >-
(
SELECT
geometrie,
left(source,3) as source,
numero,
SUBSTRING(COALESCE(voie_osm,''),1,1) AS voie_o,
SUBSTRING(fantoir,1,1) as fant
FROM cumul_adresses
WHERE source != 'CADASTRE'
AND (substring(fantoir,6,1)<='9' OR voie_osm != '')
ORDER BY voie_o desc, source
) as addr
geometry_field: geometrie

- id: addr_lz
name: addr_lz
status: off
<<: *extents84
Datasource:
<<: *banodb
table: >-
(
SELECT
co.geometrie,
co.insee_com AS insee,
nom_com,
format_cadastre,
sum(case when source='OSM' then 1 else 0 end) as osm,
sum(case when source='BAN' then 1 else 0 end) as cadastre,
100*(sum(case when source='OSM' then 1 else 0 end)+1)/(sum(case when source='BAN' then 1
else 0 end)+1) as pourcent
FROM infos_communes co
LEFT JOIN code_cadastre ca on (ca.insee_com = co.insee_com)
LEFT JOIN cumul_adresses cu on (cu.insee_com=co.insee_com)
GROUP BY co.insee_com, ca.nom_com, co.geometrie, format_cadastre
) as addr_lz
geometry_field: geometrie


- id: voie_nommee
<<: *extents84
Datasource:
<<: *bdtopo
table: >-
(
SELECT
r.geometrie,
regexp_replace(regexp_replace(regexp_replace(initcap(nom_minuscule),E' L(e |a |es |\x27)',' l\1','g'),E' D(e |u |es |\x27)',' d\1','g'),' A(|u|ux) ',' a\1 ','g') as nom,
r.qualite_passage_maj_min as qualite,
r.id_pseudo_fpb
FROM
bdtopo_voie_nommee r
WHERE
r.validite
) as troncon_de_route


- id: manque_ban
name: manque_ban
status: off
<<: *extents84
Datasource:
<<: *banodb
table: >-
(SELECT
st_buffer(st_convexhull(st_collect(b.geometrie)), 20 * !pixel_width!) as geom,
b.nom_voie,
coalesce(b.code_insee||SUBSTRING(UPPER(b.id_fantoir)||'xxxxxxxxxx',7,4)||f.cle_rivoli,'') as fant_voie,
b.code_insee,
count(*) as nb
FROM polygones_insee_geo c
JOIN ban_odbl b on (b.geometrie && c.geometrie and b.code_insee=c.insee_com)
LEFT JOIN cumul_voies v on (
v.insee_com=b.code_insee and
(v.fantoir LIKE b.code_insee||SUBSTRING(UPPER(b.id_fantoir)||'xxxxxxxxxx',7,4)||'%'
OR
v.voie_osm::text <-> b.nom_voie = 1))
LEFT JOIN fantoir_voie f on (f.code_insee = b.code_insee
AND f.fantoir = b.code_insee||SUBSTRING(UPPER(b.id_fantoir)||'xxxxxxxxxx',7,4))
WHERE
b.numero!='0'
AND b.nom_voie!=''
AND v.fantoir is null
AND c.geometrie && !bbox!
GROUP BY 2,3,4
) as manque_ban
geometry_field: geom

- id: manque
<<: *extents84
Datasource:
<<: *banodb
table: >-
(
SELECT st_buffer(st_convexhull(st_collect(cu.geometrie)), 20 * !pixel_width!) as geometrie,
cu.fantoir,
cu.voie_autre as voie_ban,
coalesce(cu.voie_osm,'') as voie_osm,
count(*) as nb,
replace(coalesce(b.source_nom_voie,cu.source),'inconnue','BAN') as source,
l.label_statut
FROM polygones_insee_geo co
JOIN cumul_adresses cu on (cu.insee_com=co.insee_com
and ((coalesce(cu.voie_osm,'')=''
and cu.source='BAN')
or (cu.fantoir=''
and cu.source='OSM')))
JOIN fantoir_voie f on (f.fantoir10=cu.fantoir and f.date_annul='0000000')
LEFT JOIN statut_fantoir s on (s.fantoir=cu.fantoir)
LEFT JOIN labels_statuts_fantoir l on (l.id_statut=s.id_statut)
LEFT JOIN ban_odbl b ON (b.code_insee=left(fantoir10,5) and id like format('%s_%s%%',left(fantoir10,5),substring(fantoir10,6,4)))
WHERE co.geometrie && !bbox!
AND substring(cu.fantoir,6,1) <= '9'
GROUP BY cu.fantoir, cu.voie_autre, cu.voie_osm, cu.source, l.label_statut, b.source_nom_voie
) as manque
WITH
fantoir
AS
(SELECT fantoir
FROM nom_fantoir
WHERE source = 'BAN'
EXCEPT
SELECT fantoir
FROM nom_fantoir
WHERE source = 'OSM'),
latest_statut
AS
(SELECT fantoir,
label_statut
FROM (SELECT *,
RANK() OVER(PARTITION BY fantoir ORDER BY timestamp_statut DESC,id_statut DESC) rang
FROM statut_fantoir)f
JOIN labels_statuts_fantoir
USING (id_statut)
WHERE rang = 1 AND
id_statut != 0)
SELECT CASE
WHEN SUBSTR(fantoir,6,1) = 'b' THEN ''
ELSE fantoir
END AS fantoir,
nom_voie,
label_statut,
count(*) as nb,
ST_Buffer(ST_Convexhull(ST_Collect(geometrie)),0.0001) as geometrie
FROM bano_adresses
JOIN fantoir
USING (fantoir)
LEFT OUTER JOIN latest_statut
USING (fantoir)
GROUP BY fantoir,nom_voie,label_statut
) as polygones
geometry_field: geometrie


- id: voies
name: voies
- id: points
name: points
<<: *extents84
Datasource:
<<: *banodb
table: >-
(
SELECT v.*
FROM cumul_voies v
LEFT JOIN cumul_adresses a on (a.fantoir=v.fantoir) where a.fantoir is null
) as voies
WITH
ban
AS
(SELECT DISTINCT fantoir
FROM nom_fantoir
WHERE source = 'BAN')
-- Lieux-dits non rapprochés
SELECT nom,
fantoir,
geometrie,
'Co'|| -- C = source Cadastre - o = inconnu d'OSM
CASE
WHEN ban.fantoir IS NULL THEN 'b'
ELSE 'B'
END ||
'P' -- lieu-dit
as cat
FROM (SELECT *
FROM bano_points_nommes
WHERE source = 'CADASTRE')c
LEFT OUTER JOIN (SELECT DISTINCT fantoir
FROM nom_fantoir
WHERE source = 'OSM')o
USING (fantoir)
LEFT OUTER JOIN ban
USING (fantoir)
WHERE o.fantoir IS NULL
UNION ALL
-- Voies & LD OSM
SELECT nom,
fantoir,
geometrie,
CASE
WHEN fantoir IS NULL THEN 'Of' -- O = source OSM - f = sans code Fantoir
ELSE 'OF' -- O = source OSM - F = avec code Fantoir
END ||
CASE
WHEN ban.fantoir IS NULL THEN 'b'
-- WHEN ban.fantoir IS NOT NULL AND nature = 'place' THEN 'B'
ELSE 'B'
END ||
CASE nature
WHEN 'place' THEN 'P'
ELSE 'V'
END as cat
FROM (SELECT *
FROM bano_points_nommes
WHERE nature IN ('place','centroide') AND
source = 'OSM') o
LEFT OUTER JOIN ban
USING (fantoir)
-- on exclut les rues rapprochées avec adresses
WHERE NOT (nature = 'centroide' AND ban.fantoir IS NOT NULL)
) as points
geometry_field: geometrie

- id: fantoir
name: fantoir
- id: commune
name: commune
<<: *extents84
Datasource:
<<: *banodb
table: >-
(
SELECT geometrie,
name as nom,
insee_com as insee,
count(*) as nb,
format_cadastre,
min(fantoir) as min_fantoir
SELECT
geometrie,
name,
code_insee,
count(*) as nb
FROM (
SELECT co.geometrie,
name,
co.insee_com,
format_cadastre,
fantoir
SELECT
co.geometrie,
co.name,
co.code_insee,
a.fantoir
FROM infos_communes co
LEFT JOIN cumul_adresses cu on (cu.insee_com=co.insee_com and source='BAN' and (coalesce(voie_osm,'')=''))
LEFT JOIN code_cadastre ca on (ca.insee_com=co.insee_com)
WHERE co.geometrie && !bbox!
AND substring(cu.fantoir,6,1) <= '9'
GROUP BY co.geometrie, name, co.insee_com, format_cadastre, fantoir
) as fantoir
GROUP BY geometrie, nom, insee, format_cadastre
) as f
geometry_field: geometrie


- id: lieuxdits
name: lieuxdits
<<: *extents84
Datasource:
<<: *banodb
table: >-
(
SELECT geometrie,
libelle_cadastre,
coalesce(libelle_osm,'') as libelle_osm,
fantoir,
ld_bati,
source
FROM cumul_places
ORDER BY source
) as place
LEFT JOIN bano_adresses a ON (a.code_insee=co.code_insee AND source='BAN')
LEFT JOIN bano_points_nommes pn ON (a.fantoir=pn.fantoir AND pn.source='OSM')
WHERE co.geometrie && !bbox! AND pn.fantoir IS NULL
GROUP BY co.geometrie, co.name, co.code_insee, a.fantoir
)
GROUP BY geometrie, name, code_insee
) as commune
geometry_field: geometrie

Loading