diff --git a/rust/geoarrow/src/array/coord/combined/builder.rs b/rust/geoarrow/src/array/coord/combined/builder.rs index 5fc4e4c8..ec83e184 100644 --- a/rust/geoarrow/src/array/coord/combined/builder.rs +++ b/rust/geoarrow/src/array/coord/combined/builder.rs @@ -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 for CoordBuffer { diff --git a/rust/geoarrow/src/array/coord/interleaved/builder.rs b/rust/geoarrow/src/array/coord/interleaved/builder.rs index 269d6051..b171afe7 100644 --- a/rust/geoarrow/src/array/coord/interleaved/builder.rs +++ b/rust/geoarrow/src/array/coord/interleaved/builder.rs @@ -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>(coords: &[G], dim: Dimension) -> Result { let mut buffer = InterleavedCoordBufferBuilder::with_capacity(coords.len(), dim); for coord in coords { diff --git a/rust/geoarrow/src/array/coord/separated/builder.rs b/rust/geoarrow/src/array/coord/separated/builder.rs index bc1fe2d7..e278fd1f 100644 --- a/rust/geoarrow/src/array/coord/separated/builder.rs +++ b/rust/geoarrow/src/array/coord/separated/builder.rs @@ -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>(coords: &[G], dim: Dimension) -> Result { let mut buffer = SeparatedCoordBufferBuilder::with_capacity(coords.len(), dim); for coord in coords {