You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@sedona.apache.org by "jesspav (via GitHub)" <gi...@apache.org> on 2025/12/05 20:33:41 UTC

[PR] Add RS_WorldToRasterCoord variants [sedona-db]

jesspav opened a new pull request, #416:
URL: https://github.com/apache/sedona-db/pull/416

   Adding functions `RS_WorldToRasterCoordX`, `RS_WorldToRasterCoordY`, `RS_WorldToRasterCoord`, with a provided x and y coordinate.
   
   Note that we should have another variant of these that accept a point, but it is out of scope for this PR. 
   
   Examples:
   ```
   > select rs_worldtorastercoord(RS_Example(), 45.08, 80.07 );
   ┌───────────────────────────────────────────────────────────────────┐
   │ rs_worldtorastercoord(rs_example(),Float64(45.08),Float64(80.07)) │
   │                              geometry                             │
   ╞═══════════════════════════════════════════════════════════════════╡
   │ POINT(1 0)                                                        │
   └───────────────────────────────────────────────────────────────────┘
   
   1 row(s)/1 column(s) fetched. 
   Elapsed 0.023 seconds.
   
   > select rs_worldtorastercoordx(RS_Example(), 45.08, 80.07 );
   ┌────────────────────────────────────────────────────────────────────┐
   │ rs_worldtorastercoordx(rs_example(),Float64(45.08),Float64(80.07)) │
   │                                int64                               │
   ╞════════════════════════════════════════════════════════════════════╡
   │                                                                  1 │
   └────────────────────────────────────────────────────────────────────┘
   
   1 row(s)/1 column(s) fetched. 
   Elapsed 0.007 seconds.
   
   > select rs_worldtorastercoordy(RS_Example(), 45.08, 80.07 );
   ┌────────────────────────────────────────────────────────────────────┐
   │ rs_worldtorastercoordy(rs_example(),Float64(45.08),Float64(80.07)) │
   │                                int64                               │
   ╞════════════════════════════════════════════════════════════════════╡
   │                                                                  0 │
   └────────────────────────────────────────────────────────────────────┘
   
   1 row(s)/1 column(s) fetched. 
   Elapsed 0.006 seconds.
   ```
   
   Benches:
   ```
   native-raster-rs_worldtorastercoord-ArrayScalarScalar(Raster(64, 64), Float64(-45.0, 45.0), Float64(...
                           time:   [1.3438 ms 1.3456 ms 1.3473 ms]
   
   native-raster-rs_worldtorastercoordx-ArrayScalarScalar(Raster(64, 64), Float64(-45.0, 45.0), Float64...
                           time:   [1.1348 ms 1.1367 ms 1.1386 ms]
   
   native-raster-rs_worldtorastercoordy-ArrayScalarScalar(Raster(64, 64), Float64(-45.0, 45.0), Float64...
                           time:   [1.1326 ms 1.1344 ms 1.1361 ms]
   
   
   ```


-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add RS_WorldToRasterCoord variants [sedona-db]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot merged PR #416:
URL: https://github.com/apache/sedona-db/pull/416


-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add RS_WorldToRasterCoord variants [sedona-db]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #416:
URL: https://github.com/apache/sedona-db/pull/416#discussion_r2594001779


