-
Notifications
You must be signed in to change notification settings - Fork 56
feat(rust/sedona-raster-functions): add RS_Value for spatial 2d rasters #974
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 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
21395fc
feat(rust/sedona-raster-functions): add RS_Value
james-willis 798b67c
chore(rust/sedona-raster-functions): benchmark RS_Value
james-willis 82b7968
fix(rust/sedona-raster-functions): tighten RS_Value point sampling an…
james-willis 62b8973
test(python): inline RS_Example and use assert_query_result for RS_Va…
james-willis d593bb5
feat(rust/sedona-raster-functions): RS_Value empty-point -> NULL, sam…
james-willis a61ec7d
docs(rs_value): use the 3-arg ST_Point(x, y, crs) form in the point e…
james-willis b9722e9
fix(rust/sedona-raster-functions): use checked arithmetic for RS_Valu…
james-willis ee7eaab
feat(rust/sedona-raster-functions): defer RS_Value grid-coordinate va…
james-willis 14e0132
test(rust/sedona-raster-functions): benchmark RS_Value scalar-raster …
james-willis 415357e
perf(rust/sedona-raster-functions): hoist scalar-raster state in RS_V…
james-willis 450d9db
perf(rust/sedona-raster-functions): hoist RS_Value CRS-transform deci…
james-willis 4ea333a
perf(rust/sedona-raster-functions): parse Point coords with a fixed-o…
james-willis e251419
refactor(rust/sedona-raster-functions): dedup RS_Value point sampling…
james-willis b9af45f
perf(rust/sedona-raster-functions): extend RS_Value scalar fast path …
james-willis 9f6c94c
docs(rust/sedona-raster-functions): explain why RS_Value errors inste…
james-willis 67af522
test(rust/sedona-geometry): hoist fixtures import to the test module
james-willis fc95617
Merge remote-tracking branch 'origin/main' into pr-974
james-willis 526e9de
test(python/sedonadb): cross-check RS_Value against rasterio
james-willis 7effb08
style(rust/sedona-geometry): fix rustfmt in wkb_header test
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| --- | ||
| # 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_Value | ||
| description: > | ||
| Returns the value of a single raster pixel as a double, selected either by a | ||
| point geometry or by 1-based grid coordinates. Returns null if the location is | ||
| outside the raster or the pixel holds the band's nodata value. | ||
| kernels: | ||
| - returns: float64 | ||
| args: | ||
| - raster | ||
| - name: point | ||
| type: geometry | ||
| description: > | ||
| The pixel that contains this point is sampled (no resampling). | ||
| Reprojected into the raster CRS when both carry one. | ||
| - returns: float64 | ||
| args: | ||
| - raster | ||
| - name: point | ||
| type: geometry | ||
| - name: band | ||
| type: int | ||
| description: Band index (1-based). Defaults to 1 if not specified. | ||
| - returns: float64 | ||
| args: | ||
| - raster | ||
| - name: colX | ||
| type: int | ||
| description: Column index (1-based). | ||
| - name: rowY | ||
| type: int | ||
| description: Row index (1-based). | ||
| - returns: float64 | ||
| args: | ||
| - raster | ||
| - name: colX | ||
| type: int | ||
| - name: rowY | ||
| type: int | ||
| - name: band | ||
| type: int | ||
| description: Band index (1-based). Defaults to 1 if not specified. | ||
| --- | ||
|
|
||
| ## Description | ||
|
|
||
| `RS_Value` samples one pixel of a raster. The location is given either as a | ||
| point geometry — the value of the pixel that contains the point is returned, with | ||
| no interpolation — or as 1-based `(colX, rowY)` grid coordinates. The band | ||
| defaults to 1. | ||
|
|
||
| The result is `NULL` when the point or grid cell falls outside the raster, or | ||
| when the sampled pixel equals the band's nodata value. Only 2-D rasters are | ||
| supported. | ||
|
|
||
| ## Examples | ||
|
|
||
| ```sql | ||
| SELECT RS_Value(RS_Example(), 2, 1); | ||
| ``` | ||
|
|
||
| ```sql | ||
| SELECT RS_Value(RS_Example(), 2, 1, 2); | ||
| ``` | ||
|
|
||
| ```sql | ||
| SELECT RS_Value(RS_Example(), ST_SetCRS(ST_Point(74.58, 110.57), 'OGC:CRS84')); | ||
|
james-willis marked this conversation as resolved.
Outdated
|
||
| ``` | ||
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,34 @@ | ||
| # 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. | ||
|
|
||
| import pytest | ||
| import sedonadb | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def raster_con(): | ||
| """A connection with a single `RS_Example()` raster registered as `rasters`. | ||
|
|
||
| Uses the in-DB `RS_Example()` raster (64x32, three UInt8 bands) so the | ||
| sedonadb package's RS_ function tests carry no zarr dependency — zarr | ||
| reader behaviors are tested in the sedonadb-zarr package. A dedicated | ||
| connection (not the shared module-level one) keeps the view from leaking | ||
| into other tests. | ||
| """ | ||
| con = sedonadb.connect() | ||
| con.sql("SELECT RS_Example() AS raster").to_view("rasters") | ||
| return con |
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
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.
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.
Indexing is typically rows, cols (e.g., numpy, R) instead of cols, rows.
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.
punted the col/row version of the function for now
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.
But the signature here is based on trying to match postgis as much as possible:
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.
also sedona spark: https://sedona.apache.org/latest/api/sql/Raster-Operators/RS_Value/
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.
Sure, but nobody asked me to review those 🙂 . Compared to GDAL and xarray the PostGIS and Sedona Spark APIs are not particularly popular...part of porting that to SedonaDB is to make it fast, but if anybody is ever going to use this we're also going to have to make it less awkward.
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.
Would it be better to keep st functions in sync between sedona and sedona_db? I understand the concern and bad decisions in the past on the orders of params, but if we'd make them different in signatures, users would need to change their SQL to adapt in between if they ever want to run on both engines.