Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing grids #25

Merged
merged 7 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
CHANGELOG
=========

1.5.4-unreleased (2024-04-xx)
-----------------------------

- Ajout des Mailles officielles manquantes, utilisées par la nouvelle version du
jacquesfize marked this conversation as resolved.
Show resolved Hide resolved
référentiel de sensibilité (2x2km, 20x20km, 50x50km)

**Note de version**
jacquesfize marked this conversation as resolved.
Show resolved Hide resolved

Pour ajouter les nouvelles mailles, éxécuter les commandes suivantes:
jacquesfize marked this conversation as resolved.
Show resolved Hide resolved

```sh
source venv/bin/activate
export SQLALCHEMY_DATABASE_URI="postgresql://user:password@localhost:543database"
cd src/ref_geo/migrations
alembic upgrade ref_geo_inpn_grids_2@head # Insertion du maillage 2x2km dl’hexagone fourni par l’INPN
jacquesfize marked this conversation as resolved.
Show resolved Hide resolved
alembic upgrade ref_geo_inpn_grids_20@head # Insertion du maillage 20x20kde l’hexagone fourni par l’INPN
jacquesfize marked this conversation as resolved.
Show resolved Hide resolved
alembic upgrade ref_geo_inpn_grids_50@head # Insertion du maillage 50x50kde l’hexagone fourni par l’INPN
jacquesfize marked this conversation as resolved.
Show resolved Hide resolved
```

1.5.3 (2024-05-23)
------------------

**🐛 Corrections**

- Correction de l'intégration des paramètres de type `list` dans la route `/areas` (#26)


1.5.2 (2024-04-10)

1.5.2 (2024-09-10)
------------------

**🚀 Nouveautés**

- Possibilité d'appeler la route `GET/areas` sans retourner les géométries (#22)
- Possibilité d'appeler la route `GET/areas` sans retourner les géométries (#22)

1.5.1 (2024-01-29)
------------------
Expand Down Expand Up @@ -124,4 +143,5 @@ Externalisation du référentiel géographique de GeoNature 2.9.2.

**🚀 Nouveautés**


* Le SRID local est déterminé automatiquement à partir du SRID de la colonne ``ref_geo.l_areas.geom``.
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ Prérequis : vous devez installer l’extension postgis sur votre base de donné

Création et remplissage du référentiel géographique :

