geoarrow_array/test/
polygon.rs

1use geo_types::{Polygon, polygon};
2use geoarrow_schema::{CoordType, Dimension, PolygonType};
3use geoarrow_test::raw;
4
5use crate::array::PolygonArray;
6use crate::builder::PolygonBuilder;
7
8pub(crate) fn p0() -> Polygon {
9    polygon![
10        (x: -111., y: 45.),
11        (x: -111., y: 41.),
12        (x: -104., y: 41.),
13        (x: -104., y: 45.),
14    ]
15}
16
17pub(crate) fn p1() -> Polygon {
18    polygon!(
19        exterior: [
20            (x: -111., y: 45.),
21            (x: -111., y: 41.),
22            (x: -104., y: 41.),
23            (x: -104., y: 45.),
24        ],
25        interiors: [
26            [
27                (x: -110., y: 44.),
28                (x: -110., y: 42.),
29                (x: -105., y: 42.),
30                (x: -105., y: 44.),
31            ],
32        ],
33    )
34}
35
36pub(crate) fn p_array(coord_type: CoordType) -> PolygonArray {
37    let geoms = vec![Some(p0()), None, Some(p1()), None];
38    let typ = PolygonType::new(Dimension::XY, Default::default()).with_coord_type(coord_type);
39    PolygonBuilder::from_nullable_polygons(&geoms, typ).finish()
40}
41
42pub fn array(coord_type: CoordType, dim: Dimension) -> PolygonArray {
43    let typ = PolygonType::new(dim, Default::default()).with_coord_type(coord_type);
44    let geoms = match dim {
45        Dimension::XY => raw::polygon::xy::geoms(),
46        Dimension::XYZ => raw::polygon::xyz::geoms(),
47        Dimension::XYM => raw::polygon::xym::geoms(),
48        Dimension::XYZM => raw::polygon::xyzm::geoms(),
49    };
50    PolygonBuilder::from_nullable_polygons(&geoms, typ).finish()
51}