Skip to content

Commit

Permalink
ref_geo point & cor area linear
Browse files Browse the repository at this point in the history
  • Loading branch information
joelclems committed Aug 2, 2023
1 parent 2272603 commit f1438a4
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
CHANGELOG
=========

1.4.0 (unreleased)
------------------

**🚀 Nouveautés**

* Ajout d'un référentiel *point* (table de type et table de geometries + modeles)
* Ajout de table de correlation entre les lineaire et les aires (+ relations associées dans les modèles)

1.3.0 (2023-03-03)
------------------

Expand Down
41 changes: 41 additions & 0 deletions src/ref_geo/migrations/data/ref_geo.points.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- tables pour gérer les référentiels géographiques points (PK/PR, ..)
-- - ref_geo.bib_points_types
-- - ref_geo.l_points

CREATE TABLE ref_geo.bib_points_types (
id_type SERIAL NOT NULL,
type_name character varying(200) NOT NULL,
type_code character varying(25) NOT NULL,
type_desc text,
ref_name character varying(200),
ref_version integer,
num_version character varying(50),
meta_create_date timestamp without time zone,
meta_update_date timestamp without time zone,
CONSTRAINT pk_ref_geo_bib_points_types_id_type PRIMARY KEY (id_type),
UNIQUE(type_code)
);

-- table des linéaires (tronçon de route, etc..)

CREATE TABLE ref_geo.l_points (
id_point SERIAL NOT NULL,
id_type INTEGER NOT NULL,
point_name character varying(250) NOT NULL,
point_code character varying(25) NOT NULL,
enable BOOLEAN NOT NULL DEFAULT (TRUE),
geom GEOMETRY(GEOMETRY, 2154),
geojson_4326 VARCHAR,
source character varying(250),
additional_data jsonb NULL,
meta_create_date timestamp without time zone,
meta_update_date timestamp without time zone,

UNIQUE (id_type, point_code),

CONSTRAINT pk_ref_geo_l_points_id_point PRIMARY KEY (id_point),
CONSTRAINT fk_ref_geo_l_points_id_type FOREIGN KEY (id_type)
REFERENCES ref_geo.bib_points_types(id_type)
ON UPDATE CASCADE ON DELETE NO ACTION
);

40 changes: 40 additions & 0 deletions src/ref_geo/migrations/data/ref_geo_cor.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- cor_areas

CREATE TABLE ref_geo.cor_areas (
id_area_group integer,
id_area integer
);

ALTER TABLE ref_geo.cor_areas
ADD CONSTRAINT fk_ref_geo_cor_areas_id_area_group FOREIGN KEY (id_area_group)
REFERENCES ref_geo.l_areas(id_area)
ON UPDATE CASCADE ON DELETE CASCADE;

ALTER TABLE ref_geo.cor_areas
ADD CONSTRAINT fk_ref_geo_cor_areas_id_area FOREIGN KEY (id_area)
REFERENCES ref_geo.l_areas(id_area)
ON UPDATE CASCADE ON DELETE CASCADE;

CREATE INDEX ref_geo_cor_areas_id_area ON ref_geo.cor_areas USING btree(id_area);
CREATE INDEX ref_geo_cor_areas_id_area_group ON ref_geo.cor_areas USING btree(id_area_group);


-- cor_areas

CREATE TABLE ref_geo.cor_linear_area (
id_linear integer,
id_area integer
);

ALTER TABLE ref_geo.cor_linear_area
ADD CONSTRAINT fk_ref_geo_cor_linear_id_area_group FOREIGN KEY (id_area)
REFERENCES ref_geo.l_areas(id_area)
ON UPDATE CASCADE ON DELETE CASCADE;

ALTER TABLE ref_geo.cor_linear_area
ADD CONSTRAINT fk_ref_geo_cor_linear_id_lineair_group FOREIGN KEY (id_linear)
REFERENCES ref_geo.l_linears(id_linear)
ON UPDATE CASCADE ON DELETE CASCADE;

