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: MultiLineString, MultiPolygonの変換 #209

Merged
merged 3 commits into from
Jan 26, 2024

Conversation

sorami
Copy link
Member

@sorami sorami commented 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 {

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

codecov bot commented Jan 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Additional details and impacted files
Components Coverage Δ
GUI ∅ <ø> (∅)
Backend 66.91% <ø> (-1.71%) ⬇️
Libraries 92.71% <100.00%> (+0.29%) ⬆️

📢 Thoughts on this report? Let us know!

@sorami sorami requested a review from a team January 26, 2024 09:04
@sorami sorami marked this pull request as ready for review January 26, 2024 09:05
.flat_map(|poly| polygon_to_shape_rings_with_mapping(&poly, &mapping))
.collect::<Vec<shapefile::PolygonRing<shapefile::PointZ>>>();

shapefile::PolygonZ::with_rings(all_rings)
Copy link
Member

Choose a reason for hiding this comment

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

なるほど
https://docs.rs/shapefile/latest/shapefile/record/polygon/enum.PolygonRing.html#note

Rings you get access from a GenericPolygon will always have its points ordered according to its type (outer, inner).
But PolygonRings you create won’t be reordered until you move them into a GenericPolygon.

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!

@ciscorn ciscorn added the Output Fomat Output format drivers label Jan 26, 2024
@sorami sorami merged commit 20e150f into main Jan 26, 2024
4 checks passed
@sorami sorami deleted the shapefile-multipolygon branch January 26, 2024 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Output Fomat Output format drivers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants