public Coordinate getCoordOnEdge(Vector obsPoint) {
   if (this == InferredEdge.emptyEdge) return null;
   final Coordinate revObsPoint = new Coordinate(obsPoint.getElement(1), obsPoint.getElement(0));
   final LinearLocation here = locationIndexedLine.project(revObsPoint);
   final Coordinate pointOnLine = locationIndexedLine.extractPoint(here);
   final Coordinate revOnLine = new Coordinate(pointOnLine.y, pointOnLine.x);
   return revOnLine;
 }
  /** Splits the input geometry into two LineStrings at a fraction of the distance covered. */
  public static P2<LineString> splitGeometryAtFraction(Geometry geometry, double fraction) {
    LineString empty = new LineString(null, gf);
    Coordinate[] coordinates = geometry.getCoordinates();
    CoordinateSequence sequence = gf.getCoordinateSequenceFactory().create(coordinates);
    LineString total = new LineString(sequence, gf);

    if (coordinates.length < 2) return new P2<LineString>(empty, empty);
    if (fraction <= 0) return new P2<LineString>(empty, total);
    if (fraction >= 1) return new P2<LineString>(total, empty);

    double totalDistance = total.getLength();
    double requestedDistance = totalDistance * fraction;

    // An index in JTS can actually refer to any point along the line. It is NOT an array index.
    LocationIndexedLine line = new LocationIndexedLine(geometry);
    LinearLocation l = LengthLocationMap.getLocation(geometry, requestedDistance);

    LineString beginning = (LineString) line.extractLine(line.getStartIndex(), l);
    LineString ending = (LineString) line.extractLine(l, line.getEndIndex());

    return new P2<LineString>(beginning, ending);
  }
Exemplo n.º 3
0
  /**
   * 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);
    }
  }
  /** Splits the input geometry into two LineStrings at the given point. */
  public static P2<LineString> splitGeometryAtPoint(Geometry geometry, Coordinate nearestPoint) {
    // An index in JTS can actually refer to any point along the line. It is NOT an array index.
    LocationIndexedLine line = new LocationIndexedLine(geometry);
    LinearLocation l = line.indexOf(nearestPoint);

    LineString beginning = (LineString) line.extractLine(line.getStartIndex(), l);
    LineString ending = (LineString) line.extractLine(l, line.getEndIndex());

    return new P2<LineString>(beginning, ending);
  }
 /**
  * Get the snapped location in projected/euclidean coordinates for the given obsPoint (in
  * lat/lon).
  *
  * @param obsPoint
  * @return
  */
 public Vector getPointOnEdge(Coordinate obsPoint) {
   if (this == InferredEdge.emptyEdge) return null;
   final LinearLocation here = locationIndexedLine.project(obsPoint);
   final Coordinate pointOnLine = locationIndexedLine.extractPoint(here);
   return VectorFactory.getDefault().createVector2D(pointOnLine.x, pointOnLine.y);
 }