1
|
from qgis.PyQt.QtCore import QCoreApplication
|
2
|
from qgis.core import (QgsProcessing,QgsFeatureSink,QgsProcessingException,QgsProcessingAlgorithm,
|
3
|
QgsProcessingParameterFeatureSource,QgsProcessingParameterFeatureSink,QgsFeatureRequest,QgsFeature,QgsProcessingParameterField,QgsProcessingParameterString,QgsRasterLayer,QgsProject,QgsProcessingParameterRasterDestination)
|
4
|
from qgis.utils import iface,QgsMessageBar
|
5
|
import processing
|
6
|
|
7
|
|
8
|
class ExampleProcessingAlgorithm(QgsProcessingAlgorithm):
|
9
|
|
10
|
|
11
|
Vector_layer_of_communes = 'Vector_layer_of_communes'
|
12
|
OUTPUT_raster = 'OUTPUT_raster'
|
13
|
Commune_name='Commune_name'
|
14
|
INSEE_code='INSEE_code'
|
15
|
EPSG_code='EPSG_code'
|
16
|
|
17
|
def tr(self, string):
|
18
|
"""
|
19
|
Returns a translatable string with the self.tr() function.
|
20
|
"""
|
21
|
return QCoreApplication.translate('Processing', string)
|
22
|
|
23
|
def createInstance(self):
|
24
|
return ExampleProcessingAlgorithm()
|
25
|
|
26
|
def name(self):
|
27
|
return 'Cadastre FR - WMS - Add a cadastral map'
|
28
|
|
29
|
def displayName(self):
|
30
|
return self.tr('Cadastre FR - WMS - Add a cadastral map')
|
31
|
|
32
|
|
33
|
def group(self):
|
34
|
return self.tr(self.groupId())
|
35
|
|
36
|
def groupId(self):
|
37
|
return 'Circet'
|
38
|
|
39
|
|
40
|
def shortHelpString(self):
|
41
|
|
42
|
return self.tr("Cadastre FR - WMS - Add a cadastral mapt")
|
43
|
|
44
|
|
45
|
def initAlgorithm(self, config=None):
|
46
|
|
47
|
|
48
|
self.addParameter(
|
49
|
QgsProcessingParameterFeatureSource(
|
50
|
self.Vector_layer_of_communes,
|
51
|
self.tr('Input Vector_layer_of_communes'),
|
52
|
[QgsProcessing.TypeVectorAnyGeometry]
|
53
|
)
|
54
|
)
|
55
|
|
56
|
|
57
|
|
58
|
|
59
|
self.addParameter(QgsProcessingParameterRasterDestination(
|
60
|
self.OUTPUT_raster,
|
61
|
self.tr("OUTPUT_raster"),
|
62
|
None, False))
|
63
|
|
64
|
|
65
|
|
66
|
self.addParameter(
|
67
|
QgsProcessingParameterField(
|
68
|
self.Commune_name,
|
69
|
description=self.Commune_name,
|
70
|
parentLayerParameterName=self.Vector_layer_of_communes,
|
71
|
type=QgsProcessingParameterField.Any
|
72
|
)
|
73
|
)
|
74
|
|
75
|
|
76
|
self.addParameter(
|
77
|
QgsProcessingParameterField(
|
78
|
self.INSEE_code,
|
79
|
description=self.INSEE_code,
|
80
|
parentLayerParameterName=self.Vector_layer_of_communes,
|
81
|
type=QgsProcessingParameterField.Any
|
82
|
)
|
83
|
)
|
84
|
|
85
|
self.addParameter(
|
86
|
QgsProcessingParameterString(
|
87
|
self.EPSG_code,
|
88
|
description='Code du projection, exemple: 2154'
|
89
|
|
90
|
|
91
|
|
92
|
)
|
93
|
)
|
94
|
|
95
|
|
96
|
def processAlgorithm(self, parameters, context, feedback):
|
97
|
|
98
|
|
99
|
shape_commune = self.parameterAsSource(parameters, self.Vector_layer_of_communes, context)
|
100
|
|
101
|
output_path_raster = self.parameterAsOutputLayer(parameters, self.OUTPUT_raster, context)
|
102
|
attribut_INSEE_code = self.parameterAsString(parameters, self.INSEE_code, context)
|
103
|
attribut_Commune_name = self.parameterAsString(parameters, self.Commune_name, context)
|
104
|
attribut_EPSG_code = self.parameterAsString(parameters, self.EPSG_code, context)
|
105
|
|
106
|
def recuperation_cadastre_commune(layer,INSEE_code,Commune_name,EPSG_code):
|
107
|
|
108
|
if EPSG_code == '2154' or EPSG_code == '3942' or EPSG_code == '3943' or EPSG_code == '3944' or EPSG_code == '3945' or EPSG_code == '3946' or EPSG_code == '3947' or EPSG_code == '3948' or EPSG_code == '3949' or EPSG_code == '3950' or EPSG_code == '32630' or EPSG_code == ' 32631' or EPSG_code == '32632' or EPSG_code == '3857' or EPSG_code == '4326' or EPSG_code == '4258' or EPSG_code == '32620' or EPSG_code == '2970' or EPSG_code == '2972' or EPSG_code == '2973' or EPSG_code == '2975' or EPSG_code == '32622' or EPSG_code == '32740' or EPSG_code == '32738' or EPSG_code == '4471' or EPSG_code == '32621' :
|
109
|
|
110
|
tab = []
|
111
|
for f in layer.getFeatures():
|
112
|
|
113
|
col_select =str(f[INSEE_code]),f[Commune_name]
|
114
|
tab.append(col_select)
|
115
|
|
116
|
|
117
|
Lt= list(set(tab))
|
118
|
Lt.sort()
|
119
|
|
120
|
for c_insee, n_couche in Lt :
|
121
|
|
122
|
|
123
|
urlWithParams = "url=http://inspire.cadastre.gouv.fr/scpc/"+c_insee+".wms?contextualWMSLegend=0&crs=EPSG:"+EPSG_code+"&dpiMode=7&featureCount=10&format=image/png&layers=AMORCES_CAD&layers=LIEUDIT&layers=CP.CadastralParcel&layers=SUBFISCAL&layers=CLOTURE&layers=DETAIL_TOPO&layers=HYDRO&layers=VOIE_COMMUNICATION&layers=BU.Building&layers=BORNE_REPERE&styles=&styles=&styles=&styles=&styles=&styles=&styles=&styles=&styles=&styles=&maxHeight=1024&maxWidth=1280"
|
124
|
|
125
|
rlayer = QgsRasterLayer(urlWithParams, 'Cadastre_'+n_couche+'_'+c_insee, 'wms')
|
126
|
|
127
|
output_path_raster=rlayer
|
128
|
|
129
|
|
130
|
|
131
|
|
132
|
|
133
|
|
134
|
'''if rlayer.isValid() == True :
|
135
|
iface.messageBar().pushMessage("Information :", "Ajout du cadastre dans Qgis_map : "+n_couche, Qgis.Info, duration=5)
|
136
|
iface.mapCanvas().refresh()
|
137
|
|
138
|
else :
|
139
|
iface.messageBar().pushMessage("Warning :", "WMS du Cadastre est invalide : "+n_couche, Qgis.Warning, duration=10)
|
140
|
|
141
|
else :
|
142
|
iface.messageBar().pushMessage("Warning :", "Projection Inconnue ", Qgis.Warning, duration=10)
|
143
|
progress.setText(u'EPSG is unknown ')'''
|
144
|
|
145
|
|
146
|
recuperation_cadastre_commune(shape_commune,attribut_INSEE_code,attribut_Commune_name,attribut_EPSG_code)
|
147
|
results = {}
|
148
|
results[self.OUTPUT_raster] = output_path_raster
|
149
|
|
150
|
return results
|