kiwi-postgis  Version 0.1.0.0
LengthToPoint Class Reference

Computes the length along a LineString to the point on the line nearest a given point. More...

Collaboration diagram for LengthToPoint:

Public Member Functions

 LengthToPoint (LineString line, Coordinate inputPt)
 
double getLength ()
 

Static Public Member Functions

static double lengthAlongSegment (LineSegment seg, Coordinate pt)
 
static double length (LineString line, Coordinate inputPt)
 Computes the length along a LineString to the point on the line nearest a given point. More...
 

Private Member Functions

void computeLength (LineString line, Coordinate inputPt)
 
void updateLength (LineSegment seg, Coordinate inputPt, double segStartLocationDistance)
 

Private Attributes

double minDistanceToPoint
 
double locationLength
 

Detailed Description

Computes the length along a LineString to the point on the line nearest a given point.

Constructor & Destructor Documentation

◆ LengthToPoint()

LengthToPoint ( LineString  line,
Coordinate  inputPt 
)

References LengthToPoint.computeLength().

Referenced by LengthToPoint.length().

41  {
42  computeLength(line, inputPt);
43  }
void computeLength(LineString line, Coordinate inputPt)
Definition: locationtech/jump/algorithm/LengthToPoint.java:50

Member Function Documentation

◆ computeLength()

void computeLength ( LineString  line,
Coordinate  inputPt 
)
private

References LengthToPoint.updateLength().

Referenced by LengthToPoint.LengthToPoint().

51  {
52  minDistanceToPoint = Double.MAX_VALUE;
53  double baseLocationDistance = 0.0;
54  Coordinate[] pts = line.getCoordinates();
55  LineSegment seg = new LineSegment();
56  for (int i = 0; i < pts.length - 1; i++) {
57  seg.p0 = pts[i];
58  seg.p1 = pts[i + 1];
59  updateLength(seg, inputPt, baseLocationDistance);
60  baseLocationDistance += seg.getLength();
61 
62  }
63  }
double minDistanceToPoint
Definition: locationtech/jump/algorithm/LengthToPoint.java:37
void updateLength(LineSegment seg, Coordinate inputPt, double segStartLocationDistance)
Definition: locationtech/jump/algorithm/LengthToPoint.java:65

◆ getLength()

double getLength ( )

References LengthToPoint.locationLength.

Referenced by LengthToPoint.length().

46  {
47  return locationLength;
48  }
double locationLength
Definition: locationtech/jump/algorithm/LengthToPoint.java:38

◆ length()

static double length ( LineString  line,
Coordinate  inputPt 
)
static

Computes the length along a LineString to the point on the line nearest a given point.

References LengthToPoint.getLength(), and LengthToPoint.LengthToPoint().

32  {
33  LengthToPoint lp = new LengthToPoint(line, inputPt);
34  return lp.getLength();
35  }
LengthToPoint(LineString line, Coordinate inputPt)
Definition: locationtech/jump/algorithm/LengthToPoint.java:40

◆ lengthAlongSegment()

static double lengthAlongSegment ( LineSegment  seg,
Coordinate  pt 
)
static
16  {
17  double projFactor = seg.projectionFactor(pt);
18  double len = 0.0;
19  if (projFactor <= 0.0)
20  len = 0.0;
21  else if (projFactor <= 1.0)
22  len = projFactor * seg.getLength();
23  else
24  len = seg.getLength();
25  return len;
26  }

◆ updateLength()

void updateLength ( LineSegment  seg,
Coordinate  inputPt,
double  segStartLocationDistance 
)
private

Referenced by LengthToPoint.computeLength().

66  {
67  double dist = seg.distance(inputPt);
68  if (dist > minDistanceToPoint) return;
69  minDistanceToPoint = dist;
70  // found new minimum, so compute location distance of point
71  double projFactor = seg.projectionFactor(inputPt);
72  if (projFactor <= 0.0)
73  locationLength = segStartLocationDistance;
74  else if (projFactor <= 1.0)
75  locationLength = segStartLocationDistance + projFactor * seg.getLength();
76  else
77  locationLength = segStartLocationDistance + seg.getLength();
78  }
double minDistanceToPoint
Definition: locationtech/jump/algorithm/LengthToPoint.java:37
double locationLength
Definition: locationtech/jump/algorithm/LengthToPoint.java:38

Member Data Documentation

◆ locationLength

double locationLength
private

Referenced by LengthToPoint.getLength().

◆ minDistanceToPoint

double minDistanceToPoint
private