gis
Database
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
calcul_num_adr
Parameters
Name
Type
Mode
pgeom
USER-DEFINED
IN
num
integer
OUT
suffixe
text
OUT
voie
integer
OUT
Definition
DECLARE numa integer; numb integer; numc integer; sens boolean; s text; rec text; suff text[]; idvoie integer; isleft boolean; test boolean; BEGIN -- Get idvoie SELECT adresse.get_id_voie(pgeom) into idvoie; -- Aucune voie dévérouillée trouvée IF idvoie IS NULL THEN return query SELECT numc, s, idvoie; END IF; SELECT adresse.calcul_point_position(adresse.calcul_segment_proche(geom, pgeom),pgeom ) into isleft FROM adresse.voie WHERE statut_voie_num IS FALSE AND id_voie=idvoie; SELECT v.sens_numerotation into sens FROM adresse.voie v WHERE v.id_voie = idvoie; SELECT numero into numa FROM( SELECT ST_Distance(pgeom, p1.geom) as dist, p1.numero as numero FROM adresse.point_adresse p1, adresse.voie v WHERE statut_voie_num IS FALSE AND p1.id_voie = idvoie AND v.id_voie = idvoie AND (ST_LineLocatePoint(v.geom, ST_ClosestPoint(v.geom, pgeom)) - ST_LineLocatePoint(v.geom, ST_ClosestPoint(v.geom, p1.geom))) >0 AND isleft = adresse.calcul_point_position(adresse.calcul_segment_proche(v.geom, p1.geom), p1.geom) ORDER BY dist LIMIT 1) AS a; suff = ARRAY ['bis', 'ter', 'qua', 'qui', 'a', 'b', 'c', 'd', 'e']; SELECT numero into numb FROM( SELECT ST_Distance(pgeom, p1.geom) as dist, p1.numero as numero FROM adresse.point_adresse p1, adresse.voie v WHERE statut_voie_num IS FALSE AND p1.id_voie = idvoie AND v.id_voie = idvoie AND (ST_LineLocatePoint(v.geom, ST_ClosestPoint(v.geom, pgeom)) - ST_LineLocatePoint(v.geom, ST_ClosestPoint(v.geom, p1.geom))) <0 AND isleft = adresse.calcul_point_position(adresse.calcul_segment_proche(v.geom, p1.geom), p1.geom) ORDER BY dist LIMIT 1) AS b; IF numa IS NOT NULL AND numb IS NOT NULL THEN test = false; IF numb - numa > 2 THEN numc = numa+2; ELSE FOREACH rec IN ARRAY suff LOOP IF (SELECT TRUE FROM adresse.point_adresse p WHERE p.id_voie = idvoie AND p.numero = numa AND p.suffixe = rec) IS NULL AND NOT test THEN test = true; numc = numa; s = rec; END IF; END LOOP; END IF; ELSIF numa IS NOT NULL AND numb IS NULL THEN numc = numa+2; ELSIF numa IS NULL AND numb IS NOT NULL THEN IF numb - 2 >0 THEN numc = numb - 2; ELSIF numb - 2 <= 0 THEN test = false; FOREACH rec IN ARRAY suff LOOP IF (SELECT TRUE FROM adresse.point_adresse p WHERE p.id_voie = idvoie AND p.numero = numb AND p.suffixe = rec) IS NULL AND NOT test THEN test = true; numc = numb; s = rec; END IF; END LOOP; END IF; ELSIF numa IS NULL AND numb IS NULL THEN IF isleft AND NOT sens THEN numc = 1; ELSIF NOT isleft AND NOT sens THEN numc = 2; ELSIF isleft AND sens THEN numc = 2; ELSIF NOT isleft AND sens THEN numc = 1; END IF; END IF; return query SELECT numc, s, idvoie; END;