Revision: 6668
          http://sourceforge.net/p/jump-pilot/code/6668
Author:   ma15569
Date:     2020-12-31 11:40:33 +0000 (Thu, 31 Dec 2020)
Log Message:
-----------
Added two methods to get the valid area  as double from Layer.class or  from 
RasterImageLayer.class. Valid area means area covered by polygonal features   
(Layer.class) or area covered by cell with valid values (RasterImageLayer.class)

Modified Paths:
--------------
    core/trunk/src/org/openjump/core/ui/util/LayerableUtil.java

Modified: core/trunk/src/org/openjump/core/ui/util/LayerableUtil.java
===================================================================
--- core/trunk/src/org/openjump/core/ui/util/LayerableUtil.java 2020-12-30 
08:18:05 UTC (rev 6667)
+++ core/trunk/src/org/openjump/core/ui/util/LayerableUtil.java 2020-12-31 
11:40:33 UTC (rev 6668)
@@ -947,4 +947,46 @@
         return worldPath;
     }
 
+    /**
+     * Returns the area of feature collection (only Polygons or MultiPolygons)
+     * in the selected Vector Layer.class.
+     * This method exclude area of the layer which are not covered by feature
+     * @param com.vividsolutions.jump.workbench.model.Layer
+     * @return area ad double
+     */
+    public static double getValidArea(Layer layer) {
+       double area=0;
+       final FeatureCollection featureCollection = layer
+                .getFeatureCollectionWrapper();
+        for (final Iterator<?> i = featureCollection.iterator(); i.hasNext();) 
{
+             final Feature feature = (Feature) i.next();
+             area+= feature.getGeometry().getArea();
+             }
+               return area;
+    }
+    
+    /**
+     * Returns the area of selected RasterImageLayer.class.
+     * This method excludes cells with no data value
+     * @param org.openjump.core.rasterimage.RasterImageLayer
+     * @return area as double
+     */
+    public static double getValidArea(RasterImageLayer layer) throws 
IOException {
+       Raster ras=layer.getRasterData(null);
+       double noData =layer.getNoDataValue();
+       double cellSize=layer.getMetadata().getOriginalCellSize();
+       int counter = 0;
+       int nx = ras.getWidth();
+        int ny = ras.getHeight();
+        for (int y = 0; y < ny; y++) {
+            for (int x = 0; x < nx; x++) {
+                double value = ras.getSampleDouble(x, y, 0);
+                if (value != noData)
+                    counter++;
+            }
+        }
+               return cellSize*cellSize*counter;
+    }
+    
+    
 }



_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to