Skip to content

Commit

Permalink
updated error handling due to issues with QGIS>=3.30 which caused cra…
Browse files Browse the repository at this point in the history
…shes
  • Loading branch information
bogind committed Nov 21, 2024
1 parent f4c46e8 commit 8083876
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions qlyrx_styler.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def apply_lyrx_symbols(self, dlg, layer, lyrx_data, geometry_general_type_str):
dataset = p['featureTable']['dataConnection']['dataset']
dataset_names.append(dataset)
except Exception as e:
QgsMessageLog.logMessage(e, 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage(str(e), 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage("there are " + str(len(label_symb_array)) + " label def", 'qlyrxStyler', level=Qgis.MessageLevel.Info)


Expand Down Expand Up @@ -208,7 +208,7 @@ def apply_lyrx_symbols(self, dlg, layer, lyrx_data, geometry_general_type_str):
try:
ret.appendSymbolLayer(line)
except Exception as e:
QgsMessageLog.logMessage(e, 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage(str(e), 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage(line.__class__.__name__, 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
for line_sym in lines_ret[1]:
allSymbolLayers[line_sym] = lines_ret[1][line_sym]
Expand Down Expand Up @@ -308,7 +308,7 @@ def apply_lyrx_symbols(self, dlg, layer, lyrx_data, geometry_general_type_str):
else:
new_symbol = ret
except Exception as e:
QgsMessageLog.logMessage(e, 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage(str(e), 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage("order fail", 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
# add user interaction

Expand Down Expand Up @@ -338,7 +338,7 @@ def apply_lyrx_symbols(self, dlg, layer, lyrx_data, geometry_general_type_str):
try:
symbol.changeSymbolLayer(0, single_symbology)
except Exception as e:
QgsMessageLog.logMessage(e, 'qlyrxStyler', level=Qgis.MessageLevel.WARNING)
QgsMessageLog.logMessage(str(e), 'qlyrxStyler', level=Qgis.MessageLevel.Warning)
symbol = single_symbology

renderer = QgsSingleSymbolRenderer(symbol)
Expand Down Expand Up @@ -407,7 +407,7 @@ def initial_lyrx_parse(self,lyrx_data,layer):
dataset = p['featureTable']['dataConnection']['dataset']
dataset_names.append(dataset)
except Exception as e:
QgsMessageLog.logMessage(e, 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage(str(e), 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage("there are " + str(len(label_symb_array)) + " label def", 'qlyrxStyler', level=Qgis.MessageLevel.Info)
# Find a renderer with the active layer field attribute
rend_to_check = []
Expand Down Expand Up @@ -485,7 +485,7 @@ def parseLabels(self, labelSymbArr, labelExpArr, layer, layerId = 0):
fontWeight = labelSymbol['symbol']['fontStyleName'] if labelSymbol['symbol']['fontStyleName'] else 'Regular'
minimumScale = labelParse['minimumScale'] if 'minimumScale' in labelParse else ''
except Exception as e:
QgsMessageLog.logMessage(e,'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage(str(e),'qlyrxStyler', level=Qgis.MessageLevel.Critical)

# Create label settings
label_settings = QgsPalLayerSettings()
Expand Down Expand Up @@ -514,7 +514,7 @@ def parseLabels(self, labelSymbArr, labelExpArr, layer, layerId = 0):
label_settings.scaleVisibility = True if not minimumScale == '' else False
label_settings.minimumScale = minimumScale if not minimumScale == '' else 0
except Exception as e:
QgsMessageLog.logMessage(e, 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage(str(e), 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
## Label visibility
label_settings.enabled = True
label_settings = QgsVectorLayerSimpleLabeling(label_settings)
Expand Down Expand Up @@ -664,7 +664,7 @@ def parseRasterGroups(self, obj, layer):
QgsMessageLog.logMessage("after raster repaint", 'qlyrxStyler', level=Qgis.MessageLevel.Info)

except Exception as e:
QgsMessageLog.logMessage(e, 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage(str(e), 'qlyrxStyler', level=Qgis.MessageLevel.Critical)


def parseRasterClassBreaks(self, obj, layer):
Expand Down Expand Up @@ -708,7 +708,7 @@ def parseRasterClassBreaks(self, obj, layer):
QgsMessageLog.logMessage("after raster repaint", 'qlyrxStyler', level=Qgis.MessageLevel.Info)

except Exception as e:
QgsMessageLog.logMessage(e, 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage(str(e), 'qlyrxStyler', level=Qgis.MessageLevel.Critical)

#return ''

Expand Down Expand Up @@ -991,7 +991,7 @@ def colorToRgbArray(self, color_array, type):
return new_color
except Exception as e:
QgsMessageLog.logMessage('Error in color conversion', 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage(e, 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage(str(e), 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
return QColor.fromRgb(255,255,255)


Expand All @@ -1017,7 +1017,8 @@ def parseSimpleRenderer(self, obj, layer):
#allSymbolLayers[v_ord] = v_symb
symbol = v_symb
#print("After simple vector")
QgsMessageLog.logMessage("parseSimpleRenderer, Geometry type is " + layer.geometryType(), 'qlyrxStyler', level=Qgis.MessageLevel.Info)
QgsMessageLog.logMessage("parseSimpleRenderer, Geometry type is " + QgsWkbTypes.displayString(layer.wkbType()), 'qlyrxStyler', level=Qgis.MessageLevel.Info)
# Polygon
if layer.geometryType() == 2:
solid_array = self.parseSolidFill({"desc": [symb_def]}, layer)
symbol = solid_array[0]
Expand Down Expand Up @@ -1194,7 +1195,7 @@ def parseVectorSymbolLine(self, obj, simple, layer):
try:
new_str = [int(i) for i in new_str]
except Exception as e:
QgsMessageLog.logMessage(e, 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
QgsMessageLog.logMessage(str(e), 'qlyrxStyler', level=Qgis.MessageLevel.Critical)
new_str = [float(i) for i in new_str]
pair.append(new_str)

Expand Down

0 comments on commit 8083876

Please sign in to comment.