-
Notifications
You must be signed in to change notification settings - Fork 40
Very basic reading and writing of a raster for InDB #406
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
Open
jesspav
wants to merge
13
commits into
apache:main
Choose a base branch
from
jesspav:raster_readwrite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c28b2a0
basic read/write of geotiffs for indb only
jesspav 6705a9f
attempting to install gdal in github workflow
jesspav 34702e1
fmt + clippy
jesspav 4e0b9cb
Restore submodules/sedona-testing to match main branch
jesspav 5f0b342
remove Cargo.lock
jesspav 801930a
derive copy for banddatatype - pr feedback
jesspav cca7d02
clippy
jesspav d6a0e44
default to none on tile_size
jesspav b26697d
Merge branch 'main' into raster_readwrite
jesspav 81dec24
fix merge
jesspav c5031fe
fixed cargo paths
jesspav 31c37d0
switch errors from Arrow to Datafusion
jesspav 7ccd25c
update exception types
jesspav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # 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. | ||
|
|
||
| [package] | ||
| name = "sedona-gdal" | ||
| version.workspace = true | ||
| homepage.workspace = true | ||
| repository.workspace = true | ||
| description.workspace = true | ||
| readme.workspace = true | ||
| edition.workspace = true | ||
| rust-version.workspace = true | ||
|
|
||
| [lints.clippy] | ||
| result_large_err = "allow" | ||
|
|
||
| [dev-dependencies] | ||
| approx = { workspace = true } | ||
| rstest = { workspace = true } | ||
| sedona-testing = { workspace = true, features = ["criterion"] } | ||
| criterion = { workspace = true} | ||
| tempfile = { workspace = true } | ||
|
|
||
| [dependencies] | ||
| arrow = { workspace = true } | ||
| arrow-array = { workspace = true } | ||
| arrow-schema = { workspace = true } | ||
| datafusion-common = { workspace = true } | ||
| datafusion-expr = { workspace = true } | ||
| gdal = {workspace = true} | ||
| gdal-sys = {workspace = true} | ||
| sedona-common = { workspace = true } | ||
| sedona-raster = { workspace = true } | ||
| sedona-schema = { workspace = true } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| // 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 | ||
| pub fn tile_size(dataset: &Dataset) -> (Option<usize>, Option<usize>) { | ||
| let tile_width = match dataset.metadata_item("TILEWIDTH", "") { | ||
| Some(val) => val.parse::<usize>().ok(), | ||
| None => None, | ||
| }; | ||
| let tile_height = match dataset.metadata_item("TILEHEIGHT", "") { | ||
| Some(val) => val.parse::<usize>().ok(), | ||
| None => None, | ||
| }; | ||
|
|
||
| (tile_width, tile_height) | ||
| } | ||
|
|
||
| pub fn to_banddatatype(gdal_data_type: GdalDataType) -> Result<BandDataType, ArrowError> { | ||
| match gdal_data_type { | ||
| GdalDataType::UInt8 => Ok(BandDataType::UInt8), | ||
| GdalDataType::UInt16 => Ok(BandDataType::UInt16), | ||
| GdalDataType::Int16 => Ok(BandDataType::Int16), | ||
| GdalDataType::UInt32 => Ok(BandDataType::UInt32), | ||
| GdalDataType::Int32 => Ok(BandDataType::Int32), | ||
| GdalDataType::Float32 => Ok(BandDataType::Float32), | ||
| GdalDataType::Float64 => Ok(BandDataType::Float64), | ||
| _ => Err(ArrowError::InvalidArgumentError(format!( | ||
| "Unsupported GDAL data type: {:?}", | ||
| gdal_data_type | ||
| ))), | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use gdal::DriverManager; | ||
|
|
||
| #[test] | ||
| fn test_geotransform_components() { | ||
| let driver = DriverManager::get_driver_by_name("MEM").unwrap(); | ||
| let mut dataset = driver | ||
| .create_with_band_type::<u8, _>("", 100, 100, 1) | ||
| .unwrap(); | ||
|
|
||
| let (upper_left_x, upper_left_y, pixel_width, pixel_height, rotation_x, rotation_y) = | ||
| (10.0, 20.0, 1.5, -2.5, 0.1, 0.2); | ||
|
|
||
| // Add some basic georeferencing | ||
| dataset | ||
| .set_geo_transform(&[ | ||
| upper_left_x, | ||
| pixel_width, | ||
| rotation_x, | ||
| upper_left_y, | ||
| rotation_y, | ||
| pixel_height, | ||
| ]) | ||
| .unwrap(); | ||
|
|
||
| let (ulx, uly, sx, sy, rx, ry) = geotransform_components(&dataset).unwrap(); | ||
| assert_eq!(ulx, upper_left_x); | ||
| assert_eq!(uly, upper_left_y); | ||
| assert_eq!(sx, pixel_width); | ||
| assert_eq!(sy, pixel_height); | ||
| assert_eq!(rx, rotation_x); | ||
| assert_eq!(ry, rotation_y); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_tile_size() -> Result<(), ArrowError> { | ||
| let driver = DriverManager::get_driver_by_name("MEM") | ||
| .map_err(|e| ArrowError::ParseError(format!("Failed to get MEM driver: {e}")))?; | ||
| let mut dataset = driver | ||
| .create_with_band_type::<u8, _>("", 256, 512, 1) | ||
| .map_err(|e| ArrowError::ParseError(format!("Failed to create dataset: {e}")))?; | ||
|
|
||
| // Set real tile size metadata | ||
| dataset | ||
| .set_metadata_item("TILEWIDTH", "256", "") | ||
| .map_err(|e| ArrowError::ParseError(format!("Failed to set TILEWIDTH: {e}")))?; | ||
| dataset | ||
| .set_metadata_item("TILEHEIGHT", "512", "") | ||
| .map_err(|e| ArrowError::ParseError(format!("Failed to set TILEHEIGHT: {e}")))?; | ||
|
|
||
| let (tile_width, tile_height) = tile_size(&dataset); | ||
| assert!(tile_width.is_some()); | ||
| assert_eq!(tile_width.unwrap(), 256); | ||
| assert_eq!(tile_height.unwrap(), 512); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_to_banddatatype() { | ||
| assert_eq!( | ||
| to_banddatatype(GdalDataType::UInt8).unwrap(), | ||
| BandDataType::UInt8 | ||
| ); | ||
| let result = to_banddatatype(GdalDataType::Unknown); | ||
| assert!(result.is_err()); | ||
| assert!(result | ||
| .err() | ||
| .unwrap() | ||
| .to_string() | ||
| .contains("Unsupported GDAL data type")); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // 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. | ||
|
|
||
| pub mod dataset; | ||
| pub mod raster_io; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The errors in this module are not from Arrow. Is ExecutionError or ExternalError a better alternative?