james-willis commented on code in PR #1068: URL: https://github.com/apache/sedona-db/pull/1068#discussion_r3634799062
########## c/sedona-gdal/src/warp.rs: ########## @@ -0,0 +1,241 @@ +// 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. + +//! GDAL warp / reproject API wrappers. +//! +//! Sits alongside the RasterIO resampling in [`crate::raster::rasterband`]: this +//! is the (re)gridding path that can move the output origin off the source grid, +//! grow the output extent beyond the source footprint, and change the CRS — +//! things RasterIO's read-into-a-buffer cannot do. + +use std::ffi::CString; +use std::os::raw::c_void; +use std::ptr::{null, null_mut}; + +use crate::dataset::Dataset; +use crate::errors::{GdalError, Result}; +use crate::gdal_api::{call_gdal_api, GdalApi}; +use crate::gdal_dyn_bindgen::{CE_Failure, CE_None}; +use crate::geo_transform::GeoTransform; +use crate::raster::types::ResampleAlg; +use crate::spatial_ref::SpatialRef; + +/// Reproject/warp `src` into the already-created `dst` dataset. +/// +/// Both datasets carry their own spatial reference (set via `set_projection` / +/// `set_spatial_ref`), so the warp reprojects from the source SRS to the +/// destination SRS, resampling with `alg`. The output grid — origin, pixel size, +/// dimensions — is whatever `dst` was created with. +/// +/// Destination cells that the (reprojected) source footprint does not cover are +/// left **untouched**: `GDALReprojectImage` with no warp options writes only +/// covered pixels. Callers that grow the extent must therefore pre-fill `dst`'s +/// band buffers with the desired background/nodata value before warping. +pub fn reproject_image( + api: &'static GdalApi, + src: &Dataset, + dst: &Dataset, + alg: ResampleAlg, +) -> Result<()> { + let gra = alg.to_gdal_warp().ok_or_else(|| { + GdalError::BadArgument(format!( + "resample algorithm {alg:?} is not supported by the warp API" + )) + })?; + + let rv = unsafe { + call_gdal_api!( + api, + GDALReprojectImage, + src.c_dataset(), + null(), // src WKT: NULL means "use the source dataset's own SRS" + dst.c_dataset(), + null(), // dst WKT: NULL means "use the destination dataset's own SRS" + gra, + 0.0, // warp memory limit (0 = GDAL default) Review Comment: im not sure if theres some value we should be passing here. -- 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]
