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

Pourvoir retrouver le nom OSM par défaut #419

Open
wants to merge 2 commits into
base: bano_v3
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
20 changes: 19 additions & 1 deletion bano/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Nom:
def __init__(
self,
nom,
nom_tag,
fantoir,
nature,
source,
Expand All @@ -26,6 +27,7 @@ def __init__(
self.code_dept = hp.get_code_dept_from_insee(code_insee)
self.code_insee_ancienne_commune = code_insee_ancienne_commune
self.nom = nom.replace("\t", " ")
self.nom_tag = nom_tag
self.nom_ancienne_commune = nom_ancienne_commune
self.fantoir = fantoir[0:9] if fantoir else None
self.nature = nature
Expand Down Expand Up @@ -64,7 +66,7 @@ def _as_csv_format_bano(self, correspondance):
fantoir = remplace_fantoir_ban(correspondance, self.niveau, self.fantoir)
else:
fantoir = self.fantoir
return f"{fantoir}\t{self.nom}\t{self.nature}\t{self.code_insee}\t{self.code_dept}\t{self.code_insee_ancienne_commune if self.code_insee_ancienne_commune else ''}\t{self.nom_ancienne_commune if self.nom_ancienne_commune else ''}\t{self.source}"
return f"{fantoir}\t{self.nom}\t{self.nom_tag}\t{self.nature}\t{self.code_insee}\t{self.code_dept}\t{self.code_insee_ancienne_commune if self.code_insee_ancienne_commune else ''}\t{self.nom_ancienne_commune if self.nom_ancienne_commune else ''}\t{self.source}"

def add_fantoir(self, topo):
if not self.fantoir:
Expand Down Expand Up @@ -104,6 +106,7 @@ def charge_noms_osm_hors_numeros(self):
for (
provenance,
name,
name_tag,
tags,
libelle_suffixe,
code_insee_ancienne_commune,
Expand All @@ -114,6 +117,7 @@ def charge_noms_osm_hors_numeros(self):
self.add_nom(
Nom(
name,
name_tag,
tags.get("ref:FR:FANTOIR"),
nature,
"OSM",
Expand All @@ -126,6 +130,7 @@ def charge_noms_osm_hors_numeros(self):
self.add_nom(
Nom(
name,
name_tag,
tags["ref:FR:FANTOIR"],
nature,
"OSM",
Expand Down Expand Up @@ -184,6 +189,7 @@ def enregistre(self, correspondance):
columns=(
"fantoir",
"nom",
"nom_tag",
"nature",
"code_insee",
"code_dept",
Expand Down Expand Up @@ -444,6 +450,7 @@ def noms_des_adresses(self, noms):
noms.add_nom(
Nom(
a.voie,
None,
a.fantoir,
"voie",
a.source,
Expand All @@ -456,6 +463,7 @@ def noms_des_adresses(self, noms):
noms.add_nom(
Nom(
a.place,
None,
a.fantoir,
"place",
a.source,
Expand Down Expand Up @@ -538,6 +546,7 @@ def __init__(
lon,
lat,
nom,
nom_tag,
fantoir=None,
code_insee_ancienne_commune=None,
nom_ancienne_commune=None,
Expand All @@ -549,6 +558,7 @@ def __init__(
self.lat = round(lat, 6)
self.nature = nature
self.nom = nom.replace("\t", " ")
self.nom_tag = nom_tag
self.nom_normalise = hp.normalize(nom)
self.fantoir = fantoir[0:9] if fantoir else None
self.code_insee_ancienne_commune = code_insee_ancienne_commune
Expand Down Expand Up @@ -609,6 +619,7 @@ def charge_points_nommes_lieux_dits_cadastre(self):
x,
y,
hp.format_toponyme(nom),
None,
code_insee_ancienne_commune=code_insee_ancienne_commune,
nom_ancienne_commune=nom_ancienne_commune,
)
Expand All @@ -623,6 +634,7 @@ def charge_points_nommes_centroides_osm(self):
x,
y,
nom,
nom_tag,
code_insee_ancienne_commune,
fantoir,
nom_ancienne_commune,
Expand All @@ -635,6 +647,7 @@ def charge_points_nommes_centroides_osm(self):
x,
y,
nom,
nom_tag,
code_insee_ancienne_commune=code_insee_ancienne_commune,
fantoir=fantoir,
nom_ancienne_commune=nom_ancienne_commune,
Expand All @@ -650,6 +663,7 @@ def charge_points_nommes_place_osm(self):
x,
y,
nom,
nom_tag,
code_insee_ancienne_commune,
fantoir,
nom_ancienne_commune,
Expand All @@ -662,6 +676,7 @@ def charge_points_nommes_place_osm(self):
x,
y,
nom,
nom_tag,
code_insee_ancienne_commune=code_insee_ancienne_commune,
fantoir=fantoir,
nom_ancienne_commune=nom_ancienne_commune,
Expand Down Expand Up @@ -689,6 +704,7 @@ def charge_points_nommes_numeros_ban(self):
x,
y,
nom,
None,
code_insee_ancienne_commune=code_insee_ancienne_commune,
fantoir=fantoir,
nom_ancienne_commune=nom_ancienne_commune,
Expand All @@ -704,6 +720,7 @@ def noms_des_points_nommes(self, noms):
noms.add_nom(
Nom(
a.nom,
None,
a.fantoir,
a.nature,
a.source,
Expand All @@ -716,6 +733,7 @@ def noms_des_points_nommes(self, noms):
noms.add_nom(
Nom(
a.nom,
a.nom_tag,
a.fantoir,
a.nature,
a.source,
Expand Down
31 changes: 24 additions & 7 deletions bano/sql/charge_noms_voies_lieux-dits_OSM.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
SELECT DISTINCT provenance,
name,
name_tag,
tags,
libelle_suffixe,
a9.code_insee,
a9.nom,
nature
FROM (SELECT 1::integer AS provenance,
pt.way,
UNNEST(ARRAY[pt.name,pt.tags->'alt_name',pt.tags->'old_name']) as name,
name_osm.name,
name_osm.name_tag,
tags,
CASE
WHEN pt.place='' THEN 'voie'::text
Expand All @@ -16,28 +18,43 @@ FROM (SELECT 1::integer AS provenance,
FROM (SELECT way FROM planet_osm_polygon WHERE "ref:INSEE" = '__code_insee__') p
JOIN (SELECT * FROM planet_osm_point WHERE ("ref:FR:FANTOIR" !='' OR place != '') AND name != '') pt
ON pt.way && p.way AND
ST_Intersects(pt.way, p.way)
ST_Intersects(pt.way, p.way),
UNNEST(
ARRAY [pt.name,pt.alt_name,pt.old_name],
ARRAY ['name','alt_name','old_name']
) AS name_osm(name,name_tag)
UNION ALL
SELECT 2,
l.way,
UNNEST(ARRAY[l.name,l.tags->'alt_name',l.tags->'old_name']) as name,
name_osm.name,
name_osm.name_tag,
tags,
'voie'
FROM (SELECT way FROM planet_osm_polygon WHERE "ref:INSEE" = '__code_insee__') p
JOIN (SELECT * FROM planet_osm_line WHERE highway != '' AND name != '') l
ON p.way && l.way AND ST_Contains(p.way, l.way)
ON p.way && l.way AND ST_Contains(p.way, l.way),
UNNEST(
ARRAY [l.name,l.alt_name,l.old_name],
ARRAY ['name','alt_name','old_name']
) AS name_osm(name,name_tag)
UNION ALL
SELECT 3,
pl.way,
UNNEST(ARRAY[pl.name,pl.tags->'alt_name',pl.tags->'old_name']) as name,
name_osm.name,
name_osm.name_tag,
tags,
'voie'
FROM (SELECT way FROM planet_osm_polygon WHERE "ref:INSEE" = '__code_insee__') p
JOIN (SELECT * FROM planet_osm_polygon WHERE (highway||"ref:FR:FANTOIR" != '' OR landuse = 'residential' OR amenity = 'parking') AND name != '') pl
ON pl.way && p.way AND
ST_Intersects(pl.way, p.way)) l
ST_Intersects(pl.way, p.way),
UNNEST(
ARRAY [pl.name,pl.alt_name,pl.old_name],
ARRAY ['name','alt_name','old_name']
) AS name_osm(name,name_tag)
) l
LEFT OUTER JOIN suffixe h
ON ST_Intersects(l.way, h.geometrie)
LEFT OUTER JOIN (SELECT * FROM polygones_insee_a9 where insee_a8 = '__code_insee__') a9
ON ST_Contains(a9.geometrie,way)
WHERE l.name IS NOT NULL;
WHERE l.name IS NOT NULL;
26 changes: 19 additions & 7 deletions bano/sql/charge_noms_voies_relation_OSM.sql
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
SELECT DISTINCT provenance,
name,
name_tag,
tags,
libelle_suffixe,
a9.code_insee,
a9.nom,
'voie'::text
FROM (SELECT 4::integer AS provenance,
UNNEST(ARRAY[l.name,l.tags->'alt_name',l.tags->'old_name']) as name,
name_osm.name,
name_osm.name_tag,
l.way,
r.tags
FROM (SELECT way FROM planet_osm_polygon WHERE "ref:INSEE" = '__code_insee__') p
JOIN (SELECT name,tags,osm_id,way FROM planet_osm_line WHERE highway != '' AND name != '') l
JOIN (SELECT name,alt_name,old_name,tags,osm_id,way FROM planet_osm_line WHERE highway != '' AND name != '') l
ON p.way && l.way AND ST_Contains(p.way, l.way)
JOIN planet_osm_rels r
ON r.osm_id = l.osm_id
ON r.osm_id = l.osm_id,
UNNEST(
ARRAY [l.name,l.alt_name,l.old_name],
ARRAY ['name','alt_name','old_name']
) AS name_osm(name,name_tag)
UNION ALL
SELECT 5,
UNNEST(ARRAY[l.name,l.tags->'alt_name',l.tags->'old_name']) as name,
name_osm.name,
name_osm.name_tag,
l.way,
r.tags
FROM (SELECT way FROM planet_osm_polygon WHERE "ref:INSEE" = '__code_insee__') p
JOIN (SELECT name,tags,osm_id,way FROM planet_osm_polygon WHERE highway != '' AND name != '') l
JOIN (SELECT name,alt_name,old_name,tags,osm_id,way FROM planet_osm_polygon WHERE highway != '' AND name != '') l
ON p.way && l.way AND ST_Contains(p.way, l.way)
JOIN planet_osm_rels r
ON r.osm_id = l.osm_id) l
ON r.osm_id = l.osm_id,
UNNEST(
ARRAY [l.name,l.alt_name,l.old_name],
ARRAY ['name','alt_name','old_name']
) AS name_osm(name,name_tag)
) l
LEFT OUTER JOIN (SELECT * FROM suffixe WHERE code_insee = '__code_insee__') h
ON ST_Intersects(way, h.geometrie)
LEFT OUTER JOIN (SELECT * FROM polygones_insee_a9 where insee_a8 = '__code_insee__') a9
ON ST_Contains(a9.geometrie,way)
WHERE l.name IS NOT NULL;
WHERE l.name IS NOT NULL;
1 change: 1 addition & 0 deletions bano/sql/charge_noms_voies_relation_bbox_OSM.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SELECT DISTINCT provenance,
name,
'name' AS name_tag,
tags,
libelle_suffixe,
a9.code_insee,
Expand Down
Loading