iGN5117 commented on code in PR #1038:
URL: https://github.com/apache/sedona/pull/1038#discussion_r1339433079
##########
common/src/main/java/org/apache/sedona/common/raster/RasterEditors.java:
##########
@@ -97,4 +106,133 @@ public static GridCoverage2D
setGeoReference(GridCoverage2D raster, double upper
String geoRedCoord = String.format("%f %f %f %f %f %f", scaleX, skewY,
skewX, scaleY, upperLeftX, upperLeftY);
return setGeoReference(raster, geoRedCoord, "GDAL");
}
+
+ public static GridCoverage2D resample(GridCoverage2D raster, double
widthOrScale, double heightOrScale, double gridX, double gridY, boolean
useScale,String algorithm) throws TransformException {
+ /*
+ * Old Parameters
+ */
+ AffineTransform2D affine = RasterUtils.getGDALAffineTransform(raster);
+ int originalWidth = RasterAccessors.getWidth(raster), originalHeight =
RasterAccessors.getHeight(raster);
+ double upperLeftX = affine.getTranslateX(), upperLeftY =
affine.getTranslateY();
+ double originalSkewX = affine.getShearX(), originalSkewY =
affine.getShearY();
+ double originalScaleX = affine.getScaleX(), originalScaleY =
affine.getScaleY();
+ CoordinateReferenceSystem crs =
raster.getCoordinateReferenceSystem2D();
+
+ /*
+ * New Parameters
+ */
+ int newWidth = useScale ? originalWidth :
(int)Math.floor(widthOrScale);
+ int newHeight = useScale ? originalHeight :
(int)Math.floor(heightOrScale);
+ double newScaleX = useScale ? widthOrScale : originalScaleX;
+ double newScaleY = useScale ? heightOrScale : originalScaleY;
+ double newUpperLeftX = upperLeftX, newUpperLeftY = upperLeftY;
+
+ if (noConfigChange(originalWidth, originalHeight, upperLeftX,
upperLeftY, originalScaleX, originalScaleY, newWidth, newHeight, gridX, gridY,
newScaleX, newScaleY, useScale)) {
+ // no reconfiguration parameters provided
+ return raster;
+ }
+
+
+ Envelope2D envelope2D = raster.getEnvelope2D();
+ //process scale changes due to changes in widthOrScale and
heightOrScale
+ if (!useScale) {
+ newScaleX = (Math.abs(envelope2D.getMaxX() -
envelope2D.getMinX())) / newWidth;
+ newScaleY = Math.signum(originalScaleY) *
Math.abs(envelope2D.getMaxY() - envelope2D.getMinY()) / newHeight;
+// newScaleX *= ((double) originalWidth / );
+// newScaleY *= ((double) originalHeight /
Math.floor(heightOrScale));
+ }else {
+ newWidth = (int) Math.abs(((envelope2D.getMaxX() -
envelope2D.getMinX())) / newScaleX);
+ newHeight = (int) Math.abs(((envelope2D.getMaxY() -
envelope2D.getMinY())) / newScaleY);
+// double maxX = RasterUtils.getWorldCornerCoordinates(raster,
originalWidth + 1, 1).getX();
+// double minY = RasterUtils.getWorldCornerCoordinates(raster, 1,
originalHeight + 1).getY();
+// newWidth = Math.max((int)Math.abs((maxX - upperLeftX) +
(newScaleX / 2) / newScaleX), 1);
+// newHeight = Math.max((int)Math.abs((upperLeftY - minY) +
(newScaleY / 2) / newScaleY), 1);
Review Comment:
Removed, this was an older approach
--
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]