예제 #1
0
  /**
   * Each edge will be built with 2 coordinates.
   *
   * @param intersectingLineStrings The geometry which edges will be based on.
   * @param onLoc position for ON.
   * @param leftLoc position for LEFT.
   * @param rightLoc position for RIGHT.
   */
  private void insertEdge(
      final Geometry intersectingLineStrings,
      final Geometry holeGeometries,
      final int onLoc,
      final int leftLoc,
      final int rightLoc) {

    for (int i = 0; i < intersectingLineStrings.getNumGeometries(); i++) {

      Geometry intersectingSegment = intersectingLineStrings.getGeometryN(i);

      if ((intersectingSegment.getNumPoints() == 2) && !holeGeometries.isEmpty()) {
        // special case, when the line has 2 coordinates and
        // its orientation can't be calculated because it hasn't.
        intersectingSegment = adjustSegmentToHoleDirection(intersectingSegment, holeGeometries);
      }

      Coordinate[] coords = intersectingSegment.getCoordinates();
      for (int j = 0; j < coords.length - 1; j++) {

        final SplitEdge edge =
            SplitEdge.newInstance(coords[j], coords[j + 1], onLoc, leftLoc, rightLoc);

        // add the list that only contains one edge because it will
        // create 2 directedEdge.
        this.graph.addEdge(edge);
      }
    }
  }
예제 #2
0
 private String geometrySignature(Geometry geom) {
   if (geom == null) return "";
   String sig = geom.getGeometryType();
   if (geom instanceof GeometryCollection) {
     sig += "[" + geom.getNumGeometries() + "]";
   } else {
     sig += "(" + geom.getNumPoints() + ")";
   }
   return sig;
 }
예제 #3
0
파일: Geo.java 프로젝트: runeengh/basex
  /**
   * Returns the nth point of a line.
   *
   * @param node xml element containing gml object(s)
   * @param number index of i-th point
   * @return n-th point as a gml element
   * @throws QueryException query exception
   */
  @Deterministic
  public ANode pointN(final ANode node, final Int number) throws QueryException {
    final Geometry geo = geo(node, Q_GML_LINEARRING, Q_GML_LINESTRING);
    if (geo == null && checkGeo(node) != null)
      throw GeoErrors.geoType(node.qname().local(), "Line");

    final int max = geo.getNumPoints();
    final long n = number.itr();
    if (n < 1 || n > max) throw GeoErrors.outOfRangeIdx(number);

    return gmlWriter(((LineString) geo).getPointN((int) n - 1));
  }
예제 #4
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);
    }
  }
예제 #5
0
 /**
  * @param lineg
  * @param g
  * @return
  */
 private boolean equalsExactBackwards(Geometry lineg, Geometry g) {
   if (lineg.getNumPoints() != g.getNumPoints()) return false;
   return reverse((LineString) g).equalsExact(lineg);
 }