Skip to content

Commit

Permalink
Add tests based on geoarrow-data (#82)
Browse files Browse the repository at this point in the history
* geoarrow-data submodule

* Add partialeq

* Add geoarrow_data files

* clone submodules

* Add debug, clone
  • Loading branch information
kylebarron authored Jul 16, 2023
1 parent da786e9 commit e6337ec
Show file tree
Hide file tree
Showing 40 changed files with 313 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "fixtures/geoarrow-data"]
path = fixtures/geoarrow-data
url = https://github.com/geoarrow/geoarrow-data
1 change: 1 addition & 0 deletions fixtures/geoarrow-data
Submodule geoarrow-data added at 212d04
2 changes: 1 addition & 1 deletion src/array/binary/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rstar::RTree;

/// A [`GeometryArrayTrait`] semantically equivalent to `Vec<Option<Geometry>>` using Arrow's
/// in-memory representation.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct WKBArray<O: Offset>(BinaryArray<O>);

// Implement geometry accessors
Expand Down
2 changes: 1 addition & 1 deletion src/array/coord/combined/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rstar::RTree;
/// This is named `CoordBuffer` instead of `CoordArray` because the buffer does not store its own
/// validity bitmask. Rather the geometry arrays that build on top of this maintain their own
/// validity masks.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub enum CoordBuffer {
Interleaved(InterleavedCoordBuffer),
Separated(SeparatedCoordBuffer),
Expand Down
2 changes: 1 addition & 1 deletion src/array/coord/interleaved/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use arrow2::datatypes::{DataType, Field};
use rstar::RTree;

