Revision: 4404
          http://sourceforge.net/p/jump-pilot/code/4404
Author:   ma15569
Date:     2015-04-22 15:08:50 +0000 (Wed, 22 Apr 2015)
Log Message:
-----------
(Giuseppe Aruta) xtend to all band "Export selected raster to XYZ table". If 
the file is a multi banded raster
 each band is extracted to a proper band named "band1", "band2", etc.
 

Modified Paths:
--------------
    core/trunk/src/org/openjump/core/rasterimage/RasterImageIOUtils.java

Modified: core/trunk/src/org/openjump/core/rasterimage/RasterImageIOUtils.java
===================================================================
--- core/trunk/src/org/openjump/core/rasterimage/RasterImageIOUtils.java        
2015-04-22 12:52:14 UTC (rev 4403)
+++ core/trunk/src/org/openjump/core/rasterimage/RasterImageIOUtils.java        
2015-04-22 15:08:50 UTC (rev 4404)
@@ -462,7 +462,8 @@
     }
 
     /**
-     * Export selected raster to XYZ table
+     * Export selected raster to XYZ table. If the file is a multi banded 
raster
+     * each band is extracted to a proper band named "band1", "band2", etc
      * 
      * @param file
      *            file to save es D:/Openjump/test.xyz
@@ -477,12 +478,12 @@
      */
 
     public static void saveXYZ(File outfile, PlugInContext context,
-            RasterImageLayer rLayer, int band) throws IOException {
+            RasterImageLayer rLayer) throws IOException {
         OutputStream out = null;
         try {
             OpenJUMPSextanteRasterLayer rstLayer = new 
OpenJUMPSextanteRasterLayer();
             rstLayer.create(rLayer);
-
+            int numBands = rLayer.getNumBands();
             out = new FileOutputStream(outfile);
             cellFormat = NumberFormat.getNumberInstance();
             cellFormat.setMaximumFractionDigits(3);
@@ -499,7 +500,12 @@
             }
 
             PrintStream po = new PrintStream(out);
-            po.println("x\ty\tz");
+            po.append("coordinateX\tcoordinateY");
+            for (int b = 0; b < numBands; b++) {
+                int n = b + 1;
+                po.append("\tband" + n);
+            }
+            po.append("\n");
             GridWrapperNotInterpolated gwrapper = new 
GridWrapperNotInterpolated(
                     rstLayer, rstLayer.getLayerGridExtent());
             int nx = rstLayer.getLayerGridExtent().getNX();
@@ -507,21 +513,32 @@
             for (int y = 0; y < ny; y++) {
                 StringBuffer b = new StringBuffer();
                 for (int x = 0; x < nx; x++) {
-                    double value = gwrapper.getCellValueAsDouble(x, y, band);
 
+                    double value0 = gwrapper.getCellValueAsDouble(x, y, 0);
+                    double value1 = gwrapper.getCellValueAsDouble(x, y, 1);
+                    double value2 = gwrapper.getCellValueAsDouble(x, y, 2);
                     Point2D pt = rstLayer.getLayerGridExtent()
                             .getWorldCoordsFromGridCoords(x, y);
                     double Xf = pt.getX();
                     double Yf = pt.getY();
 
-                    if (Double.isNaN(value)) {
-                        value = defaultNoData;
+                    if (Double.isNaN(value0) || Double.isNaN(value1)
+                            || Double.isNaN(value2)) {
+                        value0 = defaultNoData;
+                        value1 = defaultNoData;
+                        value2 = defaultNoData;
                     }
-                    if (Math.floor(value) == value)
-                        b.append(Xf + "\t" + Yf + "\t" + (int) value + "\n");
+                    if (Math.floor(value0) == value0
+                            || Math.floor(value1) == value1
+                            || Math.floor(value2) == value2)
+                        b.append(Xf + "\t" + Yf + "\t" + (double) value0 + "\t"
+                                + (double) value1 + "\t" + (double) value2
+                                + "\n");
                     else {
-                        b.append(Xf + "\t" + Yf + "\t" + value + "\n");
+                        b.append(Xf + "\t" + Yf + "\t" + value0 + value1
+                                + value2 + "\n");
                     }
+
                 }
                 po.println(b);
             }
@@ -535,7 +552,7 @@
             context.getWorkbenchFrame()
                     .getOutputFrame()
                     .addText(
-                            "SaveImageToRasterPlugIn Exception:Export Part of 
FLT/ASC or modify raster to XYZ not yet implemented. Please Use Sextante 
Plugin");
+                            "Save To Raster Exception:Export image with no 
datasource to FLT/ASC/GRD/XYZ not yet implemented. Please Use Sextante Plugin");
         } finally {
             if (out != null)
                 out.close();


------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to