Kontinuation commented on code in PR #857:
URL: https://github.com/apache/sedona/pull/857#discussion_r1227484982


##########
common/src/main/java/org/apache/sedona/common/raster/RasterConstructors.java:
##########
@@ -0,0 +1,94 @@
+/**
+ * Licensed 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ */
+package org.apache.sedona.common.raster;
+
+import org.geotools.coverage.CoverageFactoryFinder;
+import org.geotools.coverage.grid.GridCoverage2D;
+import org.geotools.coverage.grid.GridCoverageFactory;
+import org.geotools.gce.arcgrid.ArcGridReader;
+import org.geotools.gce.geotiff.GeoTiffReader;
+import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.referencing.crs.DefaultEngineeringCRS;
+
+import javax.media.jai.RasterFactory;
+
+import java.awt.image.DataBuffer;
+import java.awt.image.WritableRaster;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+public class RasterConstructors
+{
+
+    public static GridCoverage2D fromArcInfoAsciiGrid(byte[] bytes) throws 
IOException {
+        try (ByteArrayInputStream inputStream = new 
ByteArrayInputStream(bytes)) {
+            ArcGridReader reader = new ArcGridReader(inputStream);
+            return reader.read(null);
+        }
+    }
+
+    public static GridCoverage2D fromGeoTiff(byte[] bytes) throws IOException {
+        try (ByteArrayInputStream inputStream = new 
ByteArrayInputStream(bytes)) {
+            GeoTiffReader geoTiffReader = new GeoTiffReader(inputStream);
+            return geoTiffReader.read(null);
+        }
+    }
+
+    /**
+     * Create a new empty raster with the given number of empty bands
+     * The bounding envelope is defined by the upper left corner and the scale
+     * The math formula of the envelope is: minX = upperLeftX = lowerLeftX 
(minX), minY (lowerLeftY) = upperLeftY - height * pixelSizeInDegrees
+     * The raster is defined by the width and height
+     * The affine transform is defined by the skewX and skewY
+     * The upper left corner is defined by the upperLeftX and upperLeftY
+     * The scale is defined by the scaleX and scaleY
+     * @param widthInPixel
+     * @param heightInPixel
+     * @param upperLeftX the upper left corner of the raster. Note that: the 
minX of the envelope is equal to the upperLeftX
+     * @param upperLeftY the upper left corner of the raster. Note that: the 
minY of the envelope is equal to the upperLeftY - height * scaleY
+     * @param pixelSizeInDegrees the size of the pixel in degrees
+     * @param numBand the number of bands
+     * @return
+     */
+    public static GridCoverage2D makeEmptyRaster(int widthInPixel, int 
heightInPixel, double upperLeftX, double upperLeftY, double pixelSizeInDegrees, 
int numBand)

Review Comment:
   I suggest renaming the parameter `pixelSizeInDegrees` to `cellSize` or 
`pixelSize`, since the raster may not be in geodetic coordinate systems.



##########
sql/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/raster/RasterConstructors.scala:
##########
@@ -82,7 +82,40 @@ case class RS_FromGeoTiff(inputExpressions: Seq[Expression]) 
extends Expression
     if (bytes == null) {
       null
     } else {
-      Constructors.fromGeoTiff(bytes)
+      RasterConstructors.fromGeoTiff(bytes)
     }
   }
 }
+
+case class RS_MakeEmptyRaster(inputExpressions: Seq[Expression]) extends 
Expression with CodegenFallback
+  with ExpectsInputTypes with SerdeAware {

Review Comment:
   Mixin the trait `ImplicitCastInputTypes` instead of `ExpectsInputTypes` 
makes it more friendly for users, otherwise user must write 
`RS_MakeEmptyRaster(100, 80, 5.0, 4.0, 0.4)` instead of 
`RS_MakeEmptyRaster(100, 80, 5, 4, 0.4)`.



-- 
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]

Reply via email to