/// A an array of XY coordinates stored interleaved in a single buffer.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct InterleavedCoordBuffer {
pub coords: Buffer<f64>,
}
Expand Down
2 changes: 1 addition & 1 deletion src/array/coord/separated/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::error::GeoArrowError;
use crate::scalar::SeparatedCoord;
use crate::GeometryArrayTrait;

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct SeparatedCoordBuffer {
pub x: Buffer<f64>,
pub y: Buffer<f64>,
Expand Down
2 changes: 1 addition & 1 deletion src/array/geometry/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::scalar::Geometry;
use crate::GeometryArrayTrait;

/// A GeometryArray that can be any of various underlying geometry types
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub enum GeometryArray<O: Offset> {
Point(PointArray),
LineString(LineStringArray<O>),
Expand Down
25 changes: 24 additions & 1 deletion src/array/linestring/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::MutableLineStringArray;

/// A [`GeometryArrayTrait`] semantically equivalent to `Vec<Option<LineString>>` using Arrow's
/// in-memory representation.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct LineStringArray<O: Offset> {
pub coords: CoordBuffer,

Expand Down Expand Up @@ -341,6 +341,9 @@ impl<O: Offset> TryFrom<WKBArray<O>> for LineStringArray<O> {

#[cfg(test)]
mod test {
use crate::test::geoarrow_data::{
example_linestring_interleaved, example_linestring_separated, example_linestring_wkb,
};
use crate::test::linestring::{ls0, ls1};

use super::*;
Expand Down Expand Up @@ -383,4 +386,24 @@ mod test {
assert_eq!(arr.len(), 1);
assert_eq!(arr.get_as_geo(0), Some(ls1()));
}

#[test]
fn parse_wkb_geoarrow_interleaved_example() {
let linestring_arr = example_linestring_interleaved();

let wkb_arr = example_linestring_wkb();
let parsed_linestring_arr: LineStringArray<i64> = wkb_arr.try_into().unwrap();

assert_eq!(linestring_arr, parsed_linestring_arr);
}

#[test]
fn parse_wkb_geoarrow_separated_example() {
let linestring_arr = example_linestring_separated().into_coord_type(CoordType::Interleaved);

let wkb_arr = example_linestring_wkb();
let parsed_linestring_arr: LineStringArray<i64> = wkb_arr.try_into().unwrap();

assert_eq!(linestring_arr, parsed_linestring_arr);
}
}
29 changes: 28 additions & 1 deletion src/array/multilinestring/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::MutableMultiLineStringArray;

/// A [`GeometryArrayTrait`] semantically equivalent to `Vec<Option<MultiLineString>>` using Arrow's
/// in-memory representation.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct MultiLineStringArray<O: Offset> {
pub coords: CoordBuffer,

Expand Down Expand Up @@ -395,6 +395,10 @@ impl<O: Offset> TryFrom<WKBArray<O>> for MultiLineStringArray<O> {

#[cfg(test)]
mod test {
use crate::test::geoarrow_data::{
example_multilinestring_interleaved, example_multilinestring_separated,
example_multilinestring_wkb,
};
use crate::test::multilinestring::{ml0, ml1};

use super::*;
Expand All @@ -421,4 +425,27 @@ mod test {
assert_eq!(arr.len(), 1);
assert_eq!(arr.get_as_geo(0), Some(ml1()));
}

#[ignore = "WKB parsing is failing"]
#[test]
fn parse_wkb_geoarrow_interleaved_example() {
let geom_arr = example_multilinestring_interleaved();

let wkb_arr = example_multilinestring_wkb();
let parsed_geom_arr: MultiLineStringArray<i64> = wkb_arr.try_into().unwrap();

assert_eq!(geom_arr, parsed_geom_arr);
}

#[ignore = "WKB parsing is failing"]
#[test]
fn parse_wkb_geoarrow_separated_example() {
// TODO: support checking equality of interleaved vs separated coords
let geom_arr = example_multilinestring_separated().into_coord_type(CoordType::Interleaved);

let wkb_arr = example_multilinestring_wkb();
let parsed_geom_arr: MultiLineStringArray<i64> = wkb_arr.try_into().unwrap();

assert_eq!(geom_arr, parsed_geom_arr);
}
}
26 changes: 25 additions & 1 deletion src/array/multipoint/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rstar::RTree;

/// A [`GeometryArrayTrait`] semantically equivalent to `Vec<Option<MultiPoint>>` using Arrow's
/// in-memory representation.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct MultiPointArray<O: Offset> {
pub coords: CoordBuffer,

Expand Down Expand Up @@ -334,6 +334,9 @@ impl<O: Offset> From<MultiPointArray<O>> for LineStringArray<O> {
#[cfg(test)]
mod test {
use super::*;
use crate::test::geoarrow_data::{
example_multipoint_interleaved, example_multipoint_separated, example_multipoint_wkb,
};
use crate::test::multipoint::{mp0, mp1};

#[test]
Expand All @@ -358,4 +361,25 @@ mod test {
assert_eq!(arr.len(), 1);
assert_eq!(arr.get_as_geo(0), Some(mp1()));
}

#[test]
fn parse_wkb_geoarrow_interleaved_example() {
let geom_arr = example_multipoint_interleaved();

let wkb_arr = example_multipoint_wkb();
let parsed_geom_arr: MultiPointArray<i64> = wkb_arr.try_into().unwrap();

assert_eq!(geom_arr, parsed_geom_arr);
}

#[test]
fn parse_wkb_geoarrow_separated_example() {
// TODO: support checking equality of interleaved vs separated coords
let geom_arr = example_multipoint_separated().into_coord_type(CoordType::Interleaved);

let wkb_arr = example_multipoint_wkb();
let parsed_geom_arr: MultiPointArray<i64> = wkb_arr.try_into().unwrap();

assert_eq!(geom_arr, parsed_geom_arr);
}
}
28 changes: 27 additions & 1 deletion src/array/multipolygon/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::MutableMultiPolygonArray;

/// A [`GeometryArrayTrait`] semantically equivalent to `Vec<Option<MultiPolygon>>` using Arrow's
/// in-memory representation.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct MultiPolygonArray<O: Offset> {
pub coords: CoordBuffer,

Expand Down Expand Up @@ -417,6 +417,9 @@ impl<O: Offset> TryFrom<WKBArray<O>> for MultiPolygonArray<O> {
#[cfg(test)]
mod test {
use crate::array::{MutableCoordBuffer, MutableSeparatedCoordBuffer};
use crate::test::geoarrow_data::{
example_multipolygon_interleaved, example_multipolygon_separated, example_multipolygon_wkb,
};
use crate::test::multipolygon::{mp0, mp1};

use super::*;
Expand Down Expand Up @@ -618,4 +621,27 @@ mod test {
let _arr: MultiPolygonArray<i64> = mut_arr.into();
// let _tree = arr.rstar_tree();
}

#[ignore = "WKB parsing is failing"]
#[test]
fn parse_wkb_geoarrow_interleaved_example() {
let geom_arr = example_multipolygon_interleaved();

let wkb_arr = example_multipolygon_wkb();
let parsed_geom_arr: MultiPolygonArray<i64> = wkb_arr.try_into().unwrap();

assert_eq!(geom_arr, parsed_geom_arr);
}

#[ignore = "WKB parsing is failing"]
#[test]
fn parse_wkb_geoarrow_separated_example() {
// TODO: support checking equality of interleaved vs separated coords
let geom_arr = example_multipolygon_separated().into_coord_type(CoordType::Interleaved);

let wkb_arr = example_multipolygon_wkb();
let parsed_geom_arr: MultiPolygonArray<i64> = wkb_arr.try_into().unwrap();

assert_eq!(geom_arr, parsed_geom_arr);
}
}
32 changes: 31 additions & 1 deletion src/array/point/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rstar::RTree;

/// A [`GeometryArrayTrait`] semantically equivalent to `Vec<Option<Point>>` using Arrow's
/// in-memory representation.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct PointArray {
pub coords: CoordBuffer,
pub validity: Option<Bitmap>,
Expand Down Expand Up @@ -300,6 +300,9 @@ impl<O: Offset> TryFrom<WKBArray<O>> for PointArray {

#[cfg(test)]
mod test {
use crate::test::geoarrow_data::{
example_point_interleaved, example_point_separated, example_point_wkb,
};
use crate::test::point::{p0, p1, p2};

use super::*;
Expand Down Expand Up @@ -330,4 +333,31 @@ mod test {
assert_eq!(point_array.len(), 1);
assert_eq!(point_array.get_as_geo(0), Some(p1()));
}

#[ignore = "point file is invalid (https://github.com/geoarrow/geoarrow-data/issues/2)"]
#[test]
fn parse_wkb_geoarrow_interleaved_example() {
let geom_arr = example_point_interleaved();

let wkb_arr = example_point_wkb();
let parsed_geom_arr: PointArray = wkb_arr.try_into().unwrap();

// Comparisons on the point array directly currently fail because of NaN values in
// coordinate 1.
assert_eq!(geom_arr.get_as_geo(0), parsed_geom_arr.get_as_geo(0));
assert_eq!(geom_arr.get_as_geo(2), parsed_geom_arr.get_as_geo(2));
}

#[test]
fn parse_wkb_geoarrow_separated_example() {
let geom_arr = example_point_separated();

let wkb_arr = example_point_wkb();
let parsed_geom_arr: PointArray = wkb_arr.try_into().unwrap();

// Comparisons on the point array directly currently fail because of NaN values in
// coordinate 1.
assert_eq!(geom_arr.get_as_geo(0), parsed_geom_arr.get_as_geo(0));
assert_eq!(geom_arr.get_as_geo(2), parsed_geom_arr.get_as_geo(2));
}
}
28 changes: 27 additions & 1 deletion src/array/polygon/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::MutablePolygonArray;

/// A [`GeometryArrayTrait`] semantically equivalent to `Vec<Option<Polygon>>` using Arrow's
/// in-memory representation.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct PolygonArray<O: Offset> {
pub coords: CoordBuffer,

Expand Down Expand Up @@ -386,6 +386,9 @@ impl<O: Offset> From<PolygonArray<O>> for MultiLineStringArray<O> {

#[cfg(test)]
mod test {
use crate::test::geoarrow_data::{
example_polygon_interleaved, example_polygon_separated, example_polygon_wkb,
};
use crate::test::polygon::{p0, p1};

use super::*;
Expand All @@ -412,4 +415,27 @@ mod test {
assert_eq!(arr.len(), 1);
assert_eq!(arr.get_as_geo(0), Some(p1()));
}

#[ignore = "WKB parsing is failing"]
#[test]
fn parse_wkb_geoarrow_interleaved_example() {
let geom_arr = example_polygon_interleaved();

let wkb_arr = example_polygon_wkb();
let parsed_geom_arr: PolygonArray<i64> = wkb_arr.try_into().unwrap();

assert_eq!(geom_arr, parsed_geom_arr);
}

#[ignore = "WKB parsing is failing"]
#[test]
fn parse_wkb_geoarrow_separated_example() {
// TODO: support checking equality of interleaved vs separated coords
let geom_arr = example_polygon_separated().into_coord_type(CoordType::Interleaved);

let wkb_arr = example_polygon_wkb();
let parsed_geom_arr: PolygonArray<i64> = wkb_arr.try_into().unwrap();

assert_eq!(geom_arr, parsed_geom_arr);
}
}
2 changes: 1 addition & 1 deletion src/io/native/wkb/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const F64_WIDTH: u64 = 8;
/// numbers that can occur within any geometry type.
///
/// See page 65 of https://portal.ogc.org/files/?artifact_id=25355.
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub struct WKBCoord<'a> {
/// The underlying WKB buffer
buf: &'a [u8],
Expand Down
2 changes: 1 addition & 1 deletion src/io/native/wkb/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<'a, O: Offset> WKB<'a, O> {
}
}

#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub enum Endianness {
BigEndian,
LittleEndian,
Expand Down
2 changes: 1 addition & 1 deletion src/io/native/wkb/linearring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::io::native::wkb::geometry::Endianness;
/// A linear ring in a WKB buffer.
///
/// See page 65 of https://portal.ogc.org/files/?artifact_id=25355.
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub struct WKBLinearRing<'a> {
/// The underlying WKB buffer
buf: &'a [u8],
Expand Down
2 changes: 1 addition & 1 deletion src/io/native/wkb/linestring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::io::native::wkb::geometry::Endianness;

const HEADER_BYTES: u64 = 5;

#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub struct WKBLineString<'a> {
buf: &'a [u8],
byte_order: Endianness,
Expand Down
1 change: 1 addition & 0 deletions src/io/native/wkb/maybe_multi_line_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::slice::Iter;
/// An WKB object that can be either a WKBLineString or a WKBMultiLineString.
///
/// This is used for casting a mix of linestrings and multi linestrings to an array of multi linestrings
#[derive(Debug, Clone)]
pub enum WKBMaybeMultiLineString<'a> {
LineString(WKBLineString<'a>),
MultiLineString(WKBMultiLineString<'a>),
Expand Down
1 change: 1 addition & 0 deletions src/io/native/wkb/maybe_multi_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::slice::Iter;
/// An WKB object that can be either a WKBPoint or a WKBMultiPoint.
///
/// This is used for casting a mix of Points and multi Points to an array of multi Points
#[derive(Debug, Clone, Copy)]
pub enum WKBMaybeMultiPoint<'a> {
Point(WKBPoint<'a>),
MultiPoint(WKBMultiPoint<'a>),
Expand Down
Loading

0 comments on commit e6337ec

Please sign in to comment.