You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sedona.apache.org by ji...@apache.org on 2023/10/02 14:23:39 UTC
[sedona] branch master updated: Fix performance issue of RS_Count (#1042)
This is an automated email from the ASF dual-hosted git repository.
jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/master by this push:
new 0ab5cd631 Fix performance issue of RS_Count (#1042)
0ab5cd631 is described below
commit 0ab5cd631d70750e3e41fb97967b35fbd0f4c41d
Author: Kristin Cowalcijk <bo...@wherobots.com>
AuthorDate: Mon Oct 2 22:23:32 2023 +0800
Fix performance issue of RS_Count (#1042)
---
.../sedona/common/raster/RasterBandAccessors.java | 23 ++++++++++------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/common/src/main/java/org/apache/sedona/common/raster/RasterBandAccessors.java b/common/src/main/java/org/apache/sedona/common/raster/RasterBandAccessors.java
index 2ffbb0315..18860bd44 100644
--- a/common/src/main/java/org/apache/sedona/common/raster/RasterBandAccessors.java
+++ b/common/src/main/java/org/apache/sedona/common/raster/RasterBandAccessors.java
@@ -48,26 +48,23 @@ public class RasterBandAccessors {
}
public static long getCount(GridCoverage2D raster, int band, boolean excludeNoDataValue) {
- int height = RasterAccessors.getHeight(raster), width = RasterAccessors.getWidth(raster);
- if(excludeNoDataValue) {
+ Double bandNoDataValue = RasterBandAccessors.getBandNoDataValue(raster, band);
+ int width = RasterAccessors.getWidth(raster);
+ int height = RasterAccessors.getHeight(raster);
+ if (excludeNoDataValue && bandNoDataValue != null) {
RasterUtils.ensureBand(raster, band);
+ Raster r = RasterUtils.getRaster(raster.getRenderedImage());
+ double[] pixels = r.getSamples(0, 0, width, height, band - 1, (double[]) null);
long numberOfPixel = 0;
- Double bandNoDataValue = RasterBandAccessors.getBandNoDataValue(raster, band);
-
- for(int j = 0; j < height; j++){
- for(int i = 0; i < width; i++){
-
- double[] bandPixelValues = raster.evaluate(new GridCoordinates2D(i, j), (double[]) null);
- double bandValue = bandPixelValues[band - 1];
- if(bandNoDataValue == null || bandValue != bandNoDataValue){
- numberOfPixel += 1;
- }
+ for (double bandValue : pixels) {
+ if (Double.compare(bandValue, bandNoDataValue) != 0) {
+ numberOfPixel += 1;
}
}
return numberOfPixel;
} else {
// code for false
- return width * height;
+ return (long) width * (long) height;
}
}