Skip to content

Commit

Permalink
Merge pull request #451 from landryb/fix/345
Browse files Browse the repository at this point in the history
correction de la recherche sur adresse avec des codes voies n'ayant pas l'identifiant majic (ccovoi)
  • Loading branch information
Gustry authored Aug 19, 2024
2 parents 9f6f595 + 0da1a56 commit efb9087
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 18 deletions.
6 changes: 3 additions & 3 deletions cadastre/dialogs/search_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def refreshAutocomplete(self, key):
def getFeaturesFromSqlQuery(self, layer, filterExpression=None, attributes='*', orderBy=None):
"""
Get data from a db table,
optionnally filtered by given expression
optionally filtered by given expression
and get corresponding QgsFeature objects
"""
QApplication.setOverrideCursor(Qt.WaitCursor)
Expand Down Expand Up @@ -855,10 +855,10 @@ def onSearchItemChoose(self, key, label, value):
QApplication.restoreOverrideCursor()
return None

# Set filter expression for parcell child data
# Set filter expression for parcelle child data
ckey = self.searchComboBoxes[key]['search']['parcelle_child']
if key == 'adresse':
filterExpression = "voie = '%s'" % value['voie']
filterExpression = "SUBSTR(voie, 1, 6) || SUBSTR(voie, 12, 4) = '%s%s'" % (value['voie'][0:6], value['voie'][11:])

if key == 'proprietaire':
filterExpression = "comptecommunal IN (%s)" % ', '.join(value['cc'])
Expand Down
4 changes: 4 additions & 0 deletions cadastre/scripts/plugin/edigeo_create_indexes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ DROP INDEX IF EXISTS idx_local00_parcelle;
CREATE INDEX idx_local00_parcelle ON local00 (parcelle);
DROP INDEX IF EXISTS idx_local00_voie;
CREATE INDEX idx_local00_voie ON local00 (voie);
DROP INDEX IF EXISTS idx_local00_voie_substr;
CREATE INDEX idx_local00_voie_substr ON local00 ((substr(voie, 1, 6) || substr(voie, 12, 4)));
DROP INDEX IF EXISTS idx_local10_local00;
CREATE INDEX idx_local10_local00 ON local10 (local00);
DROP INDEX IF EXISTS idx_local10_comptecommunal;
Expand All @@ -69,5 +71,7 @@ DROP INDEX IF EXISTS idx_pevtaxation_pev;
CREATE INDEX idx_pevtaxation_pev ON pevtaxation (pev);
DROP INDEX IF EXISTS idx_parcelle_voie;
CREATE INDEX idx_parcelle_voie ON parcelle (voie);
DROP INDEX IF EXISTS idx_parcelle_voie_substr;
CREATE INDEX idx_parcelle_voie_substr ON parcelle ((substr(voie, 1, 6) || substr(voie, 12, 4)));
DROP INDEX IF EXISTS idx_parcelle_comptecommunal;
CREATE INDEX idx_parcelle_comptecommunal ON parcelle (comptecommunal);
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ CREATE INDEX aa ON [PREFIXE]parcelle (parcelle );
CREATE INDEX bb ON [PREFIXE]parcelle (comptecommunal );
CREATE INDEX cc ON [PREFIXE]parcelle (ccocom );
CREATE INDEX dd ON [PREFIXE]parcelle (ccodep );
CREATE INDEX ee ON [PREFIXE]parcelle (voie );
CREATE INDEX ee ON [PREFIXE]parcelle ((SUBSTR(voie, 1, 6) || SUBSTR(voie, 12, 4)));
CREATE INDEX ff ON [PREFIXE]proprietaire (comptecommunal );
CREATE INDEX gg ON [PREFIXE]geo_parcelle (geo_parcelle );
CREATE INDEX hh ON [PREFIXE]commune (ccocom );
CREATE INDEX ii ON [PREFIXE]commune (ccodep );
CREATE INDEX jj ON [PREFIXE]voie (voie );
CREATE INDEX jj ON [PREFIXE]voie ((SUBSTR(voie, 1, 6) || SUBSTR(voie, 12, 4)));

