NASA World Wind

gov.nasa.worldwind.util.measure
Class LengthMeasurer

java.lang.Object
  extended by gov.nasa.worldwind.util.measure.LengthMeasurer
All Implemented Interfaces:
MeasurableLength
Direct Known Subclasses:
AreaMeasurer

public class LengthMeasurer
extends Object
implements MeasurableLength

Utility class to measure length along a path on a globe.

The measurer must be provided a list of at least two positions to be able to compute a distance.

Segments which are longer then the current maxSegmentLength will be subdivided along lines following the current pathType - Polyline.LINEAR, Polyline.RHUMB_LINE or Polyline.GREAT_CIRCLE.

If the measurer is set to follow terrain, the computed length will account for terrain deformations as if someone was walking along that path. Otherwise the length is the sum of the cartesian distance between each positions.

When following terrain the measurer will sample terrain elevations at regular intervals along the path. The minimum number of samples used for the whole length can be set with setLengthTerrainSamplingSteps(). However, the sampling process will keep a minimum interval of 30 meters between samples.

See Also:
MeasureTool

Field Summary
protected  double length
           
 
Constructor Summary
LengthMeasurer()
           
LengthMeasurer(ArrayList<? extends Position> positions)
           
 
Method Summary
protected  void clearCachedValues()
           
protected  double computeLength(Globe globe, boolean followTerrain)
           
 Sector getBoundingSector()
           
 double getLength(Globe globe)
          Get the path length in meter.
 double getLengthTerrainSamplingSteps()
          Get the number of terrain elevation samples used along the path to approximate it's terrain following length.
 double getMaxSegmentLength()
          Get the maximum length a segment can have before being subdivided along a line following the current pathType.
 int getPathType()
           
 ArrayList<? extends Position> getPositions()
           
 boolean isClosedShape()
          Returns true if the current position list describe a closed path - one which last position is equal to the first.
 boolean isFollowTerrain()
           
 void setFollowTerrain(boolean followTerrain)
          Set whether measurements should account for terrain deformations.
 void setLengthTerrainSamplingSteps(double steps)
          Set the number of terrain elevation samples to be used along the path to approximate it's terrain following length.
 void setMaxSegmentLength(double length)
          Set the maximum length a segment can have before being subdivided along a line following the current pathType.
 void setPathType(int pathType)
          Sets the type of path used when subdividing long segments, one of Polyline.GREAT_CIRCLE, which draws segments as a great circle, Polyline.LINEAR, which determines the intermediate positions between segments by interpolating the segment endpoints, or Polyline.RHUMB_LINE, which draws segments as a line of constant heading.
 void setPositions(ArrayList<? extends LatLon> positions, double elevation)
           
 void setPositions(ArrayList<? extends Position> positions)
           
protected static ArrayList<? extends Position> subdividePositions(Globe globe, ArrayList<? extends Position> positions, double maxLength, boolean followTerrain, int pathType)
          Subdivide a list of positions so that no segment is longer then the provided maxLength.
protected static ArrayList<? extends Position> subdividePositions(Globe globe, ArrayList<? extends Position> positions, double maxLength, boolean followTerrain, int pathType, int start, int count)
          Subdivide a list of positions so that no segment is longer then the provided maxLength.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

length

protected double length
Constructor Detail

LengthMeasurer

public LengthMeasurer()

LengthMeasurer

public LengthMeasurer(ArrayList<? extends Position> positions)
Method Detail

clearCachedValues

protected void clearCachedValues()

computeLength

protected double computeLength(Globe globe,
                               boolean followTerrain)

getBoundingSector

public Sector getBoundingSector()

getLength

public double getLength(Globe globe)
Get the path length in meter.

If the measurer is set to follow terrain, the computed length will account for terrain deformations as if someone was walking along that path. Otherwise the length is the sum of the cartesian distance between each positions.

Specified by:
getLength in interface MeasurableLength
Parameters:
globe - the globe to draw terrain information from.
Returns:
the current path length or -1 if the position list is too short.

