Skip to content

Commit 01c408f

Browse files
fix: better explanation on dimension z and m
1 parent b6a39c6 commit 01c408f

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

vortex-geo/src/extension/coordinate.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
//! Coordinate building blocks for geometry extension types: the `Struct<x, y, [z], [m]>` storage,
4+
//! Coordinate building blocks for geometry extension types: the `Struct<x, y, z?, m?>` storage,
55
//! its [`Dimension`], and the decoded [`Coordinate`] value.
6+
//!
7+
//! The coordinate fields, where `?` marks an optional field, are:
8+
//! - `x` — longitude or easting
9+
//! - `y` — latitude or northing
10+
//! - `z?` — elevation
11+
//! - `m?` — measure: an arbitrary per-point value such as distance along a route or a timestamp
612
713
use std::fmt::Display;
814
use std::fmt::Formatter;
@@ -22,7 +28,7 @@ use vortex_error::VortexResult;
2228
use vortex_error::vortex_bail;
2329
use vortex_error::vortex_err;
2430

25-
/// Coordinate dimensions, matching GeoArrow. Field order is fixed: x, y, then z before m.
31+
/// Coordinate dimensions, matching GeoArrow. Field order is fixed: `x`, `y`, then `z` before `m`.
2632
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2733
pub(crate) enum Dimension {
2834
/// 2D: `x`, `y`.
@@ -48,7 +54,7 @@ impl Dimension {
4854
}
4955
}
5056

51-
/// A decoded coordinate. `z`/`m` are `Some` iff the storage dimension includes them.
57+
/// A decoded coordinate. `z?`/`m?` are `Some` iff the storage dimension includes them.
5258
///
5359
/// This is the native value produced when unpacking a [`Point`](crate::extension::Point) scalar;
5460
/// the rest of the coordinate machinery is crate-internal.
@@ -58,14 +64,14 @@ pub struct Coordinate {
5864
x: f64,
5965
/// The y (latitude/northing) ordinate.
6066
y: f64,
61-
/// The optional z (elevation) ordinate.
67+
/// The optional `z?` (elevation) ordinate.
6268
z: Option<f64>,
63-
/// The optional m (measure) ordinate.
69+
/// The optional `m?` (measure) ordinate.
6470
m: Option<f64>,
6571
}
6672

6773
impl Coordinate {
68-
/// A 2D coordinate (no `z`/`m`).
74+
/// A 2D coordinate (`z?`/`m?` unset).
6975
pub fn xy(x: f64, y: f64) -> Self {
7076
Coordinate {
7177
x,
@@ -85,12 +91,12 @@ impl Coordinate {
8591
self.y
8692
}
8793

88-
/// The z (elevation) ordinate, if the dimension includes one.
94+
/// The `z?` (elevation) ordinate, if the dimension includes one.
8995
pub fn z(&self) -> Option<f64> {
9096
self.z
9197
}
9298

93-
/// The m (measure) ordinate, if the dimension includes one.
99+
/// The `m?` (measure) ordinate, if the dimension includes one.
94100
pub fn m(&self) -> Option<f64> {
95101
self.m
96102
}
@@ -123,7 +129,7 @@ pub(crate) fn coordinate_dimension(dtype: &DType) -> VortexResult<Dimension> {
123129
Dimension::from_field_names(&names)
124130
}
125131

126-
/// Decode a [`Coordinate`] from a coordinate `Struct<x, y, [z], [m]>` scalar (`z`/`m` read iff
132+
/// Decode a [`Coordinate`] from a coordinate `Struct<x, y, z?, m?>` scalar (`z?`/`m?` read iff
127133
/// present, so the same decoder serves every dimension).
128134
pub(crate) fn coordinate_from_struct(scalar: &Scalar) -> VortexResult<Coordinate> {
129135
let fields = scalar.as_struct();
@@ -158,7 +164,7 @@ pub(crate) fn coordinate_from_scalar(scalar: &Scalar) -> VortexResult<Coordinate
158164
}
159165

160166
/// Canonicalize a point column once and return its flat `x`/`y` `f64` columns. The bulk counterpart
161-
/// to [`coordinate_from_scalar`]; distances use only `x`/`y`, so `z`/`m` are ignored.
167+
/// to [`coordinate_from_scalar`]; distances use only `x`/`y`, so `z?`/`m?` are ignored.
162168
pub(crate) fn xy_columns(
163169
points: &ArrayRef,
164170
ctx: &mut ExecutionCtx,

vortex-geo/src/extension/point.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
//! The [`Point`] geometry extension type (`vortex.geo.point`): a location stored columnarly as
5-
//! `Struct<x, y, [z], [m]>` of `f64`, tagged with [`GeoMetadata`] (CRS).
5+
//! `Struct<x, y, z?, m?>` of `f64`, tagged with [`GeoMetadata`] (CRS). `z?` is an optional
6+
//! elevation and `m?` an optional measure — an arbitrary per-point value such as distance along a
7+
//! route or a timestamp.
68
79
use prost::Message;
810
use vortex_array::dtype::extension::ExtDType;
@@ -17,7 +19,7 @@ use super::coordinate::Coordinate;
1719
use super::coordinate::coordinate_dimension;
1820
use super::coordinate::coordinate_from_struct;
1921

20-
/// A single location: `geoarrow.point`, stored as `Struct<x, y, [z], [m]>` of `f64`.
22+
/// A single location: `geoarrow.point`, stored as `Struct<x, y, z?, m?>` of `f64`.
2123
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
2224
pub struct Point;
2325

@@ -97,7 +99,7 @@ mod tests {
9799
}
98100

99101
/// `Point` accepts every GeoArrow dimension; the canonical field names round-trip to their
100-
/// dimension, so a z/m swap or a mislabel would be caught.
102+
/// dimension, so a `z?`/`m?` swap or a mislabel would be caught.
101103
#[test]
102104
fn point_validates_every_dimension() -> VortexResult<()> {
103105
let cases = [

vortex-geo/src/scalar_fn/distance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn euclidean_distance(ax: f64, ay: f64, bx: f64, by: f64) -> f64 {
3434
}
3535

3636
/// Straight-line (Euclidean) distance between two point operands — "planar" distance in GIS terms
37-
/// (e.g. PostGIS `ST_Distance`). No geodesic correction, and `z`/`m` are ignored.
37+
/// (e.g. PostGIS `ST_Distance`). No geodesic correction, and `z?`/`m?` are ignored.
3838
///
3939
/// The operands are two point columns of equal length; either (or both) may be constant, in which
4040
/// case the constant query point is decoded once and broadcast.

0 commit comments

Comments
 (0)