##########
rust/sedona-raster-functions/src/rs_rastercoordinate.rs:
##########
@@ -0,0 +1,333 @@
+// 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 std::{sync::Arc, vec};
+
+use crate::executor::RasterExecutor;
+use arrow_array::builder::{BinaryBuilder, Int64Builder};
+use arrow_schema::DataType;
+use datafusion_common::ScalarValue;
+use datafusion_common::{error::Result, exec_err};
+use datafusion_expr::{
+    scalar_doc_sections::DOC_SECTION_OTHER, ColumnarValue, Documentation, Volatility,
+};
+use sedona_expr::scalar_udf::{SedonaScalarKernel, SedonaScalarUDF};
+use sedona_raster::affine_transformation::to_raster_coordinate;
+use sedona_schema::datatypes::Edges;
+use sedona_schema::{datatypes::SedonaType, matchers::ArgMatcher};
+
+/// RS_WorldToRasterCoordY() scalar UDF documentation
+///
+/// Converts pixel coordinates to world Y coordinate
+pub fn rs_worldtorastercoordy_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "rs_worldtorastercoordy",
+        vec![Arc::new(RsCoordinateMapper { coord: Coord::Y })],
+        Volatility::Immutable,
+        Some(rs_worldtorastercoordy_doc()),
+    )
+}
+
+/// RS_WorldToRasterCoordX() scalar UDF documentation
+///
+/// Converts pixel coordinates to world X coordinate
+pub fn rs_worldtorastercoordx_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "rs_worldtorastercoordx",
+        vec![Arc::new(RsCoordinateMapper { coord: Coord::X })],
+        Volatility::Immutable,
+        Some(rs_worldtorastercoordx_doc()),
+    )
+}
+
+/// RS_WorldToRasterCoord() scalar UDF documentation
+///
+/// Converts pixel coordinates to world coordinate Point
+pub fn rs_worldtorastercoord_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "rs_worldtorastercoord",
+        vec![Arc::new(RsCoordinatePoint {})],
+        Volatility::Immutable,
+        Some(rs_worldtorastercoord_doc()),
+    )
+}
+
+fn rs_worldtorastercoordx_doc() -> Documentation {
+    Documentation::builder(
+        DOC_SECTION_OTHER,
+        "Returns the X coordinate of the grid coordinate of the given world coordinates as an integer.".to_string(),
+        "RS_WorldToRasterCoord(raster: Raster, x: Float, y: Float)".to_string(),
+    )
+    .with_argument("raster", "Raster: Input raster")
+    .with_argument("x", "Geometry: World x coordinate")
+    .with_argument("y", "Geometry: World y coordinate")
+    .with_sql_example("SELECT RS_WorldToRasterCoordX(RS_Example(), 34.865965, -111.812498)".to_string())
+    .build()
+}
+
+fn rs_worldtorastercoordy_doc() -> Documentation {
+    Documentation::builder(
+        DOC_SECTION_OTHER,
+        "Returns the Y coordinate of the grid coordinate of the given world coordinates as an integer.".to_string(),
+        "RS_WorldToRasterCoord(raster: Raster, x: Float, y: Float)".to_string(),
+    )
+    .with_argument("raster", "Raster: Input raster")
+    .with_argument("x", "Geometry: World x coordinate")
+    .with_argument("y", "Geometry: World y coordinate")

Review Comment:
   The argument type 'Geometry' is incorrect for numeric coordinate parameters. These should be documented as 'Float' to match the actual parameter types.



##########
rust/sedona-raster-functions/src/rs_rastercoordinate.rs:
##########
@@ -0,0 +1,333 @@
+// 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 std::{sync::Arc, vec};
+
+use crate::executor::RasterExecutor;
+use arrow_array::builder::{BinaryBuilder, Int64Builder};
+use arrow_schema::DataType;
+use datafusion_common::ScalarValue;
+use datafusion_common::{error::Result, exec_err};
+use datafusion_expr::{
+    scalar_doc_sections::DOC_SECTION_OTHER, ColumnarValue, Documentation, Volatility,
+};
+use sedona_expr::scalar_udf::{SedonaScalarKernel, SedonaScalarUDF};
+use sedona_raster::affine_transformation::to_raster_coordinate;
+use sedona_schema::datatypes::Edges;
+use sedona_schema::{datatypes::SedonaType, matchers::ArgMatcher};
+
+/// RS_WorldToRasterCoordY() scalar UDF documentation
+///
+/// Converts pixel coordinates to world Y coordinate

Review Comment:
   The documentation comment incorrectly states 'Converts pixel coordinates to world Y coordinate' when the function actually converts world coordinates to raster pixel Y coordinate. Update to 'Converts world coordinates to raster pixel Y coordinate'.
   ```suggestion
   /// Converts world coordinates to raster pixel Y coordinate
   ```



##########
rust/sedona-raster-functions/src/rs_rastercoordinate.rs:
##########
@@ -0,0 +1,333 @@
+// 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 std::{sync::Arc, vec};
+
+use crate::executor::RasterExecutor;
+use arrow_array::builder::{BinaryBuilder, Int64Builder};
+use arrow_schema::DataType;
+use datafusion_common::ScalarValue;
+use datafusion_common::{error::Result, exec_err};
+use datafusion_expr::{
+    scalar_doc_sections::DOC_SECTION_OTHER, ColumnarValue, Documentation, Volatility,
+};
+use sedona_expr::scalar_udf::{SedonaScalarKernel, SedonaScalarUDF};
+use sedona_raster::affine_transformation::to_raster_coordinate;
+use sedona_schema::datatypes::Edges;
+use sedona_schema::{datatypes::SedonaType, matchers::ArgMatcher};
+
+/// RS_WorldToRasterCoordY() scalar UDF documentation
+///
+/// Converts pixel coordinates to world Y coordinate
+pub fn rs_worldtorastercoordy_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "rs_worldtorastercoordy",
+        vec![Arc::new(RsCoordinateMapper { coord: Coord::Y })],
+        Volatility::Immutable,
+        Some(rs_worldtorastercoordy_doc()),
+    )
+}
+
+/// RS_WorldToRasterCoordX() scalar UDF documentation
+///
+/// Converts pixel coordinates to world X coordinate
+pub fn rs_worldtorastercoordx_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "rs_worldtorastercoordx",
+        vec![Arc::new(RsCoordinateMapper { coord: Coord::X })],
+        Volatility::Immutable,
+        Some(rs_worldtorastercoordx_doc()),
+    )
+}
+
+/// RS_WorldToRasterCoord() scalar UDF documentation
+///
+/// Converts pixel coordinates to world coordinate Point

