-
Notifications
You must be signed in to change notification settings - Fork 61
feat(rust/sedona-raster-gdal): add RS_AsGeoTiff #1028
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bbdeb8c
feat(rust/sedona-raster-gdal): add RS_AsGeoTiff
james-willis dc7c2db
fix(rust/sedona-raster-gdal): validate RS_AsGeoTiff quality and pick …
james-willis aece9ce
test(python/sedonadb): add RS_AsGeoTiff smoke tests
james-willis 216df3d
perf(rust/sedona-raster-gdal): return RS_AsGeoTiff bytes without an i…
james-willis bf306c3
Merge remote-tracking branch 'origin/main' into jw/rs-asgeotiff
james-willis b3743bf
feat(rust/sedona-raster-gdal): RS_AsGeoTiff returns BinaryView; UDF-l…
james-willis bb195db
test(python/sedonadb): hoist non-rasterio imports to module top
james-willis 15cbc8b
perf(rust/sedona-raster-gdal): RS_AsGeoTiff output views the VSI allo…
james-willis c6ead89
Merge remote-tracking branch 'origin/main' into jw/rs-asgeotiff
james-willis 3b738e5
docs(rust/sedona-raster-gdal): move misplaced jpeg_quality_option doc…
james-willis 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
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,103 @@ | ||
| --- | ||
| # 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. | ||
|
|
||
| title: RS_AsGeoTiff | ||
| description: > | ||
| Encodes a raster as a GeoTIFF and returns the bytes as binary, with optional | ||
| compression and tiling. | ||
| kernels: | ||
| - returns: binary | ||
| args: | ||
| - raster | ||
| - returns: binary | ||
| args: | ||
| - raster | ||
| - {name: tile_size, type: integer} | ||
| - returns: binary | ||
| args: | ||
| - raster | ||
| - {name: compression, type: string} | ||
| - {name: quality, type: double} | ||
| - returns: binary | ||
| args: | ||
| - raster | ||
| - {name: compression, type: string} | ||
| - {name: quality, type: double} | ||
| - {name: tile_size, type: integer} | ||
| - returns: binary | ||
| args: | ||
| - raster | ||
| - name: compression | ||
| type: string | ||
| description: > | ||
| GeoTIFF compression codec (case-insensitive): None, PackBits, Deflate, | ||
| Huffman, LZW, or JPEG. Deflate and LZW additionally enable a predictor | ||
| to improve the compression ratio (horizontal differencing for integer | ||
| bands, floating-point prediction for float bands). Huffman maps to | ||
| CCITT RLE, which GDAL only accepts for 1-bit single-band data — it is | ||
| kept for Apache Sedona parity but errors on ordinary rasters. | ||
| - name: quality | ||
| type: double | ||
| description: > | ||
| Quality factor for lossy JPEG compression as a fraction between 0.0 | ||
| and 1.0 (e.g. 0.75 for JPEG quality 75, matching Apache Sedona); | ||
| values outside that range raise an error. Ignored by the other codecs. | ||
| - name: tile_width | ||
| type: integer | ||
| description: > | ||
| Tile width in pixels. When given together with tile_height, the | ||
| GeoTIFF is written tiled rather than stripped. TIFF tile dimensions | ||
| must be multiples of 16. | ||
| - name: tile_height | ||
| type: integer | ||
| description: Tile height in pixels; must be a multiple of 16. | ||
| --- | ||
|
|
||
| ::: callout-warning | ||
| **Experimental.** This function is experimental; its behavior may change without notice. | ||
| ::: | ||
|
|
||
| ## Description | ||
|
|
||
| `RS_AsGeoTiff` encodes a raster as a GeoTIFF (via GDAL) and returns the file | ||
| bytes as a binary value — the inverse of reading a GeoTIFF into a raster. The | ||
| result is `NULL` for a `NULL` raster. A `NULL` option argument means "not | ||
| specified": e.g. a `NULL` compression writes an uncompressed GeoTIFF rather | ||
| than propagating `NULL` to the result. | ||
|
|
||
| The two-argument form `RS_AsGeoTiff(raster, tile_size)` writes a tiled GeoTIFF | ||
| with square `tile_size` blocks. Compression is selected by name; a JPEG quality | ||
| factor and explicit tile dimensions can be supplied via the longer overloads. | ||
|
|
||
| ## Examples | ||
|
|
||
| ```sql | ||
| SELECT RS_AsGeoTiff(RS_Example()) IS NOT NULL; | ||
| ``` | ||
|
|
||
| ```sql | ||
| SELECT RS_AsGeoTiff(RS_Example(), 16) IS NOT NULL; | ||
| ``` | ||
|
|
||
| ```sql | ||
| SELECT RS_AsGeoTiff(RS_Example(), 'DEFLATE', 0.85) IS NOT NULL; | ||
| ``` | ||
|
|
||
| ```sql | ||
| SELECT RS_AsGeoTiff(RS_Example(), 'LZW', 0.85, 16, 16) IS NOT NULL; | ||
| ``` | ||
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
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,120 @@ | ||
| // 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. | ||
|
|
||
| //! Benchmarks for the RS_AsGeoTiff UDF. | ||
| //! | ||
| //! Exercises the raster → GeoTIFF export path (`RS_Example` rasters, no external | ||
| //! fixtures): the uncompressed default and the compression axis (none/lzw/deflate). | ||
|
|
||
| use std::hint::black_box; | ||
| use std::sync::Arc; | ||
|
|
||
| use arrow_array::ArrayRef; | ||
| use arrow_schema::DataType; | ||
| use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; | ||
| use datafusion_common::ScalarValue; | ||
| use datafusion_expr::{ColumnarValue, ScalarUDF}; | ||
| use sedona_schema::datatypes::{SedonaType, RASTER}; | ||
| use sedona_schema::raster::BandDataType; | ||
| use sedona_testing::raster_spec::RasterSpec; | ||
| use sedona_testing::testers::ScalarUdfTester; | ||
|
|
||
| fn raster_array(rows: usize) -> ArrayRef { | ||
| assert!(rows > 0, "benchmark rows must be positive"); | ||
|
|
||
| let example: ScalarUDF = sedona_raster_functions::rs_example::rs_example_udf().into(); | ||
| let tester = ScalarUdfTester::new(example, vec![]); | ||
| match tester.invoke(vec![]).unwrap() { | ||
| ColumnarValue::Scalar(value) => value.to_array_of_size(rows).unwrap(), | ||
| ColumnarValue::Array(array) => array, | ||
| } | ||
| } | ||
|
|
||
| fn bench_rs_as_geotiff_basic(c: &mut Criterion) { | ||
| let udf: ScalarUDF = sedona_raster_gdal::rs_as_geotiff_udf().into(); | ||
| let tester = ScalarUdfTester::new(udf, vec![RASTER]); | ||
|
|
||
| let mut group = c.benchmark_group("rs_as_geotiff"); | ||
| for rows in [1usize, 32] { | ||
| let rasters = raster_array(rows); | ||
| group.throughput(Throughput::Elements(rows as u64)); | ||
| group.bench_with_input(BenchmarkId::new("basic", rows), &rasters, |b, input| { | ||
| b.iter(|| black_box(tester.invoke_arrays(vec![input.clone()]).unwrap())) | ||
| }); | ||
| } | ||
|
|
||
| // A single ~16 MB raster: large enough that per-row byte handling | ||
| // (vsimem buffer -> output array) registers against the GDAL encode. | ||
| const LARGE: i64 = 4096; | ||
| let large: ArrayRef = Arc::new( | ||
| RasterSpec::d2(LARGE, LARGE) | ||
| .band(BandDataType::UInt8) | ||
| .build(), | ||
| ); | ||
| group.throughput(Throughput::Bytes((LARGE * LARGE) as u64)); | ||
| group.bench_with_input(BenchmarkId::new("large", "16MiB"), &large, |b, input| { | ||
| b.iter(|| black_box(tester.invoke_arrays(vec![input.clone()]).unwrap())) | ||
| }); | ||
| group.finish(); | ||
| } | ||
|
|
||
| fn bench_rs_as_geotiff_compression(c: &mut Criterion) { | ||
| let udf: ScalarUDF = sedona_raster_gdal::rs_as_geotiff_udf().into(); | ||
| let tester = ScalarUdfTester::new( | ||
| udf, | ||
| vec![ | ||
| RASTER, | ||
| SedonaType::Arrow(DataType::Utf8), | ||
| SedonaType::Arrow(DataType::Float64), | ||
| ], | ||
| ); | ||
|
|
||
| let rasters = raster_array(32); | ||
| // Quality is a 0.0-1.0 fraction (ignored by these codecs, but must be valid). | ||
| let quality = ColumnarValue::Scalar(ScalarValue::Float64(Some(0.75))); | ||
|
|
||
| let mut group = c.benchmark_group("rs_as_geotiff_compression"); | ||
| group.throughput(Throughput::Elements(rasters.len() as u64)); | ||
| for compression in ["none", "lzw", "deflate"] { | ||
| let comp = ColumnarValue::Scalar(ScalarValue::Utf8(Some(compression.to_string()))); | ||
| group.bench_with_input( | ||
| BenchmarkId::new("compression", compression), | ||
| &(&rasters, &comp, &quality), | ||
| |b, (rasters, comp, quality)| { | ||
| b.iter(|| { | ||
| black_box( | ||
| tester | ||
| .invoke(vec![ | ||
| ColumnarValue::Array((*rasters).clone()), | ||
| (*comp).clone(), | ||
| (*quality).clone(), | ||
| ]) | ||
| .unwrap(), | ||
| ) | ||
| }) | ||
| }, | ||
| ); | ||
| } | ||
| group.finish(); | ||
| } | ||
|
|
||
| criterion_group!( | ||
| benches, | ||
| bench_rs_as_geotiff_basic, | ||
| bench_rs_as_geotiff_compression | ||
| ); | ||
| criterion_main!(benches); |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.