Skip to content

Commit

Permalink
Merge pull request #479 from MTES-MCT/feat-ocsge-gironde
Browse files Browse the repository at this point in the history
Ajout de l'OCS GE pour le département Gironde (33)
  • Loading branch information
alexisig authored Jul 1, 2024
2 parents 900aeda + ef172db commit 9b3bdfd
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 4 deletions.
13 changes: 13 additions & 0 deletions public_data/domain/artificialisation/use_case/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
__all__ = [
"CalculateCommuneArtificialAreas",
"CalculateCommuneDiff",
"CalculateCommuneTotalArtif",
"CalculateCommuneUsageEtCouvertureRepartition",
]

from .CalculateCommuneArtificialAreas import CalculateCommuneArtificialAreas
from .CalculateCommuneDiff import CalculateCommuneDiff
from .CalculateCommuneTotalArtif import CalculateCommuneTotalArtif
from .CalculateCommuneUsageEtCouvertureRepartition import (
CalculateCommuneUsageEtCouvertureRepartition,
)
53 changes: 53 additions & 0 deletions public_data/management/commands/mep_7_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import logging

import celery
from django.core.management import call_command
from django.core.management.base import BaseCommand

from public_data.models import Commune, DataSource, Departement
from public_data.tasks import calculate_data_for_commune

logger = logging.getLogger("management.commands")


class Command(BaseCommand):
help = "Dedicated to load data for 5.2 deployment"

def load_departement(self, departement: Departement):
call_command(
command_name="load_shapefile",
dataset=DataSource.DatasetChoices.OCSGE,
land_id=departement.source_id,
)
call_command(
command_name="update_project_ocsge",
departements=[departement.source_id],
)

def handle(self, *args, **options):
logger.info("Start mep_71")

call_command("maintenance", on=True)

logger.info("Initialize data sources")
DataSource.objects.all().delete()
call_command("loaddata", "public_data/models/data_source_fixture.json")

logger.info("Load new OCS GE")
call_command("setup_departements")

departements_source_ids = ["33"]

celery_tasks = []

for source_id in departements_source_ids:
departement = Departement.objects.get(source_id=source_id)
self.load_departement(departement)

for commune in Commune.objects.filter(departement=departement):
celery_tasks.append(calculate_data_for_commune.si(commune.insee))

celery.group(*celery_tasks).apply_async(queue="long")

call_command("maintenance", off=True)
logger.info("End mep_71")
160 changes: 160 additions & 0 deletions public_data/models/data_source_fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -3358,5 +3358,165 @@
"official_land_id": "40",
"srid": 2154
}
},
{
"model": "public_data.datasource",
"pk": 284,
"fields": {
"productor": "IGN",
"dataset": "OCSGE",
"name": "OCCUPATION_DU_SOL",
"millesimes": "[\"2018\"]",
"mapping": null,
"path": "33_OCCUPATION_DU_SOL_2018_IGN_REPACKED.shp.zip",
"shapefile_name": "OCCUPATION_SOL.shp",
"source_url": "https://data.geopf.fr/telechargement/download/OCSGE/OCS-GE_2-0__SHP_LAMB93_D033_2018-01-01/OCS-GE_2-0__SHP_LAMB93_D033_2018-01-01.7z",
"official_land_id": "33",
"srid": 2154
}
},
{
"model": "public_data.datasource",
"pk": 285,
"fields": {
"productor": "IGN",
"dataset": "OCSGE",
"name": "ZONE_CONSTRUITE",
"millesimes": "[\"2018\"]",
"mapping": null,
"path": "33_ZONE_CONSTRUITE_2018_IGN_REPACKED.shp.zip",
"shapefile_name": "ZONE_CONSTRUITE.shp",
"source_url": "https://data.geopf.fr/telechargement/download/OCSGE/OCS-GE_2-0__SHP_LAMB93_D033_2018-01-01/OCS-GE_2-0__SHP_LAMB93_D033_2018-01-01.7z",
"official_land_id": "33",
"srid": 2154
}
},
{
"model": "public_data.datasource",
"pk": 286,
"fields": {
"productor": "IGN",
"dataset": "OCSGE",
"name": "OCCUPATION_DU_SOL",
"millesimes": "[\"2021\"]",
"mapping": null,
"path": "33_OCCUPATION_DU_SOL_2021_IGN_REPACKED.shp.zip",
"shapefile_name": "OCCUPATION_SOL.shp",
"source_url": "https://data.geopf.fr/telechargement/download/OCSGE/OCS-GE_2-0__SHP_LAMB93_D033_2021-01-01/OCS-GE_2-0__SHP_LAMB93_D033_2021-01-01.7z",
"official_land_id": "33",
"srid": 2154
}
},
{
"model": "public_data.datasource",
"pk": 287,
"fields": {
"productor": "IGN",
"dataset": "OCSGE",
"name": "ZONE_CONSTRUITE",
"millesimes": "[\"2021\"]",
"mapping": null,
"path": "33_ZONE_CONSTRUITE_2021_IGN_REPACKED.shp.zip",
"shapefile_name": "ZONE_CONSTRUITE.shp",
"source_url": "https://data.geopf.fr/telechargement/download/OCSGE/OCS-GE_2-0__SHP_LAMB93_D033_2021-01-01/OCS-GE_2-0__SHP_LAMB93_D033_2021-01-01.7z",
"official_land_id": "33",
"srid": 2154
}
},
{
"model": "public_data.datasource",
"pk": 288,
"fields": {
"productor": "IGN",
"dataset": "OCSGE",
"name": "DIFFERENCE",
"millesimes": "[\"2018\", \"2021\"]",
"mapping": null,
"path": "33_DIFFERENCE_2018_2021_IGN_REPACKED.shp.zip",
"shapefile_name": "DIFF_D033_2021_2018.shp",
"source_url": "https://data.geopf.fr/telechargement/download/OCSGE/OCS-GE_2-0_DIFF_SHP_LAMB93_D033_2018-2021/OCS-GE_2-0_DIFF_SHP_LAMB93_D033_2018-2021.7z",
"official_land_id": "33",
"srid": 2154
}
},
{
"model": "public_data.datasource",
"pk": 289,
"fields": {
"productor": "MDA",
"dataset": "OCSGE",
"name": "DIFFERENCE",
"millesimes": "[\"2018\", \"2021\"]",
"mapping": null,
"path": "OCSGE_DIFFERENCE_33_2018_2021_MDA.shp.zip",
"shapefile_name": "DIFFERENCE.shp",
"source_url": null,
"official_land_id": "33",
"srid": 2154
}
},
{
"model": "public_data.datasource",
"pk": 290,
"fields": {
"productor": "MDA",
"dataset": "OCSGE",
"name": "ZONE_CONSTRUITE",
"millesimes": "[\"2018\"]",
"mapping": null,
"path": "OCSGE_ZONE_CONSTRUITE_33_2018_MDA.shp.zip",
"shapefile_name": "ZONE_CONSTRUITE.shp",
"source_url": null,
"official_land_id": "33",
"srid": 2154
}
},
{
"model": "public_data.datasource",
"pk": 291,
"fields": {
"productor": "MDA",
"dataset": "OCSGE",
"name": "ZONE_CONSTRUITE",
"millesimes": "[\"2021\"]",
"mapping": null,
"path": "OCSGE_ZONE_CONSTRUITE_33_2021_MDA.shp.zip",
"shapefile_name": "ZONE_CONSTRUITE.shp",
"source_url": null,
"official_land_id": "33",
"srid": 2154
}
},
{
"model": "public_data.datasource",
"pk": 292,
"fields": {
"productor": "MDA",
"dataset": "OCSGE",
"name": "OCCUPATION_DU_SOL",
"millesimes": "[\"2018\"]",
"mapping": null,
"path": "OCSGE_OCCUPATION_DU_SOL_33_2018_MDA.shp.zip",
"shapefile_name": "OCCUPATION_DU_SOL.shp",
"source_url": null,
"official_land_id": "33",
"srid": 2154
}
},
{
"model": "public_data.datasource",
"pk": 293,
"fields": {
"productor": "MDA",
"dataset": "OCSGE",
"name": "OCCUPATION_DU_SOL",
"millesimes": "[\"2021\"]",
"mapping": null,
"path": "OCSGE_OCCUPATION_DU_SOL_33_2021_MDA.shp.zip",
"shapefile_name": "OCCUPATION_DU_SOL.shp",
"source_url": null,
"official_land_id": "33",
"srid": 2154
}
}
]
35 changes: 31 additions & 4 deletions public_data/tasks.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging

from celery import shared_task
from celery import group, shared_task

from public_data.domain.artificialisation.use_case.CalculateCommuneArtificialAreas import (
from public_data.domain.artificialisation.use_case import (
CalculateCommuneArtificialAreas,
)
from public_data.domain.artificialisation.use_case.CalculateCommuneTotalArtif import (
CalculateCommuneDiff,
CalculateCommuneTotalArtif,
CalculateCommuneUsageEtCouvertureRepartition,
)
from public_data.models import Commune

Expand All @@ -20,3 +20,30 @@ def calculate_commune_artificial_area(commune_insee: str):
artificial_areas = CalculateCommuneArtificialAreas.execute(commune)
CalculateCommuneTotalArtif.execute(commune)
logger.info(f"Commune {commune_insee} - Artificial areas calculated: {artificial_areas.count()}")


@shared_task
def calculate_commune_artificial_diff(commune_insee: str):
logger.info(f"Commune {commune_insee} - Calculating artificial diff")
commune = Commune.objects.get(insee=commune_insee)
CalculateCommuneDiff.execute(commune)
logger.info(f"Commune {commune_insee} - Artificial diff calculated")


@shared_task
def calculate_commune_usage_et_couverture_repartition(commune_insee: str):
logger.info(f"Commune {commune_insee} - Calculating usage et couverture repartition")
commune = Commune.objects.get(insee=commune_insee)
CalculateCommuneUsageEtCouvertureRepartition.execute(commune)
logger.info(f"Commune {commune_insee} - Usage et couverture repartition calculated")


@shared_task
def calculate_data_for_commune(commune_insee: str):
logger.info(f"Commune {commune_insee} - Calculating data")
group(
calculate_commune_artificial_area.si(commune_insee),
calculate_commune_artificial_diff.si(commune_insee),
calculate_commune_usage_et_couverture_repartition.si(commune_insee),
).apply_async(queue="long")
logger.info(f"Commune {commune_insee} - Data calculated")

0 comments on commit 9b3bdfd

Please sign in to comment.