Skip to content

Commit 4b925e8

Browse files
committed
chemin gpkg relatif
1 parent 7133c17 commit 4b925e8

1 file changed

Lines changed: 13 additions & 23 deletions

File tree

backend/oeasc/commands/refresh_ref_geo.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import click
2121
import geopandas as gpd
2222
import psycopg2.extras
23+
from flask import current_app
2324
from flask.cli import with_appcontext
2425
from shapely.geometry import MultiPolygon
2526
from shapely.wkt import dumps as wkt_dumps
@@ -32,24 +33,12 @@
3233
REQUIRED_REVISION = "a1b2c3d4e5f6"
3334

3435
# ---------------------------------------------------------------------------
35-
# Chemins des fichiers GPKG
36+
# Chemins des fichiers GPKG (relatifs à ROOT_DIR, cf. backend/app.py)
3637
# ---------------------------------------------------------------------------
37-
GPKG_CADASTRE = "/home/thibaut/appli/app_oeasc/data/ref_geo/cadastres.gpkg"
38-
GPKG_COMMUNES = "/home/thibaut/appli/app_oeasc/data/ref_geo/communes_aoa.gpkg"
39-
GPKG_DGD = "/home/thibaut/appli/app_oeasc/data/ref_geo/forets_dgd.gpkg"
4038

4139

42-
# GPKG_FORET_ONF = "/home/thibaut/appli/app_oeasc/data/ref_geo/forets_gestion_onf_aoa.gpkg"
43-
GPKG_FORET_ONF = (
44-
"/home/thibaut/appli/app_oeasc/data/ref_geo/forets_gestion_onf_aoa.gpkg"
45-
)
46-
# GPKG_PARCELLE_ONF = "/home/thibaut/appli/app_oeasc/data/ref_geo/parcelles_forets_onf.gpkg"
47-
GPKG_PARCELLE_ONF = (
48-
"/home/thibaut/appli/app_oeasc/data/ref_geo/parcelles_forets_onf_new.gpkg"
49-
)
50-
GPKG_UG_ONF = (
51-
"/home/thibaut/appli/app_oeasc/data/ref_geo/unites_gestion_forets_onf.gpkg"
52-
)
40+
def _gpkg_path(filename):
41+
return os.path.join(current_app.config["ROOT_DIR"], "data", "ref_geo", filename)
5342

5443

5544
# ---------------------------------------------------------------------------
@@ -530,7 +519,7 @@ def step_load_communes():
530519
LOG.info("Étape 4a : chargement des communes depuis communes_aoa.gpkg")
531520
print("Étape 4a : chargement des communes depuis communes_aoa.gpkg")
532521
oeasc_geom = _get_oeasc_geom()
533-
gdf = gpd.read_file(GPKG_COMMUNES)
522+
gdf = gpd.read_file(_gpkg_path("communes_aoa.gpkg"))
534523
gdf = _filter_by_oeasc(gdf, oeasc_geom)
535524
gdf_4326 = gdf.to_crs(epsg=4326)
536525
LOG.info(f" {len(gdf)} communes dans le périmètre OEASC")
@@ -629,7 +618,7 @@ def step_load_cadastres():
629618
LOG.info("Étape 4b : chargement des cadastres depuis cadastre_pec.gpkg")
630619
print("Étape 4b : chargement des cadastres depuis cadastre_pec.gpkg")
631620
oeasc_geom = _get_oeasc_geom()
632-
gdf = gpd.read_file(GPKG_CADASTRE)
621+
gdf = gpd.read_file(_gpkg_path("cadastres.gpkg"))
633622
gdf = _filter_by_oeasc(gdf, oeasc_geom)
634623
gdf_4326 = gdf.to_crs(epsg=4326)
635624
LOG.info(f" {len(gdf)} cadastres dans le périmètre OEASC")
@@ -674,7 +663,7 @@ def step_build_sections():
674663
LOG.info("Étape 4c : construction des sections cadastrales par agrégation")
675664
print("Étape 4c : construction des sections cadastrales par agrégation")
676665
oeasc_geom = _get_oeasc_geom()
677-
gdf = gpd.read_file(GPKG_CADASTRE)
666+
gdf = gpd.read_file(_gpkg_path("cadastres.gpkg"))
678667
gdf = _filter_by_oeasc(gdf, oeasc_geom)
679668

680669
# Groupe par code_section = id_parcelle[:11]
@@ -721,8 +710,9 @@ def step_load_foret_dgd():
721710
import fiona
722711

723712
oeasc_geom = _get_oeasc_geom()
724-
layers = fiona.listlayers(GPKG_DGD)
725-
gdf = gpd.read_file(GPKG_DGD, layer=layers[0])
713+
gpkg_dgd = _gpkg_path("forets_dgd.gpkg")
714+
layers = fiona.listlayers(gpkg_dgd)
715+
gdf = gpd.read_file(gpkg_dgd, layer=layers[0])
726716
gdf = _filter_by_oeasc(gdf, oeasc_geom)
727717
gdf_4326 = gdf.to_crs(epsg=4326)
728718
LOG.info(f" {len(gdf)} forêts DGD dans le périmètre OEASC")
@@ -823,7 +813,7 @@ def step_load_foret_onf():
823813
LOG.info("Étape 4e : chargement des forêts ONF")
824814
print("Étape 4e : chargement des forêts ONF")
825815
oeasc_geom = _get_oeasc_geom()
826-
gdf = gpd.read_file(GPKG_FORET_ONF)
816+
gdf = gpd.read_file(_gpkg_path("forets_gestion_onf_aoa.gpkg"))
827817
gdf = _filter_by_oeasc(gdf, oeasc_geom)
828818
gdf_4326 = gdf.to_crs(epsg=4326)
829819
LOG.info(f" {len(gdf)} forêts ONF dans le périmètre OEASC")
@@ -905,7 +895,7 @@ def step_load_parcelle_onf():
905895
LOG.info("Étape 4f : chargement des parcelles ONF")
906896
print("Étape 4f : chargement des parcelles ONF")
907897
oeasc_geom = _get_oeasc_geom()
908-
gdf = gpd.read_file(GPKG_PARCELLE_ONF)
898+
gdf = gpd.read_file(_gpkg_path("parcelles_forets_onf_new.gpkg"))
909899
gdf = _filter_by_oeasc(gdf, oeasc_geom)
910900
gdf_4326 = gdf.to_crs(epsg=4326)
911901
LOG.info(f" {len(gdf)} parcelles ONF dans le périmètre OEASC")
@@ -972,7 +962,7 @@ def step_load_ug_onf():
972962
LOG.info("Étape 4g : chargement des unités de gestion ONF")
973963
print("Étape 4g : chargement des unités de gestion ONF")
974964
oeasc_geom = _get_oeasc_geom()
975-
gdf = gpd.read_file(GPKG_UG_ONF)
965+
gdf = gpd.read_file(_gpkg_path("unites_gestion_forets_onf.gpkg"))
976966
# Exclure les UG dont CCOD_PRF n'est pas un entier (parcelles "U" gérées en 4f)
977967
gdf = gdf[gdf["CCOD_PRF"].apply(lambda x: str(x).strip().isdigit())]
978968
gdf = _filter_by_oeasc(gdf, oeasc_geom)

0 commit comments

Comments
 (0)