-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ユーザーが記述したマッピングルールによる属性名の書き換え(CLI) (#324)
#251 の一部 ユーザーがマッピングルールのJSONファイルを記述し、指定することで、任意の属性名を書き換えることができる。 このPRでは、CLIによるルール指定・書き換えまでを対応している。 ## 変更 - [x] 「マッピングルール」記述の定義 - `{ "rename": { "before1": "after1" } }` という形式にしている - `rename` と名前空間を区切ることで、将来的に他の「ルール」も設定可能である - [x] Transformerでのルールの取り扱い - Requirementsを追加した - [x] 名前書換トランスフォーマーで、任意の書換ルールを適用 - `extend_rename_map(map)` メソッドを追加した - [x] CLI - `--rules` オプションの追加 - 指定されたJSONファイルを読み、Transformerのrequirementをセットする ## 備考 - `id`, `type` は書き換えできない(元データでの直接の「属性名」ではないため) - これらを書き換える必要はない/書き換えさせるべきではないと考える - Shapefile sinkの場合 - 既存の書き換えルールがnusamaiに組み込まれている - ユーザーの書き換えルールは、その既存ルールを上書きする(同名の元属性がある場合、ユーザーが定義したものが利用される) ## 質問 - `KeyValuePairAttribute` は書き換えできない - Q: なぜできないのか、それで良いのかがわかっていない ## 次にやること #251 - GUIでのルールファイル指定 #331 - ワイルドカード指定 ## 例 JSONファイルのルール記述 ```json { "rename": { "buildingIDAttribute": "建物ID", "address": "住所", "buildingDataQualityAttribute": "データ品質", "buildingDetailAttribute": "建物詳細", "genericAttribute": "ジェネリック", "measuredHeight": "高さ", "buildingDisasterRiskAttribute": "災害リスク", "name": "名前" } } ``` ```sh $ cargo run -- plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/bldg/53392546_bldg_6697_2_op.gml --sink geojson --output ~/Desktop/tmp.geojson --rules ./rules.json ``` <img width="775" alt="image" src="https://github.com/MIERUNE/PLATEAU-GIS-Converter/assets/595008/ce3453f4-6b5a-4834-89fb-cc93e0696c1c"> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **新機能** - コマンドライン引数に `rules` オプションを追加しました。 - ユーザーが指定したルールを使用して属性名をリネームする機能を追加しました。 <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
6 changed files
with
64 additions
and
4 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
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
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 @@ | ||
use hashbrown::HashMap; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Rules specified by the user in a JSON file | ||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct MappingRules { | ||
pub rename: RenameRules, | ||
} | ||
|
||
/// Rules specified by the user to rename the attributes | ||
/// Used by the `EditFieldNamesTransform` transformer | ||
pub type RenameRules = HashMap<String, String>; |
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,12 @@ | ||
{ | ||
"rename": { | ||
"buildingIDAttribute": "建物ID", | ||
"address": "住所", | ||
"buildingDataQualityAttribute": "データ品質", | ||
"buildingDetailAttribute": "建物詳細", | ||
"genericAttribute": "ジェネリック", | ||
"measuredHeight": "高さ", | ||
"buildingDisasterRiskAttribute": "災害リスク", | ||
"name": "名前" | ||
} | ||
} |