@@ -194,7 +194,7 @@ def add_action(
194
194
195
195
return action
196
196
197
- def initGui (self ):
197
+ def initGui (self ): # noqa N802
198
198
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
199
199
200
200
self .add_action (
@@ -236,23 +236,23 @@ def run(self):
236
236
)
237
237
238
238
if self .nls_user_key == "" :
239
- res = self .showSettingsDialog ()
239
+ res = self .show_settings_dialog ()
240
240
if not res :
241
241
return
242
- if not self .loadLayers ():
242
+ if not self .load_layers ():
243
243
QMessageBox .critical (
244
244
self .iface .mainWindow (),
245
245
self .tr (u"Failed to load data" ),
246
246
self .tr (u"Check that necessary files exist in data folder" ),
247
247
)
248
248
return
249
249
250
- self .product_types = self .downloadNLSProductTypes ()
250
+ self .product_types = self .download_nls_product_types ()
251
251
252
252
self .municipalities_dialog = NLSGeoPackageLoaderMunicipalitySelectionDialog ()
253
253
254
254
self .municipalities_dialog .settingsPushButton .clicked .connect (
255
- self .showSettingsDialog
255
+ self .show_settings_dialog
256
256
)
257
257
self .municipalities_dialog .fileNameEdit .setValue (self .fileName )
258
258
self .municipalities_dialog .loadLayers .setChecked (self .addDownloadedDataAsLayer )
@@ -261,17 +261,17 @@ def run(self):
261
261
)
262
262
self .municipalities_dialog .loadUtmGrids .setChecked (self .showUTMGridsAsLayer )
263
263
self .municipalities_dialog .loadSeaGrids .setChecked (self .showSeatilesAsLayer )
264
- self .municipalities_dialog .loadLayers .stateChanged .connect (self .toggleLayers )
265
- self .municipalities_dialog .loadMunLayer .stateChanged .connect (self .toggleLayers )
266
- self .municipalities_dialog .loadUtmGrids .stateChanged .connect (self .toggleLayers )
267
- self .municipalities_dialog .loadSeaGrids .stateChanged .connect (self .toggleLayers )
268
- self .toggleLayers ()
264
+ self .municipalities_dialog .loadLayers .stateChanged .connect (self .toggle_layers )
265
+ self .municipalities_dialog .loadMunLayer .stateChanged .connect (self .toggle_layers )
266
+ self .municipalities_dialog .loadUtmGrids .stateChanged .connect (self .toggle_layers )
267
+ self .municipalities_dialog .loadSeaGrids .stateChanged .connect (self .toggle_layers )
268
+ self .toggle_layers ()
269
269
270
270
for feature in self .municipality_layer .getFeatures ():
271
271
item = QListWidgetItem (feature ["NAMEFIN" ])
272
272
self .municipalities_dialog .municipalityListWidget .addItem (item )
273
273
274
- for key , value in self .product_types .items ():
274
+ for value in self .product_types .values ():
275
275
item = QListWidgetItem (value )
276
276
self .municipalities_dialog .productListWidget .addItem (item )
277
277
if value in MTK_PRESELECTED_PRODUCTS :
@@ -365,20 +365,20 @@ def run(self):
365
365
if len (product_types ) > 0 and len (self .selected_geoms ) > 0 :
366
366
QCoreApplication .processEvents ()
367
367
368
- self .getIntersectingFeatures (
368
+ self .get_intersecting_features (
369
369
self .municipality_layer .selectedFeatures (),
370
370
self .utm25lr_layer ,
371
371
selected_mun_names ,
372
372
)
373
- self .getIntersectingFeatures (
373
+ self .get_intersecting_features (
374
374
self .seatile_layer .selectedFeatures (), self .utm25lr_layer
375
375
)
376
376
for grid in grids :
377
- self .getIntersectingFeatures (
377
+ self .get_intersecting_features (
378
378
grid .selectedFeatures (), self .utm25lr_layer
379
379
)
380
380
381
- self .downloadData (product_types )
381
+ self .download_data (product_types )
382
382
383
383
else :
384
384
self .progress_dialog .hide ()
@@ -389,7 +389,7 @@ def run(self):
389
389
)
390
390
return
391
391
392
- def toggleLayers (self ):
392
+ def toggle_layers (self ):
393
393
"""Load municipality and map tile layers"""
394
394
self .addDownloadedDataAsLayer = (
395
395
self .municipalities_dialog .loadLayers .isChecked ()
@@ -424,7 +424,7 @@ def toggleLayers(self):
424
424
found_utm100_layer
425
425
) = found_utm200_layer = found_seatiles_layer = found_municipality_layer = False
426
426
427
- current_layers = self .getLayers (self .instance .layerTreeRoot ())
427
+ current_layers = self .get_layers (self .instance .layerTreeRoot ())
428
428
429
429
for current_layer in current_layers :
430
430
if current_layer .layer () == self .utm5_layer :
@@ -472,7 +472,7 @@ def toggleLayers(self):
472
472
if not found_utm5_layer and self .utm5_layer :
473
473
self .instance .addMapLayer (self .utm5_layer )
474
474
except :
475
- self .loadLayers ()
475
+ self .load_layers ()
476
476
if not found_utm200_layer and self .utm200_layer :
477
477
self .instance .addMapLayer (self .utm200_layer )
478
478
if not found_utm100_layer and self .utm100_layer :
@@ -492,17 +492,17 @@ def toggleLayers(self):
492
492
try :
493
493
self .instance .addMapLayer (self .seatile_layer )
494
494
except :
495
- self .loadLayers ()
495
+ self .load_layers ()
496
496
self .instance .addMapLayer (self .seatile_layer )
497
497
498
498
if self .showMunicipalitiesAsLayer and not found_municipality_layer :
499
499
try :
500
500
self .instance .addMapLayer (self .municipality_layer )
501
501
except :
502
- self .loadLayers ()
502
+ self .load_layers ()
503
503
self .instance .addMapLayer (self .municipality_layer )
504
504
505
- def loadLayers (self ):
505
+ def load_layers (self ):
506
506
self .municipality_layer = QgsVectorLayer (
507
507
resources_path ("data" , "SuomenKuntajako_2018_10k.shp" ),
508
508
"municipalities" ,
@@ -610,7 +610,7 @@ def loadLayers(self):
610
610
self .seatile_layer = False
611
611
612
612
self .instance = QgsProject .instance ()
613
- current_layers = self .getLayers (self .instance .layerTreeRoot ())
613
+ current_layers = self .get_layers (self .instance .layerTreeRoot ())
614
614
615
615
for lnode in current_layers :
616
616
if (
@@ -661,16 +661,16 @@ def loadLayers(self):
661
661
662
662
return True
663
663
664
- def getLayers (self , root ):
664
+ def get_layers (self , root ):
665
665
layers = []
666
666
for node in root .children ():
667
667
if isinstance (node , QgsLayerTreeGroup ):
668
- layers .extend (self .getLayers (node ))
668
+ layers .extend (self .get_layers (node ))
669
669
else :
670
670
layers .append (node )
671
671
return layers
672
672
673
- def getIntersectingFeatures (self , features , layer , selected_mun_names = None ):
673
+ def get_intersecting_features (self , features , layer , selected_mun_names = None ):
674
674
if selected_mun_names :
675
675
expression = ""
676
676
for mun in selected_mun_names :
@@ -694,15 +694,15 @@ def getIntersectingFeatures(self, features, layer, selected_mun_names=None):
694
694
if feature not in self .utm25lr_features :
695
695
self .utm25lr_features .append (layer_feature )
696
696
697
- def downloadData (self , product_types ):
697
+ def download_data (self , product_types ):
698
698
699
699
self .all_urls = []
700
700
self .total_download_count = 0
701
701
self .download_count = 0
702
702
self .layers_added_count = 0
703
703
704
704
for product_key , product_title in product_types .items ():
705
- urls = self .createDownloadURLS (product_key , product_title )
705
+ urls = self .create_download_urls (product_key , product_title )
706
706
self .all_urls .extend (urls )
707
707
self .total_download_count += len (urls )
708
708
@@ -721,9 +721,9 @@ def downloadData(self, product_types):
721
721
self .progress_dialog .progressBar .reset ()
722
722
self .progress_dialog .progressBar .show ()
723
723
self .progress_dialog .label .setText ("Downloading data..." )
724
- QTimer .singleShot (1000 , self .downloadOneFile )
724
+ QTimer .singleShot (1000 , self .download_one_file )
725
725
726
- def downloadNLSProductTypes (self ):
726
+ def download_nls_product_types (self ):
727
727
products = {}
728
728
729
729
url = (
@@ -759,7 +759,7 @@ def downloadNLSProductTypes(self):
759
759
760
760
return products
761
761
762
- def downloadOneFile (self ):
762
+ def download_one_file (self ):
763
763
if (
764
764
self .download_count == self .total_download_count
765
765
or self .download_count >= len (self .all_urls )
@@ -814,42 +814,42 @@ def downloadOneFile(self):
814
814
815
815
if self .download_count == self .total_download_count :
816
816
QgsMessageLog .logMessage ("done downloading data" , "NLSgpkgloader" , 0 )
817
- self .createGeoPackage ()
817
+ self .create_geopackage ()
818
818
else :
819
- QTimer .singleShot (10 , self .downloadOneFile )
819
+ QTimer .singleShot (10 , self .download_one_file )
820
820
821
- def createGeoPackage (self ):
821
+ def create_geopackage (self ):
822
822
"""Creates a GeoPackage from the downloaded MTK data"""
823
823
self .progress_dialog .progressBar .reset ()
824
824
self .progress_dialog .label .setText ("Writing layers to GeoPackage..." )
825
825
826
- writeTask = CreateGeoPackageTask (
826
+ write_task = CreateGeoPackageTask (
827
827
"Write GML to GPKG" ,
828
828
self .all_urls ,
829
829
self .total_download_count ,
830
830
self .selected_mtk_product_types ,
831
831
self .data_download_dir ,
832
832
self .gpkg_path ,
833
833
)
834
- dissolveTask = DissolveFeaturesTask ("Dissolve features" , self .gpkg_path )
835
- clipTask = ClipLayersTask ("Clip layers" , self .selected_geoms , self .gpkg_path )
836
- cleanupTask = CleanUpTask ("Delete temporary tables" , self .path , self .gpkg_path )
834
+ dissolve_task = DissolveFeaturesTask ("Dissolve features" , self .gpkg_path )
835
+ clip_task = ClipLayersTask ("Clip layers" , self .selected_geoms , self .gpkg_path )
836
+ cleanup_task = CleanUpTask ("Delete temporary tables" , self .path , self .gpkg_path )
837
837
838
- writeTask .taskCompleted .connect (lambda : self .runTask ( dissolveTask ))
839
- dissolveTask .taskCompleted .connect (lambda : self .runTask ( clipTask ))
840
- clipTask .taskCompleted .connect (lambda : self .runTask ( cleanupTask ))
841
- cleanupTask .taskCompleted .connect (lambda : self .finishProcessing ())
838
+ write_task .taskCompleted .connect (lambda : self .run_task ( dissolve_task ))
839
+ dissolve_task .taskCompleted .connect (lambda : self .run_task ( clip_task ))
840
+ clip_task .taskCompleted .connect (lambda : self .run_task ( cleanup_task ))
841
+ cleanup_task .taskCompleted .connect (lambda : self .finish_processing ())
842
842
843
- self .runTask ( writeTask )
843
+ self .run_task ( write_task )
844
844
845
- def runTask (self , task ):
845
+ def run_task (self , task ):
846
846
self .progress_dialog .label .setText (task .description ())
847
847
task .progressChanged .connect (
848
848
lambda : self .progress_dialog .progressBar .setValue (task .progress ())
849
849
)
850
850
QgsApplication .taskManager ().addTask (task )
851
851
852
- def finishProcessing (self ):
852
+ def finish_processing (self ):
853
853
if self .addDownloadedDataAsLayer :
854
854
self .progress_dialog .label .setText ("Adding layers to QGIS" )
855
855
self .progress_dialog .progressBar .hide ()
@@ -875,7 +875,7 @@ def finishProcessing(self):
875
875
self .progress_dialog .hide ()
876
876
return True
877
877
878
- def showSettingsDialog (self ):
878
+ def show_settings_dialog (self ):
879
879
self .nls_user_key_dialog .dataLocationQgsFileWidget .setStorageMode (
880
880
QgsFileWidget .GetDirectory
881
881
)
@@ -919,7 +919,7 @@ def showSettingsDialog(self):
919
919
)
920
920
return False
921
921
922
- def createDownloadURLS (self , product_key , product_title ):
922
+ def create_download_urls (self , product_key , product_title ):
923
923
urls = []
924
924
if (
925
925
product_key
0 commit comments