CREATE INDEX ref_geo_cor_linear_area_id_area ON ref_geo.cor_linear_area USING btree(id_area);
CREATE INDEX ref_geo_cor_linear_area_id_linear ON ref_geo.cor_linear_area USING btree(id_linear);
37 changes: 37 additions & 0 deletions src/ref_geo/migrations/versions/795f6ea8ec45_cor_linear_area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""cor_areas & cor_linear_areas
Revision ID: 795f6ea8ec45
Revises: dea1645de8c0
Create Date: 2023-08-02 11:48:06.329936
"""

import sqlalchemy as sa
import importlib

from alembic import op
from sqlalchemy.sql import text


# revision identifiers, used by Alembic.
revision = "795f6ea8ec45"
down_revision = "dea1645de8c0"
branch_labels = None
depends_on = None


def upgrade():
stmt = text(importlib.resources.read_text("ref_geo.migrations.data", "ref_geo_cor.sql"))
op.get_bind().execute(stmt)
pass


def downgrade():
op.get_bind().execute(
"""
DROP TABLE ref_geo.cor_linear_area;
DROP TABLE ref_geo.cor_areas;
"""
)

pass
38 changes: 38 additions & 0 deletions src/ref_geo/migrations/versions/dea1645de8c0_ref_geo_point.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
""" Référentiel point, cor (area, linear, point)
Revision ID: dea1645de8c0
Revises: f7374cd6e38d
Create Date: 2023-07-27 12:13:01.748452
"""
import importlib

from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import text
from ref_geo.utils import (
get_local_srid,
)

# revision identifiers, used by Alembic.
revision = "dea1645de8c0"
down_revision = "f7374cd6e38d"
branch_labels = None
depends_on = None


def upgrade():
stmt = text(importlib.resources.read_text("ref_geo.migrations.data", "ref_geo_point.sql"))
op.get_bind().execute(stmt, {"local_srid": get_local_srid(op.get_bind())})

pass


def downgrade():
op.get_bind().execute(
"""
DROP TABLE ref_geo.bib_points_types;
DROP TABLE ref_geo.l_points;
"""
)
pass
55 changes: 54 additions & 1 deletion src/ref_geo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from geoalchemy2 import Geometry
from sqlalchemy import ForeignKey
from sqlalchemy.orm import deferred
from sqlalchemy.orm import deferred, column_property
from sqlalchemy.sql import func

from sqlalchemy.dialects.postgresql import JSONB

from utils_flask_sqla.serializers import serializable
Expand Down Expand Up @@ -72,6 +74,21 @@ class CorLinearGroup(db.Model):
)


class CorLinearArea(db.Model):
__table_name__ = "cor_linear_area"
__table_args__ = {"schema": "ref_geo"}
id_area = db.Column(
db.Integer,
ForeignKey("ref_geo.l_areas.id_area"),
primary_key=True,
)
id_linear = db.Column(
db.Integer,
ForeignKey("ref_geo.l_linears.id_linear"),
primary_key=True,
)


@geoserializable
class LLinears(db.Model):
__tablename__ = "l_linears"
Expand All @@ -92,6 +109,7 @@ class LLinears(db.Model):
groups = db.relationship(
"TLinearGroups", secondary=CorLinearGroup.__table__, backref="linears"
)
areas = db.relationship("LAreas", secondary=CorLinearArea.__table__, backref="linears")


@serializable
Expand All @@ -103,6 +121,41 @@ class TLinearGroups(db.Model):
code = db.Column(db.Unicode(length=25), unique=True)


@serializable
class BibPointsTypes(db.Model):
__tablename__ = "bib_points_types"
__table_args__ = {"schema": "ref_geo"}
id_type = db.Column(db.Integer, primary_key=True)
type_name = db.Column(db.Unicode(length=200), nullable=False)
type_code = db.Column(db.Unicode(length=25), nullable=False)
type_desc = db.Column(db.Unicode)
ref_name = db.Column(db.Unicode(length=200))
ref_version = db.Column(db.Integer)
num_version = db.Column(db.Unicode(length=50))


@geoserializable
class LPoints(db.Model):
__tablename__ = "l_points"
__table_args__ = {"schema": "ref_geo"}
id_point = db.Column(db.Integer, primary_key=True)
id_type = db.Column(db.Integer, ForeignKey("ref_geo.bib_points_types.id_type"), nullable=False)
point_name = db.Column(db.Unicode(length=250))
point_code = db.Column(db.Unicode(length=25))
geom = db.Column(Geometry("GEOMETRY"))
source = db.Column(db.Unicode(length=250))
enable = db.Column(db.Boolean, nullable=False, default=True)
additional_data = db.Column(JSONB)
meta_create_date = db.Column(db.DateTime, default=datetime.now)
meta_update_date = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)
type = db.relationship("BibPointsTypes")

geom_4326 = column_property(
func.ST_TRANSFORM(geom, 4326),
deferred=True,
)


@serializable
class LiMunicipalities(db.Model):
__tablename__ = "li_municipalities"
Expand Down

0 comments on commit f1438a4

Please sign in to comment.