Package org.openstreetmap.josm.actions
Class SimplifyWayAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- org.openstreetmap.josm.actions.JosmAction
-
- org.openstreetmap.josm.actions.SimplifyWayAction
-
- All Implemented Interfaces:
java.awt.event.ActionListener,java.io.Serializable,java.lang.Cloneable,java.util.EventListener,javax.swing.Action,Destroyable
public class SimplifyWayAction extends JosmAction
Delete unnecessary nodes from a way- Since:
- 2575
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classSimplifyWayAction.SimplifyChangeListenerprivate static classSimplifyWayAction.SimplifyWayDataSelectionListener-
Nested classes/interfaces inherited from class org.openstreetmap.josm.actions.JosmAction
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapter
-
-
Field Summary
-
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
-
-
Constructor Summary
Constructors Constructor Description SimplifyWayAction()Constructs a newSimplifyWayAction.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactionPerformed(java.awt.event.ActionEvent e)protected voidalertSelectAtLeastOneWay()static doubleaskSimplifyWays(java.lang.String text, boolean auto)Asks the user for max-err value used to simplify ways, if not remembered beforestatic doubleaskSimplifyWays(java.util.List<Way> ways, java.lang.String text, boolean auto)Asks the user for max-err value used to simplify ways, if not remembered beforeprivate static doubleaskSimplifyWays(java.util.List<Way> ways, java.util.function.Supplier<java.lang.String> textSupplier, SimplifyWayAction.SimplifyWayDataSelectionListener listener, boolean auto)Asks the user for max-err value used to simplify ways, if not remembered beforeprotected static voidbuildSimplifiedNodeList(java.util.List<Node> wnew, int from, int to, double threshold, java.util.List<Node> simplifiedNodes)Builds the simplified list of nodes for a way segment given by a lower indexfromand an upper indexto.private static SequenceCommandbuildSimplifyWaysCommand(java.util.List<Way> ways, double threshold)Creates the commands to simplify the ways with the given thresholdprotected booleanconfirmSimplifyManyWays(int numWays)protected booleanconfirmWayWithNodesOutsideBoundingBox(java.util.List<? extends OsmPrimitive> primitives)private static doublecourse(double lat1, double lon1, double lat2, double lon2)static SequenceCommandcreateSimplifyCommand(Way w)Creates the SequenceCommand to simplify a way with default threshold.static SequenceCommandcreateSimplifyCommand(Way w, double threshold)Creates the SequenceCommand to simplify a way with a given threshold.private static SequenceCommandcreateSimplifyCommand(Way w, double threshold, boolean deselect)Creates the SequenceCommand to simplify a way with a given threshold.private static doubledist(double lat1, double lon1, double lat2, double lon2)private static java.util.Set<Node>getMultiUseNodes(Way w)Calculate a set of nodes which occurs more than once in the wayprotected static booleanisRequiredNode(Way way, Node node, java.util.Set<Node> multipleUseNodes)Replies true ifnodeis a required node which can't be removed in order to simplify the way.static voidsimplifyWays(java.util.List<Way> ways, double threshold)Runs the commands to simplify the ways with the given thresholdstatic intsimplifyWaysCountNodesRemoved(java.util.List<Way> ways, double threshold)Runs the commands to simplify the ways with the given thresholdprotected voidupdateEnabledState()Override in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e.protected voidupdateEnabledState(java.util.Collection<? extends OsmPrimitive> selection)Override in subclasses to update the enabled state of the action if the collection of selected primitives changes.private static doublextd(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3)-
Methods inherited from class org.openstreetmap.josm.actions.JosmAction
buildActiveLayerChangeAdapter, buildLayerChangeAdapter, checkAndConfirmOutlyingOperation, destroy, getLayerManager, getShortcut, initEnabledState, installAdapters, listenToLayerChange, listenToSelectionChange, setHelpId, setToolbarId, setTooltip, updateEnabledStateOnCurrentSelection, updateEnabledStateOnCurrentSelection, updateEnabledStateOnModifiableSelection, waitFuture
-
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
-
-
-
Constructor Detail
-
SimplifyWayAction
public SimplifyWayAction()
Constructs a newSimplifyWayAction.
-
-
Method Detail
-
confirmWayWithNodesOutsideBoundingBox
protected boolean confirmWayWithNodesOutsideBoundingBox(java.util.List<? extends OsmPrimitive> primitives)
-
alertSelectAtLeastOneWay
protected void alertSelectAtLeastOneWay()
-
confirmSimplifyManyWays
protected boolean confirmSimplifyManyWays(int numWays)
-
askSimplifyWays
public static double askSimplifyWays(java.lang.String text, boolean auto)
Asks the user for max-err value used to simplify ways, if not remembered before- Parameters:
text- the text being shownauto- whether it's called automatically (conversion) or by the user- Returns:
- the max-err value or -1 if canceled
- Since:
- 15419
-
askSimplifyWays
public static double askSimplifyWays(java.util.List<Way> ways, java.lang.String text, boolean auto)
Asks the user for max-err value used to simplify ways, if not remembered before- Parameters:
ways- the ways that are being simplified (to show estimated number of nodes to be removed)text- the text being shownauto- whether it's called automatically (conversion) or by the user- Returns:
- the max-err value or -1 if canceled
- Since:
- 16566
-
askSimplifyWays
private static double askSimplifyWays(java.util.List<Way> ways, java.util.function.Supplier<java.lang.String> textSupplier, SimplifyWayAction.SimplifyWayDataSelectionListener listener, boolean auto)
Asks the user for max-err value used to simplify ways, if not remembered before- Parameters:
ways- the ways that are being simplified (to show estimated number of nodes to be removed)textSupplier- the text being shown (called when the DataSet selection changes)auto- whether it's called automatically (conversion) or by the userlistener- The dataset selection update listener- Returns:
- the max-err value or -1 if canceled
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
-
isRequiredNode
protected static boolean isRequiredNode(Way way, Node node, java.util.Set<Node> multipleUseNodes)
Replies true ifnodeis a required node which can't be removed in order to simplify the way.- Parameters:
way- the way to be simplifiednode- the node to checkmultipleUseNodes- set of nodes which is used more than once in the way- Returns:
- true if
nodeis a required node which can't be removed in order to simplify the way.
-
getMultiUseNodes
private static java.util.Set<Node> getMultiUseNodes(Way w)
Calculate a set of nodes which occurs more than once in the way- Parameters:
w- the way- Returns:
- a set of nodes which occurs more than once in the way
-
simplifyWaysCountNodesRemoved
public static int simplifyWaysCountNodesRemoved(java.util.List<Way> ways, double threshold)
Runs the commands to simplify the ways with the given threshold- Parameters:
ways- the ways to simplifythreshold- the max error threshold- Returns:
- The number of nodes removed from the ways (does not double-count)
- Since:
- 16566
-
simplifyWays
public static void simplifyWays(java.util.List<Way> ways, double threshold)
Runs the commands to simplify the ways with the given threshold- Parameters:
ways- the ways to simplifythreshold- the max error threshold- Since:
- 15419
-
buildSimplifyWaysCommand
private static SequenceCommand buildSimplifyWaysCommand(java.util.List<Way> ways, double threshold)
Creates the commands to simplify the ways with the given threshold- Parameters:
ways- the ways to simplifythreshold- the max error threshold- Returns:
- The command to simplify ways
- Since:
- 16566 (private)
-
createSimplifyCommand
public static SequenceCommand createSimplifyCommand(Way w)
Creates the SequenceCommand to simplify a way with default threshold.- Parameters:
w- the way to simplify- Returns:
- The sequence of commands to run
- Since:
- 15419
-
createSimplifyCommand
public static SequenceCommand createSimplifyCommand(Way w, double threshold)
Creates the SequenceCommand to simplify a way with a given threshold.- Parameters:
w- the way to simplifythreshold- the max error threshold- Returns:
- The sequence of commands to run
- Since:
- 15419
-
createSimplifyCommand
private static SequenceCommand createSimplifyCommand(Way w, double threshold, boolean deselect)
Creates the SequenceCommand to simplify a way with a given threshold.- Parameters:
w- the way to simplifythreshold- the max error thresholddeselect-trueif we want to deselect the deleted nodes- Returns:
- The sequence of commands to run
-
buildSimplifiedNodeList
protected static void buildSimplifiedNodeList(java.util.List<Node> wnew, int from, int to, double threshold, java.util.List<Node> simplifiedNodes)
Builds the simplified list of nodes for a way segment given by a lower indexfromand an upper indexto. Uses the Douglas-Peucker-Algorithm.- Parameters:
wnew- the way to simplifyfrom- the lower indexto- the upper indexthreshold- the max error thresholdsimplifiedNodes- list that will contain resulting nodes
-
dist
private static double dist(double lat1, double lon1, double lat2, double lon2)
-
course
private static double course(double lat1, double lon1, double lat2, double lon2)
-
xtd
private static double xtd(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3)
-
updateEnabledState
protected void updateEnabledState()
Description copied from class:JosmActionOverride in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e. when a layer is removed or added. SeeJosmAction.updateEnabledState(Collection)to respond to changes in the collection of selected primitives. Default behavior is empty.- Overrides:
updateEnabledStatein classJosmAction- See Also:
JosmAction.updateEnabledState(Collection),JosmAction.initEnabledState(),JosmAction.listenToLayerChange()
-
updateEnabledState
protected void updateEnabledState(java.util.Collection<? extends OsmPrimitive> selection)
Description copied from class:JosmActionOverride in subclasses to update the enabled state of the action if the collection of selected primitives changes. This method is called with the new selection.- Overrides:
updateEnabledStatein classJosmAction- Parameters:
selection- the collection of selected primitives; may be empty, but not null- See Also:
JosmAction.updateEnabledState(),JosmAction.initEnabledState(),JosmAction.listenToSelectionChange()
-
-