|
|
@@ -2,20 +2,16 @@
|
|
|
|
|
|
@author: olivier.massot, 2018
|
|
|
'''
|
|
|
-from osgeo import ogr
|
|
|
-
|
|
|
-from core import mn
|
|
|
-from core.gis_ import Feature
|
|
|
from core.validation import NetgeoValidator, RelationError, \
|
|
|
DuplicatedGeom, MissingItem, DimensionError, TechnicalValidationError, \
|
|
|
- InvalidGeometry, UniqueError, PositionError
|
|
|
+ InvalidGeometry, UniqueError
|
|
|
from schemas.common import TOLERANCE
|
|
|
-from schemas.netgeo_1_12_doe.models import Artere, Cable, Equipement, Noeud, \
|
|
|
+from schemas.mn1_rec.models import Artere, Cable, Equipement, Noeud, \
|
|
|
Tranchee, Zapbo
|
|
|
|
|
|
|
|
|
-class Netgeo112DoeValidator(NetgeoValidator):
|
|
|
- schema_name = "Netgeo v1.12 DOE"
|
|
|
+class Mn1RecValidator(NetgeoValidator):
|
|
|
+ schema_name = "Mn1 REC"
|
|
|
models = [Artere, Cable, Equipement, Noeud, Tranchee, Zapbo]
|
|
|
|
|
|
def _technical_validation(self):
|
|
|
@@ -212,53 +208,6 @@ class Netgeo112DoeValidator(NetgeoValidator):
|
|
|
except (TypeError, ValueError):
|
|
|
pass
|
|
|
|
|
|
- ant_db = mn.ANTDb_0()
|
|
|
- ant_db.execute("alter session set NLS_NUMERIC_CHARACTERS = '.,';") # definit le separateur decimal sur '.'
|
|
|
-
|
|
|
- # Toutes les zapbo contiennent au moins une prise
|
|
|
- for zapbo in zapbos.values():
|
|
|
-
|
|
|
- if len(zapbo.points) >= 499:
|
|
|
- # passe l'erreur provoquée par la limite au nombre d'arguments en SQL
|
|
|
- zapbo.nb_prises = None
|
|
|
- continue
|
|
|
-
|
|
|
- sql = """Select SUM(NB_PRISE) AS NB_PRISES FROM SIG_ANT.FTTH_MN_PRISE_LOT z
|
|
|
- WHERE SDO_INSIDE(z.GEOMETRY,
|
|
|
- SDO_GEOMETRY(2003, 3949, SDO_POINT_TYPE(null,null,null), SDO_ELEM_INFO_ARRAY(1,1003,1), SDO_ORDINATE_ARRAY({}))
|
|
|
- )='TRUE';""".format(", ".join(["{},{}".format(p.GetX(), p.GetY()) for p in zapbo.points]))
|
|
|
- nb_prises = ant_db.first(sql).NB_PRISES
|
|
|
- zapbo.nb_prises = int(nb_prises) if nb_prises is not None else 0
|
|
|
-
|
|
|
- if not zapbo.nb_prises:
|
|
|
- self.log_error(MissingItem("La Zapbo ne contient aucune prise: {}".format(zapbo), filename=Zapbo.filename, field="-"))
|
|
|
-
|
|
|
-
|
|
|
- # Toutes les prises de la ou les ZAPM impactées sont dans une zapbo
|
|
|
- zapms = {}
|
|
|
- # > on déduit la liste des zapms à partir de la position des zapbos
|
|
|
- for zapbo in zapbos.values():
|
|
|
- centre = zapbo.geom.Centroid()
|
|
|
- zapm = ant_db.first("""SELECT z.ID_ZAPM
|
|
|
- FROM SIG_ANT.FTTH_MN_ZAPM z
|
|
|
- WHERE sdo_contains(z.GEOMETRY,
|
|
|
- SDO_GEOMETRY(2001, 3949, SDO_POINT_TYPE({}, {}, NULL), NULL, NULL)) = 'TRUE'
|
|
|
- """.format(centre.GetX(), centre.GetY()))
|
|
|
- try:
|
|
|
- zapms[zapm.ID_ZAPM].append(zapbo)
|
|
|
- except KeyError:
|
|
|
- zapms[zapm.ID_ZAPM] = [zapbo]
|
|
|
-
|
|
|
- for id_zapm in zapms:
|
|
|
- zapm_couverture = Feature.union(zapms[id_zapm])
|
|
|
- for prise in ant_db.read("""SELECT t.X AS x, t.Y AS y
|
|
|
- FROM SIG_ANT.FTTH_MN_PRISE_LOT z,
|
|
|
- TABLE(SDO_UTIL.GETVERTICES(z.GEOMETRY)) t
|
|
|
- WHERE T_ETAT<>'OBSOLETE' AND ID_ZAPM_PARTIELLE='{}';""".format(id_zapm)):
|
|
|
- point = ogr.Geometry(ogr.wkbPoint)
|
|
|
- point.AddPoint(prise.x, prise.y)
|
|
|
- if not zapm_couverture.Contains(point):
|
|
|
- self.log_error(MissingItem("Certaines prises de la ZAPM ne sont pas comprises dans une ZAPBO: {}".format(id_zapm), filename=Zapbo.filename, field="-"))
|
|
|
|
|
|
# Verifier que chaque equipement de type PBO est contenu dans une zapbo, et que le nom de la zapbo contient le nom de l'equipement
|
|
|
|
|
|
@@ -300,39 +249,7 @@ class Netgeo112DoeValidator(NetgeoValidator):
|
|
|
if equipement.EQ_STATUT == "REC" and not equipement.zapbo.STATUT == "REC" and not equipement.zapbo.ID_ZAPBO[:4].lower() == "att_":
|
|
|
self.log_error(TechnicalValidationError("Le statut du PBO n'est pas cohérent avec le statut de sa ZAPBO: {}".format(equipement), filename=Equipement.filename, field="-"))
|
|
|
|
|
|
- # Contrôler dans la base si des éléments portant ces codes existent à des emplacements différents
|
|
|
- for noeud in noeuds.values():
|
|
|
- sql = """SELECT z.NO_NOM, SDO_GEOM.SDO_DISTANCE(z.GEOMETRY, SDO_GEOMETRY(2001, 3949, SDO_POINT_TYPE({}, {}, NULL), NULL, NULL),0.005) AS DIST
|
|
|
- FROM SIG_ANT.FTTH_MN_GR_NOEUD_GEO z
|
|
|
- WHERE z.NO_NOM='{}';""".format(noeud.geom.GetX(), noeud.geom.GetY(), noeud.NO_NOM)
|
|
|
- existing = ant_db.first(sql)
|
|
|
- if existing:
|
|
|
- if existing.DIST > TOLERANCE and existing.DIST < 20:
|
|
|
- self.log_error(PositionError("La position du noeud ne correspond pas à l'existant: {}".format(noeud), filename=Noeud.filename, field="geom"))
|
|
|
- elif existing.DIST > 20:
|
|
|
- self.log_error(DuplicatedGeom("Un noeud portant ce nom existe déjà ailleurs sur le territoire: {}".format(noeud), filename=Noeud.filename, field="NO_NOM"))
|
|
|
-
|
|
|
- for zapbo in zapbos.values():
|
|
|
- sql = """SELECT z.ID_ZAPBO, SDO_GEOM.SDO_DISTANCE(SDO_GEOM.SDO_CENTROID(z.GEOMETRY,0.005), SDO_GEOMETRY(2001, 3949, SDO_POINT_TYPE({}, {}, NULL), NULL, NULL),0.005) AS DIST
|
|
|
- FROM SIG_ANT.FTTH_MN_GR_ZAPBO_GEO z
|
|
|
- WHERE z.ID_ZAPBO='{}';""".format(zapbo.geom.Centroid().GetX(), zapbo.geom.Centroid().GetY(), zapbo.ID_ZAPBO)
|
|
|
- existing = ant_db.first(sql)
|
|
|
- if existing:
|
|
|
- if existing.DIST > TOLERANCE and existing.DIST < 20:
|
|
|
- self.log_error(PositionError("La position de la ZAPBO ne correspond pas à l'existant: {}".format(zapbo), filename=Zapbo.filename, field="geom"))
|
|
|
- elif existing.DIST > 20:
|
|
|
- self.log_error(DuplicatedGeom("Une ZAPBO portant ce nom existe déjà ailleurs sur le territoire: {}".format(zapbo), filename=Zapbo.filename, field="ID_ZAPBO"))
|
|
|
|
|
|
- # Contrôle si un equipement portant ce nom existe, mais associé à un noeud différent
|
|
|
- for equipement in equipements.values():
|
|
|
- sql = """SELECT z.EQ_NOM, z.EQ_NOM_NOEUD
|
|
|
- FROM SIG_ANT.FTTH_MN_GR_EQ_PASSIF z
|
|
|
- WHERE z.EQ_NOM='{}';""".format(equipement.EQ_NOM)
|
|
|
- existing = ant_db.first(sql)
|
|
|
- if existing and existing.EQ_NOM_NOEUD != equipement.EQ_NOM_NOE:
|
|
|
- self.log_error(DuplicatedGeom("Un équipement portant ce nom ({}) existe déjà et est associé à un noeud différent ({})".format(equipement.NO_NOM, existing.EQ_NOM_NOEUD), filename=Noeud.filename, field="geom"))
|
|
|
-
|
|
|
-
|
|
|
if __name__ == "__main__":
|
|
|
from core.constants import MAIN
|
|
|
subject = MAIN / "work" / "SOGETREL_026AP0_REC_181001_OK"
|