jiayuasu commented on code in PR #1038:
URL: https://github.com/apache/sedona/pull/1038#discussion_r1340620142
##########
docs/api/sql/Raster-operators.md:
##########
@@ -1004,6 +1004,105 @@ Output:
```
4
```
+### RS_Resample
+
+Introduction:
+Resamples a raster using a given resampling algorithm and new dimensions
(width and height), a new grid corner to pivot the raster at (gridX and gridY)
and a set of
+georeferencing attributes (scaleX and scaleY).
+
+RS_Resample also provides an option to pass a reference raster to draw the
georeferencing attributes out of. However, the SRIDs of the input and reference
raster must be same, otherwise RS_Resample throws an IllegalArgumentException.
+
+For the purpose of resampling, width-height pair and scaleX-scaleY pair are
mutually exclusive, meaning any one of them can be used at a time.
+
+The `useScale` parameter controls whether to use width-height or
scaleX-scaleY. If `useScale` is false, the provided `widthOrScale` and
`heightOrScale` values will be floored to integers and considered as width and
height respectively (floating point width and height are not allowed).
Otherwise, they are considered as scaleX and scaleY respectively.
+
+Currently, RS_Resample does not support skewed rasters, and hence even if a
skewed reference raster is provided, its skew values are ignored. If the input
raster is skewed, the output raster geometry and interpolation may be
incorrect.
+
+The default algorithm used for resampling is `NearestNeighbor`, and hence if a
null, empty or invalid value of algorithm is provided, RS_Resample defaults to
using `NearestNeighbor`. However, the algorithm parameter is non-optional.
+
+Following are valid values for the algorithm parameter (Case-insensitive):
+
+1. NearestNeighbor
+2. Bilinear
+3. Bicubic
+
+!!!Tip
+ If you just want to resize or rescale an input raster, you can use
RS_Resample(raster: Raster, widthOrScale: Double, heightOrScale: Double,
useScale: Boolean, algorithm: String)
+Format:
+
+```sql
+RS_Resample(raster: Raster, widthOrScale: Double, heightOrScale: Double,
gridX: Double, gridY: Double, useScale: Boolean, algorithm: String)
+```
+
+```sql
+RS_Resample(raster: Raster, widthOrScale: Double, heightOrScale: Double,
useScale: Boolean, algorithm: String)
+```
+
+```sql
+RS_Resample(raster: Raster, referenceRaster: Raster, useScale: Boolean,
algorithm: String)
+```
+
+Since: `v1.5.0`
+
+Spark SQL Example:
+
+```scala
+val inputDf = Seq(Seq(1, 2, 3, 5, 4, 5, 6, 9, 7, 8, 9, 10)).toDF("band")
+val df = inputDf.selectExpr("RS_AddBandFromArray(RS_MakeEmptyRaster(1, 'd', 4,
3, 0, 0, 2, -2, 0, 0, 0), band, 1, 0d) as raster")
+val rasterDf = df.selectExpr("RS_Resample(raster, 6, 5, 1, -1, false, null) as
raster")
+val rasterOutput =
rasterDf.selectExpr("RS_AsMatrix(raster)").first().getString(0)
+val rasterMetadata =
rasterDf.selectExpr("RS_Metadata(raster)").first().getSeq[Double](0)
+```
+
+`Output`:
+```sql
+| 1.0 1.0 2.0 3.0 3.0 5.0|
+| 1.0 1.0 2.0 3.0 3.0 5.0|
+| 4.0 4.0 5.0 6.0 6.0 9.0|
+| 7.0 7.0 8.0 9.0 9.0 10.0|
+| 7.0 7.0 8.0 9.0 9.0 10.0|
+
+(-0.33333333333333326,0.19999999999999996,6,5,1.388888888888889,-1.24,0,0,0,1)
+```
+
+```scala
+val inputDf = Seq(Seq(1, 2, 3, 5, 4, 5, 6, 9, 7, 8, 9, 10)).toDF("band")
Review Comment:
Same here
##########
spark/common/src/test/scala/org/apache/sedona/sql/rasteralgebraTest.scala:
##########
@@ -1077,6 +1077,7 @@ class rasteralgebraTest extends TestBaseScala with
BeforeAndAfter with GivenWhen
val df = inputDf.selectExpr("RS_AddBandFromArray(RS_MakeEmptyRaster(1,
4, 3, 0, 0, 1, -1, 0, 0, 0), band, 1, 0d) as emptyRaster")
val resultDf = df.selectExpr("RS_AsMatrix(emptyRaster, 1, 5) as matrix")
val actual = resultDf.first().getString(0);
+ resultDf.show()
Review Comment:
Please remove .show()
##########
docs/api/sql/Raster-operators.md:
##########
@@ -1004,6 +1004,105 @@ Output:
```
4
```
+### RS_Resample
+
+Introduction:
+Resamples a raster using a given resampling algorithm and new dimensions
(width and height), a new grid corner to pivot the raster at (gridX and gridY)
and a set of
+georeferencing attributes (scaleX and scaleY).
+
+RS_Resample also provides an option to pass a reference raster to draw the
georeferencing attributes out of. However, the SRIDs of the input and reference
raster must be same, otherwise RS_Resample throws an IllegalArgumentException.
+
+For the purpose of resampling, width-height pair and scaleX-scaleY pair are
mutually exclusive, meaning any one of them can be used at a time.
+
+The `useScale` parameter controls whether to use width-height or
scaleX-scaleY. If `useScale` is false, the provided `widthOrScale` and
`heightOrScale` values will be floored to integers and considered as width and
height respectively (floating point width and height are not allowed).
Otherwise, they are considered as scaleX and scaleY respectively.
+
+Currently, RS_Resample does not support skewed rasters, and hence even if a
skewed reference raster is provided, its skew values are ignored. If the input
raster is skewed, the output raster geometry and interpolation may be
incorrect.
+
+The default algorithm used for resampling is `NearestNeighbor`, and hence if a
null, empty or invalid value of algorithm is provided, RS_Resample defaults to
using `NearestNeighbor`. However, the algorithm parameter is non-optional.
+
+Following are valid values for the algorithm parameter (Case-insensitive):
+
+1. NearestNeighbor
+2. Bilinear
+3. Bicubic
+
+!!!Tip
+ If you just want to resize or rescale an input raster, you can use
RS_Resample(raster: Raster, widthOrScale: Double, heightOrScale: Double,
useScale: Boolean, algorithm: String)
+Format:
+
+```sql
+RS_Resample(raster: Raster, widthOrScale: Double, heightOrScale: Double,
gridX: Double, gridY: Double, useScale: Boolean, algorithm: String)
+```
+
+```sql
+RS_Resample(raster: Raster, widthOrScale: Double, heightOrScale: Double,
useScale: Boolean, algorithm: String)
+```
+
+```sql
+RS_Resample(raster: Raster, referenceRaster: Raster, useScale: Boolean,
algorithm: String)
+```
+
+Since: `v1.5.0`
+
+Spark SQL Example:
+
+```scala
+val inputDf = Seq(Seq(1, 2, 3, 5, 4, 5, 6, 9, 7, 8, 9, 10)).toDF("band")
+val df = inputDf.selectExpr("RS_AddBandFromArray(RS_MakeEmptyRaster(1, 'd', 4,
3, 0, 0, 2, -2, 0, 0, 0), band, 1, 0d) as raster")
+val rasterDf = df.selectExpr("RS_Resample(raster, 6, 5, 1, -1, false, null) as
raster")
+val rasterOutput =
rasterDf.selectExpr("RS_AsMatrix(raster)").first().getString(0)
+val rasterMetadata =
rasterDf.selectExpr("RS_Metadata(raster)").first().getSeq[Double](0)
+```
+
+`Output`:
+```sql
+| 1.0 1.0 2.0 3.0 3.0 5.0|
+| 1.0 1.0 2.0 3.0 3.0 5.0|
+| 4.0 4.0 5.0 6.0 6.0 9.0|
+| 7.0 7.0 8.0 9.0 9.0 10.0|
+| 7.0 7.0 8.0 9.0 9.0 10.0|
+
+(-0.33333333333333326,0.19999999999999996,6,5,1.388888888888889,-1.24,0,0,0,1)
+```
+
+```scala
+val inputDf = Seq(Seq(1, 2, 3, 5, 4, 5, 6, 9, 7, 8, 9, 10)).toDF("band")
+val df = inputDf.selectExpr("RS_AddBandFromArray(RS_MakeEmptyRaster(1, 'd', 4,
3, 0, 0, 2, -2, 0, 0, 0), band, 1, null) as raster")
+val rasterDf = df.selectExpr("RS_Resample(raster, 1.2, -1.4, true, 'bilinear')
as raster")
+val rasterOutput =
rasterDf.selectExpr("RS_AsMatrix(raster)").first().getString(0)
+val rasterMetadata =
rasterDf.selectExpr("RS_Metadata(raster)").first().getSeq[Double](0)
+```
+
+`Output`:
+```sql
+| NaN NaN NaN NaN NaN NaN
NaN|
+| NaN 3.050000 3.650000 4.250000 5.160000 6.690000
7.200000|
+| NaN 5.150000 5.750000 6.350000 7.250000 8.750000
9.250000|
+| NaN 7.250000 7.850000 8.450000 9.070000 9.730000
9.950000|
+| NaN 7.400000 8.000000 8.600000 9.200000 9.800000
10.000000|
+
+(0.0, 0.0, 7.0, 5.0, 1.2, -1.4, 0.0, 0.0, 0.0, 1.0)
+```
+
+
+```scala
+ val inputDf = Seq(Seq(1, 2, 3, 5, 4, 5, 6, 9, 7, 8, 9, 10)).toDF("band")
Review Comment:
Same here
##########
docs/api/sql/Raster-operators.md:
##########
@@ -1004,6 +1004,105 @@ Output:
```
4
```
+### RS_Resample
+
+Introduction:
+Resamples a raster using a given resampling algorithm and new dimensions
(width and height), a new grid corner to pivot the raster at (gridX and gridY)
and a set of
+georeferencing attributes (scaleX and scaleY).
+
+RS_Resample also provides an option to pass a reference raster to draw the
georeferencing attributes out of. However, the SRIDs of the input and reference
raster must be same, otherwise RS_Resample throws an IllegalArgumentException.
+
+For the purpose of resampling, width-height pair and scaleX-scaleY pair are
mutually exclusive, meaning any one of them can be used at a time.
+
+The `useScale` parameter controls whether to use width-height or
scaleX-scaleY. If `useScale` is false, the provided `widthOrScale` and
`heightOrScale` values will be floored to integers and considered as width and
height respectively (floating point width and height are not allowed).
Otherwise, they are considered as scaleX and scaleY respectively.
+
+Currently, RS_Resample does not support skewed rasters, and hence even if a
skewed reference raster is provided, its skew values are ignored. If the input
raster is skewed, the output raster geometry and interpolation may be
incorrect.
+
+The default algorithm used for resampling is `NearestNeighbor`, and hence if a
null, empty or invalid value of algorithm is provided, RS_Resample defaults to
using `NearestNeighbor`. However, the algorithm parameter is non-optional.
+
+Following are valid values for the algorithm parameter (Case-insensitive):
+
+1. NearestNeighbor
+2. Bilinear
+3. Bicubic
+
+!!!Tip
+ If you just want to resize or rescale an input raster, you can use
RS_Resample(raster: Raster, widthOrScale: Double, heightOrScale: Double,
useScale: Boolean, algorithm: String)
+Format:
+
+```sql
+RS_Resample(raster: Raster, widthOrScale: Double, heightOrScale: Double,
gridX: Double, gridY: Double, useScale: Boolean, algorithm: String)
+```
+
+```sql
+RS_Resample(raster: Raster, widthOrScale: Double, heightOrScale: Double,
useScale: Boolean, algorithm: String)
+```
+
+```sql
+RS_Resample(raster: Raster, referenceRaster: Raster, useScale: Boolean,
algorithm: String)
+```
+
+Since: `v1.5.0`
+
+Spark SQL Example:
+
+```scala
+val inputDf = Seq(Seq(1, 2, 3, 5, 4, 5, 6, 9, 7, 8, 9, 10)).toDF("band")
Review Comment:
Please either replace this with a pure SQL example, or add a Python example.
We want to provide something that works in all cases.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]