public static double diagonalSize(Envelope env) {
    if (env.isNull()) return 0.0;

    double width = env.getWidth();
    double hgt = env.getHeight();
    return Math.sqrt(width * width + hgt * hgt);
  }
  /**
   * Creates a elliptical arc, as a LineString.
   *
   * @return an elliptical arc
   */
  public LineString createArc(double startAng, double endAng) {
    Envelope env = dim.getEnvelope();
    double xRadius = env.getWidth() / 2.0;
    double yRadius = env.getHeight() / 2.0;

    double centreX = env.getMinX() + xRadius;
    double centreY = env.getMinY() + yRadius;

    double angSize = (endAng - startAng);
    if (angSize <= 0.0 || angSize > 2 * Math.PI) angSize = 2 * Math.PI;
    double angInc = angSize / nPts;

    Coordinate[] pts = new Coordinate[nPts];
    int iPt = 0;
    for (int i = 0; i < nPts; i++) {
      double ang = startAng + i * angInc;
      double x = xRadius * Math.cos(ang) + centreX;
      double y = yRadius * Math.sin(ang) + centreY;
      Coordinate pt = new Coordinate(x, y);
      geomFact.getPrecisionModel().makePrecise(pt);
      pts[iPt++] = pt;
    }
    LineString line = geomFact.createLineString(pts);
    return line;
  }
Exemplo n.º 3
0
 /** Compute the parameters need to create each cells */
 private void initParameters() {
   this.minX = envelope.getMinX();
   this.minY = envelope.getMinY();
   double cellWidth = envelope.getWidth();
   double cellHeight = envelope.getHeight();
   this.maxI = (int) Math.ceil(cellWidth / deltaX);
   this.maxJ = (int) Math.ceil(cellHeight / deltaY);
 }
Exemplo n.º 4
0
 public void fit() throws Exception {
   MapContent generalMapContext = getGeneralMapContext();
   Dimension size = getSize();
   Envelope projectedBounds = generalMapContext.getMaxBounds();
   double destWidth = projectedBounds.getWidth();
   double destHeight = projectedBounds.getHeight();
   Coordinate centre = projectedBounds.centre();
   Point2D.Double screenLT = awtScreen2Cartesian(new Point(0, 0));
   Point2D.Double screenBR = awtScreen2Cartesian(new Point(size.width, size.height));
   double srcWidth = screenBR.x - screenLT.x;
   double srcHeight = screenBR.y - screenLT.y;
   double sx = srcWidth / destWidth;
   double sy = srcHeight / destHeight;
   double coef = Math.min(sx, sy);
   coef = snapScale(coef);
   scaleView(coef, coef, false);
   Point2D.Double projectedScreenCenter = screen2Cartesian(new Point(0, 0));
   translateView(projectedScreenCenter.x - centre.x, projectedScreenCenter.y - centre.y, true);
   repaint();
 }
  /**
   * Creates a circular {@link Polygon}.
   *
   * @return a circle
   */
  public Polygon createCircle() {

    Envelope env = dim.getEnvelope();
    double xRadius = env.getWidth() / 2.0;
    double yRadius = env.getHeight() / 2.0;

    double centreX = env.getMinX() + xRadius;
    double centreY = env.getMinY() + yRadius;

    Coordinate[] pts = new Coordinate[nPts + 1];
    int iPt = 0;
    for (int i = 0; i < nPts; i++) {
      double ang = i * (2 * Math.PI / nPts);
      double x = xRadius * Math.cos(ang) + centreX;
      double y = yRadius * Math.sin(ang) + centreY;
      Coordinate pt = new Coordinate(x, y);
      pts[iPt++] = pt;
    }
    pts[iPt] = pts[0];

    LinearRing ring = geomFact.createLinearRing(pts);
    Polygon poly = geomFact.createPolygon(ring, null);
    return poly;
  }
Exemplo n.º 6
0
 private double getArea(Envelope e) {
   return e.getWidth() * e.getHeight();
 }