Class JTSUtils


  • public final class JTSUtils
    extends java.lang.Object
    A utility class for the work with org.locationtech.jts.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static org.locationtech.jts.geom.PrecisionModel APPROXIMATELY_PRECISION  
      static org.locationtech.jts.geom.GeometryFactory GEOMETRY_FACTORY
      A static final shared GeometryFactory we use, such that every usage uses the same settings of the geometry factory.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.List<org.locationtech.jts.geom.Point> circleLineIntersectionPoints​(org.locationtech.jts.geom.Point pointA, org.locationtech.jts.geom.Point pointB, org.locationtech.jts.geom.Point center, double radius)
      Calculates the intersection Points, from a line and a circle.
      static java.util.ArrayList<org.locationtech.jts.geom.Coordinate> convexPolygonLineIntersection​(org.locationtech.jts.geom.Polygon polygon, org.locationtech.jts.geom.LineSegment line)
      Tests whether the convex polygon polygon intersects with the line line and returns the intersecting coordinates if it does.
      static boolean coordinateEqual​(org.locationtech.jts.geom.Coordinate a, org.locationtech.jts.geom.Coordinate b)  
      static org.locationtech.jts.geom.Coordinate coordinateInDistance​(org.locationtech.jts.geom.Coordinate fixed, org.locationtech.jts.geom.Coordinate floating, double scale)
      Get the coordinate a given length-unit away from fixed Coordinate in vector (fixed to floating) direction.
      static org.locationtech.jts.algorithm.ConvexHull createConvexHull​(java.util.List<org.locationtech.jts.geom.Coordinate> coordinates)
      Get the ConvexHull for a list of Coordinates.
      static org.locationtech.jts.geom.LineString createLineString​(org.locationtech.jts.geom.Point a, org.locationtech.jts.geom.Point b)  
      static org.locationtech.jts.geom.Point createPoint​(double x, double y)  
      static org.locationtech.jts.geom.Point createPoint​(org.locationtech.jts.geom.Coordinate coordinate)  
      static boolean doubleEqual​(double a, double b)  
      static boolean doubleEqualApproximately​(double a, double b)  
      static java.util.List<org.locationtech.jts.geom.Coordinate> getBoundaryIntersections​(CanvasBoundary boundary, org.locationtech.jts.geom.LineSegment infinite)
      Get the intersections between the infinite line and the visual boundary.
      static java.util.List<org.locationtech.jts.geom.Coordinate> getCoordinateList​(java.util.List<? extends org.locationtech.jts.geom.Geometry> geometries)  
      static javafx.util.Pair<java.lang.Double,​java.lang.Double> getLinearEquation​(org.locationtech.jts.geom.Point pointA, org.locationtech.jts.geom.Point pointB)
      Works only for 2-dimensional Points.
      static org.locationtech.jts.geom.Point getLineIntersection​(javafx.util.Pair<java.lang.Double,​java.lang.Double> function1, javafx.util.Pair<java.lang.Double,​java.lang.Double> function2)  
      static javafx.util.Pair<java.lang.Double,​java.lang.Double> getOrthogonal​(double gradient, org.locationtech.jts.geom.Point point)  
      static boolean isApproximatelyOnLine​(org.locationtech.jts.geom.Coordinate point, org.locationtech.jts.geom.LineSegment line)  
      static boolean isBadHint​(org.locationtech.jts.geom.Polygon rectangle, AngleHint hint)
      this function can be called to determine if the specified hint is a bad Hint defined be the paper in the context of the specified rectangle
      static org.locationtech.jts.geom.Coordinate lineWayIntersection​(org.locationtech.jts.geom.LineSegment line, org.locationtech.jts.geom.LineSegment segment)
      Tests whether the line line intersects with the linesegment segment and returns the intersecting Coordinate (if one exists).
      static org.locationtech.jts.geom.Coordinate middleOfAngleHint​(AngleHint angleHint)  
      static org.locationtech.jts.geom.Coordinate middleOfAngleHint​(org.locationtech.jts.geom.Coordinate right, org.locationtech.jts.geom.Coordinate center, org.locationtech.jts.geom.Coordinate left)  
      static org.locationtech.jts.geom.Coordinate middleOfGeometryAngle​(GeometryAngle angle)  
      static org.locationtech.jts.math.Vector2D negateX​(org.locationtech.jts.math.Vector2D vector)  
      static org.locationtech.jts.math.Vector2D negateY​(org.locationtech.jts.math.Vector2D vector)  
      static org.locationtech.jts.geom.Coordinate normalizedCoordinate​(org.locationtech.jts.geom.Coordinate fixed, org.locationtech.jts.geom.Coordinate floating)
      Get the coordinate 1 length-unit away from fixed Coordinate in vector (fixed to floating) direction.
      static org.locationtech.jts.math.Vector2D normalizedVector​(org.locationtech.jts.geom.Coordinate from, org.locationtech.jts.geom.Coordinate to)  
      static boolean pointInAngle​(GeometryAngle geometryAngle, org.locationtech.jts.geom.Coordinate coordinate)  
      static boolean pointInAngle​(org.locationtech.jts.geom.Coordinate right, org.locationtech.jts.geom.Coordinate center, org.locationtech.jts.geom.Coordinate left, org.locationtech.jts.geom.Coordinate coordinate)
      Tests, whether a given Coordinate lies inside the given angle, which is defined by right, center and left.
      static Circle randomContainedCircle​(Circle boundary, org.locationtech.jts.geom.Coordinate pivot, double radius)
      Shuffles a new circle covered by the boundary circle, containing the pivot coordinate and obtaining the given radius;
      static org.locationtech.jts.geom.Coordinate randomInCircle​(Circle circle)
      Generate a random coordinate in the given circle.
      static org.locationtech.jts.geom.Point shuffleTreasure()  
      static boolean signsEqual​(org.locationtech.jts.math.Vector2D v0, org.locationtech.jts.math.Vector2D v1)  
      static org.locationtech.jts.geom.Polygon toPolygon​(org.locationtech.jts.geom.Envelope envelope)  
      static GeometryAngle validRandomAngle​(org.locationtech.jts.geom.Coordinate searcher, org.locationtech.jts.geom.Coordinate treasure, double maxExtend)  
      static GeometryAngle validRandomAngle​(org.locationtech.jts.geom.Coordinate searcher, org.locationtech.jts.geom.Coordinate treasure, double maxExtend, double minExtend)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • GEOMETRY_FACTORY

        public static final org.locationtech.jts.geom.GeometryFactory GEOMETRY_FACTORY
        A static final shared GeometryFactory we use, such that every usage uses the same settings of the geometry factory.
      • APPROXIMATELY_PRECISION

        public static final org.locationtech.jts.geom.PrecisionModel APPROXIMATELY_PRECISION
    • Method Detail

      • createPoint

        public static org.locationtech.jts.geom.Point createPoint​(double x,
                                                                  double y)
        Parameters:
        x - x-coordinate
        y - y-coordinate
        Returns:
        Point lying on (x,y).
      • createPoint

        public static org.locationtech.jts.geom.Point createPoint​(org.locationtech.jts.geom.Coordinate coordinate)
        Parameters:
        coordinate - The Coordinate, which should be converted to a Point.
        Returns:
        Point lying on coordinate..
      • createLineString

        public static org.locationtech.jts.geom.LineString createLineString​(org.locationtech.jts.geom.Point a,
                                                                            org.locationtech.jts.geom.Point b)
        Parameters:
        a - the begin of the LineString.
        b - the end of the LineString.
        Returns:
        A LineString containing only a and b.
      • lineWayIntersection

        public static org.locationtech.jts.geom.Coordinate lineWayIntersection​(org.locationtech.jts.geom.LineSegment line,
                                                                               org.locationtech.jts.geom.LineSegment segment)
        Tests whether the line line intersects with the linesegment segment and returns the intersecting Coordinate (if one exists).
        Parameters:
        line - a LineSegment
        segment - a LineSegment
        Returns:
        an intersection Point of the LineSegment objects line and lineSegment
      • convexPolygonLineIntersection

        public static java.util.ArrayList<org.locationtech.jts.geom.Coordinate> convexPolygonLineIntersection​(org.locationtech.jts.geom.Polygon polygon,
                                                                                                              org.locationtech.jts.geom.LineSegment line)
        Tests whether the convex polygon polygon intersects with the line line and returns the intersecting coordinates if it does.
        Parameters:
        polygon - a Polygon
        line - a LineSegment
        Returns:
        an ArrayList of the intersecting coordinates if they exist, a empty ArrayList otherwise
      • doubleEqual

        public static boolean doubleEqual​(double a,
                                          double b)
      • coordinateEqual

        public static boolean coordinateEqual​(org.locationtech.jts.geom.Coordinate a,
                                              org.locationtech.jts.geom.Coordinate b)
      • doubleEqualApproximately

        public static boolean doubleEqualApproximately​(double a,
                                                       double b)
      • middleOfAngleHint

        public static org.locationtech.jts.geom.Coordinate middleOfAngleHint​(AngleHint angleHint)
        Parameters:
        angleHint - where we want the middle point to go, from.
        Returns:
        Coordinate going through the middle of the AngleHint
      • middleOfGeometryAngle

        public static org.locationtech.jts.geom.Coordinate middleOfGeometryAngle​(GeometryAngle angle)
      • middleOfAngleHint

        public static org.locationtech.jts.geom.Coordinate middleOfAngleHint​(org.locationtech.jts.geom.Coordinate right,
                                                                             org.locationtech.jts.geom.Coordinate center,
                                                                             org.locationtech.jts.geom.Coordinate left)
        Parameters:
        right - opening line of the angle
        center - of the angle
        left - closing line of the angle
        Returns:
        Coordinate going through the middle of the angle
      • normalizedVector

        public static org.locationtech.jts.math.Vector2D normalizedVector​(org.locationtech.jts.geom.Coordinate from,
                                                                          org.locationtech.jts.geom.Coordinate to)
        Parameters:
        from - vector start
        to - vector end
        Returns:
        normalized Vector2D given by two Coordinates from and to.
      • coordinateInDistance

        public static org.locationtech.jts.geom.Coordinate coordinateInDistance​(org.locationtech.jts.geom.Coordinate fixed,
                                                                                org.locationtech.jts.geom.Coordinate floating,
                                                                                double scale)
        Get the coordinate a given length-unit away from fixed Coordinate in vector (fixed to floating) direction.
        Parameters:
        fixed - fixed relative coordinate
        floating - coordinate to provide direction vector
        scale - length between fixed and asked coordinate
        Returns:
        the Coordinate a given length-unit away from fixed Coordinate in vector direction
      • normalizedCoordinate

        public static org.locationtech.jts.geom.Coordinate normalizedCoordinate​(org.locationtech.jts.geom.Coordinate fixed,
                                                                                org.locationtech.jts.geom.Coordinate floating)
        Get the coordinate 1 length-unit away from fixed Coordinate in vector (fixed to floating) direction.
        Parameters:
        fixed - fixed relative coordinate
        floating - coordinate to provide direction vector
        Returns:
        coordinate 1 length-unit away from fixed Coordinate in vector direction
      • signsEqual

        public static boolean signsEqual​(org.locationtech.jts.math.Vector2D v0,
                                         org.locationtech.jts.math.Vector2D v1)
        Parameters:
        v0 - first vector to check
        v1 - second vector to check
        Returns:
        true, if both vectors v0 and v1 have coordinate-wise the same sign. false, otherwise.
      • negateX

        public static org.locationtech.jts.math.Vector2D negateX​(org.locationtech.jts.math.Vector2D vector)
        Parameters:
        vector - vector to transform
        Returns:
        new Vector2D with negated x-Coordinate of a vector.
      • negateY

        public static org.locationtech.jts.math.Vector2D negateY​(org.locationtech.jts.math.Vector2D vector)
        Parameters:
        vector - vector to transform
        Returns:
        new Vector2D with negated y-Coordinate of a vector.
      • pointInAngle

        public static boolean pointInAngle​(GeometryAngle geometryAngle,
                                           org.locationtech.jts.geom.Coordinate coordinate)
        Parameters:
        geometryAngle - the view GeometryAngle the method looks upon searching the given point
        coordinate - the Coordinate, we want to know, whether it lies in the geometryAngle.
        Returns:
        true, if coordinate lies inside the given geometryAngle. false, otherwise.
      • pointInAngle

        public static boolean pointInAngle​(org.locationtech.jts.geom.Coordinate right,
                                           org.locationtech.jts.geom.Coordinate center,
                                           org.locationtech.jts.geom.Coordinate left,
                                           org.locationtech.jts.geom.Coordinate coordinate)
        Tests, whether a given Coordinate lies inside the given angle, which is defined by right, center and left.
        Parameters:
        right - counter-clockwise, opening line of the angle.
        center - center of the angle.
        left - counter-clockwise, closing line of the angle.
        coordinate - the Coordinate, we want to know, whether it lies in the given angle.
        Returns:
        true, if coordinate lies in the given angle. false, otherwise.
      • validRandomAngle

        public static GeometryAngle validRandomAngle​(org.locationtech.jts.geom.Coordinate searcher,
                                                     org.locationtech.jts.geom.Coordinate treasure,
                                                     double maxExtend)
        Parameters:
        searcher - the Coordinate of the Searcher.
        treasure - the Coordinate of the treasure.
        maxExtend - number of [0, 2 * Math.PI) defining, how wide the angle is opened.
        Returns:
        a valid GeometryAngle, randomly generated.
      • validRandomAngle

        public static GeometryAngle validRandomAngle​(org.locationtech.jts.geom.Coordinate searcher,
                                                     org.locationtech.jts.geom.Coordinate treasure,
                                                     double maxExtend,
                                                     double minExtend)
        Parameters:
        searcher - the Coordinate of the Searcher.
        treasure - the Coordinate of the treasure.
        maxExtend - number of [0, 2 * Math.PI) defining, how wide the angle is opened.
        minExtend - number of [0, maxExtend)
        Returns:
        a valid GeometryAngle, randomly generated.
      • getCoordinateList

        public static java.util.List<org.locationtech.jts.geom.Coordinate> getCoordinateList​(java.util.List<? extends org.locationtech.jts.geom.Geometry> geometries)
        Parameters:
        geometries - A list, containing Geometry's, which should be converted to a list of Coordinate's.
        Returns:
        A list of Coordinate's, which geometries is converted to.
      • toPolygon

        public static org.locationtech.jts.geom.Polygon toPolygon​(org.locationtech.jts.geom.Envelope envelope)
        Parameters:
        envelope - An Envelope, which will be converted to an Polygon.
        Returns:
        A Polygon, a envelope is converted to.
      • getBoundaryIntersections

        public static java.util.List<org.locationtech.jts.geom.Coordinate> getBoundaryIntersections​(CanvasBoundary boundary,
                                                                                                    org.locationtech.jts.geom.LineSegment infinite)
        Get the intersections between the infinite line and the visual boundary.
        Parameters:
        boundary - boundary supplying the border LineSegments
        infinite - infinite line
        Returns:
        the intersections between the infinite line extension and the boundary LineSegments
      • randomContainedCircle

        public static Circle randomContainedCircle​(Circle boundary,
                                                   org.locationtech.jts.geom.Coordinate pivot,
                                                   double radius)
        Shuffles a new circle covered by the boundary circle, containing the pivot coordinate and obtaining the given radius;
        Parameters:
        boundary - circle to cover the generated circle
        pivot - coordinate, that must lay inside of the generated circle
        radius - radius of the generated circle
        Returns:
        a valid generated circle
      • createConvexHull

        public static org.locationtech.jts.algorithm.ConvexHull createConvexHull​(java.util.List<org.locationtech.jts.geom.Coordinate> coordinates)
        Get the ConvexHull for a list of Coordinates.
        Parameters:
        coordinates - the list of coordinates
        Returns:
        the convex hull for the list of coordinates
      • isApproximatelyOnLine

        public static boolean isApproximatelyOnLine​(org.locationtech.jts.geom.Coordinate point,
                                                    org.locationtech.jts.geom.LineSegment line)
      • randomInCircle

        public static org.locationtech.jts.geom.Coordinate randomInCircle​(Circle circle)
        Generate a random coordinate in the given circle.
        Parameters:
        circle - circle to cover the generated coordinate
        Returns:
        random coordinate in given circle
      • isBadHint

        public static boolean isBadHint​(org.locationtech.jts.geom.Polygon rectangle,
                                        AngleHint hint)
        this function can be called to determine if the specified hint is a bad Hint defined be the paper in the context of the specified rectangle
        Parameters:
        rectangle - the rectangle as Polygon
        hint - the AngleHint
        Returns:
        true if the given angleHint is a bad hint, related on the StrategyFromPaper. false otherwise.
      • circleLineIntersectionPoints

        public static java.util.List<org.locationtech.jts.geom.Point> circleLineIntersectionPoints​(org.locationtech.jts.geom.Point pointA,
                                                                                                   org.locationtech.jts.geom.Point pointB,
                                                                                                   org.locationtech.jts.geom.Point center,
                                                                                                   double radius)
        Calculates the intersection Points, from a line and a circle. The line is described as going from pointA to pointB and the circle ist described by having his center on center and a radius of radius.
        Parameters:
        pointA - the first Point of the line
        pointB - the second Point of the line
        center - the center Point of the circle
        radius - the radius of the circle
        Returns:
        a list, containing 0, 1 or 2 Points, representing the intersections of the line and the circle.
      • getLinearEquation

        public static javafx.util.Pair<java.lang.Double,​java.lang.Double> getLinearEquation​(org.locationtech.jts.geom.Point pointA,
                                                                                                  org.locationtech.jts.geom.Point pointB)
        Works only for 2-dimensional Points.
        Parameters:
        pointA - the first Point, forming a line
        pointB - the second Point, forming a line
        Returns:
        the linear equation y = xm + b of the line, pointA and pointB form. The linear equation is returned by a Pair containing the gradient m and the y-value b, where the line cuts the y-axis.
        Throws:
        java.lang.IllegalArgumentException - if pointA and pointB does not form a function.
      • getOrthogonal

        public static javafx.util.Pair<java.lang.Double,​java.lang.Double> getOrthogonal​(double gradient,
                                                                                              org.locationtech.jts.geom.Point point)
        Parameters:
        gradient - the gradient to the line, we will calculate the orthogonal form.
        point - the Point, the orthogonal will run though.
        Returns:
        the linear equation y = xm + b of the orthogonal line to a line with gradient gradient, running through point point. The linear equation is returned by a Pair containing the gradient m and the y-value b, where the line cuts the y-axis.
        Throws:
        java.lang.IllegalArgumentException - if the gradient is 0, where there is no orthogonal.
      • getLineIntersection

        public static org.locationtech.jts.geom.Point getLineIntersection​(javafx.util.Pair<java.lang.Double,​java.lang.Double> function1,
                                                                          javafx.util.Pair<java.lang.Double,​java.lang.Double> function2)
        Parameters:
        function1 - y = m1*x + b1, given as a pair containing the gradient m and the y-coordinate b, intersecting the y-axes.
        function2 - y = m2*x + b2, given as a pair containing the gradient m and the y-coordinate b, intersecting the y-axes.
        Returns:
        the intersection Point, of function1 and function2. Thus, we return
        Throws:
        java.lang.IllegalArgumentException - if both functions have no intersection or are equal.