Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add push_xy and push_xyz to the CoordBufferBuilders #943

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions rust/geoarrow/src/array/coord/combined/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,34 @@ impl CoordBufferBuilder {
CoordBufferBuilder::Separated(cb) => cb.try_push_point(point),
}
}

pub fn push_xy(&mut self, x: f64, y: f64) {
match self {
CoordBufferBuilder::Interleaved(cb) => cb.push_xy(x, y),
CoordBufferBuilder::Separated(cb) => cb.push_xy(x, y),
}
}

pub fn try_push_xy(&mut self, x: f64, y: f64) -> Result<()> {
match self {
CoordBufferBuilder::Interleaved(cb) => cb.try_push_xy(x, y),
CoordBufferBuilder::Separated(cb) => cb.try_push_xy(x, y),
}
}

pub fn push_xyz(&mut self, x: f64, y: f64, z: f64) {
match self {
CoordBufferBuilder::Interleaved(cb) => cb.push_xyz(x, y, z),
CoordBufferBuilder::Separated(cb) => cb.push_xyz(x, y, z),
}
}

pub fn try_push_xyz(&mut self, x: f64, y: f64, z: f64) -> Result<()> {
match self {
CoordBufferBuilder::Interleaved(cb) => cb.try_push_xyz(x, y, z),
CoordBufferBuilder::Separated(cb) => cb.try_push_xyz(x, y, z),
}
}
}

impl From<CoordBufferBuilder> for CoordBuffer {
Expand Down
35 changes: 35 additions & 0 deletions rust/geoarrow/src/array/coord/interleaved/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,41 @@ impl InterleavedCoordBufferBuilder {
Ok(())
}

pub fn push_xy(&mut self, x: f64, y: f64) {
self.try_push_xy(x, y).unwrap()
}

pub fn try_push_xy(&mut self, x: f64, y: f64) -> Result<()> {
if !matches!(self.dim, Dimension::XY) {
return Err(GeoArrowError::General(format!(
"Tried to push xy but internal dimension is {:?}.",
self.dim
)));
}

self.coords.push(x);
self.coords.push(y);
Ok(())
}

pub fn push_xyz(&mut self, x: f64, y: f64, z: f64) {
self.try_push_xyz(x, y, z).unwrap()
}

pub fn try_push_xyz(&mut self, x: f64, y: f64, z: f64) -> Result<()> {
if !matches!(self.dim, Dimension::XYZ) {
return Err(GeoArrowError::General(format!(
"Tried to push xyz but internal dimension is {:?}.",
self.dim
)));
}

self.coords.push(x);
self.coords.push(y);
self.coords.push(z);
Ok(())
}

pub fn from_coords<G: CoordTrait<T = f64>>(coords: &[G], dim: Dimension) -> Result<Self> {
let mut buffer = InterleavedCoordBufferBuilder::with_capacity(coords.len(), dim);
for coord in coords {
Expand Down
35 changes: 35 additions & 0 deletions rust/geoarrow/src/array/coord/separated/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,41 @@ impl SeparatedCoordBufferBuilder {
Ok(())
}

pub fn push_xy(&mut self, x: f64, y: f64) {
self.try_push_xy(x, y).unwrap()
}

pub fn try_push_xy(&mut self, x: f64, y: f64) -> Result<()> {
if !matches!(self.dim, Dimension::XY) {
return Err(GeoArrowError::General(format!(
"Tried to push xy but internal dimension is {:?}.",
self.dim
)));
}

self.buffers[0].push(x);
self.buffers[1].push(y);
Ok(())
}

pub fn push_xyz(&mut self, x: f64, y: f64, z: f64) {
self.try_push_xyz(x, y, z).unwrap()
}

pub fn try_push_xyz(&mut self, x: f64, y: f64, z: f64) -> Result<()> {
if !matches!(self.dim, Dimension::XYZ) {
return Err(GeoArrowError::General(format!(
"Tried to push xyz but internal dimension is {:?}.",
self.dim
)));
}

self.buffers[0].push(x);
self.buffers[1].push(y);
self.buffers[2].push(z);
Ok(())
}

pub fn from_coords<G: CoordTrait<T = f64>>(coords: &[G], dim: Dimension) -> Result<Self> {
let mut buffer = SeparatedCoordBufferBuilder::with_capacity(coords.len(), dim);
for coord in coords {
Expand Down
Loading