correctif et allégement
This commit is contained in:
parent
3301c1395d
commit
3141ccb15c
@ -12,7 +12,7 @@
|
||||
name=CenRa_POSTGIS
|
||||
qgisMinimumVersion=3.0
|
||||
description=Permet de crée un dossier dans la base PostGis
|
||||
version=2.3
|
||||
version=2.4
|
||||
author=Conservatoire d'Espaces Naturels de Rhône-Alpes
|
||||
email=si_besoin@cen-rhonealpes.fr
|
||||
|
||||
@ -21,7 +21,7 @@ email=si_besoin@cen-rhonealpes.fr
|
||||
# Optional items:
|
||||
|
||||
# Uncomment the following line and add your changelog entries:
|
||||
changelog=<h2>CenRa_POSTGIS:</h2></br><p><h3>22/01/2025 - Version 2.3: </h3> - Correctif sur la creation de projet.</p></br><p><h3>21/01/2025 - Version 2.2: </h3> - Correctif sur la longeur des nom.</br></p><p><h3>07/01/2025 - Version 2.1: </h3> - ByPass du certif ssl ci erreur.</br></p><p><h3>22/10/2024 - Version 2.0:</h3>- Refont du code.</p>
|
||||
changelog=<h2>CenRa_POSTGIS:</h2></br><p><h3>23/01/2025 - Version 2.4: </h3> - Correctif sur les pkey.</p></br><p><h3>22/01/2025 - Version 2.3: </h3> - Correctif sur la creation de projet.</p></br><p><h3>21/01/2025 - Version 2.2: </h3> - Correctif sur la longeur des nom.</p></br><p><h3>07/01/2025 - Version 2.1: </h3> - ByPass du certif ssl ci erreur.</p></br><p><h3>22/10/2024 - Version 2.0:</h3>- Refont du code.</p>
|
||||
|
||||
# tags are comma separated with spaces allowed
|
||||
tags=cenra, postgis, database
|
||||
|
||||
@ -21,6 +21,10 @@ from .tools.resources import (
|
||||
resources_path,
|
||||
login_base,
|
||||
send_issues,
|
||||
create_vierge,
|
||||
create_contour,
|
||||
create_travaux,
|
||||
create_habita
|
||||
)
|
||||
from .issues import CenRa_Issues
|
||||
|
||||
@ -89,347 +93,11 @@ class Postgis_Creator(QDialog, EDITOR_CLASS):
|
||||
else:
|
||||
iface.messageBar().pushMessage("POSTGRESQL :", "Pas de couche sélectionnée, création refusée.", level=Qgis.Warning, duration=30)
|
||||
|
||||
### Creation de la table contour
|
||||
if self.couche_contour.isChecked(): # Verifie si la checkbox est cochee
|
||||
if self.annee_1.text() == 'aaaa' or self.annee_1.text() == '':
|
||||
tablename = schema + "_contour"
|
||||
else :
|
||||
tablename = schema + "_contour_" + self.annee_1.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
create_contour(self,schema,cur,con,host ,port ,dbname ,user ,mdp)
|
||||
create_habita(self,schema,cur,con,host ,port ,dbname ,user ,mdp)
|
||||
create_travaux(self,schema,cur,con,host ,port ,dbname ,user ,mdp)
|
||||
create_vierge(self,schema,cur,con,host ,port ,dbname ,user ,mdp)
|
||||
|
||||
SQL_contour = "CREATE TABLE " + schema + "."+ tablename + champ_contour
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
|
||||
SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
|
||||
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
||||
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
||||
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'contour_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_sig;GRANT ALL ON SEQUENCE "+schema+"."+tablename+"_gid_seq TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_contour)
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_area_m2)
|
||||
cur.execute(SQL_trigger_area_ha)
|
||||
cur.execute(SQL_trigger_date_creation)
|
||||
cur.execute(SQL_trigger_date_maj)
|
||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
|
||||
## Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
### Creation de la table habitat
|
||||
if self.couche_habitat.isChecked():
|
||||
if self.annee_2.text() == 'aaaa' or self.annee_2.text() == '':
|
||||
tablename = schema + "_habitat"
|
||||
else :
|
||||
tablename = schema + "_habitat_" + self.annee_2.text()
|
||||
tablename_1=tablename+"_points"
|
||||
tablename_qgis = tablename_1[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
SQL_VEGETHAB = "CREATE TABLE "+ schema + "."+ tablename_1 + champ_vegethab_point
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename_1 + " ADD CONSTRAINT " + tablename_1 + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_coordonnees = "CREATE TRIGGER coordonnees" + tablename_1 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_1 + " FOR EACH ROW EXECUTE PROCEDURE ref.coordonnees();"
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename_1 + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'vegethab_points_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_1+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_1+" TO grp_sig;GRANT ALL ON SEQUENCE "+schema+"."+tablename_1+"_gid_seq TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_VEGETHAB)
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_coordonnees)
|
||||
cur.execute(SQL_style)
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
### Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename_1, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
tablename_2=tablename+"_lignes"
|
||||
tablename_qgis = tablename_2[1:]
|
||||
SQL_VEGETHAB = "CREATE TABLE "+ schema + "."+ tablename_2 + champ_vegethab_multilinestring
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename_2 + " ADD CONSTRAINT " + tablename_2 + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_length_m = "CREATE TRIGGER length_m" + tablename_2 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_2 + " FOR EACH ROW EXECUTE PROCEDURE ref.length_m();"
|
||||
SQL_trigger_length_km = "CREATE TRIGGER length_km" + tablename_2 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_2 + " FOR EACH ROW EXECUTE PROCEDURE ref.length_km();"
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename_2 + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'vegethab_lignes_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_2+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_2+" TO grp_sig;GRANT ALL ON SEQUENCE "+schema+"."+tablename_2+"_gid_seq TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_VEGETHAB)
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_length_m)
|
||||
cur.execute(SQL_trigger_length_km)
|
||||
cur.execute(SQL_style)
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
### Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename_2, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
tablename_3=tablename+"_polygones"
|
||||
tablename_qgis = tablename_3[1:]
|
||||
SQL_VEGETHAB = "CREATE TABLE "+ schema + "."+ tablename_3 + champ_vegethab_multipolygon
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename_3 + " ADD CONSTRAINT " + tablename_3 + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename_3 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_3 + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
|
||||
SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename_3 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_3 + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename_3 + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'vegethab_polygones_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_3+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_3+" TO grp_sig;GRANT ALL ON SEQUENCE "+schema+"."+tablename_3+"_gid_seq TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_VEGETHAB)
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_area_m2)
|
||||
cur.execute(SQL_trigger_area_ha)
|
||||
cur.execute(SQL_style)
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
### Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename_3, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
'''
|
||||
SQL_habitat = "CREATE TABLE " + schema + "."+ tablename + champ_habitat
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
|
||||
SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
|
||||
SQL_trigger_concat_cd_cb = "CREATE TRIGGER concat_cd_cb" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.concat_cd_cb();"
|
||||
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
||||
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
||||
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'habitat_modele_v3'"""
|
||||
|
||||
cur.execute(SQL_habitat)
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_area_m2)
|
||||
cur.execute(SQL_trigger_area_ha)
|
||||
cur.execute(SQL_trigger_concat_cd_cb)
|
||||
cur.execute(SQL_trigger_date_creation)
|
||||
cur.execute(SQL_trigger_date_maj)
|
||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||
|
||||
con.commit()
|
||||
|
||||
## Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
'''
|
||||
### Creation de la table travaux prevus
|
||||
if self.couche_travaux_prevus.isChecked():
|
||||
#**********Poly
|
||||
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
||||
tablename = schema + "_travaux_prevus_poly"
|
||||
else :
|
||||
tablename = schema + "_travaux_prevus_poly_" + self.annee_5.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
|
||||
SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus_multipolygon
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
||||
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
||||
SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
|
||||
SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
|
||||
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'travaux_prevus_poly_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_sig;GRANT ALL ON SEQUENCE "+schema+"."+tablename+"_gid_seq TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_travaux_prevus)
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_date_creation)
|
||||
cur.execute(SQL_trigger_date_maj)
|
||||
cur.execute(SQL_trigger_area_m2)
|
||||
cur.execute(SQL_trigger_area_ha)
|
||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
|
||||
con.commit()
|
||||
|
||||
## Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
#**********ligne
|
||||
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
||||
tablename = schema + "_travaux_prevus_ligne"
|
||||
else :
|
||||
tablename = schema + "_travaux_prevus_ligne_" + self.annee_5.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
|
||||
SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus_multilinestring
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
||||
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
||||
SQL_trigger_length_m = "CREATE TRIGGER length_m" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_m();"
|
||||
SQL_trigger_length_km = "CREATE TRIGGER length_km" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_km();"
|
||||
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'travaux_prevus_ligne_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_sig;GRANT ALL ON SEQUENCE "+schema+"."+tablename+"_gid_seq TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_travaux_prevus)
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_date_creation)
|
||||
cur.execute(SQL_trigger_date_maj)
|
||||
cur.execute(SQL_trigger_length_m)
|
||||
cur.execute(SQL_trigger_length_km)
|
||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
|
||||
con.commit()
|
||||
|
||||
## Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
#**********point
|
||||
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
||||
tablename = schema + "_travaux_prevus_point"
|
||||
else :
|
||||
tablename = schema + "_travaux_prevus_point_" + self.annee_5.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
|
||||
SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus_point
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
||||
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
||||
SQL_trigger_coordonnees = "CREATE TRIGGER coordonnees" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.coordonnees();"
|
||||
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'travaux_prevus_point_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_sig;GRANT ALL ON SEQUENCE "+schema+"."+tablename+"_gid_seq TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_travaux_prevus)
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_date_creation)
|
||||
cur.execute(SQL_trigger_date_maj)
|
||||
cur.execute(SQL_trigger_coordonnees)
|
||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
|
||||
con.commit()
|
||||
|
||||
## Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
### Creation de la table vierge
|
||||
if self.couche_vierge.isChecked():
|
||||
if self.annee_4.text() == 'aaaa' or self.annee_4.text() == '':
|
||||
tablename = schema + "_" + self.nom_couche_vierge.text().lower()
|
||||
else :
|
||||
tablename = schema + "_" + self.nom_couche_vierge.text().lower() + "_" + self.annee_4.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
|
||||
if self.couche_vierge_point.isChecked() == 1 :
|
||||
champ_vierge = champ_viergePoint
|
||||
|
||||
if self.couche_vierge_ligne.isChecked() == 1 :
|
||||
champ_vierge = champ_viergeLigne
|
||||
|
||||
if self.couche_vierge_polygone.isChecked() == 1 :
|
||||
champ_vierge = champ_viergePolygone
|
||||
|
||||
SQL_vierge = "CREATE TABLE " + schema + "."+ tablename + champ_vierge
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
|
||||
|
||||
SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
|
||||
SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
|
||||
SQL_trigger_length_m = "CREATE TRIGGER length_m" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_m();"
|
||||
SQL_trigger_length_km = "CREATE TRIGGER length_km" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_km();"
|
||||
SQL_trigger_coordonnees = "CREATE TRIGGER coordonnees" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.coordonnees();"
|
||||
|
||||
cur.execute(SQL_vierge)
|
||||
cur.execute(SQL_pkey)
|
||||
|
||||
if self.couche_vierge_point.isChecked() == 1 :
|
||||
cur.execute(SQL_trigger_coordonnees)
|
||||
|
||||
if self.couche_vierge_ligne.isChecked() == 1 :
|
||||
cur.execute(SQL_trigger_length_m)
|
||||
cur.execute(SQL_trigger_length_km)
|
||||
|
||||
if self.couche_vierge_polygone.isChecked() == 1 :
|
||||
cur.execute(SQL_trigger_area_m2)
|
||||
cur.execute(SQL_trigger_area_ha)
|
||||
|
||||
con.commit()
|
||||
|
||||
### Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
else :
|
||||
con.commit()
|
||||
|
||||
con.close()
|
||||
pass
|
||||
@ -21,6 +21,10 @@ from .tools.resources import (
|
||||
resources_path,
|
||||
login_base,
|
||||
send_issues,
|
||||
create_vierge,
|
||||
create_contour,
|
||||
create_travaux,
|
||||
create_habita
|
||||
)
|
||||
from .issues import CenRa_Issues
|
||||
|
||||
@ -102,355 +106,10 @@ class Postgis_Editor(QDialog, EDITOR_CLASS):
|
||||
|
||||
schema = self.schema.currentText()
|
||||
|
||||
### Creation de la table contour
|
||||
if self.couche_contour.isChecked(): # Verifie si la checkbox est cochee
|
||||
if self.annee_1.text() == 'aaaa' or self.annee_1.text() == '':
|
||||
tablename = schema + "_contour"
|
||||
else :
|
||||
tablename = schema + "_contour_" + self.annee_1.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename+"','gid')"
|
||||
SQL_contour = "CREATE TABLE " + schema + "."+ tablename + champ_contour
|
||||
|
||||
cur.execute(SQL_contour)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
|
||||
SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
|
||||
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
||||
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
||||
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'contour_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_area_m2)
|
||||
cur.execute(SQL_trigger_area_ha)
|
||||
cur.execute(SQL_trigger_date_creation)
|
||||
cur.execute(SQL_trigger_date_maj)
|
||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
|
||||
## Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
### Creation de la table habitat
|
||||
|
||||
if self.couche_habitat.isChecked():
|
||||
if self.annee_2.text() == 'aaaa' or self.annee_2.text() == '':
|
||||
tablename = schema + "_habitat"
|
||||
else :
|
||||
tablename = schema + "_habitat_" + self.annee_2.text()
|
||||
|
||||
tablename_1=tablename+"_points"
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename_1+"','gid')"
|
||||
tablename_qgis = tablename_1[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
SQL_VEGETHAB = "CREATE TABLE "+ schema + "."+ tablename_1 + champ_vegethab_point
|
||||
|
||||
cur.execute(SQL_VEGETHAB)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename_1 + " ADD CONSTRAINT " + tablename_1 + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_coordonnees = "CREATE TRIGGER coordonnees" + tablename_1 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_1 + " FOR EACH ROW EXECUTE PROCEDURE ref.coordonnees();"
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename_1 + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'vegethab_points_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_1+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_1+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_coordonnees)
|
||||
cur.execute(SQL_style)
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
### Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename_1, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
tablename_2=tablename+"_lignes"
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename_2+"','gid')"
|
||||
tablename_qgis = tablename_2[1:]
|
||||
SQL_VEGETHAB = "CREATE TABLE "+ schema + "."+ tablename_2 + champ_vegethab_multilinestring
|
||||
|
||||
cur.execute(SQL_VEGETHAB)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename_2 + " ADD CONSTRAINT " + tablename_2 + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_length_m = "CREATE TRIGGER length_m" + tablename_2 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_2 + " FOR EACH ROW EXECUTE PROCEDURE ref.length_m();"
|
||||
SQL_trigger_length_km = "CREATE TRIGGER length_km" + tablename_2 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_2 + " FOR EACH ROW EXECUTE PROCEDURE ref.length_km();"
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename_2 + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'vegethab_lignes_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_2+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_2+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_length_m)
|
||||
cur.execute(SQL_trigger_length_km)
|
||||
cur.execute(SQL_style)
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
### Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename_2, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
tablename_3=tablename+"_polygones"
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename_3+"','gid')"
|
||||
tablename_qgis = tablename_3[1:]
|
||||
SQL_VEGETHAB = "CREATE TABLE "+ schema + "."+ tablename_3 + champ_vegethab_multipolygon
|
||||
|
||||
cur.execute(SQL_VEGETHAB)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename_3 + " ADD CONSTRAINT " + tablename_3 + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename_3 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_3 + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
|
||||
SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename_3 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_3 + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename_3 + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'vegethab_polygones_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_3+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_3+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_area_m2)
|
||||
cur.execute(SQL_trigger_area_ha)
|
||||
cur.execute(SQL_style)
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
### Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename_3, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
### Creation de la table travaux prevus
|
||||
if self.couche_travaux_prevus.isChecked():
|
||||
#**********Poly
|
||||
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
||||
tablename = schema + "_travaux_prevus_poly"
|
||||
else :
|
||||
tablename = schema + "_travaux_prevus_poly_" + self.annee_5.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename+"','gid')"
|
||||
SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus_multipolygon
|
||||
|
||||
cur.execute(SQL_travaux_prevus)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
||||
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
||||
SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
|
||||
SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
|
||||
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'travaux_prevus_poly_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_date_creation)
|
||||
cur.execute(SQL_trigger_date_maj)
|
||||
cur.execute(SQL_trigger_area_m2)
|
||||
cur.execute(SQL_trigger_area_ha)
|
||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
|
||||
## Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
#**********ligne
|
||||
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
||||
tablename = schema + "_travaux_prevus_ligne"
|
||||
else :
|
||||
tablename = schema + "_travaux_prevus_ligne_" + self.annee_5.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename+"','gid')"
|
||||
SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus_multilinestring
|
||||
|
||||
cur.execute(SQL_travaux_prevus)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
||||
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
||||
SQL_trigger_length_m = "CREATE TRIGGER length_m" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_m();"
|
||||
SQL_trigger_length_km = "CREATE TRIGGER length_km" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_km();"
|
||||
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'travaux_prevus_ligne_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_date_creation)
|
||||
cur.execute(SQL_trigger_date_maj)
|
||||
cur.execute(SQL_trigger_length_m)
|
||||
cur.execute(SQL_trigger_length_km)
|
||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
|
||||
## Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
#**********point
|
||||
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
||||
tablename = schema + "_travaux_prevus_point"
|
||||
else :
|
||||
tablename = schema + "_travaux_prevus_point_" + self.annee_5.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename+"','gid')"
|
||||
SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus_point
|
||||
|
||||
cur.execute(SQL_travaux_prevus)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
||||
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
||||
SQL_trigger_coordonnees = "CREATE TRIGGER coordonnees" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.coordonnees();"
|
||||
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'travaux_prevus_point_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_date_creation)
|
||||
cur.execute(SQL_trigger_date_maj)
|
||||
cur.execute(SQL_trigger_coordonnees)
|
||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
|
||||
## Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
### Creation de la table vierge
|
||||
if self.couche_vierge.isChecked():
|
||||
if self.annee_4.text() == 'aaaa' or self.annee_4.text() == '':
|
||||
tablename = schema + "_" + self.nom_couche_vierge.text().lower()
|
||||
else :
|
||||
tablename = schema + "_" + self.nom_couche_vierge.text().lower() + "_" + self.annee_4.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
|
||||
if self.couche_vierge_point.isChecked() == 1 :
|
||||
champ_vierge = champ_viergePoint
|
||||
|
||||
if self.couche_vierge_ligne.isChecked() == 1 :
|
||||
champ_vierge = champ_viergeLigne
|
||||
|
||||
if self.couche_vierge_polygone.isChecked() == 1 :
|
||||
champ_vierge = champ_viergePolygone
|
||||
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename+"','gid')"
|
||||
SQL_vierge = "CREATE TABLE " + schema + "."+ tablename + champ_vierge
|
||||
|
||||
cur.execute(SQL_vierge)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
|
||||
|
||||
SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
|
||||
SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
|
||||
SQL_trigger_length_m = "CREATE TRIGGER length_m" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_m();"
|
||||
SQL_trigger_length_km = "CREATE TRIGGER length_km" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_km();"
|
||||
SQL_trigger_coordonnees = "CREATE TRIGGER coordonnees" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.coordonnees();"
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
if self.couche_vierge_point.isChecked() == 1 :
|
||||
cur.execute(SQL_trigger_coordonnees)
|
||||
|
||||
if self.couche_vierge_ligne.isChecked() == 1 :
|
||||
cur.execute(SQL_trigger_length_m)
|
||||
cur.execute(SQL_trigger_length_km)
|
||||
|
||||
if self.couche_vierge_polygone.isChecked() == 1 :
|
||||
cur.execute(SQL_trigger_area_m2)
|
||||
cur.execute(SQL_trigger_area_ha)
|
||||
|
||||
con.commit()
|
||||
|
||||
### Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
else :
|
||||
con.commit()
|
||||
create_contour(self,schema,cur,con,host ,port ,dbname ,user ,mdp)
|
||||
create_habita(self,schema,cur,con,host ,port ,dbname ,user ,mdp)
|
||||
create_travaux(self,schema,cur,con,host ,port ,dbname ,user ,mdp)
|
||||
create_vierge(self,schema,cur,con,host ,port ,dbname ,user ,mdp)
|
||||
|
||||
con.close()
|
||||
pass
|
||||
@ -7,6 +7,8 @@ import base64
|
||||
import psycopg2
|
||||
import psycopg2.extras
|
||||
from os.path import abspath, join, pardir, dirname
|
||||
from qgis.core import QgsDataSourceUri
|
||||
from .PythonSQL import *
|
||||
|
||||
from qgis.PyQt import uic
|
||||
|
||||
@ -17,170 +19,519 @@ __revision__ = "$Format:%H$"
|
||||
|
||||
|
||||
def plugin_path(*args):
|
||||
"""Get the path to plugin root folder.
|
||||
"""Get the path to plugin root folder.
|
||||
|
||||
:param args List of path elements e.g. ['img', 'logos', 'image.png']
|
||||
:type args: str
|
||||
:param args List of path elements e.g. ['img', 'logos', 'image.png']
|
||||
:type args: str
|
||||
|
||||
:return: Absolute path to the plugin path.
|
||||
:rtype: str
|
||||
"""
|
||||
path = dirname(dirname(__file__))
|
||||
path = abspath(abspath(join(path, pardir)))
|
||||
for item in args:
|
||||
path = abspath(join(path, item))
|
||||
:return: Absolute path to the plugin path.
|
||||
:rtype: str
|
||||
"""
|
||||
path = dirname(dirname(__file__))
|
||||
path = abspath(abspath(join(path, pardir)))
|
||||
for item in args:
|
||||
path = abspath(join(path, item))
|
||||
|
||||
return path
|
||||
return path
|
||||
|
||||
|
||||
def plugin_name():
|
||||
"""Return the plugin name according to metadata.txt.
|
||||
"""Return the plugin name according to metadata.txt.
|
||||
|
||||
:return: The plugin name.
|
||||
:rtype: basestring
|
||||
"""
|
||||
metadata = metadata_config()
|
||||
name = metadata["general"]["name"]
|
||||
return name
|
||||
:return: The plugin name.
|
||||
:rtype: basestring
|
||||
"""
|
||||
metadata = metadata_config()
|
||||
name = metadata["general"]["name"]
|
||||
return name
|
||||
|
||||
|
||||
def metadata_config() -> configparser:
|
||||
"""Get the INI config parser for the metadata file.
|
||||
"""Get the INI config parser for the metadata file.
|
||||
|
||||
:return: The config parser object.
|
||||
:rtype: ConfigParser
|
||||
"""
|
||||
path = plugin_path("metadata.txt")
|
||||
config = configparser.ConfigParser()
|
||||
config.read(path, encoding='utf8')
|
||||
return config
|
||||
:return: The config parser object.
|
||||
:rtype: ConfigParser
|
||||
"""
|
||||
path = plugin_path("metadata.txt")
|
||||
config = configparser.ConfigParser()
|
||||
config.read(path, encoding='utf8')
|
||||
return config
|
||||
|
||||
|
||||
def plugin_test_data_path(*args, copy=False):
|
||||
"""Get the path to the plugin test data path.
|
||||
"""Get the path to the plugin test data path.
|
||||
|
||||
:param args List of path elements e.g. ['img', 'logos', 'image.png']
|
||||
:type args: str
|
||||
:param args List of path elements e.g. ['img', 'logos', 'image.png']
|
||||
:type args: str
|
||||
|
||||
:param copy: If the file must be copied into a temporary directory first.
|
||||
:type copy: bool
|
||||
:param copy: If the file must be copied into a temporary directory first.
|
||||
:type copy: bool
|
||||
|
||||
:return: Absolute path to the resources folder.
|
||||
:rtype: str
|
||||
"""
|
||||
path = abspath(abspath(join(plugin_path(), "test", "data")))
|
||||
for item in args:
|
||||
path = abspath(join(path, item))
|
||||
:return: Absolute path to the resources folder.
|
||||
:rtype: str
|
||||
"""
|
||||
path = abspath(abspath(join(plugin_path(), "test", "data")))
|
||||
for item in args:
|
||||
path = abspath(join(path, item))
|
||||
|
||||
if copy:
|
||||
temp = tempfile.mkdtemp()
|
||||
shutil.copy(path, temp)
|
||||
return join(temp, args[-1])
|
||||
else:
|
||||
return path
|
||||
if copy:
|
||||
temp = tempfile.mkdtemp()
|
||||
shutil.copy(path, temp)
|
||||
return join(temp, args[-1])
|
||||
else:
|
||||
return path
|
||||
|
||||
|
||||
def resources_path(*args):
|
||||
"""Get the path to our resources folder.
|
||||
"""Get the path to our resources folder.
|
||||
|
||||
:param args List of path elements e.g. ['img', 'logos', 'image.png']
|
||||
:type args: str
|
||||
:param args List of path elements e.g. ['img', 'logos', 'image.png']
|
||||
:type args: str
|
||||
|
||||
:return: Absolute path to the resources folder.
|
||||
:rtype: str
|
||||
"""
|
||||
path = abspath(abspath(join(plugin_path(), "CenRa_POSTGIS\\tools")))
|
||||
for item in args:
|
||||
path = abspath(join(path, item))
|
||||
return path
|
||||
:return: Absolute path to the resources folder.
|
||||
:rtype: str
|
||||
"""
|
||||
path = abspath(abspath(join(plugin_path(), "CenRa_POSTGIS\\tools")))
|
||||
for item in args:
|
||||
path = abspath(join(path, item))
|
||||
return path
|
||||
|
||||
|
||||
def load_ui(*args):
|
||||
"""Get compile UI file.
|
||||
"""Get compile UI file.
|
||||
|
||||
:param args List of path elements e.g. ['img', 'logos', 'image.png']
|
||||
:type args: str
|
||||
:param args List of path elements e.g. ['img', 'logos', 'image.png']
|
||||
:type args: str
|
||||
|
||||
:return: Compiled UI file.
|
||||
"""
|
||||
ui_class, _ = uic.loadUiType(resources_path("ui", *args))
|
||||
:return: Compiled UI file.
|
||||
"""
|
||||
ui_class, _ = uic.loadUiType(resources_path("ui", *args))
|
||||
|
||||
return ui_class
|
||||
return ui_class
|
||||
|
||||
def login_base(take=None):
|
||||
from CenRa_Metabase.resources.PythonSQL import host,port,dbname,password,os_user
|
||||
first_conn = psycopg2.connect("host=" + host + " port=" + port + " dbname="+dbname+" user=first_cnx password=" + password)
|
||||
first_cur = first_conn.cursor(cursor_factory = psycopg2.extras.DictCursor)
|
||||
first_cur.execute("SELECT mdp_w, login_w FROM pg_catalog.pg_user t1, admin_sig.vm_users_sig t2 WHERE t2.oid = t1.usesysid AND (login_w = '" + os_user + "' OR login_w = '" + os_user + "')")
|
||||
res_ident = first_cur.fetchone()
|
||||
mdp = base64.b64decode(str(res_ident[0])).decode('utf-8')
|
||||
user = res_ident[1]
|
||||
from .PythonSQL import host,port,dbname,password,os_user
|
||||
first_conn = psycopg2.connect("host=" + host + " port=" + port + " dbname="+dbname+" user=first_cnx password=" + password)
|
||||
first_cur = first_conn.cursor(cursor_factory = psycopg2.extras.DictCursor)
|
||||
first_cur.execute("SELECT mdp_w, login_w FROM pg_catalog.pg_user t1, admin_sig.vm_users_sig t2 WHERE t2.oid = t1.usesysid AND (login_w = '" + os_user + "' OR login_w = '" + os_user + "')")
|
||||
res_ident = first_cur.fetchone()
|
||||
mdp = base64.b64decode(str(res_ident[0])).decode('utf-8')
|
||||
user = res_ident[1]
|
||||
|
||||
con = psycopg2.connect("host=" + host + " port=" + port + " dbname="+dbname+" user=" + user + " password=" + mdp)
|
||||
con = psycopg2.connect("host=" + host + " port=" + port + " dbname="+dbname+" user=" + user + " password=" + mdp)
|
||||
|
||||
cur = con.cursor(cursor_factory = psycopg2.extras.DictCursor)
|
||||
first_conn.close()
|
||||
cur = con.cursor(cursor_factory = psycopg2.extras.DictCursor)
|
||||
first_conn.close()
|
||||
|
||||
if take:
|
||||
return cur,con
|
||||
else:
|
||||
return cur
|
||||
if take:
|
||||
return cur,con
|
||||
else:
|
||||
return cur
|
||||
def send_issues(url,titre,body,labels):
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
import qgis
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
import qgis
|
||||
|
||||
usr = os.environ['USERNAME']
|
||||
token = '9d0a4e0bea561710e0728f161f7edf4e5201e112'
|
||||
url=url+'?token='+token
|
||||
usr = os.environ['USERNAME']
|
||||
token = '9d0a4e0bea561710e0728f161f7edf4e5201e112'
|
||||
url=url+'?token='+token
|
||||
|
||||
headers = {'Authorization': 'token ' + token,'accept': 'application/json','Content-Type': 'application/json'}
|
||||
headers = {'Authorization': 'token ' + token,'accept': 'application/json','Content-Type': 'application/json'}
|
||||
|
||||
|
||||
payload = {'title': titre, 'body': body, 'labels': labels}
|
||||
try:
|
||||
urllib.request.urlopen('https://google.com')
|
||||
binar = True
|
||||
except:
|
||||
binar = False
|
||||
r = ''
|
||||
if binar:
|
||||
r = requests.post(url, data=json.dumps(payload), headers=headers)
|
||||
return r
|
||||
payload = {'title': titre, 'body': body, 'labels': labels}
|
||||
try:
|
||||
urllib.request.urlopen('https://google.com')
|
||||
binar = True
|
||||
except:
|
||||
binar = False
|
||||
r = ''
|
||||
if binar:
|
||||
r = requests.post(url, data=json.dumps(payload), headers=headers)
|
||||
return r
|
||||
|
||||
def maj_verif(NAME):
|
||||
import qgis
|
||||
import urllib.request
|
||||
iface = qgis.utils.iface
|
||||
from qgis.core import Qgis
|
||||
import qgis
|
||||
import urllib.request
|
||||
iface = qgis.utils.iface
|
||||
from qgis.core import Qgis
|
||||
|
||||
url = qgis.utils.pluginMetadata(NAME,'repository')
|
||||
#URL = url+'/raw/branch/main/plugins.xml'
|
||||
URL = 'https://gitea.cenra-outils.org/CEN-RA/Plugin_QGIS/releases/download/releases/plugins.xml'
|
||||
url = qgis.utils.pluginMetadata(NAME,'repository')
|
||||
#URL = url+'/raw/branch/main/plugins.xml'
|
||||
URL = 'https://gitea.cenra-outils.org/CEN-RA/Plugin_QGIS/releases/download/releases/plugins.xml'
|
||||
# print(URL)
|
||||
version = qgis.utils.pluginMetadata(NAME,'version')
|
||||
len_version = len(version)
|
||||
try:
|
||||
urllib.request.urlopen('https://google.com')
|
||||
binar = True
|
||||
except:
|
||||
binar = False
|
||||
if binar:
|
||||
try:
|
||||
version_web = str(urllib.request.urlopen(URL).read())
|
||||
plugin_num = version_web.find(NAME)
|
||||
valeur_version_web = version_web.find('<version>',plugin_num)+9
|
||||
version_plugin = version_web[valeur_version_web:valeur_version_web+len_version]
|
||||
if version_plugin != version:
|
||||
iface.messageBar().pushMessage("MAJ :", "Des mise à jour de plugin sont disponibles.", level=Qgis.Info, duration=30)
|
||||
except:
|
||||
print("error gitea version ssl")
|
||||
else:
|
||||
iface.messageBar().pushMessage("WiFi :", "Pas de connection à internet.", level=Qgis.Warning, duration=30)
|
||||
version = qgis.utils.pluginMetadata(NAME,'version')
|
||||
len_version = len(version)
|
||||
try:
|
||||
urllib.request.urlopen('https://google.com')
|
||||
binar = True
|
||||
except:
|
||||
binar = False
|
||||
if binar:
|
||||
try:
|
||||
version_web = str(urllib.request.urlopen(URL).read())
|
||||
plugin_num = version_web.find(NAME)
|
||||
valeur_version_web = version_web.find('<version>',plugin_num)+9
|
||||
version_plugin = version_web[valeur_version_web:valeur_version_web+len_version]
|
||||
if version_plugin != version:
|
||||
iface.messageBar().pushMessage("MAJ :", "Des mise à jour de plugin sont disponibles.", level=Qgis.Info, duration=30)
|
||||
except:
|
||||
print("error gitea version ssl")
|
||||
else:
|
||||
iface.messageBar().pushMessage("WiFi :", "Pas de connection à internet.", level=Qgis.Warning, duration=30)
|
||||
|
||||
def devlog(NAME):
|
||||
import qgis
|
||||
devmaj = '<head><style>* {margin:0; padding:0; }</style></head>'
|
||||
devmaj = devmaj+qgis.utils.pluginMetadata(NAME,'changelog')
|
||||
return devmaj
|
||||
import qgis
|
||||
devmaj = '<head><style>* {margin:0; padding:0; }</style></head>'
|
||||
devmaj = devmaj+qgis.utils.pluginMetadata(NAME,'changelog')
|
||||
return devmaj
|
||||
|
||||
def create_contour(self,schema,cur,con,host ,port ,dbname ,user ,mdp):
|
||||
### Creation de la table contour
|
||||
if self.couche_contour.isChecked(): # Verifie si la checkbox est cochee
|
||||
if self.annee_1.text() == 'aaaa' or self.annee_1.text() == '':
|
||||
tablename = schema + "_contour"
|
||||
else :
|
||||
tablename = schema + "_contour_" + self.annee_1.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename+"','gid')"
|
||||
SQL_contour = "CREATE TABLE " + schema + "."+ tablename + champ_contour
|
||||
|
||||
cur.execute(SQL_contour)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename[len(schema):] + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
|
||||
SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
|
||||
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
||||
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
||||
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'contour_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_area_m2)
|
||||
cur.execute(SQL_trigger_area_ha)
|
||||
cur.execute(SQL_trigger_date_creation)
|
||||
cur.execute(SQL_trigger_date_maj)
|
||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
|
||||
## Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
def create_travaux(self,schema,cur,con,host ,port ,dbname ,user ,mdp):
|
||||
### Creation de la table travaux prevus
|
||||
if self.couche_travaux_prevus.isChecked():
|
||||
#**********Poly
|
||||
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
||||
tablename = schema + "_travaux_prevus_poly"
|
||||
else :
|
||||
tablename = schema + "_travaux_prevus_poly_" + self.annee_5.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename+"','gid')"
|
||||
SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus_multipolygon
|
||||
|
||||
cur.execute(SQL_travaux_prevus)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename[len(schema):] + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
||||
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
||||
SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
|
||||
SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
|
||||
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'travaux_prevus_poly_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_date_creation)
|
||||
cur.execute(SQL_trigger_date_maj)
|
||||
cur.execute(SQL_trigger_area_m2)
|
||||
cur.execute(SQL_trigger_area_ha)
|
||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
|
||||
## Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
#**********ligne
|
||||
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
||||
tablename = schema + "_travaux_prevus_ligne"
|
||||
else :
|
||||
tablename = schema + "_travaux_prevus_ligne_" + self.annee_5.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename+"','gid')"
|
||||
SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus_multilinestring
|
||||
|
||||
cur.execute(SQL_travaux_prevus)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename[len(schema):] + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
||||
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
||||
SQL_trigger_length_m = "CREATE TRIGGER length_m" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_m();"
|
||||
SQL_trigger_length_km = "CREATE TRIGGER length_km" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_km();"
|
||||
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'travaux_prevus_ligne_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_date_creation)
|
||||
cur.execute(SQL_trigger_date_maj)
|
||||
cur.execute(SQL_trigger_length_m)
|
||||
cur.execute(SQL_trigger_length_km)
|
||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
|
||||
## Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
#**********point
|
||||
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
||||
tablename = schema + "_travaux_prevus_point"
|
||||
else :
|
||||
tablename = schema + "_travaux_prevus_point_" + self.annee_5.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename+"','gid')"
|
||||
SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus_point
|
||||
|
||||
cur.execute(SQL_travaux_prevus)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename[len(schema):] + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
||||
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
||||
SQL_trigger_coordonnees = "CREATE TRIGGER coordonnees" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.coordonnees();"
|
||||
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'travaux_prevus_point_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_date_creation)
|
||||
cur.execute(SQL_trigger_date_maj)
|
||||
cur.execute(SQL_trigger_coordonnees)
|
||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
|
||||
## Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
def create_habita(self,schema,cur,con,host ,port ,dbname ,user ,mdp):
|
||||
### Creation de la table habitat
|
||||
if self.couche_habitat.isChecked():
|
||||
if self.annee_2.text() == 'aaaa' or self.annee_2.text() == '':
|
||||
tablename = schema + "_habitat"
|
||||
else :
|
||||
tablename = schema + "_habitat_" + self.annee_2.text()
|
||||
|
||||
tablename_1=tablename+"_points"
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename_1[len(schema):]+"','gid')"
|
||||
tablename_qgis = tablename_1[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
SQL_VEGETHAB = "CREATE TABLE "+ schema + "."+ tablename_1 + champ_vegethab_point
|
||||
|
||||
cur.execute(SQL_VEGETHAB)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename_1 + " ADD CONSTRAINT " + tablename_1 + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_coordonnees = "CREATE TRIGGER coordonnees" + tablename_1 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_1 + " FOR EACH ROW EXECUTE PROCEDURE ref.coordonnees();"
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename_1 + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'vegethab_points_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_1+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_1+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_coordonnees)
|
||||
cur.execute(SQL_style)
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
### Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename_1, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
tablename_2=tablename+"_lignes"
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename_2+"','gid')"
|
||||
tablename_qgis = tablename_2[1:]
|
||||
SQL_VEGETHAB = "CREATE TABLE "+ schema + "."+ tablename_2 + champ_vegethab_multilinestring
|
||||
|
||||
cur.execute(SQL_VEGETHAB)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename_2 + " ADD CONSTRAINT " + tablename_2[len(schema):] + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_length_m = "CREATE TRIGGER length_m" + tablename_2 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_2 + " FOR EACH ROW EXECUTE PROCEDURE ref.length_m();"
|
||||
SQL_trigger_length_km = "CREATE TRIGGER length_km" + tablename_2 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_2 + " FOR EACH ROW EXECUTE PROCEDURE ref.length_km();"
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename_2 + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'vegethab_lignes_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_2+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_2+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_length_m)
|
||||
cur.execute(SQL_trigger_length_km)
|
||||
cur.execute(SQL_style)
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
### Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename_2, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
tablename_3=tablename+"_polygones"
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename_3+"','gid')"
|
||||
tablename_qgis = tablename_3[1:]
|
||||
SQL_VEGETHAB = "CREATE TABLE "+ schema + "."+ tablename_3 + champ_vegethab_multipolygon
|
||||
|
||||
cur.execute(SQL_VEGETHAB)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename_3 + " ADD CONSTRAINT " + tablename_3[len(schema):] + "_pkey" + " PRIMARY KEY (gid)"
|
||||
SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename_3 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_3 + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
|
||||
SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename_3 + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename_3 + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
|
||||
SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
|
||||
SELECT f_table_catalog, '""" + schema + "', '" + tablename_3 + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
|
||||
FROM layer_styles
|
||||
WHERE description = 'vegethab_polygones_modele_v3'"""
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_3+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename_3+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_trigger_area_m2)
|
||||
cur.execute(SQL_trigger_area_ha)
|
||||
cur.execute(SQL_style)
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
con.commit()
|
||||
### Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename_3, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
def create_vierge(self,schema,cur,con,host ,port ,dbname ,user ,mdp):
|
||||
### Creation de la table vierge
|
||||
if self.couche_vierge.isChecked():
|
||||
if self.annee_4.text() == 'aaaa' or self.annee_4.text() == '':
|
||||
tablename = schema + "_" + self.nom_couche_vierge.text().lower()
|
||||
else :
|
||||
tablename = schema + "_" + self.nom_couche_vierge.text().lower() + "_" + self.annee_4.text()
|
||||
tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
|
||||
|
||||
if self.couche_vierge_point.isChecked() == 1 :
|
||||
champ_vierge = champ_viergePoint
|
||||
|
||||
if self.couche_vierge_ligne.isChecked() == 1 :
|
||||
champ_vierge = champ_viergeLigne
|
||||
|
||||
if self.couche_vierge_polygone.isChecked() == 1 :
|
||||
champ_vierge = champ_viergePolygone
|
||||
|
||||
RETURNE = "SELECT pg_get_serial_sequence('"+schema + "."+ tablename+"','gid')"
|
||||
SQL_vierge = "CREATE TABLE " + schema + "."+ tablename + champ_vierge
|
||||
|
||||
cur.execute(SQL_vierge)
|
||||
cur.execute(RETURNE)
|
||||
sequence_name = cur.fetchone()[0]
|
||||
|
||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename[len(schema):] + "_pkey" + " PRIMARY KEY (gid)"
|
||||
|
||||
SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
|
||||
SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
|
||||
SQL_trigger_length_m = "CREATE TRIGGER length_m" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_m();"
|
||||
SQL_trigger_length_km = "CREATE TRIGGER length_km" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_km();"
|
||||
SQL_trigger_coordonnees = "CREATE TRIGGER coordonnees" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.coordonnees();"
|
||||
SQL_GRANT_TABLE="GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_qgis;GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON "+schema+"."+tablename+" TO grp_sig;GRANT ALL ON SEQUENCE "+sequence_name+" TO grp_qgis;"
|
||||
|
||||
cur.execute(SQL_pkey)
|
||||
cur.execute(SQL_GRANT_TABLE)
|
||||
|
||||
if self.couche_vierge_point.isChecked() == 1 :
|
||||
cur.execute(SQL_trigger_coordonnees)
|
||||
|
||||
if self.couche_vierge_ligne.isChecked() == 1 :
|
||||
cur.execute(SQL_trigger_length_m)
|
||||
cur.execute(SQL_trigger_length_km)
|
||||
|
||||
if self.couche_vierge_polygone.isChecked() == 1 :
|
||||
cur.execute(SQL_trigger_area_m2)
|
||||
cur.execute(SQL_trigger_area_ha)
|
||||
|
||||
con.commit()
|
||||
|
||||
### Affichage de la table
|
||||
uri = QgsDataSourceUri()
|
||||
# set host name, port, database name, username and password
|
||||
uri.setConnection(host ,port ,dbname ,user ,mdp)
|
||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||
uri.setDataSource(schema, tablename, geom)
|
||||
|
||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
<?xml version = '1.0' encoding = 'UTF-8'?>
|
||||
<plugins>
|
||||
<pyqgis_plugin name="CenRa_POSTGIS" version="2.3">
|
||||
<pyqgis_plugin name="CenRa_POSTGIS" version="2.4">
|
||||
<description><![CDATA[Dépôt pour les extensiont QGIS du CEN Rhone-Alpes, sur GitHub.]]></description>
|
||||
<version>2.3</version>
|
||||
<version>2.4</version>
|
||||
<qgis_minimum_version>3.16</qgis_minimum_version>
|
||||
<homepage>https://plateformesig.cenra-outils.org/</homepage>
|
||||
<file_name>CenRa_POSTGIS.zip</file_name>
|
||||
@ -11,7 +11,7 @@
|
||||
<download_url>https://gitea.cenra-outils.org/CEN-RA/Plugin_QGIS/releases/download/latest/CenRa_POSTGIS.zip</download_url>
|
||||
<uploaded_by>CEN-Rhone-Alpes</uploaded_by>
|
||||
<create_date>2024-02-06</create_date>
|
||||
<update_date>2025-01-22</update_date>
|
||||
<update_date>2025-01-23</update_date>
|
||||
<experimental>False</experimental>
|
||||
<deprecated>False</deprecated>
|
||||
<tags>cenra,postgis</tags>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user