com.mizar.geometry
Class Polyline

java.lang.Object
  extended by com.mizar.geometry.Geometry
      extended by com.mizar.geometry.Polyline
All Implemented Interfaces:
OneCell
Direct Known Subclasses:
OrthoPolyline, Polygon

public class Polyline
extends Geometry
implements OneCell


Nested Class Summary
 
Nested classes/interfaces inherited from class com.mizar.geometry.Geometry
Geometry.Results
 
Field Summary
protected static boolean equiangular
           
protected static boolean equilateral
           
protected static boolean orthogonal
           
 
Fields inherited from class com.mizar.geometry.Geometry
defaultOrdinates, dimensions, geographic, LEFTSIDE, maximumCoordinates, mbr, minimumCoordinates, ONLINE, ordinates, precision, results, RIGHTSIDE, SIDE, toStringDecimals
 
Constructor Summary
Polyline()
           
Polyline(double precision)
           
Polyline(double[] ordinates)
           
Polyline(double[] ordinates, double precision)
           
Polyline(double[] ordinates, int dimensions)
           
Polyline(double[] ordinates, int dimensions, double precision)
           
Polyline(Line line)
           
Polyline(java.util.List<Point> points)
           
Polyline(Point start, Point end)
           
 
Method Summary
 void addCoordinate(double[] coordinate)
           
 void addCoordinate(double[] coordinate, int coordinateIndex)
           
 void addPoint(Point point, int coordinateIndex)
           
 Polyline[] breakAtCoordinateIndex(int coordinateIndex)
           
 void changeDimensionality(int dimensionality)
          Converts the geometry entity to a different dimensionality
 Polyline clone(Polyline polyline)
           
 void conflateTo(Polyline guide, double tolerance)
           
 boolean contains(double[] p)
           
 boolean contains(Point p)
           
 boolean contains(Polyline p)
           
 double[] getClosestPoint(double[] point)
           
 int getClosestSegment(double[] point)
           
 double[] getCoordinateOnLine(double[] point)
          TODO:
 double getDistanceTo(double[] p)
           
 double getDistanceTo(Point p)
           
 Point getEndPoint()
           
 Point getEndPointXY()
           
 double getLength()
           
 double getLength3D(double zScale)
           
 Line getLine()
           
 Line getLine(int coordinateIndex)
           
 double[] getLineOrdinates()
           
 double[] getOrdinatesBetween(double[] point1, double[] point2)
          The method finds a sub polyline between two points.
 double[] getPointAsCrowFlies(double distance)
           
static double[] getPointAsCrowFlies(double distance, double[] ordinates, int dim, double precision)
           
 Point getPointAtDistance(double distance)
           
static double[] getPointAtDistance(double distance, double[] ordinates, int dim, double precision)
           
 double[] getRemainingOrdinates(double[] point)
           
 Line getSegmentAtDistance(double distance)
           
static Line getSegmentAtDistance(double distance, double[] ordinates, int dimensions, double precision)
          Determines which segment of a polyline is being traversed when the distance provided is reached.
 Line[] getSegments()
           
 double[] getSelfIntersections()
          TODO:
 double getShortestDistance(double[] point)
           
 Point getStartPoint()
           
 Point getStartPointXY()
           
 java.lang.String getWkt()
           
 boolean hasIntersections(Polyline inPoly)
           
 boolean hasNonconnectingIntersections(Polyline inPoly)
           
 IntersectionInfo[] intersect(Line[] line1, Line[] line2)
           
 IntersectionInfo[] intersect(Polyline inPoly)
           
 boolean isEquiangular()
           
 boolean isEquilateral()
           
 boolean isOrthogonal()
           
 boolean isPointOnLine(double[] point)
           
 boolean isSame(Polyline polyline)
          Extends Geometry.isSame by adding tests for orthogonality, equiangularity, and equilateralarity.
 boolean isSelfIntersecting()
           
 Polyline join(Polyline pline)
          Joins two polylines into one polyline
static double length(double[] ordinates)
           
static double length(double[] ordinates, int dim, double precision)
          Calculates the total length in storage units of a line described by an array or ordinates
 double lengthAlong(double[] myPoint)
           
 double lengthAlong(Point point)
           
 double lengthBetween(double[] point1, double[] point2)
           
 double lengthBetween(int segment1, double[] p1, int segment2, double[] p2)
           
static void main(java.lang.String[] argv)
           
static double[] patch(double[] polyline, double[] reference, double[] replaceWith, int dimensions, double tolerance)
          The method patches Polylines replacing reference coordinates with new coordinates; useful for conflation and partial edge updates.
static Polyline patch(Polyline polyline, Polyline reference, Polyline replaceWith)
           
 void removeCoordinate(int coordinateIndex)
           
 void reverse()
           
static double[] reverse(double[] ordinates, int dimensions)
           
 void setEquiangular(boolean equiangular)
           
 void setEquilateral(boolean equilength)
           
 void setOrthogonal(boolean orthogonal)
           
 void shiftParallel(double distance, double[] side)
           
 void shiftParallel(double distance, double[] side, double startDistance, double endDistance)
           
 void shiftParallel(double distance, Point side)
          The method moves the polyline the given distance parallel to its original
 void shiftParallel(double distance, Point side, int startCoordinate, int endCoordinate)
           
static boolean snap(java.util.ArrayList<OneCell> polylines, double tolerance)
           
static boolean snap(java.util.ArrayList<Point> nodes, java.util.ArrayList<OneCell> polylines, double tolerance)
           
static boolean snap(Point node, OneCell polyline, double tolerance)
          The method snaps the endpoints of polyline if they fall within tolerance of node
static boolean snap(Polyline pl1, Polyline pl2, double tolerance, int method)
          Snaps two polylines so that if one of their sets of endpoints is coincident it makes them exactly the same.
 Polyline[] split(double[] point)
          Creates two polylines from a single polyline breaking the original polyline at a point closest to the point.
 Polyline[] split(Point point)
          Creates two polylines from a single polyline breaking the original polyline at a point closest to the point.
 void thin()
           
 void thin(double precision)
          This is a first pass algorithm that just removes any segment that is shorter than the minimumDistance
static double[] thin(double[] ordinates, int dimensions, double minimumDistance)
           
 void thinSimple(double precision)
          This is a first pass algorithm that just removes any segment that is shorter than the minimumDistance
static double[] thinSimple(double[] ordinates, int dimensions, double minimumDistance)
           
 
Methods inherited from class com.mizar.geometry.Geometry
adjustEndPoints, adjustEndPoints, adjustEndPoints, adjustEndPoints, changeDimensions, computeMbr, computeMbr, computeMbr, computeNearestDistance, computeNearestDistance, connectsTo, connectsTo, connectsTo, connectsTo, constructDefaultPoint, equals, expandMbr, getCoordinate, getCoordinates, getCoordinates, getCoordinates, getCoordinates, getDefaultOrdinates, getDimensions, getEndCoordinateIndex, getFirstPoint, getFirstPoint, getLastPoint, getLastPoint, getLeastDimension, getLeastPrecise, getLength, getMaximumCoordinates, getMbr, getMbrCorner, getMbrCorner, getMinimumCoordinates, getMostPrecise, getNumberOfCoordiates, getOrdinates, getPoints, getPointWithMatchingDimensions, getPrecision, getRange, getRange, getResults, getSegment, getToStringDecimals, getXYCoordinates, getXYCoordinates, hashCode, isCoveredByMbr, isEqualOrBetween, isGeographic, isInsideMbr, isSame, mbrIntersect, mbrOverlap, mbrOverlap, mbrOverlapRatio, mbrValid, polygonizeMbr, quadrant, seedMbr, setCoordinate, setCoordinates, setCoordinates, setDefaultOrdinates, setDimensions, setFirstPoint, setGeographic, setLastPoint, setMaximumCoordinates, setMinimumCoordinates, setOrdinates, setPrecision, setSegment, setToStringDecimals, toString, updateMbr
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.mizar.geometry.OneCell
getDimensions, getFirstPoint, getLastPoint, setFirstPoint, setLastPoint
 

Field Detail

orthogonal

protected static boolean orthogonal

equiangular

protected static boolean equiangular

equilateral

protected static boolean equilateral
Constructor Detail

Polyline

public Polyline()

Polyline

public Polyline(double[] ordinates)
         throws GeometryException
Parameters:
ordinates -
Throws:
GeometryException

Polyline

public Polyline(double[] ordinates,
                int dimensions)
         throws GeometryException
Throws:
GeometryException

Polyline

public Polyline(double precision)
Parameters:
precision -

Polyline

public Polyline(double[] ordinates,
                double precision)
         throws GeometryException
Parameters:
ordinates -
precision -
Throws:
GeometryException

Polyline

public Polyline(double[] ordinates,
                int dimensions,
                double precision)
         throws GeometryException
Throws:
GeometryException

Polyline

public Polyline(Line line)
         throws GeometryException
Parameters:
line -
Throws:
GeometryException

Polyline

public Polyline(Point start,
                Point end)
         throws GeometryException
Throws:
GeometryException

Polyline

public Polyline(java.util.List<Point> points)
         throws GeometryException
Throws:
GeometryException
Method Detail

join

public Polyline join(Polyline pline)
              throws java.lang.Exception
Joins two polylines into one polyline

Parameters:
pline -
Returns:
Throws:
java.lang.Exception

length

public static double length(double[] ordinates,
                            int dim,
                            double precision)
                     throws GeometryException
Calculates the total length in storage units of a line described by an array or ordinates

Parameters:
ordinates - The collection of ordinates which can be split up in to unique points by dividing the array in to groups according to the ordinates arguments
dim - The dimensionality of the ordinates. This method assumes 2D so this should always be 2.
precision - The spatial precision of the data storage units. For example, in the case of latitude and longitude, a precision of 0.000001 at the latitude of Ohio is approximately 2 feet.
Returns:
The total length as a double
Throws:
GeometryException

length

public static double length(double[] ordinates)
                     throws GeometryException
Throws:
GeometryException

getLength

public double getLength()
                 throws GeometryException
Specified by:
getLength in interface OneCell
Overrides:
getLength in class Geometry
Throws:
GeometryException

getSegmentAtDistance

public static Line getSegmentAtDistance(double distance,
                                        double[] ordinates,
                                        int dimensions,
                                        double precision)
                                 throws GeometryException
Determines which segment of a polyline is being traversed when the distance provided is reached. Direction of travel is from start to end point. For example, imagine a polyline is made up of three segments each 50 units long. If the distance being sought is 80, the second segement will be returned because 80 lies between 50 and 100, which are the distance measures of the second segment. If 120 is sought then the third segment will be returned because 120 is between the 100 and 150 distance markers that describe the third segment.

Parameters:
distance -
ordinates -
dimensions -
precision -
Returns:
Throws:
GeometryException

isPointOnLine

public boolean isPointOnLine(double[] point)

getSegmentAtDistance

public Line getSegmentAtDistance(double distance)
                          throws GeometryException
Throws:
GeometryException

contains

public boolean contains(double[] p)
                 throws GeometryException
Throws:
GeometryException

contains

public boolean contains(Point p)
                 throws GeometryException
Throws:
GeometryException

contains

public boolean contains(Polyline p)
                 throws GeometryException
Throws:
GeometryException

getPointAtDistance

public Point getPointAtDistance(double distance)
                         throws GeometryException
Throws:
GeometryException

getPointAtDistance

public static double[] getPointAtDistance(double distance,
                                          double[] ordinates,
                                          int dim,
                                          double precision)
                                   throws GeometryException
Throws:
GeometryException

getPointAsCrowFlies

public double[] getPointAsCrowFlies(double distance)
                             throws GeometryException
Parameters:
distance - the straight line distance to a point on the polyline.
Returns:
the first point on the polyline that is distance from the start of the polyline as a straight line distance.
Throws:
GeometryException
See Also:
getPointAtDistance(double distance, double[] ordinates, int dim, double precision)

getPointAsCrowFlies

public static double[] getPointAsCrowFlies(double distance,
                                           double[] ordinates,
                                           int dim,
                                           double precision)
                                    throws GeometryException
Parameters:
distance - the straight line distance to a point on the polyline.
ordinates -
dim -
precision -
Returns:
the first point on the polyline that is distance from the start of the polyline as a straight line distance.
Throws:
GeometryException
See Also:
getPointAtDistance(double distance, double[] ordinates, int dim, double precision)

getLength3D

public double getLength3D(double zScale)
                   throws GeometryException
Throws:
GeometryException

setOrthogonal

public void setOrthogonal(boolean orthogonal)
Parameters:
orthogonal -

isOrthogonal

public boolean isOrthogonal()
Returns:

setEquiangular

public void setEquiangular(boolean equiangular)
Parameters:
equiangular -

isEquiangular

public boolean isEquiangular()
Returns:

setEquilateral

public void setEquilateral(boolean equilength)
Parameters:
equilength -

isEquilateral

public boolean isEquilateral()
Returns:

getCoordinateOnLine

public double[] getCoordinateOnLine(double[] point)
                             throws GeometryException
TODO:

Parameters:
point -
Returns:
Throws:
GeometryException

getSelfIntersections

public double[] getSelfIntersections()
TODO:

Returns:
an array of ordinates that are points where the polyline intersects itself.

isSelfIntersecting

public boolean isSelfIntersecting()
                           throws GeometryException
Throws:
GeometryException

getSegments

public Line[] getSegments()
                   throws GeometryException
Throws:
GeometryException

intersect

public IntersectionInfo[] intersect(Polyline inPoly)
                             throws GeometryException
Throws:
GeometryException

intersect

public IntersectionInfo[] intersect(Line[] line1,
                                    Line[] line2)
                             throws GeometryException
Throws:
GeometryException

hasNonconnectingIntersections

public boolean hasNonconnectingIntersections(Polyline inPoly)
                                      throws GeometryException
Throws:
GeometryException

hasIntersections

public boolean hasIntersections(Polyline inPoly)
                         throws GeometryException
Throws:
GeometryException

addCoordinate

public void addCoordinate(double[] coordinate,
                          int coordinateIndex)
                   throws GeometryException
Parameters:
coordinate -
coordinateIndex -
Throws:
GeometryException

addCoordinate

public void addCoordinate(double[] coordinate)
                   throws GeometryException
Throws:
GeometryException

addPoint

public void addPoint(Point point,
                     int coordinateIndex)
              throws GeometryException
Parameters:
point -
coordinateIndex -
Throws:
GeometryException

removeCoordinate

public void removeCoordinate(int coordinateIndex)
                      throws GeometryException
Parameters:
coordinateIndex -
Throws:
GeometryException

breakAtCoordinateIndex

public Polyline[] breakAtCoordinateIndex(int coordinateIndex)
                                  throws GeometryException
Parameters:
coordinateIndex -
Returns:
Throws:
GeometryException

split

public Polyline[] split(Point point)
                 throws GeometryException
Creates two polylines from a single polyline breaking the original polyline at a point closest to the point. If the closest point on this polyline to point is one of the endpoints of this polyline then the polyline is copied into the first element of the returned array and the second element of the returned array is null.

Parameters:
point -
Returns:
an array of two Polyline instances
Throws:
GeometryException

split

public Polyline[] split(double[] point)
                 throws GeometryException
Creates two polylines from a single polyline breaking the original polyline at a point closest to the point. If the closest point on this polyline to point is one of the endpoints of this polyline then the polyline is copied into the first element of the returned array and the second element of the returned array is null.

Parameters:
point -
Returns:
an array of two Polyline instances
Throws:
GeometryException

clone

public Polyline clone(Polyline polyline)
               throws GeometryException
Parameters:
polyline -
Returns:
Throws:
GeometryException

getLine

public Line getLine(int coordinateIndex)
             throws GeometryException
Throws:
GeometryException

getStartPoint

public Point getStartPoint()
                    throws GeometryException
Specified by:
getStartPoint in interface OneCell
Throws:
GeometryException

getEndPoint

public Point getEndPoint()
                  throws GeometryException
Specified by:
getEndPoint in interface OneCell
Throws:
GeometryException

getStartPointXY

public Point getStartPointXY()
                      throws GeometryException
Throws:
GeometryException

getEndPointXY

public Point getEndPointXY()
                    throws GeometryException
Throws:
GeometryException

getDistanceTo

public double getDistanceTo(double[] p)
                     throws GeometryException
Throws:
GeometryException

getDistanceTo

public double getDistanceTo(Point p)
                     throws GeometryException
Throws:
GeometryException

getClosestSegment

public int getClosestSegment(double[] point)
                      throws GeometryException
Parameters:
point -
Returns:
the Coordinate index of the segment of the polyline that is closest to the point.
Throws:
GeometryException
See Also:
Polyline#getClosestSegment, Polyline#getShortestDistance, Polyline#getClosestPoint

getShortestDistance

public double getShortestDistance(double[] point)
                           throws GeometryException
Parameters:
point -
Returns:
Throws:
GeometryException

getClosestPoint

public double[] getClosestPoint(double[] point)
                         throws GeometryException
Parameters:
point -
Returns:
Throws:
GeometryException

lengthAlong

public double lengthAlong(Point point)
                   throws GeometryException
Throws:
GeometryException

lengthAlong

public double lengthAlong(double[] myPoint)
                   throws GeometryException
Parameters:
myPoint -
Returns:
Throws:
GeometryException

lengthBetween

public double lengthBetween(double[] point1,
                            double[] point2)
                     throws GeometryException
Parameters:
point1 -
point2 -
Returns:
Throws:
GeometryException

lengthBetween

public double lengthBetween(int segment1,
                            double[] p1,
                            int segment2,
                            double[] p2)
                     throws GeometryException
Parameters:
segment1 -
p1 -
segment2 -
p2 -
Returns:
the area between the closest two points on the line.
Throws:
GeometryException

getOrdinatesBetween

public double[] getOrdinatesBetween(double[] point1,
                                    double[] point2)
                             throws GeometryException
The method finds a sub polyline between two points. If the input points are not very close to the laying on the polyline the results are unpredicatable.

Parameters:
point1 - a point that will be projected to the polyline
point2 - another point that will be projected to the polyline
Returns:
an array of points from polyline between point1 and point2 inclusive of those points
Throws:
GeometryException
See Also:
getClosestPoint(double[])

getRemainingOrdinates

public double[] getRemainingOrdinates(double[] point)
                               throws GeometryException
Parameters:
point -
Returns:
Throws:
GeometryException

reverse

public void reverse()
             throws GeometryException
Throws:
GeometryException

reverse

public static double[] reverse(double[] ordinates,
                               int dimensions)
                        throws GeometryException
Throws:
GeometryException

thin

public static double[] thin(double[] ordinates,
                            int dimensions,
                            double minimumDistance)
                     throws GeometryException
Parameters:
ordinates -
dimensions -
minimumDistance -
Returns:
Throws:
GeometryException
See Also:
thin(double)

thinSimple

public static double[] thinSimple(double[] ordinates,
                                  int dimensions,
                                  double minimumDistance)
                           throws GeometryException
Parameters:
ordinates -
dimensions -
minimumDistance -
Returns:
Throws:
GeometryException
See Also:
thin(double)

thin

public void thin()
          throws GeometryException
Throws:
GeometryException
See Also:
thin(double)

thin

public void thin(double precision)
          throws GeometryException
This is a first pass algorithm that just removes any segment that is shorter than the minimumDistance

Parameters:
precision -
Throws:
GeometryException
See Also:
thin()

thinSimple

public void thinSimple(double precision)
                throws GeometryException
This is a first pass algorithm that just removes any segment that is shorter than the minimumDistance

Parameters:
precision -
Throws:
GeometryException
See Also:
thin()

isSame

public boolean isSame(Polyline polyline)
               throws GeometryException
Extends Geometry.isSame by adding tests for orthogonality, equiangularity, and equilateralarity.

Parameters:
polyline -
Returns:
true if the two Polylines are effectively the same.
Throws:
GeometryException

snap

public static boolean snap(Point node,
                           OneCell polyline,
                           double tolerance)
                    throws GeometryException
