From 529d7d5b5ff70572734718dd8b03607957cc5e5c Mon Sep 17 00:00:00 2001 From: bordoray Date: Wed, 9 Aug 2023 16:31:55 +0900 Subject: [PATCH 1/8] implement unsupported renderer --- translator/vector/process.py | 42 +++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/translator/vector/process.py b/translator/vector/process.py index 9a19d4f..fb4cdcd 100644 --- a/translator/vector/process.py +++ b/translator/vector/process.py @@ -119,7 +119,8 @@ def process_vector( result = _process_graduated(layer, extent, idx, output_dir) elif layer.renderer().type() == "singleSymbol": result = _process_singlesymbol(layer, extent, idx, output_dir) - + else: + result = _process_unsupported_renderer(layer, extent, idx, output_dir) return result @@ -306,3 +307,42 @@ def _process_singlesymbol( "has_unsupported_symbol": has_unsupported_symbol, "completed": True, } + + +def _process_unsupported_renderer( + layer: QgsVectorLayer, extent: QgsRectangle, idx: int, output_dir: str +) -> dict: + # shp + shp_path = os.path.join(output_dir, f"layer_{idx}.shp") + layer_intersected = _clip_in_projectcrs(layer, extent) + output_layer = QgsVectorFileWriter( + shp_path, + "UTF-8", + layer.fields(), + layer.wkbType(), + QgsProject.instance().crs(), + "ESRI Shapefile", + ) + output_layer.addFeatures(layer_intersected.getFeatures()) + del output_layer + + # json + layer_json = { + "layer": layer.name(), + "type": _get_layer_type(layer), + "symbols": "unsupported", + "usingSymbolLevels": layer.renderer().usingSymbolLevels(), + "opacity": layer.opacity(), + "blend_mode": get_blend_mode_string(layer.blendMode()), + } + write_json( + layer_json, + os.path.join(output_dir, f"layer_{idx}.json"), + ) + + return { + "idx": idx, + "layer_name": layer.name(), + "has_unsupported_symbol": True, + "completed": True, + } From 7df30468049eb55ddde922857d2b426137d23e3a Mon Sep 17 00:00:00 2001 From: bordoray Date: Wed, 9 Aug 2023 16:40:27 +0900 Subject: [PATCH 2/8] Documentation --- docs/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/README.md b/docs/README.md index ce33088..face97e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -112,6 +112,9 @@ "legend": "1 - 20000", // 凡例名 (categoricalかグラデーションの場合のみ) } ``` +※シンプルシンボル、カテゴリー別、分類別以外は対応してありません。 +`symbol=unsupported`として出力されます。 + #### raster layer From 3003e29468b3e86a441def87d368f7423f49fd40 Mon Sep 17 00:00:00 2001 From: bordoray Date: Wed, 9 Aug 2023 17:14:17 +0900 Subject: [PATCH 3/8] Remove common process for unsupported renderer --- translator/vector/process.py | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/translator/vector/process.py b/translator/vector/process.py index fb4cdcd..b19d3ac 100644 --- a/translator/vector/process.py +++ b/translator/vector/process.py @@ -312,37 +312,10 @@ def _process_singlesymbol( def _process_unsupported_renderer( layer: QgsVectorLayer, extent: QgsRectangle, idx: int, output_dir: str ) -> dict: - # shp - shp_path = os.path.join(output_dir, f"layer_{idx}.shp") - layer_intersected = _clip_in_projectcrs(layer, extent) - output_layer = QgsVectorFileWriter( - shp_path, - "UTF-8", - layer.fields(), - layer.wkbType(), - QgsProject.instance().crs(), - "ESRI Shapefile", - ) - output_layer.addFeatures(layer_intersected.getFeatures()) - del output_layer - - # json - layer_json = { - "layer": layer.name(), - "type": _get_layer_type(layer), - "symbols": "unsupported", - "usingSymbolLevels": layer.renderer().usingSymbolLevels(), - "opacity": layer.opacity(), - "blend_mode": get_blend_mode_string(layer.blendMode()), - } - write_json( - layer_json, - os.path.join(output_dir, f"layer_{idx}.json"), - ) - return { "idx": idx, "layer_name": layer.name(), - "has_unsupported_symbol": True, - "completed": True, + "has_unsupported_symbol": False, + "reason": "unsupported renderer", + "completed": False, } From 426c7c7f0c6be40c56f436ae4feaac729db50cb4 Mon Sep 17 00:00:00 2001 From: bordoray Date: Wed, 9 Aug 2023 17:22:18 +0900 Subject: [PATCH 4/8] Add message error --- ui/main_dialog.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ui/main_dialog.py b/ui/main_dialog.py index 11f3f4d..f3670dd 100644 --- a/ui/main_dialog.py +++ b/ui/main_dialog.py @@ -107,6 +107,14 @@ def _run(self): ) ) + # list-up layers NOT completed + layers_not_completed = list( + map( + lambda r: r["layer_name"], + list(filter(lambda r: r["completed"] is False, results)), + ) + ) + # list-up layers processed successfully: layer_0, layer_2, layer_5, ... layers_processed_successfully = list( map( @@ -147,6 +155,8 @@ def _run(self): シンプルシンボルに変換しました。\n" + "\n".join(layers_has_unsupported_symbol) ) + if len(layers_not_completed) > 0: + msg += "\n\n以下レイヤに対応不可。\n" + "\n".join(layers_not_completed) QMessageBox.information( None, "完了", From b7a160de5666d5829c5d403d665056ae3ff6bfd0 Mon Sep 17 00:00:00 2001 From: bordoray Date: Wed, 9 Aug 2023 17:22:51 +0900 Subject: [PATCH 5/8] undo documentation --- docs/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index face97e..ce33088 100644 --- a/docs/README.md +++ b/docs/README.md @@ -112,9 +112,6 @@ "legend": "1 - 20000", // 凡例名 (categoricalかグラデーションの場合のみ) } ``` -※シンプルシンボル、カテゴリー別、分類別以外は対応してありません。 -`symbol=unsupported`として出力されます。 - #### raster layer From 504571b1064d720c6df4f544b754adc164366e0d Mon Sep 17 00:00:00 2001 From: bordoray Date: Wed, 9 Aug 2023 17:29:34 +0900 Subject: [PATCH 6/8] Edit message (reason, wording) --- ui/main_dialog.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/main_dialog.py b/ui/main_dialog.py index f3670dd..d3445fc 100644 --- a/ui/main_dialog.py +++ b/ui/main_dialog.py @@ -107,10 +107,10 @@ def _run(self): ) ) - # list-up layers NOT completed + # list-up layers NOT completed with_reason layers_not_completed = list( map( - lambda r: r["layer_name"], + lambda r: f"{r['layer_name']} : {r['reason']}", list(filter(lambda r: r["completed"] is False, results)), ) ) @@ -156,7 +156,7 @@ def _run(self): + "\n".join(layers_has_unsupported_symbol) ) if len(layers_not_completed) > 0: - msg += "\n\n以下レイヤに対応不可。\n" + "\n".join(layers_not_completed) + msg += "\n\n以下レイヤに対応してませんでした。\n" + "\n".join(layers_not_completed) QMessageBox.information( None, "完了", From 4271e4b721f1ebc1cc94f055495670c1084e7d99 Mon Sep 17 00:00:00 2001 From: bordoray Date: Wed, 9 Aug 2023 17:35:10 +0900 Subject: [PATCH 7/8] Lint and wording --- ui/main_dialog.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ui/main_dialog.py b/ui/main_dialog.py index d3445fc..f1f9523 100644 --- a/ui/main_dialog.py +++ b/ui/main_dialog.py @@ -107,7 +107,7 @@ def _run(self): ) ) - # list-up layers NOT completed with_reason + # list-up layers NOT completed and its reason layers_not_completed = list( map( lambda r: f"{r['layer_name']} : {r['reason']}", @@ -156,7 +156,8 @@ def _run(self): + "\n".join(layers_has_unsupported_symbol) ) if len(layers_not_completed) > 0: - msg += "\n\n以下レイヤに対応してませんでした。\n" + "\n".join(layers_not_completed) + msg += "\n\n以下レイヤに対応しませんでした。\n" + msg += "\n".join(layers_not_completed) QMessageBox.information( None, "完了", From a46c947f50565ad7a52cfc11859c3b723845dc87 Mon Sep 17 00:00:00 2001 From: Raymond Lay Date: Wed, 9 Aug 2023 21:46:29 +0900 Subject: [PATCH 8/8] Japanese wording Co-authored-by: IGUCHI Kanahiro --- ui/main_dialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/main_dialog.py b/ui/main_dialog.py index f1f9523..0df0d34 100644 --- a/ui/main_dialog.py +++ b/ui/main_dialog.py @@ -156,7 +156,7 @@ def _run(self): + "\n".join(layers_has_unsupported_symbol) ) if len(layers_not_completed) > 0: - msg += "\n\n以下レイヤに対応しませんでした。\n" + msg += "\n\n以下のレイヤーは出力できませんでした。\n" msg += "\n".join(layers_not_completed) QMessageBox.information( None,