|
|
@@ -25,17 +25,16 @@ from core.sqlformatter import SqlFormatter
|
|
|
|
|
|
logger = logging.getLogger("qgis_sync_compactage")
|
|
|
logconf.start("qgis_sync_compactage", logging.DEBUG)
|
|
|
-debug = False
|
|
|
|
|
|
# # POUR TESTER, décommenter les lignes suivantes
|
|
|
##-----------------------------------------------
|
|
|
|
|
|
-ControlesDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\cg67Parc_data.mdb")
|
|
|
-CSigDb.server = "TR-POSTGIS-02"
|
|
|
-CSigDb.pwd = "Am5VOMkdFHU7WwrfVOs9"
|
|
|
-COMPACTAGE_DIR = Path(__file__).parent / "resources" / "test_qgis_sync_compactage"
|
|
|
-logger.handlers = [h for h in logger.handlers if (type(h) == logging.StreamHandler)]
|
|
|
-logger.warning("<<<<<<<<<<<<<< Mode TEST >>>>>>>>>>>>>>>>>")
|
|
|
+# ControlesDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\cg67Parc_data.mdb")
|
|
|
+# CSigDb.server = "TR-POSTGIS-02"
|
|
|
+# CSigDb.pwd = "Am5VOMkdFHU7WwrfVOs9"
|
|
|
+# COMPACTAGE_DIR = Path(__file__).parent / "resources" / "test_qgis_sync_compactage"
|
|
|
+# logger.handlers = [h for h in logger.handlers if (type(h) == logging.StreamHandler)]
|
|
|
+# logger.warning("<<<<<<<<<<<<<< Mode TEST >>>>>>>>>>>>>>>>>")
|
|
|
|
|
|
##-----------------------------------------------
|
|
|
|
|
|
@@ -48,8 +47,7 @@ csig_db = CSigDb(autocommit=False)
|
|
|
controles_db = ControlesDb(autocommit=False)
|
|
|
|
|
|
# Regex pour parser les noms de repertoires
|
|
|
-rx = re.compile(r"^(I_)?(\d{5,6})(-S?\d{1,2})?[\s_]?(.*)$") # tous
|
|
|
-rxi = re.compile(r"^(\d{5,6})(-S?\d{1,2})?[\s_]?(.*)$") # non importés
|
|
|
+rxi = re.compile(r"^(\d{5,6})([-_]S?\d*)?[\s_]?(.*)$") # non importés
|
|
|
|
|
|
a_importer = [subdir for subdir in COMPACTAGE_DIR.dirs() if rxi.search(subdir.name)]
|
|
|
|
|
|
@@ -71,9 +69,9 @@ for chantier_dir_path in a_importer:
|
|
|
chantier.dir_path = chantier_dir_path
|
|
|
|
|
|
logger.debug("> parse path")
|
|
|
- parsed = rx.search(chantier_dir_path.name)
|
|
|
- chantier.number = parsed.group(2)
|
|
|
- chantier.complement = parsed.group(3)
|
|
|
+ parsed = rxi.search(chantier_dir_path.name)
|
|
|
+ chantier.number = parsed.group(1)
|
|
|
+ chantier.complement = parsed.group(2).replace("_", "-") if parsed.group(2) else ""
|
|
|
logger.debug("> number: %s, compl: %s", chantier.number, chantier.complement)
|
|
|
|
|
|
# query for name in ControlesDb
|
|
|
@@ -83,7 +81,7 @@ for chantier_dir_path in a_importer:
|
|
|
ON tblChantiers.strCollectiviteId = tblCollectivites.strCollectiviteId
|
|
|
WHERE lngChantierId = {lngChantierId};""".format(lngChantierId=chantier.number))
|
|
|
|
|
|
- chantier.name = "{} {}".format(chantier.number, row.strNom)
|
|
|
+ chantier.name = "{}{} {}".format(chantier.number, chantier.complement, row.strNom)
|
|
|
logger.debug("> {}".format(chantier.name))
|
|
|
|
|
|
# importe le fichier shape dans une couche temp
|
|
|
@@ -114,12 +112,14 @@ for chantier_dir_path in a_importer:
|
|
|
logger.debug("> {}".format(point))
|
|
|
chantier.points.append(point)
|
|
|
|
|
|
+ del sf, sh_points
|
|
|
+
|
|
|
# compute the chantier's rect coordinates
|
|
|
logger.debug("Compute the chantier's rect coordinates")
|
|
|
- chantier.x0 = min([point.x for point in chantier.points]) - 10
|
|
|
- chantier.x1 = max([point.x for point in chantier.points]) + 10
|
|
|
- chantier.y0 = min([point.y for point in chantier.points]) - 10
|
|
|
- chantier.y1 = max([point.y for point in chantier.points]) + 10
|
|
|
+ chantier.x0 = min([point.x for point in chantier.points]) - 5
|
|
|
+ chantier.x1 = max([point.x for point in chantier.points]) + 5
|
|
|
+ chantier.y0 = min([point.y for point in chantier.points]) - 5
|
|
|
+ chantier.y1 = max([point.y for point in chantier.points]) + 5
|
|
|
logger.debug("> ({}, {}, {}, {})".format(chantier.x0, chantier.x1, chantier.y0, chantier.y1))
|
|
|
|
|
|
chantiers.append(chantier)
|
|
|
@@ -171,13 +171,14 @@ for chantier in chantiers:
|
|
|
# create the points
|
|
|
for point in chantier.points:
|
|
|
csig_db.execute("""INSERT INTO t_points_compactage(numero, nom, id_chantier, geom, archive)
|
|
|
- VALUES ({number}, '{name}', {chantier_id}, {geom}, {archive});
|
|
|
+ VALUES ({number}, '{name}', {chantier_id}, ST_GeomFromText('POINT({x} {y})', {srid}), False);
|
|
|
""".format(
|
|
|
number=point.number,
|
|
|
name=point.name,
|
|
|
chantier_id=chantier.pgid,
|
|
|
- geom="ST_GeomFromText('POINT({x} {y})', {srid})".format(x=point.x, y=point.y, srid=SRID),
|
|
|
- archive="FALSE"
|
|
|
+ x=point.x,
|
|
|
+ y=point.y,
|
|
|
+ srid=SRID
|
|
|
)
|
|
|
)
|
|
|
|
|
|
@@ -192,10 +193,11 @@ for chantier in chantiers:
|
|
|
except:
|
|
|
logger.error("Impossible de renommer le dossier")
|
|
|
|
|
|
- logger.info("Chantier importé")
|
|
|
+ logger.info("Le chantier %s a été importé", chantier.name)
|
|
|
|
|
|
-csig_db.close()
|
|
|
|
|
|
+csig_db.close()
|
|
|
+controles_db.close()
|
|
|
|
|
|
|
|
|
|