The method snaps the endpoints of polyline if they fall within tolerance of node

Parameters:
node -
polyline -
tolerance -
Returns:
Throws:
GeometryException

snap

public static boolean snap(Polyline pl1,
                           Polyline pl2,
                           double tolerance,
                           int method)
                    throws GeometryException
Snaps two polylines so that if one of their sets of endpoints is coincident it makes them exactly the same. Four tests are made comparing the first points, first and last repectively of each polyline and then the last points. If all four points fall within the tolerance all four endpoints will be set to the same "snap" point: garbage in compacted garbage out!

Parameters:
pl1 -
pl2 -
tolerance - if endpoints of pl1 or pl2 are within tolerance move something to co-locate them.
method - 0=move both points to average, 1=snap to pl1, 2=snap to pl2
Returns:
Throws:
GeometryException
See Also:
which does the same thing but differently

snap

public static boolean snap(java.util.ArrayList<OneCell> polylines,
                           double tolerance)
                    throws GeometryException
Throws:
GeometryException

snap

public static boolean snap(java.util.ArrayList<Point> nodes,
                           java.util.ArrayList<OneCell> polylines,
                           double tolerance)
                    throws GeometryException
Throws:
GeometryException

patch

public static Polyline patch(Polyline polyline,
                             Polyline reference,
                             Polyline replaceWith)
                      throws GeometryException
Parameters:
polyline - Original polyline
reference - Polyline to find
replaceWith - Replacement polyline
Returns:
Throws:
GeometryException - if dimensions mismatch or @{link Polyline#reverse Polyline.reverse} fails
See Also:
patch(double[],double[],double[],int,double)

patch

public static double[] patch(double[] polyline,
                             double[] reference,
                             double[] replaceWith,
                             int dimensions,
                             double tolerance)
                      throws GeometryException
The method patches Polylines replacing reference coordinates with new coordinates; useful for conflation and partial edge updates. If the reference polyline is in reverse order then the replacement will be swapped into reverse order

Parameters:
polyline - polyline ordinates to be updated
reference - a set of polyline ordinates to be replaced
replaceWith - a set ordinates to insert into polyline
dimensions -
tolerance -
Returns:
Throws:
GeometryException - by @{link Polyline#reverse Polyline.reverse}

getWkt

public java.lang.String getWkt()

changeDimensionality

public void changeDimensionality(int dimensionality)
                          throws GeometryException
Description copied from interface: OneCell
Converts the geometry entity to a different dimensionality

Specified by:
changeDimensionality in interface OneCell
Parameters:
dimensionality - new dimension number if dimensions is less than current dimensionality then excess points are thrown away if dimensions is greater than current dimensionality then points are added as needed and set to 0 The function has no effect if dimensions = dimensionality
Throws:
GeometryException

getLineOrdinates

public double[] getLineOrdinates()
                          throws GeometryException
Throws:
GeometryException

getLine

public Line getLine()
             throws GeometryException
Throws:
GeometryException

main

public static void main(java.lang.String[] argv)
                 throws GeometryException
Throws:
GeometryException

conflateTo

public void conflateTo(Polyline guide,
                       double tolerance)
Parameters:
guide -
tolerance -
Since:
planned The method conflates the polyline to a guide polyline where the guide polyline is within the tolerance. Where conflation occurs the vertices of the new polyline will be identical to the verticies of the guide polyline.

shiftParallel

public void shiftParallel(double distance,
                          Point side)
The method moves the polyline the given distance parallel to its original

Parameters:
distance -
side -
Since:
planned

shiftParallel

public void shiftParallel(double distance,
                          double[] side)
Parameters:
distance -
side -
Since:
planned

shiftParallel

public void shiftParallel(double distance,
                          Point side,
                          int startCoordinate,
                          int endCoordinate)
Parameters:
distance -
side -
startCoordinate -
endCoordinate -
Since:
planned

shiftParallel

public void shiftParallel(double distance,
                          double[] side,
                          double startDistance,
                          double endDistance)
Parameters:
distance -
side -
startDistance -
endDistance -
Since:
planned
See Also:
shiftParallel(double,Point,int,int)