-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d8fadc
commit 358b115
Showing
15 changed files
with
104 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ mod multipoint; | |
mod multipolygon; | ||
mod point; | ||
mod polygon; | ||
mod rect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::array::offset_builder::OffsetsBuilder; | ||
use crate::array::{RectArray, WKBArray}; | ||
use crate::trait_::ArrayAccessor; | ||
use crate::ArrayBase; | ||
use arrow_array::{GenericBinaryArray, OffsetSizeTrait}; | ||
use arrow_buffer::Buffer; | ||
use std::io::Cursor; | ||
use wkb::writer::{rect_wkb_size, write_rect}; | ||
use wkb::Endianness; | ||
|
||
impl<O: OffsetSizeTrait> From<&RectArray> for WKBArray<O> { | ||
fn from(value: &RectArray) -> Self { | ||
let mut offsets: OffsetsBuilder<O> = OffsetsBuilder::with_capacity(value.len()); | ||
|
||
// First pass: calculate binary array offsets | ||
for maybe_geom in value.iter() { | ||
if let Some(geom) = maybe_geom { | ||
offsets.try_push_usize(rect_wkb_size(&geom)).unwrap(); | ||
} else { | ||
offsets.extend_constant(1); | ||
} | ||
} | ||
|
||
let values = { | ||
let values = Vec::with_capacity(offsets.last().to_usize().unwrap()); | ||
let mut writer = Cursor::new(values); | ||
|
||
for geom in value.iter().flatten() { | ||
write_rect(&mut writer, &geom, Endianness::LittleEndian).unwrap(); | ||
} | ||
|
||
writer.into_inner() | ||
}; | ||
|
||
let binary_arr = GenericBinaryArray::new( | ||
offsets.into(), | ||
Buffer::from_vec(values), | ||
value.nulls().cloned(), | ||
); | ||
WKBArray::new(binary_arr, value.metadata()) | ||
} | ||
} |