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

nusamai-shapefile: クレート作成, MultiPointの変換 #203

Merged
merged 7 commits into from
Jan 26, 2024
Merged

Conversation

sorami
Copy link
Member

@sorami sorami commented Jan 25, 2024

概要

  • nusamai-shapefile クレートの作成
  • nusamai_geometry::MultiPoint から Shapefile形式への変換
  • examples/{read,write}.rs - ファイル読み書きの参考例(tmp - 最終的に削除する)

まず例として小さく、MultiPointの部分のみを作ったプルリクです。方向性に問題ないかご確認いただけますでしょうか!

外部クレート shapefile を用いて実装しています。

リファクタしてもらった nusamai-geojson の形(#154)をもとにしています(ので、それをやった @ciscorn さんを明示的にレビューアーへ入れてみました)。

3D地物(nusamai_geometry::MultiPoint::<3>, shapefile::MultiPointZ)のみで、2Dは考慮していません。

その後の進め方

related #198

この方向性で問題なければ、それを踏まえて、以下の順に進めていく予定です:

  • MultiLineString, MultiPolygonの変換
  • Shapefile全体での出力
  • Shapefile Sink
  • (属性付与)

@sorami sorami self-assigned this Jan 25, 2024
Copy link

codecov bot commented Jan 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Additional details and impacted files
Components Coverage Δ
GUI ∅ <ø> (∅)
Backend 68.61% <ø> (+0.50%) ⬆️
Libraries 92.41% <100.00%> (+0.02%) ⬆️

📢 Thoughts on this report? Let us know!

@sorami sorami changed the title nusamai-shapefile: Shapefileの作成(ジオメトリのみ) nusamai-shapefile: クレート作成, MultiPointの変換 Jan 26, 2024
@sorami sorami requested review from a team and ciscorn January 26, 2024 05:47
@sorami sorami marked this pull request as ready for review January 26, 2024 05:52
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. 不要な .to_vec() を抜いてみました。これでどうでしょう。

32c4327

Comment on lines +4 to +9
// Attribute fields for the features
// FieldName byte representation cannot exceed 11 bytes
let table_builder = dbase::TableWriterBuilder::new()
.add_character_field("name".try_into().unwrap(), 50)
.add_float_field("lon".try_into().unwrap(), 50, 10)
.add_float_field("lat".try_into().unwrap(), 50, 10);
Copy link
Member

Choose a reason for hiding this comment

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

Shapefile もやはりはじめにテーブルを宣言しないといけない形式ですね。

@sorami
Copy link
Member Author

sorami commented Jan 26, 2024

LGTM. 不要な .to_vec() を抜いてみました。これでどうでしょう。

32c4327

ありがとうございます!

@sorami sorami enabled auto-merge (squash) January 26, 2024 06:54
@sorami sorami merged commit 90c2aed into main Jan 26, 2024
2 checks passed
@sorami sorami deleted the shapefile branch January 26, 2024 06:55
sorami added a commit that referenced this pull request Jan 26, 2024
#203 (MultiPoint)と同じ形で、nusamai-geometryのMultiLineString,
MultiPolygonを、Shapefileの形式へ変換する。

## 参考

### ポリゴンは、複数のOuterリングを持つことができる


https://github.com/tmontaigu/shapefile-rs/blob/cd52bcfde8ce24aeaffec0968f155119e02c5a66/src/record/polygon.rs#L198C1-L204C59
```
/// # Notes
/// - A Polygon ring is a connected sequence of 4 or more points
///   **(this is not checked)**
/// - Polygon's rings MUST be closed (the first and last points MUST be the same) (p 13/34)
///   **(this is done by the constructors if you do not do it yourself)**
/// - The order of rings is not significant (p 13/34)
/// - A polygon may have multiple [`Outer`] rings (p12/34)
```

### リングのオーダー


https://github.com/tmontaigu/shapefile-rs/blob/cd52bcfde8ce24aeaffec0968f155119e02c5a66/src/record/polygon.rs#L26-L37
```
/// In shapefile, the point ordering is what is used to know if
/// a ring is an outer or inner one:
/// - **Outer** ring => points in clockwise order
/// - **Inner** ring => points in counter-clockwise order
///
/// # Note
///
/// Rings you get access from a [`GenericPolygon`] will always have its points ordered
/// according to its type (outer, inner).
///
/// But `PolygonRing`s you create won't be reordered until you move them into
/// a [`GenericPolygon`].
```


https://github.com/tmontaigu/shapefile-rs/blob/cd52bcfde8ce24aeaffec0968f155119e02c5a66/src/record/mod.rs#L118-L134
```
/// Given the points, check if they represent an outer ring of a polygon
///
/// As per ESRI's Shapefile 1998 whitepaper:
/// `
/// The order of vertices or orientation for a ring indicates which side of the ring
/// is the interior of the polygon.
/// The neighborhood to the right of an observer walking along
/// the ring in vertex order is the neighborhood inside the polygon.
/// Vertices of rings defining holes in polygons are in a counterclockwise direction.
/// Vertices for a single, ringed polygon are, therefore, always in clockwise order.
/// `
///
/// Inner Rings defines holes -> points are in counterclockwise order
/// Outer Rings's points are un clockwise order
///
/// https://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order/1180256#1180256
pub(crate) fn ring_type_from_points_ordering<PointType: HasXY>(points: &[PointType]) -> RingType {
```
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