ofLine static method
Computes the length of a linestring specified by a sequence of points.
@param pts the points specifying the linestring @return the length of the linestring
Implementation
static double ofLine(CoordinateSequence pts) {
// optimized for processing CoordinateSequences
int n = pts.size();
if (n <= 1) return 0.0;
double len = 0.0;
Coordinate p = new Coordinate.empty2D();
pts.getCoordinateInto(0, p);
double x0 = p.x;
double y0 = p.y;
for (int i = 1; i < n; i++) {
pts.getCoordinateInto(i, p);
double x1 = p.x;
double y1 = p.y;
double dx = x1 - x0;
double dy = y1 - y0;
len += math.sqrt(dx * dx + dy * dy);
x0 = x1;
y0 = y1;
}
return len;
}