Class 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
    • Constructor Detail

    • Method Detail

      • 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 shown
        auto - 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 shown
        auto - 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 user
        listener - 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 if node is a required node which can't be removed in order to simplify the way.
        Parameters:
        way - the way to be simplified
        node - the node to check
        multipleUseNodes - set of nodes which is used more than once in the way
        Returns:
        true if node is a required node which can't be removed in order to simplify the way.
      • getMultiUseNodes

        private static java.util.Set<NodegetMultiUseNodes​(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 simplify
        threshold - 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 simplify
        threshold - 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 simplify
        threshold - 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 simplify
        threshold - 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 simplify
        threshold - the max error threshold
        deselect - true if 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 index from and an upper index to. Uses the Douglas-Peucker-Algorithm.
        Parameters:
        wnew - the way to simplify
        from - the lower index
        to - the upper index
        threshold - the max error threshold
        simplifiedNodes - 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)