Class BufferedLine

  • All Implemented Interfaces:
    Shape

    public class BufferedLine
    extends BaseShape<SpatialContext>
    INTERNAL: A line between two points with a buffer distance extending in every direction. By contrast, an un-buffered line covers no area and as such is extremely unlikely to intersect with a point. BufferedLine isn't yet aware of geodesics (e.g. the anti-meridian); it operates in Euclidean space.
    • Field Detail

      • pA

        private final Point pA
      • pB

        private final Point pB
      • buf

        private final double buf
      • linePrimary

        private final InfBufLine linePrimary
        the primary line; passes through pA & pB
      • linePerp

        private final InfBufLine linePerp
        perpendicular to the primary line, centered between pA & pB
    • Constructor Detail

      • BufferedLine

        public BufferedLine​(Point pA,
                            Point pB,
                            double buf,
                            SpatialContext ctx)
        Creates a buffered line from pA to pB. The buffer extends on both sides of the line, making the width 2x the buffer. The buffer extends out from pA & pB, making the line in effect 2x the buffer longer than pA to pB.
        Parameters:
        pA - start point
        pB - end point
        buf - the buffer distance in degrees
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Shape
        Shapes can be "empty", which is to say it exists nowhere. The underlying coordinates are typically NaN.
      • getBuffered

        public Shape getBuffered​(double distance,
                                 SpatialContext ctx)
        Description copied from interface: Shape
        Returns a buffered version of this shape. The buffer is usually a rounded-corner buffer, although some shapes might buffer differently. This is an optional operation.
        Returns:
        Not null, and the returned shape should contain the current shape.
      • expandBufForLongitudeSkew

        public static double expandBufForLongitudeSkew​(Point pA,
                                                       Point pB,
                                                       double buf)
        Calls DistanceUtils.calcLonDegreesAtLat(double, double) given pA or pB's latitude; whichever is farthest. It's useful to expand a buffer of a line segment when used in a geospatial context to cover the desired area.
      • relate

        public SpatialRelation relate​(Shape other)
        Description copied from interface: Shape
        Describe the relationship between the two objects. For example
        • this is WITHIN other
        • this CONTAINS other
        • this is DISJOINT other
        • this INTERSECTS other
        Note that a Shape implementation may choose to return INTERSECTS when the true answer is WITHIN or CONTAINS for performance reasons. If a shape does this then it must document when it does. Ideally the shape will not do this approximation in all circumstances, just sometimes.

        If the shapes are equal then the result is CONTAINS (preferred) or WITHIN.

      • contains

        public boolean contains​(Point p)
      • getBoundingBox

        public Rectangle getBoundingBox()
        Description copied from interface: Shape
        Get the bounding box for this Shape. This means the shape is within the bounding box and that it touches each side of the rectangle.

        Postcondition: this.getBoundingBox().relate(this) == CONTAINS

      • hasArea

        public boolean hasArea()
        Description copied from interface: Shape
        Does the shape have area? This will be false for points and lines. It will also be false for shapes that normally have area but are constructed in a degenerate case as to not have area (e.g. a circle with 0 radius or rectangle with no height or no width).
      • getArea

        public double getArea​(SpatialContext ctx)
        Description copied from interface: Shape
        Calculates the area of the shape, in square-degrees. If ctx is null then simple Euclidean calculations will be used. This figure can be an estimate.
      • getCenter

        public Point getCenter()
        Description copied from interface: Shape
        Returns the center point of this shape. This is usually the same as getBoundingBox().getCenter() but it doesn't have to be.

        Postcondition: this.relate(this.getCenter()) == CONTAINS

      • getA

        public Point getA()
      • getB

        public Point getB()
      • getBuf

        public double getBuf()
      • getLinePrimary

        public InfBufLine getLinePrimary()
        INTERNAL
      • getLinePerp

        public InfBufLine getLinePerp()
        INTERNAL
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Description copied from interface: Shape
        The sub-classes of Shape generally implement the same contract for Object.equals(Object) and Object.hashCode() amongst the same sub-interface type. This means, for example, that multiple Point implementations of different classes are equal if they share the same x & y.
        Specified by:
        equals in interface Shape
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object