Esempio n. 1
0
  /** @see java.awt.geom.PathIterator#currentSegment(double[]) */
  public int currentSegment(double[] coords) {
    if (currentCoord == 0) {
      coords[0] = (double) coordinates.getX(0);
      coords[1] = (double) coordinates.getY(0);
      at.transform(coords, 0, coords, 0, 1);
      return SEG_MOVETO;
    } else if ((currentCoord == coordinateCount) && isClosed) {
      return SEG_CLOSE;
    } else {
      coords[0] = coordinates.getX(currentCoord);
      coords[1] = coordinates.getY(currentCoord);
      at.transform(coords, 0, coords, 0, 1);

      return SEG_LINETO;
    }
  }
Esempio n. 2
0
  /**
   * Converts a JTS {@link Polygon}, which represents a ROI, int an AWT {@link java.awt.Polygon} by
   * means of the provided {@link MathTransform}.
   *
   * <p>It also stores the points for this polygon into the provided {@link List}.
   *
   * @param roiInput the input ROI as a JTS {@link Polygon}.
   * @param worldToGridTransform the {@link MathTransform} to apply to the input ROI.
   * @param points a {@link List} that should hold the transformed points.
   * @return an AWT {@link java.awt.Polygon}.
   * @throws TransformException in case the provided {@link MathTransform} chokes.
   */
  public static java.awt.Polygon convertPolygonToPointArray(
      final Polygon roiInput, MathTransform worldToGridTransform, List<Point2D> points)
      throws TransformException {
    final boolean isIdentity = worldToGridTransform.isIdentity();
    final double coords[] = new double[2];
    final LineString exteriorRing = roiInput.getExteriorRing();
    final CoordinateSequence exteriorRingCS = exteriorRing.getCoordinateSequence();
    final int numCoords = exteriorRingCS.size();
    final java.awt.Polygon retValue = new java.awt.Polygon();
    for (int i = 0; i < numCoords; i++) {
      // get the actual coord
      coords[0] = exteriorRingCS.getX(i);
      coords[1] = exteriorRingCS.getY(i);

      // transform it
      if (!isIdentity) worldToGridTransform.transform(coords, 0, coords, 0, 1);

      // send it back to the returned polygon
      final int x = (int) (coords[0] + 0.5d);
      final int y = (int) (coords[1] + 0.5d);
      if (points != null) points.add(new Point2D.Double(coords[0], coords[1]));

      // send it back to the returned polygon
      retValue.addPoint(x, y);
    }

    // return the created polygon.
    return retValue;
  }
Esempio n. 3
0
  /**
   * Write the coordinates of a geometry
   *
   * @param coords The coordinates to write
   * @return this
   * @throws JSONException
   */
  private JSONBuilder writeCoordinates(CoordinateSequence coords) throws JSONException {
    this.array();

    // guess the dimension of the coordinate sequence
    int dim = CoordinateSequences.coordinateDimension(coords);

    final int coordCount = coords.size();
    for (int i = 0; i < coordCount; i++) {
      if (dim > 2) {
        writeCoordinate(coords.getX(i), coords.getY(i), coords.getOrdinate(i, 2));
      } else {
        writeCoordinate(coords.getX(i), coords.getY(i));
      }
    }

    return this.endArray();
  }
Esempio n. 4
0
  /**
   * Moves the iterator to the next segment of the path forwards along the primary direction of
   * traversal as long as there are more points in that direction.
   */
  public void next() {
    if (((currentCoord == (coordinateCount - 1)) && !isClosed)
        || ((currentCoord == coordinateCount) && isClosed)) {
      done = true;
    } else {
      if (generalize) {
        if (Float.isNaN(oldX)) {
          currentCoord++;
          oldX = (float) coordinates.getX(currentCoord);
          oldY = (float) coordinates.getY(currentCoord);
        } else {
          float distx = 0;
          float disty = 0;
          float x = 0;
          float y = 0;

          do {
            currentCoord++;
            x = (float) coordinates.getX(currentCoord);
            y = (float) coordinates.getY(currentCoord);

            if (currentCoord < coordinateCount) {
              distx = Math.abs(x - oldX);
              disty = Math.abs(y - oldY);
            }
          } while (((distx * xScale) < maxDistance)
              && ((disty * yScale) < maxDistance)
              && ((!isClosed && (currentCoord < (coordinateCount - 1)))
                  || (isClosed && (currentCoord < coordinateCount))));

          oldX = x;
          oldY = y;
        }
      } else {
        currentCoord++;
      }
    }
  }
Esempio n. 5
0
  @Override
  protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) {

    int n = coords.size();
    Coordinate outCoords[] = new Coordinate[n];
    int outIndex = 0;

    for (int i = 0; i != n; ++i) {
      Point px = map.fromLatLngToPixel(new AiLatLng(coords.getY(i), coords.getX(i)));
      outCoords[outIndex] = new Coordinate(px.getDoubleX(), px.getDoubleY());
      outIndex++;
    }
    return new CoordinateArraySequence(Arrays.copyOf(outCoords, outIndex));
  }
  /**
   *
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
    CoordinateReferenceSystem crs = GML3ParsingUtils.crs(node);

    if (node.getChild("lowerCorner") != null) {
      DirectPosition l = (DirectPosition) node.getChildValue("lowerCorner");
      DirectPosition u = (DirectPosition) node.getChildValue("upperCorner");

      return new ReferencedEnvelope(
          l.getOrdinate(0), u.getOrdinate(0), l.getOrdinate(1), u.getOrdinate(1), crs);
    }

    if (node.hasChild(Coordinate.class)) {
      List c = node.getChildValues(Coordinate.class);
      Coordinate c1 = (Coordinate) c.get(0);
      Coordinate c2 = (Coordinate) c.get(1);

      return new ReferencedEnvelope(c1.x, c2.x, c1.y, c2.y, crs);
    }

    if (node.hasChild(DirectPosition.class)) {
      List dp = node.getChildValues(DirectPosition.class);
      DirectPosition dp1 = (DirectPosition) dp.get(0);
      DirectPosition dp2 = (DirectPosition) dp.get(1);

      return new ReferencedEnvelope(
          dp1.getOrdinate(0), dp2.getOrdinate(0), dp1.getOrdinate(1), dp2.getOrdinate(1), crs);
    }

    if (node.hasChild(CoordinateSequence.class)) {
      CoordinateSequence seq = (CoordinateSequence) node.getChildValue(CoordinateSequence.class);

      return new ReferencedEnvelope(seq.getX(0), seq.getX(1), seq.getY(0), seq.getY(1), crs);
    }

    return null;
  }
  public static double getLengthMultiplierFromElevation(CoordinateSequence elev) {

    double trueLength = 0;
    double flatLength = 0;
    double lastX = elev.getX(0);
    double lastY = elev.getY(0);
    for (int i = 1; i < elev.size(); ++i) {
      Coordinate c = elev.getCoordinate(i);
      double x = c.x - lastX;
      double y = c.y - lastY;
      trueLength += Math.sqrt(x * x + y * y);
      flatLength += x;
      lastX = c.x;
      lastY = c.y;
    }
    if (flatLength == 0) {
      return 0;
    }
    return trueLength / flatLength;
  }