/* computes the distance, in meters, along a geometry */ protected static double distanceAlongGeometry( Geometry geometry, LinearLocation startIndex, LinearLocation endIndex) { if (endIndex == null) { endIndex = LinearLocation.getEndLocation(geometry); } double total = 0; LinearIterator it = new LinearIterator(geometry, startIndex); LinearLocation index = startIndex; Coordinate previousCoordinate = startIndex.getCoordinate(geometry); it.next(); index = it.getLocation(); while (index.compareTo(endIndex) < 0) { Coordinate thisCoordinate = index.getCoordinate(geometry); double distance = SphericalDistanceLibrary.fastDistance(previousCoordinate, thisCoordinate); total += distance; previousCoordinate = thisCoordinate; if (!it.hasNext()) break; it.next(); index = it.getLocation(); } // now, last bit of last segment Coordinate finalCoordinate = endIndex.getCoordinate(geometry); total += SphericalDistanceLibrary.distance(previousCoordinate, finalCoordinate); return total; }
/** * Calculates the width of a point if it is not set in the gaf file.<br> * For PP points, it is just the distance to the first point.<br> * For non-pp points, it is the station of the point projected to the pp-line. */ private BigDecimal getOrCalculatePoint( final GafPart gafPart, final GafPoint gafPoint, final GafPart projectionPart) { final BigDecimal width = gafPoint.getWidth(); if (width != null) return width; final com.vividsolutions.jts.geom.Point location = gafPoint.getPoint(); if (GafKind.P.equals(gafPart.getKind()) || projectionPart == null) { return calculateWidthFromDistance(gafPart, location); } else { final Geometry line = projectionPart.getLine(m_dbType); if (!(line instanceof LineString) || line.getNumPoints() < 2) return calculateWidthFromDistance(gafPart, location); final LineString ls = (LineString) line; final LocationIndexedLine lineRef = new LocationIndexedLine(line); final LinearLocation loc = lineRef.project(location.getCoordinate()); final Coordinate closestPt = loc.getCoordinate(line); final double distance = ls.getCoordinateN(0).distance(closestPt); return new BigDecimal(distance).setScale(3, BigDecimal.ROUND_HALF_UP); } }