Skip to content

Commit

Permalink
Shapefile: gml_idを親のジオメトリに格納するように修正 (#445)
Browse files Browse the repository at this point in the history
close #426
rootの地物にidを格納するように修正しました。

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

- **新機能**
	- 属性内に特定のデータが格納されている場所を示すコメントを追加しました。
	- エンティティの根底にあるパターンマッチングを更新し、`obj`に`mut`を使用するように変更しました。
-
`ObjectStereotype::Feature`のパターンマッチングを更新し、`id`と`geometries`を分解するようにしました。
	- `obj.attributes`に`id`属性の挿入を追加しました。
- テーブル作成クエリを変更して、新しい列`fid`を含め、`INTEGER PRIMARY KEY AUTOINCREMENT NOT
NULL`としました。
	- テストでの列の取得を`id`から`fid`に調整しました。
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
nokonoko1203 authored Mar 11, 2024
1 parent 84d3e58 commit 18c3d7b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions nusamai/src/sink/shapefile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,17 @@ impl DataSink for ShapefileSink {
/// Each feature for MultiPolygon, MultiLineString, and MultiPoint will be created (if it exists)
/// TODO: Implement MultiLineString and MultiPoint handling
pub fn entity_to_shape(entity: Entity) -> (shapefile::Shape, Map) {
let Value::Object(obj) = entity.root else {
let Value::Object(mut obj) = entity.root else {
return (shapefile::Shape::NullShape, Map::default());
};

let ObjectStereotype::Feature { id: _, geometries } = &obj.stereotype else {
let ObjectStereotype::Feature { id, geometries } = obj.stereotype else {
return (shapefile::Shape::NullShape, obj.attributes);
};

// Insert Feature id as a attribute
obj.attributes.insert("id".to_string(), Value::String(id));

let geom_store = entity.geometry_store.read().unwrap();

let mut mpoly = nusamai_geometry::MultiPolygon::<1, u32>::new();
Expand Down Expand Up @@ -293,7 +296,10 @@ mod tests {
};

let (shapes, attributes) = entity_to_shape(obj);
assert_eq!(attributes.len(), 0);
assert_eq!(
attributes.get("id").unwrap(),
&Value::String("dummy".into())
);

if let shapefile::Shape::PolygonZ(polygon) = &shapes {
assert_eq!(polygon.rings().len(), 1);
Expand Down

0 comments on commit 18c3d7b

Please sign in to comment.