Revision: 6153 http://sourceforge.net/p/jump-pilot/code/6153 Author: ma15569 Date: 2019-03-17 06:34:36 +0000 (Sun, 17 Mar 2019) Log Message: ----------- Removed deprecated Raster classes: * RasterLayerStatisticasPlugIn class, substituded by DEMStatisticsPlugIn class * ProfileUtils class, substituded by ProfileGraphAlgorithms and ProfileGraphGUI classes
Removed Paths: ------------- core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileUtils.java core/trunk/src/org/openjump/core/ui/plugin/raster/RasterLayerStatisticsPlugIn.java Deleted: core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileUtils.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileUtils.java 2019-03-17 06:27:27 UTC (rev 6152) +++ core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileUtils.java 2019-03-17 06:34:36 UTC (rev 6153) @@ -1,576 +0,0 @@ -package org.openjump.core.ui.plugin.raster; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.IOException; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import javax.swing.JButton; -import javax.swing.JInternalFrame; -import javax.swing.JLayeredPane; -import javax.swing.JTable; -import javax.swing.table.DefaultTableModel; - -import org.math.plot.plots.Plot; -import org.math.plot.render.AbstractDrawer; -import org.openjump.core.attributeoperations.AttributeOp; -import org.openjump.core.rasterimage.RasterImageLayer; -import org.openjump.core.ui.plot.Plot2DPanelOJ; -import org.openjump.sextante.core.ObjectAndDescription; -import org.openjump.sextante.gui.additionalResults.AdditionalResults; -import org.openjump.sextante.gui.additionalResults.AdditionalResultsFrame; - -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.Geometry; -import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.LineString; -import com.vividsolutions.jts.geom.Point; -import com.vividsolutions.jump.I18N; -import com.vividsolutions.jump.feature.AttributeType; -import com.vividsolutions.jump.feature.BasicFeature; -import com.vividsolutions.jump.feature.Feature; -import com.vividsolutions.jump.feature.FeatureCollection; -import com.vividsolutions.jump.feature.FeatureDataset; -import com.vividsolutions.jump.feature.FeatureSchema; -import com.vividsolutions.jump.workbench.JUMPWorkbench; -import com.vividsolutions.jump.workbench.WorkbenchContext; -import com.vividsolutions.jump.workbench.model.StandardCategoryNames; -import com.vividsolutions.jump.workbench.ui.HTMLFrame; -import com.vividsolutions.jump.workbench.ui.HTMLPanel; -import com.vividsolutions.jump.workbench.ui.JTablePanel; -import com.vividsolutions.jump.workbench.ui.TableFrame; -import com.vividsolutions.jump.workbench.ui.images.IconLoader; - -public class ProfileUtils { - /** - * Use ProfileGraphGUI and ProfileGraphAlgorithms instead - * - * @deprecated - */ - @Deprecated - public final static String LAYER_NAME = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.layer_name"); - public final static String MIN = I18N - .get("org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.minimum"); - public final static String MEAN = I18N - .get("org.openjump.core.ui.plugin.tools.statistics.StatisticOverViewTableModel.mean-mode"); - public final static String MAX = I18N - .get("org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.maximum"); - public final static String SUM = I18N - .get("org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.sum"); - public final static String CELL_SIZE = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.dimension_cell"); - public final static String PLOT = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Profile-Plot"); - public final static String PROFILEPTS = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.profile-pts"); - public final static String PROFILE_INFO = I18N - .get("org.openjump.core.ui.plugin.layer.LayerPropertiesPlugIn.Info"); - public final static String PROFILE_LENGTH = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Profile-length"); - public final static String STARTING_POINT = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.starting-point"); - public final static String ENDING_POINT = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.ending-point"); - public final static String MEAN_SLOPE = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.mean-slope"); - public final static String HEIGHT = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.values"); - public final static String WIDTH = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.2d-distance"); - - public final static String TIMES = I18N - .get("org.openjump.core.ui.plugin.edittoolbox.cursortools.Travel-time"); - public final static String SLOPE = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Slope"); - - public static WorkbenchContext context = JUMPWorkbench.getInstance() - .getFrame().getContext(); - - public static RasterImageLayer getLayer() { - return ProfileGraphPlugIn.dialog - .getRasterLayer(ProfileGraphPlugIn.CLAYER); - - } - - public static GeometryFactory gf = new GeometryFactory(); - public static FeatureCollection resultFC = null; - public static FeatureSchema resultFSchema = null; - public static double dDist = 0, dHorzDist = 0, dSlope = 0, dY = 0; - public static double m_dLastX, m_dLastY, m_dLastZ; - - public static int nPoints = 0; - public static int n = 0; - public static ArrayList<Coordinate> coordinates = new ArrayList<Coordinate>(); - static double max, min, sum, mean, width, height, slope, cellsize, - profLenght; - protected static Font darkLabelFont = AbstractDrawer.DEFAULT_FONT; - - public static void calculateProfile(Coordinate[] coords) - throws IOException, RasterImageLayer.RasterDataNotFoundException { - - final RasterImageLayer rLayer = getLayer(); - - final LineString line = gf.createLineString(coords); - if (line.within(rLayer.getWholeImageEnvelopeAsGeometry())) { - final Random rand = new Random(); - - n = rand.nextInt(100) + 1; - processLine(line); - if ((resultFC != null) && (resultFC.size() > 0)) { - final FeatureDataset fd = new FeatureDataset(resultFSchema); - fd.addAll(resultFC.getFeatures()); - max = AttributeOp.evaluateAttributes(AttributeOp.MAX, - fd.getFeatures(), "Z"); - min = AttributeOp.evaluateAttributes(AttributeOp.MIN, - fd.getFeatures(), "Z"); - width = AttributeOp.evaluateAttributes(AttributeOp.MAX, - fd.getFeatures(), "PlaneDist") - - AttributeOp.evaluateAttributes(AttributeOp.MIN, - fd.getFeatures(), "PlaneDist"); - height = max - min; - mean = AttributeOp.evaluateAttributes(AttributeOp.MEAN, - fd.getFeatures(), "Z"); - sum = AttributeOp.evaluateAttributes(AttributeOp.SUM, - fd.getFeatures(), "Z"); - slope = Math.toDegrees(Math.atan((max - min) / width)); - - profLenght = AttributeOp.evaluateAttributes(AttributeOp.MAX, - fd.getFeatures(), "TerrainDist"); - - // featColl().addAll(resultFC.getFeatures()); - context.getLayerManager().addLayer( - StandardCategoryNames.RESULT, - PLOT + "-" + n + " " + PROFILEPTS, fd); - } - AdditionalResults.addAdditionalResultAndShow(PLOT + "-" + n, - getPlotPanel(resultFC, "" + n)); - - } else { - context.getLayerViewPanel() - .getContext() - .warnUser( - "Query outside the extension of selected Raster layer"); - } - } - - protected static Coordinate[] toArray(List<Coordinate> coordinates) { - return coordinates.toArray(new Coordinate[] {}); - } - - public static void processSegment(double x, double y, double x2, double y2) - throws RasterImageLayer.RasterDataNotFoundException, IOException { - double dx, dy, d, n; - dx = Math.abs(x2 - x); - dy = Math.abs(y2 - y); - if (dx > 0.0 || dy > 0.0) { - if (dx > dy) { - dx /= getLayer().getMetadata().getOriginalCellSize();// this.rstLayer.getWindowCellSize().x; - n = dx; - dy /= dx; - dx = getLayer().getMetadata().getOriginalCellSize();// this.rstLayer.getWindowCellSize().x; - } else { - dy /= getLayer().getMetadata().getOriginalCellSize();// this.rstLayer.getWindowCellSize().y; - n = dy; - dx /= dy; - dy = getLayer().getMetadata().getOriginalCellSize();// this.rstLayer.getWindowCellSize().y; - } - if (x2 < x) { - dx = -dx; - } - if (y2 < y) { - dy = -dy; - } - for (d = 0.0; d <= n; d++, x += dx, y += dy) { - addPoint(x, y); - } - } - } - - public static void processLine(Geometry line) throws IOException, - RasterImageLayer.RasterDataNotFoundException { - double x, y, x2, y2; - final Coordinate[] coords = line.getCoordinates(); - for (int i = 0; i < coords.length - 1; i++) { - x = coords[i].x; - y = coords[i].y; - x2 = coords[i + 1].x; - y2 = coords[i + 1].y; - processSegment(x, y, x2, y2); - } - // Giuseppe Aruta (2018-4-17) Missing last point of the profile - addPoint(coords[coords.length - 1].x, coords[coords.length - 1].y); - } - - public static void addPoint(double x, double y) - throws RasterImageLayer.RasterDataNotFoundException, IOException { - if (resultFSchema == null) { - resultFSchema = new FeatureSchema(); - resultFSchema.addAttribute("geometry", AttributeType.GEOMETRY); - resultFSchema.addAttribute("X", AttributeType.DOUBLE); - resultFSchema.addAttribute("Y", AttributeType.DOUBLE); - resultFSchema.addAttribute("Z", AttributeType.DOUBLE); - resultFSchema.addAttribute("PlaneDist", AttributeType.DOUBLE); - resultFSchema.addAttribute("TerrainDist", AttributeType.DOUBLE); - resultFC = new FeatureDataset(resultFSchema); - } - double z; - double dDX, dDY, dDZ; - z = getLayer().getCellValue(x, y, 0); - if (nPoints == 0) { - dDist = 0.0; - dHorzDist = 0.0; - } else { - - dDX = x - m_dLastX; - dDY = y - m_dLastY; - if (z == getLayer().getNoDataValue() - || m_dLastZ == getLayer().getNoDataValue()) { - dDZ = 0.0; - } else { - dDZ = z - m_dLastZ; - } - dDist += Math.sqrt(dDX * dDX + dDY * dDY); - dHorzDist += Math.sqrt(dDX * dDX + dDY * dDY + dDZ * dDZ); - - } - m_dLastX = x; - m_dLastY = y; - m_dLastZ = z; - nPoints++; - final Point geometry = new GeometryFactory() - .createPoint(new Coordinate(x, y)); - - final Feature fpoint = new BasicFeature(resultFSchema); - fpoint.setGeometry(geometry); - fpoint.setAttribute("X", new Double(x)); - fpoint.setAttribute("Y", new Double(y)); - fpoint.setAttribute("Z", new Double(z)); - fpoint.setAttribute("PlaneDist", new Double(dDist)); - fpoint.setAttribute("TerrainDist", new Double(dHorzDist)); - final Coordinate coord = new Coordinate(new Double(z), new Double( - dHorzDist)); - coordinates.add(coord); - resultFC.add(fpoint); - } - - public static Plot2DPanelOJ getPlotPanel(FeatureCollection fc, String name) { - final Plot2DPanelOJ plot2dA = new Plot2DPanelOJ(); - plot2dA.setName(name); - plot2dA.removeAllPlots(); - plot2dA.plotToolBar.remove(5); - plot2dA.plotToolBar.remove(4); - - // Build a 2D data set - final double[][] datas1 = new double[fc.size()][2]; - for (int j = 0; j < fc.size(); j++) { - final Feature f = fc.getFeatures().get(j); - datas1[j][0] = (Double) f.getAttribute("PlaneDist"); - datas1[j][1] = (Double) f.getAttribute("Z"); - } - plot2dA.addLinePlot("Profile", datas1); - - // plot2dA.addScatterPlot("pts",datas1); - // ==================== - plot2dA.setAxisLabel(0, WIDTH); - plot2dA.setAxisLabel(1, HEIGHT); - // change axis title position relatively to the base of the plot - plot2dA.getAxis(0).setLabelPosition(0.5, -0.15); - // change axis title position relatively to the base of the plot - plot2dA.getAxis(1).setLabelPosition(-0.15, 0.5); - // change axis title angle relatively to the base of the plot - plot2dA.getAxis(1).setLabelAngle(-Math.PI / 2); - - // Table part - double[][] dataTableDouble = null; - Object[][] dataTableObject = null; - for (final Plot plot2 : plot2dA.getPlots()) { - dataTableDouble = plot2.getData(); - } - dataTableObject = plot2dA.plotCanvas.reverseMapedData(dataTableDouble); - final double[][] slopeMatrixData = getRelativeSlope(dataTableObject); - final Object[] slopeData = getXdoubleData(slopeMatrixData); - final Object[] ZData = getYData(dataTableObject); - final Object[] LData = getXData(dataTableObject); - // final Object[] data_3d = get3Ddata(dataTableObject); - - // Buttons/////// - final JButton tableBtn = new JButton(IconLoader.icon("Row_16.gif")); - tableBtn.setToolTipText(PROFILE_INFO); - tableBtn.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - - final TableFrame freqFrame = new TableFrame(); - freqFrame.setLayout(new BorderLayout()); - freqFrame.setResizable(true); - freqFrame.setClosable(true); - freqFrame.setIconifiable(true); - freqFrame.setMaximizable(true); - freqFrame.setPreferredSize(new Dimension(900, 450)); - freqFrame.setSize(900, 450); - freqFrame.setLayer(JLayeredPane.MODAL_LAYER); - freqFrame.setTitle(PROFILE_INFO); - - final JTable jTable = new JTable(); - - final DefaultTableModel dtm = (DefaultTableModel) jTable - .getModel(); - dtm.addColumn("Z", ZData); - dtm.addColumn("PlaneDist", LData); - dtm.addColumn(SLOPE + " (\xB0)", slopeData); - final JTablePanel jTablePanel = new JTablePanel(dtm); - jTablePanel.getCommandPanel().setVisible(false); - freqFrame.add(jTablePanel); - freqFrame.setVisible(true); - context.getWorkbench().getFrame() - .addInternalFrame(freqFrame, true, true); - } - }); - - final JButton slopeBtn = new JButton( - IconLoader.icon("profileSlope.png")); - slopeBtn.setToolTipText(SLOPE); - slopeBtn.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - - final Plot2DPanelOJ plotSlope = new Plot2DPanelOJ(); - plotSlope.plotToolBar.remove(5); - plotSlope.plotToolBar.remove(4); - plotSlope.setName(SLOPE); - plotSlope.addLinePlot(SLOPE, Color.red, slopeMatrixData); - plotSlope.setAxisLabel(0, WIDTH); - plotSlope.setAxisLabel(1, SLOPE + " (\xB0)"); - plotSlope.getAxis(0).setLabelPosition(0.5, -0.15); - plotSlope.getAxis(1).setLabelPosition(-0.15, 0.5); - plotSlope.getAxis(1).setLabelAngle(-Math.PI / 2); - plotSlope.setFixedBounds(0, 0, width); - final ArrayList<ObjectAndDescription> m_Components = new ArrayList<ObjectAndDescription>(); - final ObjectAndDescription ob = new ObjectAndDescription( - "Slope", - // If the string below is activated, slope profile can - // be exported also to dxf - // The main problem is to fix the Y axe scale on - // AdditionalResultsFrame.exportToDxf(..) method - // I18N.get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Profile-Plot"), - plotSlope); - m_Components.add(ob); - - final AdditionalResultsFrame slopeFrame = new AdditionalResultsFrame( - m_Components); - slopeFrame.setTitle("Slope"); - slopeFrame.setName(I18N.get("Slope")); - slopeFrame.pack(); - final JInternalFrame[] frames = JUMPWorkbench.getInstance() - .getFrame().getInternalFrames(); - final ArrayList<JInternalFrame> list = new ArrayList<JInternalFrame>(); - for (final JInternalFrame iFrame : frames) { - if (iFrame instanceof AdditionalResultsFrame) { - list.add(iFrame); - } - } - - if (list.size() == 1) { - slopeFrame.setSize(plot2dA.getWidth(), plot2dA.getHeight()); - context.getWorkbench().getFrame() - .addInternalFrame(slopeFrame, true, true); - - } else { - // slopeFrame.repaint(); - slopeFrame.toFront(); - - } - final int xpos = 0; - int ypos = 0; - final Dimension deskDim = context.getWorkbench().getFrame() - .getDesktopPane().getSize(); - int deskWidth = deskDim.width; - final int deskHeight = deskDim.height; - deskWidth = deskDim.width; - final int frameWidth = deskWidth; - final int frameHeight = deskHeight / 2; - - for (final JInternalFrame iFrame : JUMPWorkbench.getInstance() - .getFrame().getInternalFrames()) { - if (iFrame instanceof AdditionalResultsFrame) { - ((AdditionalResultsFrame) iFrame).reshape(xpos, ypos, - frameWidth, frameHeight); - ((AdditionalResultsFrame) iFrame).setLocation(xpos, - ypos); - ((AdditionalResultsFrame) iFrame).getSplitPanel() - .setDividerLocation(0); - ((AdditionalResultsFrame) iFrame).moveToFront(); - ypos += frameHeight; - } - } - } - }); - - final JButton infoBtn = new JButton( - IconLoader.icon("information_16x16.png")); - infoBtn.setToolTipText(PROFILE_INFO); - infoBtn.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - final DecimalFormat df = new DecimalFormat("##.###"); - final HTMLPanel out = new HTMLPanel(); - out.getRecordPanel().removeAll(); - out.createNewDocument(); - out.setBackground(Color.lightGray); - String htmlString = "<HTML><BODY>"; - htmlString += "<h2 align=\"left\">" + PROFILE_INFO + "</h2>"; - htmlString += "<b><font face=\"" + darkLabelFont + "\">" + MIN - + ": </b>" + df.format(min) + "<br>"; - htmlString += "<b><font face=\"" + darkLabelFont + "\">" + MAX - + ": </b>" + df.format(max) + "<br>"; - htmlString += "<b><font face=\"" + darkLabelFont + "\">" - + PROFILE_LENGTH + ": </b>" + df.format(profLenght) - + "<br>"; - htmlString += "<b><font face=\"" + darkLabelFont + "\">" - + WIDTH + ": </b>" + df.format(width) + "<br>"; - htmlString += "<b><font face=\"" + darkLabelFont + "\">" - + HEIGHT + ": </b>" + df.format(height) + "<br>"; - htmlString += "<b><font face=\"" + darkLabelFont + "\">" - + MEAN_SLOPE + ": </b>" + df.format(slope) + "\xB0<br>"; - htmlString += "</DIV></BODY></HTML>"; - out.append(htmlString); - final HTMLFrame frame = new HTMLFrame(); - frame.setTitle(PROFILE_INFO); - frame.add(out); - frame.setClosable(true); - frame.setResizable(true); - frame.setMaximizable(true); - frame.setSize(200, 280); - frame.setVisible(true); - context.getWorkbench().getFrame() - .addInternalFrame(frame, true, true); - } - }); - // To do: giving a downslope/upslope/flat speed, it calculates the - // travel time along the profile - final JButton timeBtn = new JButton(TIMES); - timeBtn.setToolTipText(TIMES); - timeBtn.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - - // final ProfileTimesDialog ptd = new ProfileTimesDialog( - // slopeMatrixData); - // ptd.setLocationRelativeTo(JUMPWorkbench.getInstance() - // .getFrame()); - // ptd.setVisible(true); - } - }); - - plot2dA.plotToolBar.addSeparator(new Dimension(16, 16)); - plot2dA.plotToolBar.add(infoBtn); - plot2dA.plotToolBar.add(tableBtn); - plot2dA.plotToolBar.add(slopeBtn); - // plot2dA.plotToolBar.add(timeBtn); - - plot2dA.setFixedBounds(0, 0, width); - return plot2dA; - - } - - private static Object[] getXdoubleData(double[][] slopeData) { - final Object[] column = new Object[slopeData.length]; - double value; - for (int i = 0; i < column.length; i++) { - value = ((Double) slopeData[i][1]).doubleValue(); - column[i] = value; - } - return column; - - } - - public static double[][] getRelativeSlope(Object[][] dataTableObject) { - final double[][] column = new double[dataTableObject.length][2]; - for (int i = 0; i < column.length; i++) { - if (i == 0) { - column[i][1] = 0; - column[i][0] = ((Double) dataTableObject[i][0]).doubleValue(); - } else { - final double dDist1 = ((Double) dataTableObject[i][1]) - .doubleValue(); - final double dDist0 = ((Double) dataTableObject[i - 1][1]) - .doubleValue(); - final double Z1 = ((Double) dataTableObject[i][0]) - .doubleValue(); - final double Z0 = ((Double) dataTableObject[i - 1][0]) - .doubleValue(); - double number = 0; - final double slope = Math.atan(((Z1 - Z0) / (dDist1 - dDist0))); - if (slope > 0 || slope == 0) { - number = 90 - Math.toDegrees(slope); - } else if (slope < 0) { - number = -90 - Math.toDegrees(slope); - } - column[i][1] = number; - column[i][0] = Z1; - } - } - return column; - } - - public static Object[] getXData(Object[][] dataTableObject) { - final Object[] column = new Object[dataTableObject.length]; - double value; - for (int i = 0; i < column.length; i++) { - value = ((Double) dataTableObject[i][0]).doubleValue(); - column[i] = value; - } - return column; - } - - public static Object[] getD3Data(Object[][] dataTableObject) { - final Object[] column = new Object[dataTableObject.length]; - - for (int i = 0; i < column.length; i++) { - if (i == 0) { - column[i] = 0; - } else { - final double dDist1 = ((Double) dataTableObject[i][1]) - .doubleValue(); - final double dDist0 = ((Double) dataTableObject[i - 1][1]) - .doubleValue(); - final double Z1 = ((Double) dataTableObject[i][0]) - .doubleValue(); - final double Z0 = ((Double) dataTableObject[i - 1][0]) - .doubleValue(); - column[i] = Math.sqrt(Z1 * Z0 + dDist1 * dDist0); - } - } - return column; - } - - public static Object[] getYData(Object[][] dataTableObject) { - final Object[] column = new Object[dataTableObject.length]; - for (int i = 0; i < column.length; i++) { - final double value = ((Double) dataTableObject[i][1]).doubleValue(); - column[i] = value; - } - return column; - } - - public static double[][] getDataAsDouble(Object[][] dataTableObject) { - final double[][] column = new double[dataTableObject.length][2]; - for (int i = 0; i < column.length; i++) { - final double value1 = ((Double) dataTableObject[i][1]) - .doubleValue(); - final double value0 = ((Double) dataTableObject[i][0]) - .doubleValue(); - column[i][0] = value0; - column[i][1] = value1; - } - return column; - } -} Deleted: core/trunk/src/org/openjump/core/ui/plugin/raster/RasterLayerStatisticsPlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/raster/RasterLayerStatisticsPlugIn.java 2019-03-17 06:27:27 UTC (rev 6152) +++ core/trunk/src/org/openjump/core/ui/plugin/raster/RasterLayerStatisticsPlugIn.java 2019-03-17 06:34:36 UTC (rev 6153) @@ -1,307 +0,0 @@ -/* - * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI - * for visualizing and manipulating spatial features with geometry and attributes. - * - * Copyright (C) 2003 Vivid Solutions - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * For more information, contact: - * - * Vivid Solutions - * Suite #1A - * 2328 Government Street - * Victoria BC V8T 5G5 - * Canada - * - * (250)385-6040 - * www.vividsolutions.com - */ - -package org.openjump.core.ui.plugin.raster; - -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.geom.NoninvertibleTransformException; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.Locale; - -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JInternalFrame; -import javax.swing.JPanel; - -import org.openjump.core.apitools.LayerTools; -import org.openjump.core.rasterimage.RasterImageLayer; -import org.openjump.core.rasterimage.TiffTags.TiffReadingException; -import org.openjump.core.rasterimage.sextante.OpenJUMPSextanteRasterLayer; -import org.openjump.core.rasterimage.sextante.rasterWrappers.GridWrapperNotInterpolated; - -import com.vividsolutions.jts.geom.Envelope; -import com.vividsolutions.jump.I18N; -import com.vividsolutions.jump.workbench.WorkbenchContext; -import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn; -import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory; -import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck; -import com.vividsolutions.jump.workbench.plugin.PlugInContext; -import com.vividsolutions.jump.workbench.ui.HTMLPanel; -import com.vividsolutions.jump.workbench.ui.images.IconLoader; - -/** - * Giuseppe Aruta 2015_01_21 Class derived from LayerStatiticsPlugIn.class - * Computes various statistics on cells for selected Raster Image Layers. - * - * Giuseppe Aruta 2015_01_31.RasterLayerStatistics.class. Upgraded statistics to all bands - * Add plugin icon. Change name to "Raster statistics" - */ -public class RasterLayerStatisticsPlugIn extends AbstractPlugIn { - private final static String CANCEL = I18N.get("ui.OKCancelPanel.cancel"); - private final static String LAYER_STATISTICS = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.raster-statistics"); - private final static String LAYER = I18N - .get("ui.plugin.LayerStatisticsPlugIn.layer"); - private final static String ENV = I18N - .get("ui.plugin.LayerStatisticsPlugIn.envelope"); - private final static String NUMBANDS = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.file.bands_number"); - private final static String BAND = I18N - .get("org.openjump.core.ui.plugin.raster.CreatePolygonGridFromSelectedImageLayerPlugIn.band"); - private final static String MAX = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.cell.max"); - private final static String MIN = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.cell.min"); - private final static String MEAN = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.cell.mean"); - private final static String SUM = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.sum"); - private final static String NODATA = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.cell.nodata"); - private final static String VARIANCE = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.variance"); - private final static String STD = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.std"); - private final static String CVAR = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.cvar"); - private final static String NODATACELLS = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.nodatacell"); - private final static String VALIDCELLS = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.validcells"); - - public static MultiEnableCheck createEnableCheck( - WorkbenchContext workbenchContext) { - EnableCheckFactory checkFactory = new EnableCheckFactory( - workbenchContext); - - return new MultiEnableCheck().add( - checkFactory.createWindowWithLayerNamePanelMustBeActiveCheck()) - .add(checkFactory.createAtLeastNLayerablesMustBeSelectedCheck( - 1, RasterImageLayer.class)); - } - - /* - * Count the number of cells (of a Sextante monoband raster layer) with no - * data value - */ - public int nodata(PlugInContext context, - OpenJUMPSextanteRasterLayer rstLayer) { - int counter = 0; - GridWrapperNotInterpolated gwrapper = new GridWrapperNotInterpolated( - rstLayer, rstLayer.getLayerGridExtent()); - int nx = rstLayer.getLayerGridExtent().getNX(); - int ny = rstLayer.getLayerGridExtent().getNY(); - for (int y = 0; y < ny; y++) { - for (int x = 0; x < nx; x++) { - double value = gwrapper.getCellValueAsDouble(x, y, 0); - if (value == rstLayer.getNoDataValue()) - counter++; - } - } - return counter; - } - - public String StatisticsText(PlugInContext context, RasterImageLayer rLayer) - throws NoninvertibleTransformException, TiffReadingException, - Exception { - /* - * Overwrite Locale to UK Decimal format ####.## - */ - Locale locale = new Locale("en", "UK"); - String pattern = "###.########"; - DecimalFormat df = (DecimalFormat) NumberFormat - .getNumberInstance(locale); - df.applyPattern(pattern); - - String infotext = null; - OpenJUMPSextanteRasterLayer rstLayer = new OpenJUMPSextanteRasterLayer(); - rstLayer.create(rLayer); - Envelope layerEnv = rLayer.getWholeImageEnvelope(); - // Get the statistics - int numBands = rLayer.getNumBands(); - - String bandstring = ": " + String.valueOf(numBands); - df.format(rstLayer.getMinValue()); - df.format(rstLayer.getMaxValue()); - df.format(rstLayer.getMeanValue()); - int X = rstLayer.getNX(); // Number of columns - int Y = rstLayer.getNY(); // Number of rows - df.format(rstLayer.getMeanValue() * (X * Y - nodata(context, rstLayer))); - String nodata = df.format(rstLayer.getNoDataValue());// No data - df.format(rstLayer.getVariance()); - double var = rstLayer.getVariance();// Variance as double - df.format(Math.sqrt(var)); - df.format(var / rstLayer.getMeanValue()); - int validcells = X * Y - nodata(context, rstLayer);// Number of - // valid cells - - int nodatacells = nodata(context, rstLayer);// number of no data - // cells - - infotext = "<HTML><BODY>"; - infotext += "<table border='0.1'>"; - infotext += "<tr><td><b>" + LAYER + "</b> </td><td>" + rLayer.getName() - + "</td></tr>"; - infotext += "</table><br>"; - - infotext += "<table border='0.1'>"; - infotext += "<tr><td><b>" + ENV + "</b> </td><td>" - + layerEnv.toString() + "</td></tr>"; - infotext += "<tr><td><b>" + NUMBANDS + "</b> </td><td>" + bandstring - + "</td></tr>"; - infotext += "<tr><td><b>" + NODATA + "</b> </td><td>" + nodata - + "</td></tr>"; - infotext += "<tr><td><b>" + VALIDCELLS + "</b> </td><td>" - + Integer.toString(validcells) + "</td></tr>"; - infotext += "<tr><td><b>" + NODATACELLS + "</b> </td><td>" - + Integer.toString(nodatacells) + "</td></tr>"; - infotext += "</table><br>"; - - infotext += "<table border='1'>"; - infotext += "<tr><td bgcolor=#CCCCCC align='center'> " + BAND - + "</td><td bgcolor=#CCCCCC align='center'> " + MIN - + "</td><td bgcolor=#CCCCCC align='center'> " + MAX - + "</td><td bgcolor=#CCCCCC align='center'> " + MEAN - + "</td><td bgcolor=#CCCCCC align='center'> " + SUM - + "</td><td bgcolor=#CCCCCC align='center'> " + VARIANCE - + "</td><td bgcolor=#CCCCCC align='center'> " + STD - + "</td><td bgcolor=#CCCCCC align='center'> " + CVAR - - + "</td></tr>"; - for (int b = 0; b < numBands; b++) { - - infotext += "</td><td align='right'>" - + b - + "</td><td align='right'>" - + df.format(rstLayer.getMinValue(b))// min - + "</td><td align='right'>" - + df.format(rstLayer.getMaxValue(b))// max - + "</td><td align='right'>" - + df.format(rstLayer.getMeanValue(b))// mean - + "</td><td align='right'>" - + df.format(rstLayer.getMeanValue(b) - * (X * Y - nodata(context, rstLayer)))// sum - - + "</td><td align='right'>" - + df.format(rstLayer.getVariance(b))// variance - + "</td><td align='right'>" - + df.format(Math.sqrt(rstLayer.getVariance(b)))// std - + "</td><td align='right'>" - + df.format(rstLayer.getVariance(b) - / rstLayer.getMeanValue(b))// cvar - - + "</td></tr>"; - } - infotext += "</table>"; - infotext += "</DIV></BODY></HTML>"; - - return infotext; - } - - public boolean execute(PlugInContext context) throws Exception { - - RasterImageLayer rLayer = (RasterImageLayer) LayerTools - .getSelectedLayerable(context, RasterImageLayer.class); - // final WorkbenchContext wbcontext = context.getWorkbenchContext(); - /* - * Overwrite Locale to UK Decimal format ####.## - */ - Locale locale = new Locale("en", "UK"); - String pattern = "###.########"; - DecimalFormat df = (DecimalFormat) NumberFormat - .getNumberInstance(locale); - df.applyPattern(pattern); - - context.getWorkbenchContext(); - - // HTMLFrame out = context.getOutputFrame(); - final JInternalFrame frame = new JInternalFrame(LAYER_STATISTICS); - HTMLPanel out = new HTMLPanel(); - out.getRecordPanel().removeAll(); - out.createNewDocument(); - out.addHeader(1, LAYER_STATISTICS); - // for (Iterator i = wbcontext.getLayerNamePanel() - // .selectedNodes(RasterImageLayer.class).iterator(); i.hasNext();) { - // RasterImageLayer rLayer = (RasterImageLayer) i.next(); - - out.append(StatisticsText(context, rLayer)); - // } - // -- OK button Panel - JPanel okPanel = new JPanel(); - final JButton okButton = new JButton(CANCEL) { - @Override - public Dimension getPreferredSize() { - return new Dimension(100, 25); - } - }; - okButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - frame.dispose(); - return; - } - }); - okPanel.add(okButton); - // -- End of OK Buttom - - /* - * JTabbedPane tabbedPane = new JTabbedPane(); Border - * mainComponentBorder = BorderFactory.createCompoundBorder( - * BorderFactory.createEtchedBorder(), - * BorderFactory.createEmptyBorder(5, 5, 5, 5)); - * tabbedPane.setBorder(mainComponentBorder); tabbedPane.add(out, - * LAYER_STATISTICS); frame.add(tabbedPane, BorderLayout.CENTER); - */ - - frame.add(out, BorderLayout.CENTER); - frame.add(okPanel, BorderLayout.SOUTH); - - frame.setClosable(true); - frame.setResizable(true); - frame.setMaximizable(true); - frame.setSize(800, 450); - frame.setVisible(true); - context.getWorkbenchFrame().addInternalFrame(frame); - // } - - return true; - } - - public String getName() { - return LAYER_STATISTICS; - } - - public static final ImageIcon ICON = IconLoader.icon("statistics16.png"); - -} _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel