Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions docs/reference/sql/rs_pixelascentroid.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
# 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_PixelAsCentroid
description: Returns the centroid of the specified pixel as a Point geometry.
kernels:
- returns: geometry
args:
- raster
- name: colX
type: integer
- name: rowY
type: integer
---

## Examples

```sql
SELECT RS_PixelAsCentroid(RS_Example(), 1, 1);
```
35 changes: 35 additions & 0 deletions docs/reference/sql/rs_pixelaspoint.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
# 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_PixelAsPoint
description: Returns the upper-left corner of the specified pixel as a Point geometry.
kernels:
- returns: geometry
args:
- raster
- name: colX
type: integer
- name: rowY
type: integer
---

## Examples

```sql
SELECT RS_PixelAsPoint(RS_Example(), 1, 1);
```
35 changes: 35 additions & 0 deletions docs/reference/sql/rs_pixelaspolygon.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
# 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_PixelAsPolygon
description: Returns the bounding polygon of the specified pixel.
kernels:
- returns: geometry
args:
- raster
- name: colX
type: integer
- name: rowY
type: integer
---

## Examples

```sql
SELECT RS_PixelAsPolygon(RS_Example(), 1, 1);
```
22 changes: 22 additions & 0 deletions rust/sedona-raster-functions/benches/native-raster-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ fn criterion_benchmark(c: &mut Criterion) {
);
benchmark::scalar(c, &f, "native-raster", "rs_height", Raster(64, 64));
benchmark::scalar(c, &f, "native-raster", "rs_numbands", Raster(64, 64));
// RS_PixelAsPoint, RS_PixelAsCentroid, RS_PixelAsPolygon
benchmark::scalar(
c,
&f,
"native-raster",
"rs_pixelaspoint",
BenchmarkArgs::ArrayScalarScalar(Raster(64, 64), Int32(1, 64), Int32(1, 64)),
);
benchmark::scalar(
c,
&f,
"native-raster",
"rs_pixelascentroid",
BenchmarkArgs::ArrayScalarScalar(Raster(64, 64), Int32(1, 64), Int32(1, 64)),
);
benchmark::scalar(
c,
&f,
"native-raster",
"rs_pixelaspolygon",
BenchmarkArgs::ArrayScalarScalar(Raster(64, 64), Int32(1, 64), Int32(1, 64)),
);
benchmark::scalar(
c,
&f,
Expand Down
1 change: 1 addition & 0 deletions rust/sedona-raster-functions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod rs_example;
pub mod rs_georeference;
pub mod rs_geotransform;
pub mod rs_numbands;
pub mod rs_pixel_functions;
pub mod rs_rastercoordinate;
pub mod rs_setsrid;
pub mod rs_size;
Expand Down
3 changes: 3 additions & 0 deletions rust/sedona-raster-functions/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ pub fn default_function_set() -> FunctionSet {
crate::rs_geotransform::rs_upperleftx_udf,
crate::rs_geotransform::rs_upperlefty_udf,
crate::rs_numbands::rs_numbands_udf,
crate::rs_pixel_functions::rs_pixelaspoint_udf,
crate::rs_pixel_functions::rs_pixelascentroid_udf,
crate::rs_pixel_functions::rs_pixelaspolygon_udf,
crate::rs_rastercoordinate::rs_worldtorastercoord_udf,
crate::rs_rastercoordinate::rs_worldtorastercoordx_udf,
crate::rs_rastercoordinate::rs_worldtorastercoordy_udf,
Expand Down
26 changes: 25 additions & 1 deletion rust/sedona-raster-functions/src/rs_bandpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn get_band_path(
#[cfg(test)]
mod tests {
use super::*;
use arrow_array::{Array, Int32Array, StringArray};
use arrow_array::{Array, Int32Array, Int64Array, StringArray};
use datafusion_common::ScalarValue;
use datafusion_expr::ScalarUDF;
use sedona_schema::datatypes::RASTER;
Expand Down Expand Up @@ -209,6 +209,30 @@ mod tests {
assert!(string_array.is_null(2));
}

#[test]
fn udf_bandpath_with_int64_band_index() {
let udf: ScalarUDF = rs_bandpath_udf().into();
let tester = ScalarUdfTester::new(udf, vec![RASTER, SedonaType::Arrow(DataType::Int64)]);

let rasters = build_outdb_rasters();
let band_indices = Int64Array::from(vec![1i64, 1, 2]);
let result = tester
.invoke_arrays(vec![Arc::new(rasters), Arc::new(band_indices)])
.unwrap();

let string_array = result
.as_any()
.downcast_ref::<StringArray>()
.expect("Expected StringArray");

// Raster 0, band 1: OutDbRef -> URL
assert_eq!(string_array.value(0), "s3://bucket/raster_0.tif");
// Raster 1: null raster -> null
assert!(string_array.is_null(1));
// Raster 2, band 2: OutDbRef -> URL
assert_eq!(string_array.value(2), "s3://bucket/raster_2.tif");
}

#[test]
fn udf_bandpath_invalid_band_index() {
let udf: ScalarUDF = rs_bandpath_udf().into();
Expand Down
Loading