getLengthTerrainSamplingSteps

public double getLengthTerrainSamplingSteps()
Get the number of terrain elevation samples used along the path to approximate it's terrain following length.

Returns:
the number of terrain elevation samples used.

getMaxSegmentLength

public double getMaxSegmentLength()
Get the maximum length a segment can have before being subdivided along a line following the current pathType.

Returns:
the maximum length a segment can have before being subdivided.

getPathType

public int getPathType()

getPositions

public ArrayList<? extends Position> getPositions()

isClosedShape

public boolean isClosedShape()
Returns true if the current position list describe a closed path - one which last position is equal to the first.

Returns:
true if the current position list describe a closed path.

isFollowTerrain

public boolean isFollowTerrain()

setFollowTerrain

public void setFollowTerrain(boolean followTerrain)
Set whether measurements should account for terrain deformations.

Parameters:
followTerrain - set to true if measurements should account for terrain deformations.

setLengthTerrainSamplingSteps

public void setLengthTerrainSamplingSteps(double steps)
Set the number of terrain elevation samples to be used along the path to approximate it's terrain following length.

Parameters:
steps - the number of terrain elevation samples to be used.

setMaxSegmentLength

public void setMaxSegmentLength(double length)
Set the maximum length a segment can have before being subdivided along a line following the current pathType.

Parameters:
length - the maximum length a segment can have before being subdivided.

setPathType

public void setPathType(int pathType)
Sets the type of path used when subdividing long segments, one of Polyline.GREAT_CIRCLE, which draws segments as a great circle, Polyline.LINEAR, which determines the intermediate positions between segments by interpolating the segment endpoints, or Polyline.RHUMB_LINE, which draws segments as a line of constant heading.

Parameters:
pathType - the type of path to measure.

setPositions

public void setPositions(ArrayList<? extends LatLon> positions,
                         double elevation)

setPositions

public void setPositions(ArrayList<? extends Position> positions)

subdividePositions

protected static ArrayList<? extends Position> subdividePositions(Globe globe,
                                                                  ArrayList<? extends Position> positions,
                                                                  double maxLength,
                                                                  boolean followTerrain,
                                                                  int pathType)
Subdivide a list of positions so that no segment is longer then the provided maxLength.

If needed, new intermediate positions will be created along lines that follow the given pathType - one of Polyline.LINEAR, Polyline.RHUMB_LINE or Polyline.GREAT_CIRCLE. All position elevations will be either at the terrain surface if followTerrain is true, or interpolated according to the original elevations.

Parameters:
globe - the globe to draw elevations and points from.
positions - the original position list
maxLength - the maximum length for one segment.
followTerrain - true if the positions should be on the terrain surface.
pathType - the type of path to use in between two positions.
Returns:
a list of positions with no segment longer then maxLength and elevations following terrain or not.

subdividePositions

protected static ArrayList<? extends Position> subdividePositions(Globe globe,
                                                                  ArrayList<? extends Position> positions,
                                                                  double maxLength,
                                                                  boolean followTerrain,
                                                                  int pathType,
                                                                  int start,
                                                                  int count)
Subdivide a list of positions so that no segment is longer then the provided maxLength. Only the positions between start and start + count - 1 will be processed.

If needed, new intermediate positions will be created along lines that follow the given pathType - one of Polyline.LINEAR, Polyline.RHUMB_LINE or Polyline.GREAT_CIRCLE. All position elevations will be either at the terrain surface if followTerrain is true, or interpolated according to the original elevations.

Parameters:
globe - the globe to draw elevations and points from.
positions - the original position list
maxLength - the maximum length for one segment.
followTerrain - true if the positions should be on the terrain surface.
pathType - the type of path to use in between two positions.
start - the first position indice in the original list.
count - how many positions from the original list have to be processed and returned.
Returns:
a list of positions with no segment longer then maxLength and elevations following terrain or not.

NASA World Wind