python3 -m venv venv
source venv/bin/activate
pip install -e .
pip install psycopg2 # for postgresql database
export SQLALCHEMY_DATABASE_URI="postgresql://user:password@localhost:5432/database"
cd src/ref_geo/migrations
alembic -x local-srid=2154 upgrade ref_geo@head
alembic upgrade ref_geo_fr_municipalities@head # Insertion des communes françaises
alembic upgrade ref_geo_fr_departments@head # Insertion des départements français
alembic upgrade ref_geo_fr_regions@head # Insertion des régions françaises
alembic upgrade ref_geo_fr_regions_1970@head # Insertion des anciennes régions françaises
alembic upgrade ref_geo_inpn_grids_1@head # Insertion du maillage 1×1km de l’hexagone fourni par l’INPN
alembic upgrade ref_geo_inpn_grids_5@head # Insertion du maillage 5×5km de l’hexagone fourni par l’INPN
alembic upgrade ref_geo_inpn_grids_10@head # Insertion du maillage 10×10km de l’hexagone fourni par l’INPN
```sh
python3 -m venv venv
source venv/bin/activate
pip install -e .
pip install psycopg2 # for postgresql database
export SQLALCHEMY_DATABASE_URI="postgresql://user:password@localhost:5432database"
cd src/ref_geo/migrations
alembic -x local-srid=2154 upgrade ref_geo@head
alembic upgrade ref_geo_fr_municipalities@head # Insertion des communesfrançaises
alembic upgrade ref_geo_fr_departments@head # Insertion des départementsfrançais
alembic upgrade ref_geo_fr_regions@head # Insertion des régions françaises
alembic upgrade ref_geo_fr_regions_1970@head # Insertion des anciennesrégions françaises
alembic upgrade ref_geo_inpn_grids_1@head # Insertion du maillage 1×1km del’hexagone fourni par l’INPN
alembic upgrade ref_geo_inpn_grids_2@head # Insertion du maillage 2x2km del’hexagone fourni par l’INPN
alembic upgrade ref_geo_inpn_grids_5@head # Insertion du maillage 5×5km del’hexagone fourni par l’INPN
alembic upgrade ref_geo_inpn_grids_10@head # Insertion du maillage 10×10kmde l’hexagone fourni par l’INPN
alembic upgrade ref_geo_inpn_grids_20@head # Insertion du maillage 20x20kmde l’hexagone fourni par l’INPN
alembic upgrade ref_geo_inpn_grids_50@head # Insertion du maillage 50x50kmde l’hexagone fourni par l’INPN
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""ref_geo_inpn_grids_20
jacquesfize marked this conversation as resolved.
Show resolved Hide resolved

Revision ID: 10a587fb63d1
Create Date: 2024-04-23 16:14:56.846732

"""

from alembic import op

from utils_flask_sqla.migrations.utils import logger, open_remote_file
from ref_geo.migrations.utils import (
schema,
create_temporary_grids_table,
delete_area_with_type,
insert_grids_and_drop_temporary_table,
)


# revision identifiers, used by Alembic.
revision = "10a587fb63d1"
down_revision = None
branch_labels = ("ref_geo_inpn_grids_20",)
depends_on = "6afe74833ed0"

grid = "20"
filename = f"inpn_grids_{grid}.csv.xz"
base_url = "http://geonature.fr/data/inpn/layers/2024/"
temp_table_name = f"temp_grids_{grid}"
area_type = f"M{grid}"


def upgrade():
op.execute(
f"""
INSERT INTO {schema}.bib_areas_types (type_name,
type_code,
type_desc,
ref_name,
ref_version,
num_version)
VALUES ('Mailles {grid}*{grid}', 'M{grid}', 'Type maille INPN {grid}*{grid}km', NULL, NULL, NULL)
ON CONFLICT (type_code) DO NOTHING;
"""
)
create_temporary_grids_table(schema, temp_table_name)
cursor = op.get_bind().connection.cursor()
with open_remote_file(base_url, filename) as geofile:
logger.info("Inserting grids data in temporary table…")
cursor.copy_expert(f"COPY {schema}.{temp_table_name} FROM STDIN", geofile)
insert_grids_and_drop_temporary_table(schema, temp_table_name, area_type)


def downgrade():
delete_area_with_type(area_type)
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Insert INPN 2x2 grids in ref_geo

Revision ID: 175cdb17343f
Create Date: 2024-04-23 16:15:17.317930

"""

from alembic import op

from utils_flask_sqla.migrations.utils import logger, open_remote_file
from ref_geo.migrations.utils import (
schema,
create_temporary_grids_table,
delete_area_with_type,
insert_grids_and_drop_temporary_table,
)

# revision identifiers, used by Alembic.
revision = "175cdb17343f"
down_revision = None
branch_labels = ("ref_geo_inpn_grids_2",)
depends_on = "6afe74833ed0"

grid = "2"
filename = f"inpn_grids_{grid}.csv.xz"
base_url = "http://geonature.fr/data/inpn/layers/2024/"
temp_table_name = f"temp_grids_{grid}"
area_type = f"M{grid}"


def upgrade():
op.execute(
f"""
INSERT INTO {schema}.bib_areas_types (type_name,
type_code,
type_desc,
ref_name,
ref_version,
num_version)
VALUES ('Mailles {grid}*{grid}', 'M{grid}', 'Type maille INPN {grid}*{grid}km', NULL, NULL, NULL)
ON CONFLICT (type_code) DO NOTHING;
"""
)
create_temporary_grids_table(schema, temp_table_name)
cursor = op.get_bind().connection.cursor()
with open_remote_file(base_url, filename) as geofile:
logger.info("Inserting grids data in temporary table…")
cursor.copy_expert(f"COPY {schema}.{temp_table_name} FROM STDIN", geofile)
insert_grids_and_drop_temporary_table(schema, temp_table_name, area_type)


def downgrade():
delete_area_with_type(area_type)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""ref_geo_inpn_grids_50
jacquesfize marked this conversation as resolved.
Show resolved Hide resolved

Revision ID: 4d0c35ea0cfe
Create Date: 2024-04-23 16:15:26.220548

"""

from alembic import op

from utils_flask_sqla.migrations.utils import logger, open_remote_file
from ref_geo.migrations.utils import (
schema,
create_temporary_grids_table,
delete_area_with_type,
insert_grids_and_drop_temporary_table,
)


# revision identifiers, used by Alembic.
revision = "4d0c35ea0cfe"
down_revision = None
branch_labels = ("ref_geo_inpn_grids_50",)
depends_on = "6afe74833ed0"

grid = "50"
filename = f"inpn_grids_{grid}.csv.xz"
base_url = "http://geonature.fr/data/inpn/layers/2024/"
temp_table_name = f"temp_grids_{grid}"
area_type = f"M{grid}"


def upgrade():
op.execute(
f"""
INSERT INTO {schema}.bib_areas_types (type_name,
type_code,
type_desc,
ref_name,
ref_version,
num_version)
VALUES ('Mailles {grid}*{grid}', 'M{grid}', 'Type maille INPN {grid}*{grid}km', NULL, NULL, NULL)
ON CONFLICT (type_code) DO NOTHING;
"""
)
create_temporary_grids_table(schema, temp_table_name)
cursor = op.get_bind().connection.cursor()
with open_remote_file(base_url, filename) as geofile:
logger.info("Inserting grids data in temporary table…")
cursor.copy_expert(f"COPY {schema}.{temp_table_name} FROM STDIN", geofile)
insert_grids_and_drop_temporary_table(schema, temp_table_name, area_type)


def downgrade():
delete_area_with_type(area_type)
Loading