jesspav commented on code in PR #253:
URL: https://github.com/apache/sedona-db/pull/253#discussion_r2476006476


##########
rust/sedona-raster/src/builder.rs:
##########
@@ -0,0 +1,1600 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow_array::BinaryViewArray;
+use arrow_array::{
+    builder::{
+        BinaryBuilder, BinaryViewBuilder, Float64Builder, ListBuilder, 
StringBuilder,
+        StringViewBuilder, StructBuilder, UInt32Builder, UInt64Builder,
+    },
+    Array, BinaryArray, Float64Array, ListArray, StringArray, StringViewArray, 
StructArray,
+    UInt32Array, UInt64Array,
+};
+use arrow_schema::{ArrowError, DataType, Field};
+use datafusion_common::error::Result;
+use sedona_schema::raster::{
+    band_indices, band_metadata_indices, bounding_box_indices, column, 
metadata_indices,
+    raster_indices, BandDataType, RasterSchema, StorageType,
+};
+
+/// Builder for constructing raster arrays with zero-copy band data writing
+pub struct RasterBuilder {
+    main_builder: StructBuilder,
+}
+
+/// Metadata for a raster
+#[derive(Debug, Clone)]
+pub struct RasterMetadata {
+    pub width: u64,
+    pub height: u64,
+    pub upperleft_x: f64,
+    pub upperleft_y: f64,
+    pub scale_x: f64,
+    pub scale_y: f64,
+    pub skew_x: f64,
+    pub skew_y: f64,
+}
+
+/// Bounding box coordinates
+#[derive(Debug, Clone)]
+pub struct BoundingBox {
+    pub min_x: f64,
+    pub min_y: f64,
+    pub max_x: f64,
+    pub max_y: f64,
+}
+
+/// Metadata for a single band
+#[derive(Debug, Clone)]
+pub struct BandMetadata {
+    pub nodata_value: Option<Vec<u8>>,
+    pub storage_type: StorageType,
+    pub datatype: BandDataType,
+    /// URL for OutDb reference (only used when storage_type == OutDbRef)
+    pub outdb_url: Option<String>,
+    /// Band ID within the OutDb resource (only used when storage_type == 
OutDbRef)
+    pub outdb_band_id: Option<u32>,
+}
+
+impl RasterBuilder {
+    /// Create a new raster builder with the specified capacity
+    pub fn new(capacity: usize) -> Self {
+        let metadata_builder = StructBuilder::from_fields(
+            match RasterSchema::metadata_type() {
+                DataType::Struct(fields) => fields,
+                _ => panic!("Expected struct type for metadata"),
+            },
+            capacity,
+        );
+
+        let crs_builder = StringViewBuilder::new();
+
+        let bbox_builder = StructBuilder::from_fields(
+            match RasterSchema::bounding_box_type() {
+                DataType::Struct(fields) => fields,
+                _ => panic!("Expected struct type for bounding box"),
+            },
+            capacity,
+        );
+
+        let band_struct_builder = StructBuilder::from_fields(
+            match RasterSchema::band_type() {
+                DataType::Struct(fields) => fields,
+                _ => panic!("Expected struct type for band"),
+            },
+            0,
+        );
+
+        let bands_builder = 
ListBuilder::new(band_struct_builder).with_field(Field::new(
+            column::BAND,
+            RasterSchema::band_type(),
+            false,
+        ));
+
+        // Now create the main builder with pre-built components
+        let main_builder = StructBuilder::new(
+            RasterSchema::fields(),
+            vec![
+                Box::new(metadata_builder),
+                Box::new(crs_builder),
+                Box::new(bbox_builder),
+                Box::new(bands_builder),
+            ],
+        );
+
+        Self { main_builder }
+    }
+
+    /// Start a new raster with metadata, optional CRS, and optional bounding 
box
+    ///
+    /// This is the unified method for starting a raster with all optional 
parameters.
+    ///
+    /// # Arguments
+    /// * `metadata` - Raster metadata (dimensions, geotransform parameters)
+    /// * `crs` - Optional coordinate reference system as string
+    /// * `bbox` - Optional bounding box coordinates
+    ///
+    /// # Examples

Review Comment:
   Done. Was excited to learn that it gets run as part of `cargo test`!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to