Skip to content

Commit c013a7f

Browse files
authored
Add as_wkt to AsGeoArrowArray (#1029)
### Change list - Remove `as_large_wkb`, change `as_wkb` to take a type parameter `O: OffsetSizeTrait` - Add `as_wkt` with the same signature as `as_wkb`
1 parent 545ebc3 commit c013a7f

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

rust/geoarrow-array/src/cast.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
use std::sync::Arc;
44

5+
use arrow_array::OffsetSizeTrait;
6+
57
use crate::array::*;
68
use crate::trait_::GeoArrowArray;
79

@@ -118,22 +120,22 @@ pub trait AsGeoArrowArray {
118120
self.as_geometry_opt().unwrap()
119121
}
120122

121-
/// Downcast this to a [`WKBArray`] with `i32` offsets returning `None` if not possible
122-
fn as_wkb_opt(&self) -> Option<&WKBArray<i32>>;
123+
/// Downcast this to a [`WKBArray`] with `O` offsets returning `None` if not possible
124+
fn as_wkb_opt<O: OffsetSizeTrait>(&self) -> Option<&WKBArray<O>>;
123125

124-
/// Downcast this to a [`WKBArray`] with `i32` offsets panicking if not possible
126+
/// Downcast this to a [`WKBArray`] with `O` offsets panicking if not possible
125127
#[inline]
126-
fn as_wkb(&self) -> &WKBArray<i32> {
127-
self.as_wkb_opt().unwrap()
128+
fn as_wkb<O: OffsetSizeTrait>(&self) -> &WKBArray<O> {
129+
self.as_wkb_opt::<O>().unwrap()
128130
}
129131

130-
/// Downcast this to a [`WKBArray`] with `i64` offsets returning `None` if not possible
131-
fn as_large_wkb_opt(&self) -> Option<&WKBArray<i64>>;
132+
/// Downcast this to a [`WKTArray`] with `O` offsets returning `None` if not possible
133+
fn as_wkt_opt<O: OffsetSizeTrait>(&self) -> Option<&WKTArray<O>>;
132134

133-
/// Downcast this to a [`WKBArray`] with `i64` offsets panicking if not possible
135+
/// Downcast this to a [`WKTArray`] with `O` offsets panicking if not possible
134136
#[inline]
135-
fn as_large_wkb(&self) -> &WKBArray<i64> {
136-
self.as_large_wkb_opt().unwrap()
137+
fn as_wkt<O: OffsetSizeTrait>(&self) -> &WKTArray<O> {
138+
self.as_wkt_opt::<O>().unwrap()
137139
}
138140
}
139141

@@ -185,13 +187,13 @@ impl AsGeoArrowArray for dyn GeoArrowArray + '_ {
185187
}
186188

187189
#[inline]
188-
fn as_wkb_opt(&self) -> Option<&WKBArray<i32>> {
189-
self.as_any().downcast_ref::<WKBArray<i32>>()
190+
fn as_wkb_opt<O: OffsetSizeTrait>(&self) -> Option<&WKBArray<O>> {
191+
self.as_any().downcast_ref::<WKBArray<O>>()
190192
}
191193

192194
#[inline]
193-
fn as_large_wkb_opt(&self) -> Option<&WKBArray<i64>> {
194-
self.as_any().downcast_ref::<WKBArray<i64>>()
195+
fn as_wkt_opt<O: OffsetSizeTrait>(&self) -> Option<&WKTArray<O>> {
196+
self.as_any().downcast_ref::<WKTArray<O>>()
195197
}
196198
}
197199

@@ -242,12 +244,12 @@ impl AsGeoArrowArray for Arc<dyn GeoArrowArray> {
242244
}
243245

244246
#[inline]
245-
fn as_wkb_opt(&self) -> Option<&WKBArray<i32>> {
246-
self.as_any().downcast_ref::<WKBArray<i32>>()
247+
fn as_wkb_opt<O: OffsetSizeTrait>(&self) -> Option<&WKBArray<O>> {
248+
self.as_any().downcast_ref::<WKBArray<O>>()
247249
}
248250

249251
#[inline]
250-
fn as_large_wkb_opt(&self) -> Option<&WKBArray<i64>> {
251-
self.as_any().downcast_ref::<WKBArray<i64>>()
252+
fn as_wkt_opt<O: OffsetSizeTrait>(&self) -> Option<&WKTArray<O>> {
253+
self.as_any().downcast_ref::<WKTArray<O>>()
252254
}
253255
}

0 commit comments

Comments
 (0)