Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding script to load layer and script to load styles
- Loading branch information
Showing
16 changed files
with
7,178 additions
and
461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
""" | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
""" | ||
|
||
__author__ = '3liz' | ||
__date__ = '2019-02-15' | ||
__copyright__ = '(C) 2019 by 3liz' | ||
|
||
# This will get replaced with a git SHA1 when you do a git archive | ||
|
||
__revision__ = '$Format:%H$' | ||
|
||
from qgis.core import ( | ||
QgsProcessingAlgorithm, | ||
QgsProcessingParameterString, | ||
QgsProcessingOutputString, | ||
QgsProcessingOutputNumber, | ||
QgsExpressionContextUtils, | ||
QgsVectorLayer, | ||
QgsProcessingOutputMultipleLayers, | ||
QgsProcessingContext, | ||
QgsApplication, | ||
QgsProject | ||
) | ||
from qgis.PyQt.QtSql import * | ||
from .tools import * | ||
from processing.tools.postgis import uri_from_name, GeoDB | ||
import os | ||
|
||
class AddStyles(QgsProcessingAlgorithm): | ||
""" | ||
""" | ||
|
||
# Constants used to refer to parameters and outputs. They will be | ||
# used when calling the algorithm from another algorithm, or when | ||
# calling from the QGIS console. | ||
|
||
INPUT_SQL = 'INPUT_SQL' | ||
|
||
OUTPUT_LAYERS = 'OUTPUT_LAYERS' | ||
OUTPUT_STRING = 'OUTPUT_STRING' | ||
|
||
def name(self): | ||
return 'add_styles' | ||
|
||
def displayName(self): | ||
return self.tr('Load styles on layers') | ||
|
||
def group(self): | ||
return self.tr('Configuration') | ||
|
||
def groupId(self): | ||
return 'raepa_configuration' | ||
|
||
def tr(self, string): | ||
return QCoreApplication.translate('Processing', string) | ||
|
||
def createInstance(self): | ||
return self.__class__() | ||
|
||
def initAlgorithm(self, config): | ||
""" | ||
Here we define the inputs and output of the algorithm, along | ||
with some other properties. | ||
""" | ||
# INPUTS | ||
self.addParameter( | ||
QgsProcessingParameterString( | ||
self.INPUT_SQL, 'INPUT_SQL', | ||
optional=True | ||
) | ||
) | ||
|
||
|
||
# OUTPUTS | ||
# Add output for message | ||
self.addOutput( | ||
QgsProcessingOutputString( | ||
self.OUTPUT_STRING, | ||
self.tr('Output message') | ||
) | ||
) | ||
|
||
def processAlgorithm(self, parameters, context, feedback): | ||
""" | ||
Here is where the processing itself takes place. | ||
""" | ||
msg = '' | ||
msgl = '' | ||
Sdir_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),'..','..','qgis', 'qml') | ||
layers = QgsProject.instance().mapLayers() | ||
for lyr in layers: | ||
layer = context.project().mapLayer(lyr) | ||
if layer.isValid(): | ||
name = layer.name() | ||
fileName= '' | ||
if name == "raepa_canalaep_l": | ||
fileName = "canalisations_AEP.qml" | ||
if name == "raepa_canalass_l": | ||
fileName = "canalisations_ASS.qml" | ||
if name == "raepa_ouvraep_p": | ||
fileName = "ouvrages_AEP.qml" | ||
if name == "raepa_ouvrass_p": | ||
fileName = "ouvrages_ASS.qml" | ||
if name == "raepa_apparaep_p": | ||
fileName = "appareils_AEP.qml" | ||
if name == "raepa_apparass_p": | ||
fileName = "appareils_ASS.qml" | ||
if fileName != '': | ||
layer.loadNamedStyle(os.path.join(Sdir_path, fileName)) | ||
layer.triggerRepaint() | ||
msg +=' path : '+ Sdir_path + fileName +' style: '+ layer.name()+ ' is load' | ||
msg = os.path.join(Sdir_path, fileName) | ||
|
||
else: | ||
msgl += "!! "+layer.name()+" style not load !!" | ||
return { | ||
self.OUTPUT_STRING: msg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
""" | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
""" | ||
|
||
__author__ = '3liz' | ||
__date__ = '2019-02-15' | ||
__copyright__ = '(C) 2019 by 3liz' | ||
|
||
# This will get replaced with a git SHA1 when you do a git archive | ||
|
||
__revision__ = '$Format:%H$' | ||
|
||
from qgis.core import ( | ||
QgsProcessingAlgorithm, | ||
QgsProcessingParameterString, | ||
QgsProcessingOutputString, | ||
QgsProcessingOutputNumber, | ||
QgsExpressionContextUtils, | ||
QgsVectorLayer, | ||
QgsProcessingOutputMultipleLayers, | ||
QgsProcessingContext, | ||
QgsApplication, | ||
QgsProject | ||
) | ||
from qgis.PyQt.QtSql import * | ||
from .tools import * | ||
from processing.tools.postgis import uri_from_name, GeoDB | ||
import os | ||
|
||
class LoadProject(QgsProcessingAlgorithm): | ||
""" | ||
""" | ||
|
||
# Constants used to refer to parameters and outputs. They will be | ||
# used when calling the algorithm from another algorithm, or when | ||
# calling from the QGIS console. | ||
|
||
INPUT_SQL = 'INPUT_SQL' | ||
|
||
OUTPUT_LAYERS = 'OUTPUT_LAYERS' | ||
OUTPUT_STRING = 'OUTPUT_STRING' | ||
|
||
def name(self): | ||
return 'load_project' | ||
|
||
def displayName(self): | ||
return self.tr('Load project after generated database') | ||
|
||
def group(self): | ||
return self.tr('Configuration') | ||
|
||
def groupId(self): | ||
return 'raepa_configuration' | ||
|
||
def tr(self, string): | ||
return QCoreApplication.translate('Processing', string) | ||
|
||
def createInstance(self): | ||
return self.__class__() | ||
|
||
def initAlgorithm(self, config): | ||
""" | ||
Here we define the inputs and output of the algorithm, along | ||
with some other properties. | ||
""" | ||
# INPUTS | ||
self.addParameter( | ||
QgsProcessingParameterString( | ||
self.INPUT_SQL, 'INPUT_SQL', | ||
optional=True | ||
) | ||
) | ||
|
||
|
||
# OUTPUTS | ||
# Add output for message | ||
self.addOutput( | ||
QgsProcessingOutputString( | ||
self.OUTPUT_STRING, | ||
self.tr('Output message') | ||
) | ||
) | ||
|
||
self.addOutput( | ||
QgsProcessingOutputMultipleLayers( | ||
self.OUTPUT_LAYERS, | ||
self.tr('Output message') | ||
) | ||
) | ||
|
||
def processAlgorithm(self, parameters, context, feedback): | ||
""" | ||
Here is where the processing itself takes place. | ||
""" | ||
uri = uri_from_name(QgsExpressionContextUtils.globalScope().variable('raepa_connection_name')) | ||
def initLayer(schema, table, geom, sql, id): | ||
layer = None | ||
uri.setDataSource(schema, table, geom, sql, id) | ||
layer = QgsVectorLayer(uri.uri(), table, "postgres") | ||
if not layer.isValid(): | ||
msgl = 'tt' | ||
context.temporaryLayerStore().addMapLayer(layer) | ||
context.addLayerToLoadOnCompletion( | ||
layer.id(), | ||
QgsProcessingContext.LayerDetails(table, | ||
context.project(), | ||
self.OUTPUT_LAYERS | ||
) | ||
) | ||
return layer | ||
|
||
layers_name = { | ||
"sys_structure_metadonnee": {'geomfield': None, 'pk': 'id'}, | ||
"sys_liste_table": {'geomfield': None, 'pk': 'id'}, | ||
"sys_organisme_gestionnaire": {'geomfield': None, 'pk': 'id'}, | ||
"val_raepa_cat_canal_ae": {'geomfield': None, 'pk': 'id'}, | ||
"val_raepa_cat_canal_ass": {'geomfield': None, 'pk': 'id'}, | ||
"val_raepa_fonc_app_ae":{'geomfield': None, 'pk': 'id'}, | ||
"val_raepa_fonc_app_ass":{'geomfield': None, 'pk': 'id'}, | ||
"val_raepa_fonc_canal_ae":{'geomfield': None, 'pk': 'id'}, | ||
"val_raepa_fonc_canal_ass":{'geomfield': None, 'pk': 'id'}, | ||
"val_raepa_fonc_ouv_ae":{'geomfield': None, 'pk': 'id'}, | ||
"commune": {'geomfield': "geom", 'pk': 'id'}, | ||
"_val_raepa_precision_annee":{'geomfield': None, 'pk': 'id'}, | ||
"_val_raepa_type_intervention_ass":{'geomfield': None, 'pk': 'id'}, | ||
"raepa_apparaep_p": {'geomfield': "geom", 'pk': 'id'}, | ||
"raepa_apparass_p": {'geomfield': "geom", 'pk': 'id'}, | ||
"affleurant_pcrs": {'geomfield': "geom", 'pk': 'id'}, | ||
"_val_raepa_etat_canal_ass":{'geomfield': None, 'pk': 'id'}, | ||
"_val_raepa_forme_canal_ass":{'geomfield': None, 'pk': 'id'}, | ||
"raepa_canalaep_l": {'geomfield': "geom", 'pk': 'id'}, | ||
"raepa_reparaep_p": {'geomfield': "geom", 'pk': 'id'}, | ||
"raepa_reparass_p": {'geomfield': "geom", 'pk': 'id'}, | ||
"raepa_ouvraep_p": {'geomfield': "geom", 'pk': 'id'}, | ||
"raepa_ouvrass_p": {'geomfield': "geom", 'pk': 'id'}, | ||
"raepa_canalass_l": {'geomfield': "geom", 'pk': 'id'}, | ||
"v_canalisation_avec_z_manquant":{'geomfield': "geom", 'pk': 'id'}, | ||
"v_canalisation_avec_zaval_manquant":{'geomfield': "geom", 'pk': 'id'}, | ||
"v_canalisation_branchement":{'geomfield': "geom", 'pk': 'id'}, | ||
"v_canalisation_sans_ouvrage":{'geomfield': "geom", 'pk': 'id'}, | ||
"val_raepa_qualite_geoloc":{'geomfield': None, 'pk': 'id'}, | ||
"val_raepa_qualite_anpose":{'geomfield': None, 'pk': 'id'}, | ||
"val_raepa_typ_reseau_ass":{'geomfield': None, 'pk': 'id'}, | ||
"val_raepa_materiau":{'geomfield': None, 'pk': 'id'}, | ||
"val_raepa_mode_circulation":{'geomfield': None, 'pk': 'id'}, | ||
"val_raepa_fonc_ouv_ass":{'geomfield': None, 'pk': 'id'}, | ||
"val_raepa_type_defaillance":{'geomfield': None, 'pk': 'id'}, | ||
"val_raepa_support_reparation":{'geomfield': None, 'pk': 'id'} | ||
} | ||
output_layers = [] | ||
msg = '' | ||
msgl = '' | ||
|
||
for e in layers_name: | ||
layer = initLayer("raepa", e, layers_name[e]['geomfield'], "", layers_name[e]['pk']) | ||
if layer.isValid(): | ||
output_layers.append(layer) | ||
msgl += " ## "+layer.name()+" loaded ##" | ||
|
||
else: | ||
msgl += " !! "+layer.name()+" did not load !!" | ||
|
||
|
||
if len(output_layers) > 0: | ||
msg = 'Import de couche ok ! ' | ||
msg += msgl | ||
return { | ||
self.OUTPUT_LAYERS: output_layers, | ||
self.OUTPUT_STRING: msg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'> | ||
<qgis version="3.4.13-Madeira" styleCategories="Actions"> | ||
<attributeactions> | ||
<defaultAction key="Canvas" value="{00000000-0000-0000-0000-000000000000}"/> | ||
<actionsetting action="from qgis.utils import plugins
plugins['raepa'].run_action(
 'parcourir_reseau_depuis_cet_objet',
 '[% idappareil %]',
 0
)" capture="0" isEnabledOnlyWhenEditable="0" type="1" id="{b3bb6295-70ae-44c6-97f7-bbc71a51d4ee}" name="Parcourir le réseau depuis cet objet" shortTitle="" icon="" notificationMessage=""> | ||
<actionScope id="Feature"/> | ||
<actionScope id="Field"/> | ||
<actionScope id="Canvas"/> | ||
</actionsetting> | ||
<actionsetting action="from qgis.utils import plugins
plugins['raepa'].run_action(
 'calcul_orientation_appareil',
 '[% idappareil %]',
)" capture="0" isEnabledOnlyWhenEditable="0" type="1" id="{efbd9a79-f784-43b0-876a-c3254754d686}" name="Calcul de l'orientation de l'appareil" shortTitle="" icon="" notificationMessage=""> | ||
<actionScope id="Feature"/> | ||
<actionScope id="Field"/> | ||
<actionScope id="Canvas"/> | ||
</actionsetting> | ||
</attributeactions> | ||
<layerGeometryType>0</layerGeometryType> | ||
</qgis> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'> | ||
<qgis version="3.4.13-Madeira" styleCategories="Actions"> | ||
<attributeactions> | ||
<defaultAction key="Canvas" value="{00000000-0000-0000-0000-000000000000}"/> | ||
<actionsetting action="from qgis.utils import plugins
plugins['raepa'].run_action(
 'parcourir_reseau_depuis_cet_objet',
 '[% idappareil %]',
 0
)" capture="0" isEnabledOnlyWhenEditable="0" type="1" id="{c540b6cc-c2a0-4402-9a85-9e666ea76ba7}" name="Parcourir le réseau depuis cet objet" shortTitle="" icon="" notificationMessage=""> | ||
<actionScope id="Feature"/> | ||
<actionScope id="Field"/> | ||
<actionScope id="Canvas"/> | ||
</actionsetting> | ||
</attributeactions> | ||
<layerGeometryType>0</layerGeometryType> | ||
</qgis> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'> | ||
<qgis version="3.4.13-Madeira" styleCategories="Actions"> | ||
<attributeactions> | ||
<defaultAction key="Canvas" value="{00000000-0000-0000-0000-000000000000}"/> | ||
<actionsetting action="from qgis.utils import plugins
plugins['raepa'].run_action(
 'inverser_canalisation',
 '[% id %]',
 '[% @layer_id %]'
)" capture="0" isEnabledOnlyWhenEditable="0" type="1" id="{b661253b-1f14-4077-a7e2-8375868562db}" name="Inverser la canalisation" shortTitle="Inverser la canalisation" icon="" notificationMessage=""> | ||
<actionScope id="Feature"/> | ||
<actionScope id="Field"/> | ||
</actionsetting> | ||
<actionsetting action="from qgis.utils import plugins
plugins['raepa'].run_action(
 'parcourir_reseau_depuis_cet_objet',
 '[% idcana %]',
 0
)" capture="0" isEnabledOnlyWhenEditable="0" type="1" id="{2a9144ec-949e-42c0-89d3-9fe9020b32dd}" name="Parcourir le réseau depuis cet objet" shortTitle="" icon="" notificationMessage=""> | ||
<actionScope id="Feature"/> | ||
<actionScope id="Field"/> | ||
<actionScope id="Canvas"/> | ||
</actionsetting> | ||
<actionsetting action="from qgis.utils import plugins
plugins['raepa'].run_action(
 'network_to_vanne',
 '[% idcana %]'
)" capture="0" isEnabledOnlyWhenEditable="0" type="1" id="{1249ed38-1d64-4036-a8e3-bdf8a363898a}" name="Parcourir le sous réseau jusqu'à une vanne" shortTitle="Parcours réseau vanne" icon="" notificationMessage=""> | ||
<actionScope id="Feature"/> | ||
<actionScope id="Field"/> | ||
<actionScope id="Canvas"/> | ||
</actionsetting> | ||
</attributeactions> | ||
<layerGeometryType>1</layerGeometryType> | ||
</qgis> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'> | ||
<qgis version="3.4.13-Madeira" styleCategories="Actions"> | ||
<attributeactions> | ||
<defaultAction key="Canvas" value="{00000000-0000-0000-0000-000000000000}"/> | ||
<actionsetting action="from qgis.utils import plugins
plugins['raepa'].run_action(
 'inverser_canalisation',
 '[% id %]',
 '[% @layer_id %]'
)" capture="0" isEnabledOnlyWhenEditable="0" type="1" id="{5fbb59c5-2b60-4b1f-a2ce-cc5d45cf3aba}" name="Inverser la canalisation" shortTitle="Inverser la canalisation" icon="" notificationMessage=""> | ||
<actionScope id="Feature"/> | ||
<actionScope id="Field"/> | ||
<actionScope id="Canvas"/> | ||
</actionsetting> | ||
<actionsetting action="from qgis.utils import plugins
plugins['raepa'].run_action(
 'parcourir_reseau_depuis_cet_objet',
 '[% idcana %]',
 0
)" capture="0" isEnabledOnlyWhenEditable="0" type="1" id="{f4852f46-9647-4400-9fde-d1975d6ce816}" name="Parcourir le réseau depuis cet objet" shortTitle="" icon="" notificationMessage=""> | ||
<actionScope id="Feature"/> | ||
<actionScope id="Field"/> | ||
<actionScope id="Canvas"/> | ||
</actionsetting> | ||
</attributeactions> | ||
<layerGeometryType>1</layerGeometryType> | ||
</qgis> |
Oops, something went wrong.