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 MNT sub-command #14

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all 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
31 changes: 30 additions & 1 deletion src/ref_geo/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def ref_geo():
@ref_geo.command()
@with_appcontext
def info():
click.echo("RefGeo : nombre de zones par type")
click.echo("[RefGeo]")
click.echo("Nombre de zones par type :")
q = (
db.session.query(BibAreasTypes, func.count(LAreas.id_area).label("count"))
.join(LAreas)
Expand All @@ -23,3 +24,31 @@ def info():
)
for area_type, count in q.all():
click.echo("\t{}: {}".format(area_type.type_name, count))
click.echo("Modèle numérique de terrain :")
dem_count = db.session.execute("SELECT count(*) FROM ref_geo.dem").scalar()
click.echo(f"\tRaster : {dem_count} entrées")
dem_count = db.session.execute("SELECT count(*) FROM ref_geo.dem_vector").scalar()
click.echo(f"\tVectoriel : {dem_count} entrées")


@ref_geo.group(help="Gestion du MNT")
def mnt():
pass


@mnt.command()
@with_appcontext
def vectorize(help="Convertir le MNT raster en vectoriel"):
click.echo("[1/2] Peuplement de ref_geo.dem_vector à partir de ref_geo.dem …")
db.session.execute(
"INSERT INTO ref_geo.dem_vector (geom, val) SELECT (ST_DumpAsPolygons(rast)).* FROM ref_geo.dem"
)
click.echo("[2/2] Actualisation de l’index ref_geo.index_dem_vector_geom …")
db.session.execute("REINDEX INDEX ref_geo.index_dem_vector_geom")


@mnt.command()
@with_appcontext
def delete_vector(help="Supprimer le MNT vectoriel"):
click.echo("Suppression du MNT vectoriel …")
db.session.execute("TRUNCATE ref_geo.dem_vector")
Loading