Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KML Sink:属性(第一階層) #279

Merged
merged 11 commits into from
Feb 15, 2024
Merged

KML Sink:属性(第一階層) #279

merged 11 commits into from
Feb 15, 2024

Conversation

xinmiaooo
Copy link
Member

@xinmiaooo xinmiaooo commented Feb 14, 2024

#278
のマージが前提です。

属性をKML地物に付与し、Google Earth上で表示可能なSchemaを付与。

ExtendedDataなので、機械的にも可読である
スクリーンショット 2024-02-15 12 15 28

スクリーンショット 2024-02-15 12 12 28

TODO:

  • 属性の階層を処理していないので、文字列になっている

Summary by CodeRabbit

  • 新機能
    • KmlPolygonVec<KmlPolygon>への変更
    • polygon_to_kml_polygon_with_mappingの導入
    • 既存の関数の更新
    • CityObjectsからGeoJSONオブジェクトからKMLオブジェクトへの切り替え
    • 新しいデータ構造の導入: Element, Geometry, Polygon, SimpleData
    • プロパティの処理とKML要素の生成ロジックの更新
    • スキーマデータエントリの作成
    • 拡張データの処理
    • KML出力の構造の調整
    • .gitignoredata/**.kmlを追加して、これらのファイルとディレクトリをバージョン管理から除外
    • .vscode/launch.jsonにLLDBを使用してプロジェクト内の異なるコンポーネントとテストをデバッグするための様々な起動構成を設定
    • 実行可能ファイル、ユニットテスト、統合テスト、ライブラリ、およびワークスペース内の複数のパッケージの例をデバッグするための構成のセットアップ

Copy link

coderabbitai bot commented Feb 14, 2024

Walkthrough

この変更は、nusamaiライブラリ全体のKML変換機能を大幅に改善しました。複数のファイルでの類似変更や新しいデータ構造の導入などが含まれます。

変更

ファイルパス 変更概要
nusamai-kml/src/conversion.rs Vec<KmlPolygon>を返す機能への更新とコードのリファクタリング
nusamai/src/sink/kml/mod.rs CityObjectsからKMLオブジェクトへの変換、新データ構造の導入、プロパティ処理とKML要素生成のロジック更新
.gitignore .gitignoreファイルにdata/*および*.kmlを追加
.vscode/launch.json LLDBを使用したデバッグ用の複数の起動構成の設定

🐰💻
ある日、コードの森に
新しい変更が舞い降りた
ベクターの輝き、ポリゴンの踊り
KMLの歌が空に響き渡る
今日もまた、データが旅立つ


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@xinmiaooo xinmiaooo self-assigned this Feb 14, 2024
Copy link

codecov bot commented Feb 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Additional details and impacted files
Components Coverage Δ
GUI ∅ <ø> (∅)
Backend 81.27% <100.00%> (+0.35%) ⬆️
Libraries 90.56% <ø> (-0.02%) ⬇️

📢 Thoughts on this report? Let us know!

@xinmiaooo xinmiaooo requested a review from a team February 15, 2024 03:18
@xinmiaooo xinmiaooo marked this pull request as ready for review February 15, 2024 03:19
@xinmiaooo xinmiaooo changed the title KML Sink:属性 KML Sink:属性(第一階層) Feb 15, 2024
@ciscorn ciscorn changed the base branch from main to kml-multipolygon February 15, 2024 03:20
nusamai/src/sink/kml/mod.rs Outdated Show resolved Hide resolved
nusamai/src/sink/kml/mod.rs Outdated Show resolved Hide resolved
Comment on lines 204 to 208
// let mut kml_writer = KmlWriter::from_writer(&mut buf_writer);
// let _ = kml_writer.write(&folder);

let mut kml_writer = KmlWriter::from_writer(&mut buf_writer);
let _ = kml_writer.write(&folder);
let _ = kml_writer.write(&kml_doc);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメントアウトされたkml_writerfolderの使用に関するコードは削除するか、将来的な使用のために残す意図がある場合は、その旨をコメントで説明することをお勧めします。

Comment on lines +238 to +258
pub fn entity_to_properties(entity: &Entity) -> Option<geojson::JsonObject> {
extract_properties(&entity.root)
}

pub fn property_to_schema_data_entries(properties: &geojson::JsonObject) -> Vec<SimpleData> {
let mut simple_data_entries = Vec::new();

for (key, value) in properties.iter() {
let simpledata = SimpleData {
name: key.to_string(),
value: serde_json::to_string(value).unwrap(),
attrs: {
let mut attrs = HashMap::new();
attrs.insert("name".to_string(), key.to_string());
attrs
},
};
simple_data_entries.push(simpledata);
}
simple_data_entries
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract_properties関数のpanic!は、予期しない値型である場合にプログラムを強制終了させます。より安全なエラーハンドリングを検討してください。例えば、Result型を返すようにして、呼び出し元で適切に処理する方法が考えられます。

Base automatically changed from kml-multipolygon to main February 15, 2024 04:45
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 7

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 670821f and c55d12b.
Files selected for processing (3)
  • .gitignore (1 hunks)
  • .vscode/launch.json (1 hunks)
  • nusamai/src/sink/kml/mod.rs (6 hunks)
Files skipped from review due to trivial changes (1)
  • .gitignore
Additional comments: 1
.vscode/launch.json (1)
  • 1-889: launch.jsonファイルの変更点については、特に問題は見受けられません。デバッグ設定が適切に追加されており、各設定項目も正しく構成されています。

@@ -79,6 +79,34 @@ impl DataSink for KmlSink {

let polygons = entity_to_kml_polygons(&parcel.entity);

let _properties = entity_to_properties(&parcel.entity).unwrap_or_default();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entity_to_properties関数の戻り値を_properties変数に代入していますが、この変数は後続のコードで使用されていません。不要な変数代入はパフォーマンスと可読性の観点から避けるべきです。

nusamai/src/sink/kml/mod.rs Outdated Show resolved Hide resolved
nusamai/src/sink/kml/mod.rs Outdated Show resolved Hide resolved
nusamai/src/sink/kml/mod.rs Show resolved Hide resolved
nusamai/src/sink/kml/mod.rs Outdated Show resolved Hide resolved
nusamai/src/sink/kml/mod.rs Outdated Show resolved Hide resolved
Comment on lines +236 to +238
pub fn entity_to_properties(entity: &Entity) -> Option<geojson::JsonObject> {
extract_properties(&entity.root)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract_properties関数内でpanic!を使用していますが、これは予期しない値型である場合にプログラムを強制終了させます。より安全なエラーハンドリングを検討してください。例えば、Result型を返すようにして、呼び出し元で適切に処理する方法が考えられます。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c55d12b and f920511.
Files selected for processing (1)
  • nusamai/src/sink/kml/mod.rs (6 hunks)
Additional comments: 8
nusamai/src/sink/kml/mod.rs (8)
  • 82-82: entity_to_properties関数の戻り値を_properties変数に代入していますが、この変数は後続のコードで使用されています。変数名の先頭にアンダースコアを付けるのは、通常、その変数が使用されないことを示すためです。変数が使用される場合は、アンダースコアを削除することをお勧めします。
  • 83-83: property_to_schema_data_entries関数の戻り値を_simple_data_items変数に代入していますが、この変数は後続のコードで使用されています。変数名の先頭にアンダースコアを付けるのは、通常、その変数が使用されないことを示すためです。変数が使用される場合は、アンダースコアを削除することをお勧めします。
  • 86-90: コメントアウトされたコードは削除するか、その理由を明記するコメントを追加することをお勧めします。未使用のコードは可読性を低下させ、メンテナンスの負担を増加させます。
  • 131-167: Schema要素のchildrenプロパティがコメントアウトされていますが、この部分は将来的な使用を意図しているのでしょうか。もし使用予定がない場合は、コメントアウトされたコードを削除することをお勧めします。使用予定がある場合は、その旨をコメントで説明してください。
  • 192-196: コメントアウトされたkml_writerfolderの使用に関するコードは削除するか、将来的な使用のために残す意図がある場合は、その旨をコメントで説明することをお勧めします。
  • 192-194: コメントアウトされたkml_writerの使用に関するコードは削除するか、将来的な使用のために残す意図がある場合は、その旨をコメントで説明することをお勧めします。
  • 226-246: extract_properties関数のpanic!は、予期しない値型である場合にプログラムを強制終了させます。より安全なエラーハンドリングを検討してください。例えば、Result型を返すようにして、呼び出し元で適切に処理する方法が考えられます。
  • 226-228: extract_properties関数内でpanic!を使用していますが、これは予期しない値型である場合にプログラムを強制終了させます。より安全なエラーハンドリングを検討してください。例えば、Result型を返すようにして、呼び出し元で適切に処理する方法が考えられます。

@ciscorn
Copy link
Member

ciscorn commented Feb 15, 2024

@xinmiaooo もし Schema を使う場合は、データ側からスキーマを id で参照してあげる必要があるのかなと思います

Untitled

@xinmiaooo
Copy link
Member Author

@ciscorn
ダミーのSchema_1を参照するようにしました!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

デバッガ用の設定が混入しているようです!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ciscorn
すみません!掃除しました。。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f920511 and e8630db.
Files selected for processing (2)
  • .gitignore (1 hunks)
  • nusamai/src/sink/kml/mod.rs (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .gitignore
Additional comments: 2
nusamai/src/sink/kml/mod.rs (2)
  • 131-167: Schema要素のchildrenプロパティがコメントアウトされています。将来的な使用を意図している場合は、その旨をコメントで説明してください。使用予定がない場合は、コメントアウトされたコードを削除することをお勧めします。
  • 224-244: extract_properties関数内でpanic!を使用していますが、これは予期しない値型である場合にプログラムを強制終了させます。より安全なエラーハンドリングを検討してください。例えば、Result型を返すようにして、呼び出し元で適切に処理する方法が考えられます。

Comment on lines 82 to 108
let _simple_data_items = property_to_schema_data_entries(
&entity_to_properties(&parcel.entity).unwrap_or_default(),
);
let _schema_data = Element {
name: "SchemaData".to_string(),
attrs: {
let mut attrs = HashMap::new();
attrs.insert("schemaUrl".to_string(), "#Schema_1".to_string());
attrs
},
content: None,
children: _simple_data_items
.into_iter()
.map(|simple_data| Element {
name: "SimpleData".to_string(),
attrs: simple_data.attrs,
content: Some(simple_data.value),
children: Vec::new(),
})
.collect::<Vec<_>>(),
};
let extended_data_entry = Element {
name: "ExtendedData".to_string(),
attrs: HashMap::new(),
content: None,
children: vec![_schema_data],
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property_to_schema_data_entries関数の戻り値を_simple_data_itemsとして受け取っていますが、この変数はその後のコードで使用されていません。不要な変数の割り当てを避けるために、この行を削除するか、変数を使用するようにコードを修正してください。

Comment on lines 82 to 93
let _simple_data_items = property_to_schema_data_entries(
&entity_to_properties(&parcel.entity).unwrap_or_default(),
);
let _schema_data = Element {
name: "SchemaData".to_string(),
attrs: {
let mut attrs = HashMap::new();
attrs.insert("schemaUrl".to_string(), "#Schema_1".to_string());
attrs
},
content: None,
children: _simple_data_items
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使われている変数のアンダースコアを外すとよさそうです

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e8630db and 36f55f8.
Files selected for processing (1)
  • nusamai/src/sink/kml/mod.rs (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • nusamai/src/sink/kml/mod.rs

Comment on lines +170 to 181
// let placemarks = receiver.into_iter();
let placemarks = receiver.into_iter().collect::<Vec<_>>();
let folder = Kml::Folder {

let kml_doc = Kml::Document {
attrs: HashMap::new(),
elements: placemarks.into_iter().map(Kml::Placemark).collect(),
elements: {
let mut elements = Vec::<Kml>::new();
elements.push(Kml::Element(schema_element));
elements.extend(placemarks.into_iter().map(Kml::Placemark));
elements
},
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

今後:
このへん、メモリに溜め込んでから、一気に書き出すのではなく、Placemarkストリーミングで書き出せるといいかもしれませんね(余裕があればPR出します)。

Copy link
Member

@ciscorn ciscorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@xinmiaooo xinmiaooo merged commit 9ce23fc into main Feb 15, 2024
4 checks passed
@xinmiaooo xinmiaooo deleted the kml-attribute branch February 15, 2024 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants