Revision: 5707 http://sourceforge.net/p/jump-pilot/code/5707 Author: ma15569 Date: 2018-03-12 13:40:57 +0000 (Mon, 12 Mar 2018) Log Message: ----------- Updated ProfileGraph plugin: options to choose trace profile from a selected linestring, or to draw it. Output on Additional result frame
Modified Paths: -------------- core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphPlugIn.java core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphTool.java Added Paths: ----------- core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileUtils.java Property Changed: ---------------- core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphPlugIn.java core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphTool.java Modified: core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphPlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphPlugIn.java 2018-03-12 12:59:56 UTC (rev 5706) +++ core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphPlugIn.java 2018-03-12 13:40:57 UTC (rev 5707) @@ -29,68 +29,184 @@ * USA * * (850)862-7321 - * www.ashs.isa.com */ package org.openjump.core.ui.plugin.raster; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + import javax.swing.Icon; +import javax.swing.JRadioButton; +import org.openjump.core.apitools.LayerTools; import org.openjump.core.rasterimage.RasterImageLayer; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jump.I18N; +import com.vividsolutions.jump.feature.Feature; +import com.vividsolutions.jump.task.TaskMonitor; +import com.vividsolutions.jump.workbench.JUMPWorkbench; 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.plugin.ThreadedBasePlugIn; +import com.vividsolutions.jump.workbench.ui.GUIUtil; import com.vividsolutions.jump.workbench.ui.MenuNames; +import com.vividsolutions.jump.workbench.ui.MultiInputDialog; import com.vividsolutions.jump.workbench.ui.images.IconLoader; -public class ProfileGraphPlugIn extends AbstractPlugIn { - ProfileGraphTool profileTool; - private final static String sErrorSeeOutputWindow = I18N - .get("org.openjump.core.ui.plugin.tools.MeasureM_FPlugIn.Error-see-output-window"); - private String sName = "Create Thiessen Polygons"; +//import org.openjump.core.rasterimage.sextante.OpenJUMPSextanteRasterLayer; +public class ProfileGraphPlugIn extends ThreadedBasePlugIn { + + /** + * 2015_01_31. Giuseppe Aruta Add new panel which display profile info: + * length, mean slope, coordinates of starting and ending points, cell + * dimension, cell statistics. + */ + + private final List<Coordinate> savedCoordinates = new ArrayList<Coordinate>(); + + private RasterImageLayer rLayer = null; + + final static String drawn = I18N + .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.draw-linstring-as-trace"); + final static String selected = I18N + .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.use-selected-linstring-as-trace");; + private String sName; + private final String warning = I18N + .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.select-one-linstring");; + final static String MONITOR_STRING = "Calculating profile..."; + + private boolean drawnType = true; + private boolean selectedType = false; + public static MultiInputDialog dialog; + JRadioButton radioButton1 = new JRadioButton(drawn, drawnType); + JRadioButton radioButton2 = new JRadioButton(selected, selectedType); + + @Override public void initialize(PlugInContext context) throws Exception { - - this.sName = I18N + sName = I18N .get("org.openjump.core.ui.plugin.raster.ProfileGraphPlugIn.Profile-Graph"); - - // context.getWorkbenchContext().getWorkbench().getFrame().getToolBar().addPlugIn(getIcon(), - // this, new MultiEnableCheck(), context.getWorkbenchContext()); context.getFeatureInstaller().addMainMenuPlugin(this, - new String[] { MenuNames.RASTER }, this.sName + "...", false, + new String[] { MenuNames.RASTER }, sName + "...", false, getIcon(), createEnableCheck(context.getWorkbenchContext())); - profileTool = new ProfileGraphTool(); } - public boolean execute(PlugInContext context) throws Exception { - try { - context.getLayerViewPanel().setCurrentCursorTool(profileTool); - return true; - } catch (Exception e) { - e.printStackTrace(); - context.getWorkbenchFrame().warnUser(sErrorSeeOutputWindow); - context.getWorkbenchFrame().getOutputFrame().createNewDocument(); - context.getWorkbenchFrame().getOutputFrame() - .addText("MeasureM_FPlugIn Exception:" + e.toString()); - return false; + public static MultiEnableCheck createEnableCheck( + WorkbenchContext workbenchContext) { + final EnableCheckFactory checkFactory = new EnableCheckFactory( + workbenchContext); + final MultiEnableCheck multiEnableCheck = new MultiEnableCheck(); + + multiEnableCheck.add( + checkFactory.createExactlyNLayerablesMustBeSelectedCheck(1, + RasterImageLayer.class)).add( + checkFactory + .createRasterImageLayerExactlyNBandsMustExistCheck(1)); + + return multiEnableCheck; + } + + private void getDialogValues(MultiInputDialog dialog) { + drawnType = dialog.getBoolean(drawn); + selectedType = dialog.getBoolean(selected); + // dialog.getLayer(CLAYER); + } + + private void setDialogValues(MultiInputDialog dialog, PlugInContext context) { + final String OUTPUT_GROUP = "Match Type"; + dialog.setTitle(sName); + dialog.addRadioButton(drawn, OUTPUT_GROUP, drawnType, null); + + final Collection<Feature> features = context.getLayerViewPanel() + .getSelectionManager().getFeaturesWithSelectedItems(); + if (features.size() == 0 || features.size() > 1) { + dialog.addRadioButton(selected, OUTPUT_GROUP, selectedType, null) + .setEnabled(false); + } else { + dialog.addRadioButton(selected, OUTPUT_GROUP, selectedType, null) + .setEnabled(true); } + + dialog.setResizable(false); + } - private Icon getIcon() { + public Icon getIcon() { return IconLoader.icon("profile.png"); } - public MultiEnableCheck createEnableCheck( - final WorkbenchContext workbenchContext) { - EnableCheckFactory checkFactory = new EnableCheckFactory( - workbenchContext); - return new MultiEnableCheck().add( - checkFactory.createTaskWindowMustBeActiveCheck()).add( - checkFactory.createAtLeastNLayerablesMustBeSelectedCheck(1, - RasterImageLayer.class)); + @Override + public boolean execute(PlugInContext context) throws Exception { + + dialog = new MultiInputDialog(context.getWorkbenchFrame(), getName(), + true); + setDialogValues(dialog, context); + GUIUtil.centreOnWindow(dialog); + dialog.setVisible(true); + return true; } + + @Override + public void run(TaskMonitor monitor, PlugInContext context) + throws Exception { + if (ProfileUtils.resultFC != null || ProfileUtils.nPoints > 0) { + ProfileUtils.resultFC.clear(); + ProfileUtils.nPoints = 0; + } + + savedCoordinates.clear(); + rLayer = (RasterImageLayer) LayerTools.getSelectedLayerable(context, + RasterImageLayer.class); + if (rLayer == null) { + context.getLayerViewPanel() + .getContext() + .warnUser( + I18N.get("pirol.plugIns.EditAttributeByFormulaPlugIn.no-layer-selected")); + return; + } + + if (!dialog.wasOKPressed()) { + return; + } + + getDialogValues(dialog); + + if (drawnType) { + final ProfileGraphTool profileTool = new ProfileGraphTool(); + context.getLayerViewPanel().setCurrentCursorTool(profileTool); + } + + else if (selectedType) { + + final Collection<Feature> features = context.getLayerViewPanel() + .getSelectionManager().getFeaturesWithSelectedItems(); + if (features.size() == 0 || features.size() > 1) { + JUMPWorkbench + .getInstance() + .getFrame() + .warnUser( + I18N.getMessage( + "com.vividsolutions.jump.workbench.plugin.Exactly-n-features-must-be-selected", //$NON-NLS-1$ + new Object[] { 1 })); + + } else { + final Geometry geom = features.iterator().next().getGeometry(); + if (geom instanceof LineString) { + final Coordinate[] coords = geom.getCoordinates(); + ProfileUtils.calculateProfile(coords); + } else { + JUMPWorkbench.getInstance().getFrame().warnUser(warning); + } + + } + } + + } } Property changes on: core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphPlugIn.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Modified: core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphTool.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphTool.java 2018-03-12 12:59:56 UTC (rev 5706) +++ core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphTool.java 2018-03-12 13:40:57 UTC (rev 5707) @@ -33,57 +33,31 @@ package org.openjump.core.ui.plugin.raster; -import java.awt.BorderLayout; import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.event.ActionEvent; import java.awt.event.MouseEvent; import java.awt.geom.NoninvertibleTransformException; import java.io.IOException; import java.text.DecimalFormat; -import java.text.NumberFormat; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Locale; -import javax.swing.BorderFactory; import javax.swing.Icon; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JInternalFrame; -import javax.swing.JPanel; -import javax.swing.JTabbedPane; -import javax.swing.border.Border; -import org.openjump.core.apitools.LayerTools; -import org.openjump.core.attributeoperations.AttributeOp; import org.openjump.core.rasterimage.RasterImageLayer; -import org.openjump.core.ui.plot.Plot2DPanelOJ; 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.WorkbenchContext; -import com.vividsolutions.jump.workbench.model.StandardCategoryNames; -import com.vividsolutions.jump.workbench.plugin.PlugInContext; -import com.vividsolutions.jump.workbench.ui.HTMLPanel; import com.vividsolutions.jump.workbench.ui.LayerViewPanel; import com.vividsolutions.jump.workbench.ui.cursortool.MultiClickTool; import com.vividsolutions.jump.workbench.ui.images.IconLoader; + //import org.openjump.core.rasterimage.sextante.OpenJUMPSextanteRasterLayer; public class ProfileGraphTool extends MultiClickTool { + private final static String sDistance = I18N + .get("org.openjump.core.ui.plugin.tools.MeasureM_FTool.Distance"); /** * 2015_01_31. Giuseppe Aruta Add new panel which display profile info: * length, mean slope, coordinates of starting and ending points, cell @@ -90,71 +64,12 @@ * dimension, cell statistics. */ - private final static String CANCEL = I18N.get("ui.OKCancelPanel.cancel"); - private final static String sDistance = I18N - .get("org.openjump.core.ui.plugin.tools.MeasureM_FTool.Distance"); - private final static String sMeters = I18N - .get("org.openjump.core.ui.plugin.tools.MeasureM_FTool.meters"); - private final static String LAYER_NAME = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.layer_name"); - private final static String MIN = I18N - .get("org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.minimum"); - private final static String MEAN = I18N - .get("org.openjump.core.ui.plugin.tools.statistics.StatisticOverViewTableModel.mean-mode"); - private final static String MAX = I18N - .get("org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.maximum"); - private final static String SUM = I18N - .get("org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.sum"); - private final static String INFO = I18N.get("ui.AboutDialog.info"); - private final static String CELL_SIZE = I18N - .get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.dimension_cell"); - private final static String PLOT = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Profile-Plot"); - private final static String PROFILEPTS = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.profile-pts"); - - private final static String CELL_STAT = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.cell-statistics"); - private final static String PROFILE = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Profile"); - private final static String PROFILE_INFO = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Profile-info"); - private final static String PROFILE_LENGTH = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Profile-length"); - private final static String STARTING_POINT = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.starting-point"); - private final static String ENDING_POINT = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.ending-point"); - private final static String MEAN_SLOPE = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.mean-slope"); - private List<Coordinate> savedCoordinates = new ArrayList<Coordinate>(); + public static Coordinate currCoord; + public Coordinate[] coordinates; - private Coordinate currCoord; - // private OpenJUMPSextanteRasterLayer rstLayer = null; - private RasterImageLayer rLayer = null; - private GeometryFactory gf = new GeometryFactory(); - private FeatureCollection resultFC = null; - private FeatureSchema resultFSchema = null; - private double dDist = 0, dHorzDist = 0; - private double m_dLastX, m_dLastY, m_dLastZ; - private int nPoints = 0; - private String sBand = "band"; - - // private FeatureDatasetFactory fdf = new FeatureDatasetFactory(); - // private GridWrapperNotInterpolated gwrapper = null; - public ProfileGraphTool() { - this.allowSnapping(); - // -- do on init - this.resultFSchema = new FeatureSchema(); - this.resultFSchema.addAttribute("geometry", AttributeType.GEOMETRY); - this.resultFSchema.addAttribute("X", AttributeType.DOUBLE); - this.resultFSchema.addAttribute("Y", AttributeType.DOUBLE); - this.resultFSchema.addAttribute("Z", AttributeType.DOUBLE); - this.resultFSchema.addAttribute("PlaneDist", AttributeType.DOUBLE); - this.resultFSchema.addAttribute("TerrainDist", AttributeType.DOUBLE); - this.resultFC = new FeatureDataset(this.resultFSchema); + allowSnapping(); } @Override @@ -168,7 +83,6 @@ add(savedCoordinates.get(i)); } return createCursor(IconLoader.icon("profile_icon.gif").getImage()); - } @Override @@ -175,20 +89,21 @@ public void mouseLocationChanged(MouseEvent e) { try { if (isShapeOnScreen()) { - ArrayList<Coordinate> currentCoordinates = new ArrayList<Coordinate>( + @SuppressWarnings("unchecked") + final ArrayList<Coordinate> currentCoordinates = new ArrayList<Coordinate>( getCoordinates()); currentCoordinates.add(getPanel().getViewport() .toModelCoordinate(e.getPoint())); display(currentCoordinates, getPanel()); } - currCoord = snap(e.getPoint()); super.mouseLocationChanged(e); - } catch (Throwable t) { + } catch (final Throwable t) { getPanel().getContext().handleThrowable(t); } } + @SuppressWarnings("unchecked") @Override public void mousePressed(MouseEvent e) { super.mousePressed(e); @@ -195,20 +110,15 @@ savedCoordinates = new ArrayList<Coordinate>(getCoordinates()); } + @SuppressWarnings("unchecked") @Override protected void gestureFinished() throws NoninvertibleTransformException, IOException, RasterImageLayer.RasterDataNotFoundException { + reportNothingToUndoYet(); savedCoordinates.clear(); - - // Status bar is cleared before #gestureFinished is called. So redisplay - // the length. [Jon Aquino] display(getCoordinates(), getPanel()); - - // -- [sstein] now all the raster profile stuff - this.rLayer = (RasterImageLayer) LayerTools.getSelectedLayerable(this - .getWorkbench().getContext(), RasterImageLayer.class); - if (rLayer == null) { + if (ProfileUtils.getLayer() == null) { getPanel() .getContext() .warnUser( @@ -215,45 +125,16 @@ I18N.get("pirol.plugIns.EditAttributeByFormulaPlugIn.no-layer-selected")); return; } - // this.rstLayer = new OpenJUMPSextanteRasterLayer(); - // [mmichaud 2013-05-25] false : this is a temporary image not a file - // based image - // this.rstLayer.create(rLayer, false); - // this.rstLayer.setFullExtent(); // not sure why this needs to be done - // but - // it seems to - // be necessary (otherwise I get an NPE - // when - // doing - // this.rstLayer.getWindowCellSize()) - // GridExtent extent = this.rstLayer.getWindowGridExtent(); // not sure - // if - // this needs - // to be done - - // but it was - // in the - // Sextante - // class - // -- clear the resultFC - this.resultFC.clear(); - this.nPoints = 0; - // -- create a gridwrapper to access the cells - // this.gwrapper = new GridWrapperNotInterpolated(rstLayer, - // rstLayer.getLayerGridExtent()); - this.calculateProfile(getCoordinates(), getWorkbench().getContext()); - /* - * //-- this was used for testing double rvalue = 0.0; Coordinate - * startCoord = (Coordinate)getCoordinates().get(0); GridCell cell = - * rstLayer - * .getLayerGridExtent().getGridCoordsFromWorldCoords(startCoord.x, - * startCoord.y); // rvalue = cell.getValue(); //can't use this, since - * the value will be zero, so I assume the cell //object is just a place - * holder for the coordinates rvalue = - * gwrapper.getCellValueAsDouble(cell.getX(), cell.getY(), 0); //get - * value for first band //--output - * getPanel().getContext().setStatusMessage("starting point value: " + - * rvalue); - */ + + coordinates = new Coordinate[getCoordinates().size()]; + int i = 0; + for (final Iterator<Coordinate> iterator = getCoordinates().iterator(); iterator + .hasNext();) { + final Coordinate c = iterator.next(); + coordinates[i] = c; + i++; + } + ProfileUtils.calculateProfile(coordinates); } private void display(List<Coordinate> coordinates, LayerViewPanel panel) @@ -262,20 +143,18 @@ } private void display(double distance, LayerViewPanel panel) { - DecimalFormat df3 = new DecimalFormat("###,###,##0.0##"); - String distString = df3.format(distance / 0.3048); + final DecimalFormat df3 = new DecimalFormat("###,###,##0.0##"); + final String distString = df3.format(distance / 0.3048); panel.getContext().setStatusMessage( - sDistance + ": " + panel.format(distance) + " " + sMeters + " " - + " = " + distString + " feet"); + sDistance + ": " + panel.format(distance) + " " + " m" + " " + + " (" + distString + " ft)"); } private double distance(List<Coordinate> coordinates) { double distance = 0; - for (int i = 1; i < coordinates.size(); i++) { distance += coordinates.get(i - 1).distance(coordinates.get(i)); } - if ((currCoord != null) && (coordinates.size() > 1)) { distance -= coordinates.get(coordinates.size() - 2).distance( coordinates.get(coordinates.size() - 1)); @@ -282,304 +161,7 @@ distance += coordinates.get(coordinates.size() - 2).distance( currCoord); } - return distance; } - // HTMLPanel outpanel; - - private void calculateProfile(List<Coordinate> coordinates, - WorkbenchContext context) throws IOException, - RasterImageLayer.RasterDataNotFoundException { - RasterImageLayer rLayer = (RasterImageLayer) LayerTools - .getSelectedLayerable(this.getWorkbench().getContext(), - RasterImageLayer.class); - final JInternalFrame frame = new JInternalFrame(PLOT); - - // -- create a linestring - Coordinate[] coords = new Coordinate[coordinates.size()]; - int i = 0; - for (Iterator iterator = coordinates.iterator(); iterator.hasNext();) { - Coordinate c = (Coordinate) iterator.next(); - coords[i] = c; - i++; - } - LineString line = gf.createLineString(coords); - - if (line.within(rLayer.getWholeImageEnvelopeAsGeometry())) { - this.processLine(line); - PlugInContext pc = context.createPlugInContext(); - if ((this.resultFC != null) && (this.resultFC.size() > 0)) { - pc.addLayer(StandardCategoryNames.RESULT, PROFILEPTS, - this.resultFC); - } - - // -- HTML Info panel - final HTMLPanel outpanel = new HTMLPanel(); - outpanel.getRecordPanel().removeAll(); - Coordinate end = line.getEndPoint().getCoordinate(); - Coordinate start = line.getStartPoint().getCoordinate(); - double max, min, sum, mean; - max = AttributeOp.evaluateAttributes(AttributeOp.MAX, - this.resultFC.getFeatures(), "Z"); - min = AttributeOp.evaluateAttributes(AttributeOp.MIN, - this.resultFC.getFeatures(), "Z"); - mean = AttributeOp.evaluateAttributes(AttributeOp.MEAN, - this.resultFC.getFeatures(), "Z"); - sum = AttributeOp.evaluateAttributes(AttributeOp.SUM, - this.resultFC.getFeatures(), "Z"); - /* - * Overwrite Locale to UK Decimal format ####.## - */ - Locale locale = new Locale("en", "UK"); - String pattern = "###.####"; - DecimalFormat df = (DecimalFormat) NumberFormat - .getNumberInstance(locale); - df.applyPattern(pattern); - - String tooltip = "<HTML><BODY>"; - tooltip += "<DIV style=\"width: 500px; text-justification: justify;\">"; - tooltip += "<b><font size=+2>" + PROFILE_INFO + "</font></b><br>"; - tooltip += "<br>"; - tooltip += "<b><font size=+1>" + LAYER_NAME + ": </font></b>" - + rLayer.getName() + "<br>"; - tooltip += "<br>"; - tooltip += "<b><font size=+1>" + PROFILE + "</font></b><br>"; - tooltip += "<b>" + PROFILE_LENGTH + ": </b>" - + df.format(new Double(line.getLength())) + "<br>";// Lenght - // of - // profile - tooltip += "<b>" + MEAN_SLOPE + ": </b>" - + df.format(Math.atan((max - min) / line.getLength())) - + "\xB0<br>";// Slope - tooltip += "<b>" + STARTING_POINT + ": </b>" + df.format(start.x) - + " - " + df.format(start.y) + "<br>";// Coordinate of - // starting point of - // profile - tooltip += "<b>" + ENDING_POINT + ": </b>" + df.format(end.x) - + " - " + df.format(end.y) + "<br>";// Coordinate of ending - // point of profile - - tooltip += "<b>" - + CELL_SIZE - + ": </b>" - + (rLayer.getWholeImageEnvelope().getMaxX() - rLayer - .getWholeImageEnvelope().getMinX()) - / rLayer.getOrigImageWidth() + "<br>";// Cell size // - // profile - tooltip += "<br>"; - - tooltip += "<b><font size=+1>" + CELL_STAT + "</font></b><br>"; - tooltip += "<table border='1'>"; - tooltip += "</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></tr>"; - tooltip += "</td><td align='right'>" + new Double(min)// min - + "</td><td align='right'>" + new Double(max) // max - + "</td><td align='right'>" + new Double(mean)// mean - + "</td><td align='right'>" + new Double(sum)// sum - - + "</td></tr>"; - - tooltip += "</table>"; - - tooltip += "</DIV></BODY></HTML>"; - outpanel.createNewDocument(); - outpanel.append(tooltip); - // -- End of HTML Info Panel - - // -- graph stuff - ShowProfile myScorePlot = new ShowProfile(this.resultFC); - Plot2DPanelOJ plot = myScorePlot.getPlot(); - - // -- End graph stuff - - // -- 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() { - @Override - 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(plot, PLOT); - tabbedPane.add(outpanel, INFO); - - frame.add(tabbedPane, BorderLayout.CENTER); - frame.add(okPanel, BorderLayout.SOUTH); - - frame.setClosable(true); - frame.setResizable(true); - frame.setMaximizable(true); - frame.setSize(800, 450); - frame.setVisible(true); - - context.getWorkbench().getFrame().addInternalFrame(frame); - } else { - - getPanel().getContext().warnUser( - "Query outside the extension of selected Raster layer"); - } - - } - - private void processLine(Geometry line) throws IOException, - RasterImageLayer.RasterDataNotFoundException { - - double x, y, x2, y2; - 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); - } - - } - - private 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 /= rLayer.getMetadata().getOriginalCellSize();// this.rstLayer.getWindowCellSize().x; - n = dx; - dy /= dx; - dx = rLayer.getMetadata().getOriginalCellSize();// this.rstLayer.getWindowCellSize().x; - } else { - dy /= rLayer.getMetadata().getOriginalCellSize();// this.rstLayer.getWindowCellSize().y; - n = dy; - dx /= dy; - dy = rLayer.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); - } - } - - } - - private void addPoint(double x, double y) - throws RasterImageLayer.RasterDataNotFoundException, IOException { - - double z; - double dDX, dDY, dDZ; - - // z = this.rstLayer.getValueAt(x, y); - z = this.rLayer.getCellValue(x, y, 0); - - if (this.nPoints == 0) { - dDist = 0.0; - dHorzDist = 0.0; - } else { - dDX = x - m_dLastX; - dDY = y - m_dLastY; - if (z == rLayer.getNoDataValue() - || m_dLastZ == rLayer.getNoDataValue()) { - // if (this.rstLayer.isNoDataValue(z) - // || this.rstLayer.isNoDataValue(m_dLastZ)) { - 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; - - this.nPoints++; - - Point geometry = new GeometryFactory() - .createPoint(new Coordinate(x, y)); - Feature fpoint = new BasicFeature(this.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)); - - /* - * z //--graph stuff if (!this.rstLayer.isNoDataValue(z)){ - * serie.add(dDist, z); } - */ - this.resultFC.add(fpoint); - - } - - protected Feature[] features = null; - } - -final class ShowProfile extends JFrame { - Plot2DPanelOJ plot = null; - - public ShowProfile(FeatureCollection fc) { - - // Build a 2D data set - double[][] datas1 = new double[fc.size()][2]; - for (int j = 0; j < fc.size(); j++) { - Feature f = fc.getFeatures().get(j); - datas1[j][0] = (Double) f.getAttribute("PlaneDist"); - datas1[j][1] = (Double) f.getAttribute("Z"); - } - // Build the 2D scatterplot of the datas in a Panel - // LINE, SCATTER, BAR, QUANTILE, STAIRCASE, (HISTOGRAMM?) - Plot2DPanelOJ plot2dA = new Plot2DPanelOJ(); - plot2dA.addLinePlot("graph", datas1); - // plot2dA.addScatterPlot("pts",datas1); - // ==================== - plot2dA.setAxisLabel( - 0, - I18N.get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.2d-distance")); - plot2dA.setAxisLabel( - 1, - I18N.get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.values")); - // Display a Frame containing the plot panel - // new FrameView(plot2dA); - this.plot = plot2dA; - - } - - public Plot2DPanelOJ getPlot() { - return this.plot; - } - -} Property changes on: core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphTool.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileUtils.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileUtils.java (rev 0) +++ core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileUtils.java 2018-03-12 13:40:57 UTC (rev 5707) @@ -0,0 +1,315 @@ +package org.openjump.core.ui.plugin.raster; + +import java.awt.Font; +import java.io.IOException; +import java.text.DateFormat; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +import org.math.plot.render.AbstractDrawer; +import org.openjump.core.apitools.LayerTools; +import org.openjump.core.attributeoperations.AttributeOp; +import org.openjump.core.rasterimage.RasterImageLayer; +import org.openjump.core.ui.plot.Plot2DPanelOJ; +import org.openjump.sextante.gui.additionalResults.AdditionalResults; + +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.HTMLPanel; + +public class ProfileUtils { + + 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 static WorkbenchContext context = JUMPWorkbench.getInstance() + .getFrame().getContext(); + + public static RasterImageLayer getLayer() { + return (RasterImageLayer) LayerTools.getSelectedLayerable(context, + RasterImageLayer.class); + } + + public static GeometryFactory gf = new GeometryFactory(); + public static FeatureCollection resultFC = null; + public static FeatureSchema resultFSchema = null; + public static double dDist = 0, dHorzDist = 0; + public static double m_dLastX, m_dLastY, m_dLastZ; + public static int nPoints = 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())) { + processLine(line); + if ((resultFC != null) && (resultFC.size() > 0)) { + context.getLayerManager().addLayer( + StandardCategoryNames.RESULT, PROFILEPTS, resultFC); + } + + final DateFormat dateFormat = new SimpleDateFormat( + "yyyy/MM/dd HH:mm:ss"); + final Date date = new Date(); + + AdditionalResults.addAdditionalResult( + PLOT + "-" + dateFormat.format(date) + " " + PROFILE_INFO, + getStatisticPanel(rLayer, line)); + // AdditionalResults.addAdditionalResult(namePlot + "-" + // + "Collection of data", fcpan); + AdditionalResults.addAdditionalResultAndShow(PLOT + "-" + + dateFormat.format(date), getPlotPanel(resultFC)); + + } 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); + } + } + + 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); + // resultFSchema.addAttribute("Section", AttributeType.STRING); + 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 HTMLPanel getStatisticPanel(RasterImageLayer rLayer, + LineString line) { + final HTMLPanel outpanel = new HTMLPanel(); + outpanel.getRecordPanel().removeAll(); + final Coordinate end = line.getEndPoint().getCoordinate(); + final Coordinate start = line.getStartPoint().getCoordinate(); + max = AttributeOp.evaluateAttributes(AttributeOp.MAX, + resultFC.getFeatures(), "Z"); + min = AttributeOp.evaluateAttributes(AttributeOp.MIN, + resultFC.getFeatures(), "Z"); + width = AttributeOp.evaluateAttributes(AttributeOp.MAX, + resultFC.getFeatures(), "PlaneDist") + - AttributeOp.evaluateAttributes(AttributeOp.MIN, + resultFC.getFeatures(), "PlaneDist"); + height = max - min; + mean = AttributeOp.evaluateAttributes(AttributeOp.MEAN, + resultFC.getFeatures(), "Z"); + sum = AttributeOp.evaluateAttributes(AttributeOp.SUM, + resultFC.getFeatures(), "Z"); + /* + * Overwrite Locale to UK Decimal format ####.## + */ + final Locale locale = new Locale("en", "UK"); + final String pattern = "###.###"; + final DecimalFormat df = (DecimalFormat) NumberFormat + .getNumberInstance(locale); + df.applyPattern(pattern); + slope = (Math.atan((max - min) / line.getLength()) * 100); + cellsize = (rLayer.getWholeImageEnvelope().getMaxX() - rLayer + .getWholeImageEnvelope().getMinX()) + / rLayer.getOrigImageWidth(); + profLenght = new Double(line.getLength()); + + String htmlString = "<HTML><BODY>"; + htmlString += "<b><font face=\"" + darkLabelFont + "\">" + LAYER_NAME + + ": </b>" + rLayer.getName() + "<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) + "%<br>"; + htmlString += "<b><font face=\"" + darkLabelFont + "\">" + + STARTING_POINT + ": </b>" + df.format(start.x) + " - " + + df.format(start.y) + "<br>"; + htmlString += "<b><font face=\"" + darkLabelFont + "\">" + ENDING_POINT + + ": </b>" + df.format(end.x) + " - " + df.format(end.y) + + "<br>"; + htmlString += "<b><font face=\"" + darkLabelFont + "\">" + MIN + + ": </b>" + new Double(min) + "<br>"; + htmlString += "<b><font face=\"" + darkLabelFont + "\">" + MAX + + ": </b>" + new Double(max) + "</font><br>"; + htmlString += "</DIV></BODY></HTML>"; + outpanel.createNewDocument(); + outpanel.append(htmlString); + outpanel.getSaveButton().setVisible(false); + return outpanel; + } + + public static Plot2DPanelOJ getPlotPanel(FeatureCollection fc) { + final Plot2DPanelOJ plot2dA = new Plot2DPanelOJ(); + plot2dA.removeAllPlots(); + + // 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"); + } + + // To avoid that two or more consequiensal plots are drawn together + + // Build the 2D scatterplot of the datas in a Panel + // LINE, SCATTER, BAR, QUANTILE, STAIRCASE, (HISTOGRAMM?) + // Plot2DPanelOJ plot2dA = new Plot2DPanelOJ(); + plot2dA.addLinePlot("graph", 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); + return plot2dA; + + } +} Property changes on: core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileUtils.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel