Class LengthMeasurer
- java.lang.Object
-
- gov.nasa.worldwind.util.measure.LengthMeasurer
-
- All Implemented Interfaces:
MeasurableLength
- Direct Known Subclasses:
AreaMeasurer
public class LengthMeasurer extends java.lang.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 - AVKey.LINEAR, AVKey.RHUMB_LINE or AVKey.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 the 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 minimum sampling interval is 30 meters.
- See Also:
MeasureTool
-
-
Field Summary
Fields Modifier and Type Field Description protected double
length
-
Constructor Summary
Constructors Constructor Description LengthMeasurer()
LengthMeasurer(java.util.ArrayList<? extends Position> positions)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
clearCachedValues()
protected double
computeLength(Globe globe, boolean followTerrain)
java.lang.String
getAVKeyPathType()
Get the type of path used when subdividing long segments, one of AVKey.GREAT_CIRCLE, which draws segments as a great circle, AVKey.LINEAR, which determines the intermediate positions between segments by interpolating the segment endpoints, or AVKey.RHUMB_LINE, which draws segments as a line of constant heading.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.java.util.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(java.lang.String pathType)
Sets the type of path used when subdividing long segments, one of AVKey.GREAT_CIRCLE, which draws segments as a great circle, AVKey.LINEAR, which determines the intermediate positions between segments by interpolating the segment endpoints, or AVKey.RHUMB_LINE, which draws segments as a line of constant heading.void
setPositions(java.lang.Iterable<? extends Position> positions)
void
setPositions(java.util.ArrayList<? extends LatLon> positions, double elevation)
void
setPositions(java.util.ArrayList<? extends Position> positions)
protected static java.util.ArrayList<? extends Position>
subdividePositions(Globe globe, java.util.ArrayList<? extends Position> positions, double maxLength, boolean followTerrain, java.lang.String avkeyPathType)
Subdivide a list of positions so that no segment is longer then the provided maxLength.protected static java.util.ArrayList<? extends Position>
subdividePositions(Globe globe, java.util.ArrayList<? extends Position> positions, double maxLength, boolean followTerrain, java.lang.String pathType, int start, int count)
Subdivide a list of positions so that no segment is longer then the provided maxLength.
-
-
-
Constructor Detail
-
LengthMeasurer
public LengthMeasurer()
-
LengthMeasurer
public LengthMeasurer(java.util.ArrayList<? extends Position> positions)
-
-
Method Detail
-
clearCachedValues
protected void clearCachedValues()
-
getPositions
public java.util.ArrayList<? extends Position> getPositions()
-
setPositions
public void setPositions(java.util.ArrayList<? extends LatLon> positions, double elevation)
-
setPositions
public void setPositions(java.lang.Iterable<? extends Position> positions)
-
setPositions
public void setPositions(java.util.ArrayList<? extends Position> positions)
-
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.
-
getAVKeyPathType
public java.lang.String getAVKeyPathType()
Get the type of path used when subdividing long segments, one of AVKey.GREAT_CIRCLE, which draws segments as a great circle, AVKey.LINEAR, which determines the intermediate positions between segments by interpolating the segment endpoints, or AVKey.RHUMB_LINE, which draws segments as a line of constant heading.- Returns:
- The path type
-
setPathType
public void setPathType(java.lang.String pathType)
Sets the type of path used when subdividing long segments, one of AVKey.GREAT_CIRCLE, which draws segments as a great circle, AVKey.LINEAR, which determines the intermediate positions between segments by interpolating the segment endpoints, or AVKey.RHUMB_LINE, which draws segments as a line of constant heading.- Parameters:
pathType
- the type of path to measure.
-
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.
-
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.
-
getBoundingSector
public Sector getBoundingSector()
-
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.
-
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.
-
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.
-
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 interfaceMeasurableLength
- Parameters:
globe
- the globe to draw terrain information from.- Returns:
- the current path length or -1 if the position list is too short.
-
computeLength
protected double computeLength(Globe globe, boolean followTerrain)
-
subdividePositions
protected static java.util.ArrayList<? extends Position> subdividePositions(Globe globe, java.util.ArrayList<? extends Position> positions, double maxLength, boolean followTerrain, java.lang.String avkeyPathType)
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 AVKey.LINEAR, AVKey.RHUMB_LINE or AVKey.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 listmaxLength
- the maximum length for one segment.followTerrain
- true if the positions should be on the terrain surface.avkeyPathType
- 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 java.util.ArrayList<? extends Position> subdividePositions(Globe globe, java.util.ArrayList<? extends Position> positions, double maxLength, boolean followTerrain, java.lang.String 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 AVKey.LINEAR, AVKey.RHUMB_LINE or AVKey.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 listmaxLength
- 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 index 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.
-
-