Skip to content

Commit

Permalink
gpkg: PKを INTEGER (AUTOINCREMENT) にする (#450)
Browse files Browse the repository at this point in the history
close #287, close #440

- `INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL`の`fid`フィールドを追加しました
  - GeoPackageではINTEGERのPKEYが必要
  - QGISではGeoPackage出力時に、`fid`という名称で出力
  - ジオメトリを持たない(地物ではない)ものはidという名称でPKEYを出力
- CityObjectのgml_idを`id`というテキスト型のカラムに格納するように修正

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **新機能**
    - 地理情報が存在するかに基づいて、異なる主キーフィールドを使用してテーブル作成ロジックを変更しました。
- **バグ修正**
    - テストモジュール内の列定義を、主キーの変更を反映するように更新しました。
- **ドキュメント**
    - ObjectStereotypeのFeatureとObjectのidを属性に保存することを明確にするコメントを追加しました。
- **リファクタ**
-
`entity_to_shape`内のパターンマッチングを修正して、`entity.root`を可変として分解し、`obj.stereotype`に追加フィールドを加えました。
    - `obj.attributes`に`id`属性を挿入し、特定の値でその存在をチェックするテストアサーションを調整しました。

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
nokonoko1203 authored Mar 11, 2024
1 parent 18c3d7b commit c1c44f1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions nusamai-gpkg/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,11 @@ impl<'c> GpkgTransaction<'c> {
// Create the table
let mut query_string = format!("CREATE TABLE \"{}\" (", table_info.name);
if table_info.has_geometry {
query_string.push_str("id STRING NOT NULL PRIMARY KEY");
query_string.push_str("fid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL");
query_string.push_str(", id TEXT NOT NULL");
query_string.push_str(", geometry BLOB NOT NULL");
} else {
query_string.push_str("id INTEGER NOT NULL PRIMARY KEY");
query_string.push_str("id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL");
}
table_info.columns.iter().for_each(|column| {
query_string.push_str(&format!(", \"{}\" {}", column.name, column.data_type));
Expand Down Expand Up @@ -402,7 +403,8 @@ mod tests {
assert_eq!(
columns,
vec![
("id".into(), "STRING".into(), 1),
("fid".into(), "INTEGER".into(), 1),
("id".into(), "TEXT".into(), 1),
("geometry".into(), "BLOB".into(), 1),
("attr1".into(), "TEXT".into(), 0),
("attr2".into(), "INTEGER".into(), 0),
Expand Down

0 comments on commit c1c44f1

Please sign in to comment.