-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #469 from MTES-MCT/feat-impermeabilisation
Ajout de la méthode de calcul de l'imperméabilisation
- Loading branch information
Showing
13 changed files
with
305 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
public_data/domain/shapefile_builder/infra/gdal/is_impermeable_case.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
def is_impermeable_case( | ||
code_cs: str, | ||
true_value=1, | ||
false_value=0, | ||
) -> str: | ||
return f""" CASE | ||
WHEN {code_cs} = 'CS1.1.1.1' THEN {true_value} | ||
WHEN {code_cs} = 'CS1.1.1.2' THEN {true_value} | ||
ELSE {false_value} | ||
END""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from django.db import connection | ||
from django.test import TransactionTestCase | ||
|
||
from .is_artif_case import is_artif_case | ||
from .is_impermeable_case import is_impermeable_case | ||
|
||
|
||
class TestGdalShapefileBuilder(TransactionTestCase): | ||
def test_carriere_is_not_artif(self): | ||
couverture = "CS1.1.2.1" # zones à matériaux minéraux | ||
usage = "US1.3" # activité d'extraction | ||
|
||
query = f""" | ||
WITH test_data AS ( | ||
SELECT | ||
'{couverture}' AS code_cs, | ||
'{usage}' AS code_us | ||
) | ||
SELECT | ||
{is_artif_case( | ||
code_cs="code_cs", | ||
code_us="code_us", | ||
)} | ||
FROM | ||
test_data | ||
""" | ||
|
||
with connection.cursor() as cursor: | ||
cursor.execute(query) | ||
result = cursor.fetchone() | ||
|
||
self.assertEqual(result[0], 0) | ||
|
||
def test_only_zone_baties_and_zones_non_baties_are_impermeable(self): | ||
impermeable_couvertures = [ | ||
"CS1.1.1.1", # Zones bâties | ||
"CS1.1.1.2", # Zones non bâties | ||
] | ||
|
||
non_impermeable_couvertures = [ | ||
"CS1.1.2.1", # zones à matériaux minéraux | ||
"CS1.1.2.2", # zones à matériaux composites | ||
"CS1.2.1", # sol nuls | ||
"CS1.2.2", # eau | ||
"CS1.2.3", # nevé et glaciers | ||
"CS2.1.1.1", # peuplement de feuillus | ||
"CS2.1.1.2", # peuplement de conifères | ||
"CS2.1.1.3", # peuplement mixte | ||
"CS2.1.2", # formations arbustives et sous-abrisseaux | ||
"CS2.1.3", # autres formations ligneuses | ||
"CS2.2.1", # prairies | ||
"CS2.2.2", # autres formations non ligneuses | ||
] | ||
|
||
def get_query(couverture): | ||
return f""" | ||
WITH test_data AS ( | ||
SELECT | ||
'{couverture}' AS code_cs | ||
) | ||
SELECT | ||
{is_impermeable_case( | ||
code_cs="code_cs", | ||
)} | ||
FROM | ||
test_data | ||
""" | ||
|
||
for couverture in impermeable_couvertures: | ||
with connection.cursor() as cursor: | ||
cursor.execute(get_query(couverture)) | ||
result = cursor.fetchone() | ||
|
||
self.assertEqual(result[0], 1) | ||
|
||
for couverture in non_impermeable_couvertures: | ||
with connection.cursor() as cursor: | ||
cursor.execute(get_query(couverture)) | ||
result = cursor.fetchone() | ||
|
||
self.assertEqual(result[0], 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
public_data/migrations/0182_ocsge_is_impermeable_ocsgediff_is_new_impermeable_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Generated by Django 4.2.13 on 2024-06-24 22:20 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("public_data", "0181_alter_epci_options_remove_artificialarea_new_method"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="ocsge", | ||
name="is_impermeable", | ||
field=models.BooleanField(blank=True, null=True, verbose_name="Est imperméable"), | ||
), | ||
migrations.AddField( | ||
model_name="ocsgediff", | ||
name="is_new_impermeable", | ||
field=models.BooleanField(blank=True, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="ocsgediff", | ||
name="is_new_not_impermeable", | ||
field=models.BooleanField(blank=True, null=True, verbose_name="Aussi appelé désimperméabilisation"), | ||
), | ||
migrations.AlterField( | ||
model_name="ocsgediff", | ||
name="is_new_natural", | ||
field=models.BooleanField(verbose_name="Aussi appelé désartificialisation"), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Generated by Django 4.2.13 on 2024-06-24 22:20 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def add_impermeable_to_ocsge_and_ocsge_diff(apps, schema_editor): | ||
Ocsge = apps.get_model("public_data", "Ocsge") | ||
OcsgeDiff = apps.get_model("public_data", "OcsgeDiff") | ||
|
||
impermeable_couvertures = [ | ||
"CS1.1.1.1", # Zones bâties | ||
"CS1.1.1.2", # Zones non bâties | ||
] | ||
|
||
Ocsge.objects.filter( | ||
is_impermeable=None, | ||
couverture__in=impermeable_couvertures, | ||
).update(is_impermeable=True) | ||
|
||
Ocsge.objects.filter( | ||
is_impermeable=None, | ||
).update(is_impermeable=False) | ||
|
||
OcsgeDiff.objects.filter( | ||
is_new_impermeable=None, | ||
cs_new__in=impermeable_couvertures, | ||
).exclude( | ||
cs_old__in=impermeable_couvertures, | ||
).update(is_new_impermeable=True) | ||
|
||
OcsgeDiff.objects.filter( | ||
is_new_not_impermeable=None, | ||
cs_old__in=impermeable_couvertures, | ||
).exclude( | ||
cs_new__in=impermeable_couvertures, | ||
).update(is_new_not_impermeable=True) | ||
|
||
OcsgeDiff.objects.filter( | ||
is_new_impermeable=None, | ||
).update(is_new_impermeable=False) | ||
|
||
OcsgeDiff.objects.filter( | ||
is_new_not_impermeable=None, | ||
).update(is_new_not_impermeable=False) | ||
|
||
|
||
def reverse_add_impermeable_to_ocsge_and_ocsge_diff(apps, schema_editor): | ||
Ocsge = apps.get_model("public_data", "Ocsge") | ||
OcsgeDiff = apps.get_model("public_data", "OcsgeDiff") | ||
|
||
Ocsge.objects.update(is_impermeable=None) | ||
OcsgeDiff.objects.update(is_new_impermeable=None) | ||
OcsgeDiff.objects.update(is_new_not_impermeable=None) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("public_data", "0182_ocsge_is_impermeable_ocsgediff_is_new_impermeable_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
code=add_impermeable_to_ocsge_and_ocsge_diff, | ||
reverse_code=reverse_add_impermeable_to_ocsge_and_ocsge_diff, | ||
) | ||
] |
27 changes: 27 additions & 0 deletions
27
public_data/migrations/0184_alter_ocsge_is_impermeable_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 4.2.13 on 2024-06-25 06:45 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("public_data", "0183_auto_20240625_0020"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="ocsge", | ||
name="is_impermeable", | ||
field=models.BooleanField(verbose_name="Est imperméable"), | ||
), | ||
migrations.AlterField( | ||
model_name="ocsgediff", | ||
name="is_new_impermeable", | ||
field=models.BooleanField(), | ||
), | ||
migrations.AlterField( | ||
model_name="ocsgediff", | ||
name="is_new_not_impermeable", | ||
field=models.BooleanField(verbose_name="Aussi appelé désimperméabilisation"), | ||
), | ||
] |
21 changes: 21 additions & 0 deletions
21
public_data/migrations/0185_remove_couvertureusagematrix_is_consumed_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 4.2.13 on 2024-06-25 07:06 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("public_data", "0184_alter_ocsge_is_impermeable_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="couvertureusagematrix", | ||
name="is_consumed", | ||
), | ||
migrations.AddField( | ||
model_name="couvertureusagematrix", | ||
name="is_impermeable", | ||
field=models.BooleanField(blank=True, null=True, verbose_name="Imperméable"), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Generated by Django 4.2.13 on 2024-06-25 07:06 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def add_is_impermeable_to_couverture_usage_matrix(apps, schema_editor): | ||
CouvertureUsageMatrix = apps.get_model("public_data", "CouvertureUsageMatrix") | ||
|
||
CouvertureUsageMatrix.objects.filter( | ||
is_impermeable=None, | ||
couverture__code_prefix__in=[ | ||
"CS1.1.1.1", | ||
"CS1.1.1.2", | ||
], | ||
).update(is_impermeable=True) | ||
|
||
CouvertureUsageMatrix.objects.filter( | ||
is_impermeable=None, | ||
).update(is_impermeable=False) | ||
|
||
|
||
def reverse_add_is_impermeable_to_couverture_usage_matrix(apps, schema_editor): | ||
CouvertureUsageMatrix = apps.get_model("public_data", "CouvertureUsageMatrix") | ||
|
||
CouvertureUsageMatrix.objects.update(is_impermeable=None) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("public_data", "0185_remove_couvertureusagematrix_is_consumed_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
code=add_is_impermeable_to_couverture_usage_matrix, | ||
reverse_code=reverse_add_is_impermeable_to_couverture_usage_matrix, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.