Review Comment:
   The documentation comment incorrectly states 'Converts pixel coordinates to world coordinate Point' when the function actually converts world coordinates to raster pixel coordinate Point. Update to 'Converts world coordinates to raster pixel coordinate Point'.
   ```suggestion
   /// Converts world coordinates to raster pixel coordinate Point
   ```



##########
rust/sedona-raster-functions/src/rs_rastercoordinate.rs:
##########
@@ -0,0 +1,333 @@
+// 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 std::{sync::Arc, vec};
+
+use crate::executor::RasterExecutor;
+use arrow_array::builder::{BinaryBuilder, Int64Builder};
+use arrow_schema::DataType;
+use datafusion_common::ScalarValue;
+use datafusion_common::{error::Result, exec_err};
+use datafusion_expr::{
+    scalar_doc_sections::DOC_SECTION_OTHER, ColumnarValue, Documentation, Volatility,
+};
+use sedona_expr::scalar_udf::{SedonaScalarKernel, SedonaScalarUDF};
+use sedona_raster::affine_transformation::to_raster_coordinate;
+use sedona_schema::datatypes::Edges;
+use sedona_schema::{datatypes::SedonaType, matchers::ArgMatcher};
+
+/// RS_WorldToRasterCoordY() scalar UDF documentation
+///
+/// Converts pixel coordinates to world Y coordinate
+pub fn rs_worldtorastercoordy_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "rs_worldtorastercoordy",
+        vec![Arc::new(RsCoordinateMapper { coord: Coord::Y })],
+        Volatility::Immutable,
+        Some(rs_worldtorastercoordy_doc()),
+    )
+}
+
+/// RS_WorldToRasterCoordX() scalar UDF documentation
+///
+/// Converts pixel coordinates to world X coordinate
+pub fn rs_worldtorastercoordx_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "rs_worldtorastercoordx",
+        vec![Arc::new(RsCoordinateMapper { coord: Coord::X })],
+        Volatility::Immutable,
+        Some(rs_worldtorastercoordx_doc()),
+    )
+}
+
+/// RS_WorldToRasterCoord() scalar UDF documentation
+///
+/// Converts pixel coordinates to world coordinate Point
+pub fn rs_worldtorastercoord_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "rs_worldtorastercoord",
+        vec![Arc::new(RsCoordinatePoint {})],
+        Volatility::Immutable,
+        Some(rs_worldtorastercoord_doc()),
+    )
+}
+
+fn rs_worldtorastercoordx_doc() -> Documentation {
+    Documentation::builder(
+        DOC_SECTION_OTHER,
+        "Returns the X coordinate of the grid coordinate of the given world coordinates as an integer.".to_string(),
+        "RS_WorldToRasterCoord(raster: Raster, x: Float, y: Float)".to_string(),
+    )
+    .with_argument("raster", "Raster: Input raster")
+    .with_argument("x", "Geometry: World x coordinate")
+    .with_argument("y", "Geometry: World y coordinate")
+    .with_sql_example("SELECT RS_WorldToRasterCoordX(RS_Example(), 34.865965, -111.812498)".to_string())
+    .build()
+}
+
+fn rs_worldtorastercoordy_doc() -> Documentation {
+    Documentation::builder(
+        DOC_SECTION_OTHER,
+        "Returns the Y coordinate of the grid coordinate of the given world coordinates as an integer.".to_string(),
+        "RS_WorldToRasterCoord(raster: Raster, x: Float, y: Float)".to_string(),
+    )
+    .with_argument("raster", "Raster: Input raster")
+    .with_argument("x", "Geometry: World x coordinate")
+    .with_argument("y", "Geometry: World y coordinate")
+    .with_sql_example("SELECT RS_WorldToRasterCoordY(RS_Example(), 34.865965, -111.812498)".to_string())
+    .build()
+}
+
+fn rs_worldtorastercoord_doc() -> Documentation {
+    Documentation::builder(
+        DOC_SECTION_OTHER,
+        "Returns the grid coordinate of the given world coordinates as a Point.".to_string(),
+        "RS_WorldToRasterCoord(raster: Raster, x: Float, y: Float)".to_string(),
+    )
+    .with_argument("raster", "Raster: Input raster")
+    .with_argument("x", "Geometry: World x coordinate")
+    .with_argument("y", "Geometry: World y coordinate")

Review Comment:
   The argument type 'Geometry' is incorrect for numeric coordinate parameters. These should be documented as 'Float' to match the actual parameter types.



##########
rust/sedona-raster-functions/src/rs_rastercoordinate.rs:
##########
@@ -0,0 +1,333 @@
+// 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 std::{sync::Arc, vec};
+
+use crate::executor::RasterExecutor;
+use arrow_array::builder::{BinaryBuilder, Int64Builder};
+use arrow_schema::DataType;
+use datafusion_common::ScalarValue;
+use datafusion_common::{error::Result, exec_err};
+use datafusion_expr::{
+    scalar_doc_sections::DOC_SECTION_OTHER, ColumnarValue, Documentation, Volatility,
+};
+use sedona_expr::scalar_udf::{SedonaScalarKernel, SedonaScalarUDF};
+use sedona_raster::affine_transformation::to_raster_coordinate;
+use sedona_schema::datatypes::Edges;
+use sedona_schema::{datatypes::SedonaType, matchers::ArgMatcher};
+
+/// RS_WorldToRasterCoordY() scalar UDF documentation
+///
+/// Converts pixel coordinates to world Y coordinate
+pub fn rs_worldtorastercoordy_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "rs_worldtorastercoordy",
+        vec![Arc::new(RsCoordinateMapper { coord: Coord::Y })],
+        Volatility::Immutable,
+        Some(rs_worldtorastercoordy_doc()),
+    )
+}
+
+/// RS_WorldToRasterCoordX() scalar UDF documentation
+///
+/// Converts pixel coordinates to world X coordinate
+pub fn rs_worldtorastercoordx_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "rs_worldtorastercoordx",
+        vec![Arc::new(RsCoordinateMapper { coord: Coord::X })],
+        Volatility::Immutable,
+        Some(rs_worldtorastercoordx_doc()),
+    )
+}
+
+/// RS_WorldToRasterCoord() scalar UDF documentation
+///
+/// Converts pixel coordinates to world coordinate Point
+pub fn rs_worldtorastercoord_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "rs_worldtorastercoord",
+        vec![Arc::new(RsCoordinatePoint {})],
+        Volatility::Immutable,
+        Some(rs_worldtorastercoord_doc()),
+    )
+}
+
+fn rs_worldtorastercoordx_doc() -> Documentation {
+    Documentation::builder(
+        DOC_SECTION_OTHER,
+        "Returns the X coordinate of the grid coordinate of the given world coordinates as an integer.".to_string(),
+        "RS_WorldToRasterCoord(raster: Raster, x: Float, y: Float)".to_string(),
+    )
+    .with_argument("raster", "Raster: Input raster")
+    .with_argument("x", "Geometry: World x coordinate")
+    .with_argument("y", "Geometry: World y coordinate")

Review Comment:
   The argument type 'Geometry' is incorrect for numeric coordinate parameters. These should be documented as 'Float' to match the actual parameter types.



##########
rust/sedona-raster-functions/src/rs_rastercoordinate.rs:
##########
@@ -0,0 +1,333 @@
+// 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 std::{sync::Arc, vec};
+
+use crate::executor::RasterExecutor;
+use arrow_array::builder::{BinaryBuilder, Int64Builder};
+use arrow_schema::DataType;
+use datafusion_common::ScalarValue;
+use datafusion_common::{error::Result, exec_err};
+use datafusion_expr::{
+    scalar_doc_sections::DOC_SECTION_OTHER, ColumnarValue, Documentation, Volatility,
+};
+use sedona_expr::scalar_udf::{SedonaScalarKernel, SedonaScalarUDF};
+use sedona_raster::affine_transformation::to_raster_coordinate;
+use sedona_schema::datatypes::Edges;
+use sedona_schema::{datatypes::SedonaType, matchers::ArgMatcher};
+
+/// RS_WorldToRasterCoordY() scalar UDF documentation
+///
+/// Converts pixel coordinates to world Y coordinate
+pub fn rs_worldtorastercoordy_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "rs_worldtorastercoordy",
+        vec![Arc::new(RsCoordinateMapper { coord: Coord::Y })],
+        Volatility::Immutable,
+        Some(rs_worldtorastercoordy_doc()),
+    )
+}
+
+/// RS_WorldToRasterCoordX() scalar UDF documentation
+///
+/// Converts pixel coordinates to world X coordinate

Review Comment:
   The documentation comment incorrectly states 'Converts pixel coordinates to world X coordinate' when the function actually converts world coordinates to raster pixel X coordinate. Update to 'Converts world coordinates to raster pixel X coordinate'.
   ```suggestion
   /// Converts world coordinates to raster pixel X coordinate
   ```



-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org