INSERT INTO [PREFIXE]parcelle_info
SELECT gp.ogc_fid AS ogc_fid, gp.geo_parcelle, gp.idu AS idu, gp.tex AS tex, gp.geo_section AS geo_section,
Expand Down Expand Up @@ -89,7 +89,7 @@ LEFT OUTER JOIN [PREFIXE]parcelle p ON gp.geo_parcelle = p.parcelle
LEFT OUTER JOIN [PREFIXE]proprietaire pr ON p.comptecommunal = pr.comptecommunal
LEFT OUTER JOIN [PREFIXE]ccodro ON ccodro.ccodro = pr.ccodro
LEFT OUTER JOIN [PREFIXE]commune c ON p.ccocom = c.ccocom AND c.ccodep = p.ccodep
LEFT OUTER JOIN [PREFIXE]voie v ON v.voie = p.voie
LEFT OUTER JOIN [PREFIXE]voie v ON SUBSTR(p.voie, 1, 6) || SUBSTR(p.voie, 12, 4) = SUBSTR(v.voie, 1, 6) || SUBSTR(v.voie, 12, 4)
GROUP BY gp.geo_parcelle, gp.ogc_fid, gp.idu, gp.tex, gp.geo_section, gp.lot,
c.libcom, p.ccocom, gp.geom, p.dcntpa, v.libvoi, p.dnvoiri, v.natvoi,
p.comptecommunal, p.cconvo, p.voie, p.dvoilib, p.gurbpa, p.gparbat,
Expand All @@ -111,7 +111,7 @@ DROP INDEX jj;
ALTER TABLE [PREFIXE]parcelle_info ADD CONSTRAINT parcelle_info_pk PRIMARY KEY (ogc_fid);
CREATE INDEX parcelle_info_geom_idx ON [PREFIXE]parcelle_info USING gist (geom);
CREATE INDEX parcelle_info_geo_section_idx ON [PREFIXE]parcelle_info (geo_section);
CREATE INDEX parcelle_info_voie_idx ON [PREFIXE]parcelle_info (voie);
CREATE INDEX parcelle_info_voie_substr_idx ON [PREFIXE]parcelle_info ((substr(voie, 1, 6) || substr(voie, 12, 4)));
CREATE INDEX parcelle_info_comptecommunal_idx ON [PREFIXE]parcelle_info (comptecommunal);
CREATE INDEX parcelle_info_codecommune_idx ON [PREFIXE]parcelle_info (codecommune );
CREATE INDEX parcelle_info_geo_parcelle_idx ON [PREFIXE]parcelle_info (geo_parcelle );
Expand Down
2 changes: 2 additions & 0 deletions cadastre/scripts/plugin/edigeo_drop_indexes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ DROP INDEX IF EXISTS idx_proprietaire_proprietaire;
DROP INDEX IF EXISTS idx_proprietaire_comptecommunal;
DROP INDEX IF EXISTS idx_local00_parcelle;
DROP INDEX IF EXISTS idx_local00_voie;
DROP INDEX IF EXISTS idx_local00_voie_substr;
DROP INDEX IF EXISTS idx_local10_local00;
DROP INDEX IF EXISTS idx_local10_comptecommunal;
DROP INDEX IF EXISTS idx_pevexoneration_pev;
DROP INDEX IF EXISTS idx_pevtaxation_pev;
DROP INDEX IF EXISTS idx_parcelle_voie;
DROP INDEX IF EXISTS idx_parcelle_voie_substr;
DROP INDEX IF EXISTS idx_parcelle_comptecommunal;
DROP INDEX IF EXISTS idx_geo_unite_fonciere_id;
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ WITH infos AS (
INNER JOIN local00 l ON l.parcelle = p.parcelle
INNER JOIN local10 l10 ON l10.local00 = l.local00
INNER JOIN pev ON pev.local10 = l10.local10
LEFT JOIN voie v ON v.voie = l.voie
LEFT JOIN voie v ON SUBSTR(l.voie, 1, 6) || SUBSTR(l.voie, 12, 4) = SUBSTR(v.voie, 1, 6) || SUBSTR(v.voie, 12, 4)
LEFT JOIN pevtaxation pt ON pt.pev = pev.pev
LEFT JOIN pevexoneration px ON px.pev = pev.pev
LEFT JOIN "dteloc" ON l10.dteloc = dteloc.dteloc
Expand Down
5 changes: 3 additions & 2 deletions cadastre/templates/parcelle_info_locaux_detail.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ WITH infos AS (

-- adresse
ltrim(l.dnvoiri, '0') || l.dindic AS l_numero_voirie,
CASE WHEN v.libvoi IS NOT NULL THEN v.natvoi || v.libvoi ELSE p.cconvo || p.dvoilib END AS l_adresse,
CASE WHEN v.libvoi IS NOT NULL THEN v.natvoi || ' ' || v.libvoi ELSE p.cconvo || ' ' || p.dvoilib END AS l_adresse,

-- proprio et acte
string_agg((l10.ccodep || l10.ccocom || '-' ||l10.dnupro), '|') AS l10_compte_proprietaire,
Expand Down Expand Up @@ -66,7 +66,8 @@ WITH infos AS (
INNER JOIN local00 l ON l.parcelle = p.parcelle
INNER JOIN local10 l10 ON l10.local00 = l.local00
INNER JOIN pev ON pev.local10 = l10.local10
LEFT JOIN voie v ON v.voie = l.voie
LEFT JOIN voie v
ON SUBSTR(l.voie, 1, 6) || SUBSTR(l.voie, 12, 4) = SUBSTR(v.voie, 1, 6) || SUBSTR(v.voie, 12, 4)
LEFT JOIN pevtaxation pt ON pt.pev = pev.pev
LEFT JOIN pevexoneration px ON px.pev = pev.pev
LEFT JOIN "dteloc" ON l10.dteloc = dteloc.dteloc
Expand Down
4 changes: 2 additions & 2 deletions cadastre/templates/parcelle_info_parcelle_majic.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SELECT
coalesce(
CASE
WHEN v.libvoi IS NOT NULL THEN trim(ltrim(p.dnvoiri, '0') || ' ' || trim(coalesce(v.natvoi, '')) || ' ' || v.libvoi)
ELSE ltrim(p.cconvo, '0') || p.dvoilib
ELSE trim(ltrim(p.cconvo, '0') || ' ' || p.dvoilib)
END, '') ||
'</td></tr>' ||
'<tr><th>Urbaine</th> <td>' ||
Expand All @@ -39,7 +39,7 @@ LEFT OUTER JOIN geo_batiment b
LEFT OUTER JOIN commune c
ON p.ccocom = c.ccocom AND c.ccodep = p.ccodep
LEFT OUTER JOIN voie v
ON v.voie = p.voie
ON SUBSTR(p.voie, 1, 6) || SUBSTR(p.voie, 12, 4) = SUBSTR(v.voie, 1, 6) || SUBSTR(v.voie, 12, 4)
WHERE 2>1
AND parcelle = '%s'
GROUP BY p.ccosec, p.dnupla, c.libcom, p.jdatat, p.dcntpa,
Expand Down
5 changes: 3 additions & 2 deletions cadastre/templates/proprietes_baties_line.tpl.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SELECT
l.ccosec AS section, ltrim(l.dnupla, '0') AS ndeplan,
ltrim(l.dnvoiri, '0') || l.dindic AS ndevoirie,
CASE WHEN v.libvoi IS NOT NULL THEN v.natvoi || ' ' || v.libvoi ELSE p.cconvo || p.dvoilib END AS adresse,
CASE WHEN v.libvoi IS NOT NULL THEN v.natvoi || ' ' || v.libvoi ELSE p.cconvo || ' ' || p.dvoilib END AS adresse,
l.ccoriv AS coderivoli,
l.dnubat AS bat, l.descr AS ent, l.dniv AS niv, l.dpor AS ndeporte, substring(l.invar, 4, length(l.invar)) || ' ' || l.cleinvar AS numeroinvar,
pev.ccostb AS star, l10.ccoeva AS meval, pev.ccoaff AS af, l10.cconlc AS natloc, pev.dcapec AS cat,
Expand All @@ -16,7 +16,8 @@ $schema"parcelle" p
INNER JOIN $schema"local00" l ON l.parcelle = p.parcelle
INNER JOIN $schema"local10" l10 ON l10.local00 = l.local00
INNER JOIN $schema"pev" pev ON pev.local10 = l10.local10
LEFT OUTER JOIN $schema"voie" v ON v.voie = l.voie
LEFT OUTER JOIN $schema"voie" v
ON SUBSTR(l.voie, 1, 6) || SUBSTR(l.voie, 12, 4) = SUBSTR(v.voie, 1, 6) || SUBSTR(v.voie, 12, 4)
LEFT JOIN $schema"pevexoneration" px ON px.pev = pev.pev
LEFT JOIN $schema"pevtaxation" pt ON pt.pev = pev.pev
WHERE 2>1
Expand Down
13 changes: 9 additions & 4 deletions cadastre/templates/proprietes_non_baties_line.tpl.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SELECT
p.ccosec AS section, ltrim(p.dnupla, '0') AS ndeplan,
ltrim(p.dnvoiri, '0') || p.dindic AS ndevoirie,
CASE WHEN v.libvoi IS NOT NULL THEN v.natvoi || ' ' || v.libvoi ELSE p.cconvo || p.dvoilib END AS adresse,
CASE WHEN v.libvoi IS NOT NULL THEN v.natvoi || ' ' || v.libvoi ELSE p.cconvo || ' ' || p.dvoilib END AS adresse,
p.ccoriv AS coderivoli,
p.dparpi AS nparcprim, p.gparnf AS fpdp, s.ccostn AS star, s.ccosub AS suf, s.cgrnum || '/' || s.dsgrpf AS grssgr, s.dclssf AS cl, s.cnatsp AS natcult,
CASE WHEN length(Cast(s.dcntsf AS text)) > 4 THEN substring(Cast(s.dcntsf AS text), 0, length(Cast(s.dcntsf AS text))-3) ELSE '0' END AS ha_contenance,
Expand All @@ -12,10 +12,15 @@ s.drcsuba AS revenucadastral, se.ccolloc AS coll, se.gnexts AS natexo, se.jfinex
round(Cast(s.drcsuba * Cast(se.pexn / 100 AS numeric(10,2)) / 100 AS numeric) , 2) as fractionrcexo,
Cast(se.pexn / 100 AS numeric(10,2)) AS pourcentageexo, '' AS tc,
p.dreflf AS lff

FROM $schema"parcelle" p
INNER JOIN $schema"suf" s ON p.parcelle = s.parcelle
LEFT OUTER JOIN $schema"voie" v ON v.voie = p.voie
LEFT JOIN $schema"sufexoneration" se ON s.suf = se.suf
INNER JOIN $schema"suf" s
ON p.parcelle = s.parcelle
LEFT OUTER JOIN $schema"voie" v
ON SUBSTR(p.voie, 1, 6) || SUBSTR(p.voie, 12, 4) = SUBSTR(v.voie, 1, 6) || SUBSTR(v.voie, 12, 4)
LEFT JOIN $schema"sufexoneration" se
ON s.suf = se.suf

WHERE 2>1
$and
ORDER BY p.parcelle, s.suf

0 comments on commit efb9087

Please sign in to comment.