jesspav commented on code in PR #406: URL: https://github.com/apache/sedona-db/pull/406#discussion_r2594254655
########## rust/sedona-gdal/src/dataset.rs: ########## @@ -0,0 +1,141 @@ +// 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_schema::ArrowError; +use gdal::raster::GdalDataType; +use gdal::Dataset; +use gdal::Metadata; +use sedona_schema::raster::BandDataType; + +/// Extract geotransform components from a GDAL dataset +/// Returns (upper_left_x, upper_left_y, scale_x, scale_y, skew_x, skew_y) +pub fn geotransform_components( + dataset: &Dataset, +) -> Result<(f64, f64, f64, f64, f64, f64), ArrowError> { + let geotransform = dataset + .geo_transform() + .map_err(|e| ArrowError::ParseError(format!("Failed to get geotransform: {e}")))?; + Ok(( + geotransform[0], // Upper-left X coordinate + geotransform[3], // Upper-left Y coordinate + geotransform[1], // scale_x (pixel width) + geotransform[5], // scale_y (pixel height, usually negative) + geotransform[2], // skew_x (X-direction skew) + geotransform[4], // skew_y (Y-direction skew) + )) +} + +/// Extract tile size from a GDAL dataset +/// If not provided, defaults to raster size. In future, will consider +/// defaulting to an ideal tile size instead of full raster size once we know +/// what the idea tile size should be. +pub fn tile_size(dataset: &Dataset) -> Result<(usize, usize), ArrowError> { + let raster_width = dataset.raster_size().0; + let raster_height = dataset.raster_size().1; + + let tile_width = match dataset.metadata_item("TILEWIDTH", "") { + Some(val) => val.parse::<usize>().unwrap_or(raster_width), + None => raster_width, + }; + let tile_height = match dataset.metadata_item("TILEHEIGHT", "") { + Some(val) => val.parse::<usize>().unwrap_or(raster_height), Review Comment: changed it to not default. -- 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]
