예제 #1
0
  /**
   * Cast to a ReferencedEnvelope (used to ensure that an Envelope if a ReferencedEnvelope).
   * Supporting 2d as well as 3d envelopes (returning the right class).
   *
   * @param env The opgenis Envelope object
   * @return ReferencedEnvelope, ReferencedEnvelope3D if it is 3d,<br>
   *     results in a null/an empty envelope, if input envelope was a null/an empty envelope (by JTS
   *     Envelope definition: getMaximum(0) < getMinimum(0))
   */
  public static ReferencedEnvelope reference(org.opengis.geometry.Envelope env) {

    if (env == null) {
      return null;
    }

    if (env instanceof ReferencedEnvelope3D) {
      return (ReferencedEnvelope3D) env;
    }

    if (env instanceof ReferencedEnvelope) {
      return (ReferencedEnvelope) env;
    }

    if (env.getDimension() >= 3) {
      // emptiness test according to com.vividsolutions.jts.geom.Envelope
      if (env.getMaximum(0) < env.getMinimum(0)) {
        return new ReferencedEnvelope3D(env.getCoordinateReferenceSystem());
      } else {
        return new ReferencedEnvelope3D(env);
      }
    }

    // emptiness test according to com.vividsolutions.jts.geom.Envelope
    if (env.getMaximum(0) < env.getMinimum(0))
      return new ReferencedEnvelope(env.getCoordinateReferenceSystem());

    return new ReferencedEnvelope(env);
  }
예제 #2
0
  /**
   * Constructs two-dimensional envelope defined by an other {@link Envelope}.
   *
   * @param envelope The envelope to copy.
   */
  public Envelope2D(final Envelope envelope) {
    super(
        envelope.getMinimum(0), envelope.getMinimum(1),
        envelope.getSpan(0), envelope.getSpan(1));

    // TODO: check below should be first, if only Sun could fix RFE #4093999.
    final int dimension = envelope.getDimension();
    if (dimension != 2) {
      throw new MismatchedDimensionException(
          Errors.format(ErrorKeys.NOT_TWO_DIMENSIONAL_$1, dimension));
    }
    setCoordinateReferenceSystem(envelope.getCoordinateReferenceSystem());
  }
예제 #3
0
 /**
  * Returns a string representation of the {@code Bounding Box}. It is a comma-separated list
  * matching with this pattern: minx,miny,maxx,maxy.
  *
  * @param envelope The envelope to return the string representation.
  */
 public static String toBboxValue(final Envelope envelope) {
   final StringBuilder builder = new StringBuilder();
   final int dimEnv = envelope.getDimension();
   for (int i = 0; i < dimEnv; i++) {
     builder.append(envelope.getMinimum(i)).append(',');
   }
   for (int j = 0; j < dimEnv; j++) {
     if (j > 0) {
       builder.append(',');
     }
     builder.append(envelope.getMaximum(j));
   }
   return builder.toString();
 }
예제 #4
0
  /**
   * Utility method to create a ReferencedEnvelope from an opengis Envelope class, supporting 2d as
   * well as 3d envelopes (returning the right class).
   *
   * @param env The opgenis Envelope object
   * @return ReferencedEnvelope, ReferencedEnvelope3D if it is 3d,<br>
   *     results in a null/an empty envelope, if input envelope was a null/an empty envelope
   * @see {@link #reference(org.opengis.geometry.Envelope)}
   */
  public static ReferencedEnvelope create(
      org.opengis.geometry.Envelope env, CoordinateReferenceSystem crs) {

    if (env == null) {
      return null;
    }

    if (env.getDimension() >= 3) {
      // emptiness test is inside reference-method
      return new ReferencedEnvelope3D((ReferencedEnvelope3D) reference(env), crs);
    }

    return new ReferencedEnvelope(reference(env), crs);
  }
예제 #5
0
 private Map<String, String> toString(final Envelope envelope) {
   final Map<String, String> params = new HashMap<String, String>();
   final StringBuilder sb = new StringBuilder();
   final double minx = envelope.getMinimum(0);
   final double maxx = envelope.getMaximum(0);
   final double miny = envelope.getMinimum(1);
   final double maxy = envelope.getMaximum(1);
   sb.append(minx).append(',').append(miny).append(',').append(maxx).append(',').append(maxy);
   if (envelope.getDimension() > 2) {
     sb.append(',').append(envelope.getMinimum(2)).append(',').append(envelope.getMaximum(2));
   }
   params.put("BBOX", sb.toString());
   try {
     CoordinateReferenceSystem crs2d =
         CRSUtilities.getCRS2D(envelope.getCoordinateReferenceSystem());
     params.put("CRS", IdentifiedObjects.lookupIdentifier(crs2d, true));
   } catch (FactoryException ex) {
     LOGGER.log(Level.WARNING, null, ex);
   } catch (TransformException ex) {
     LOGGER.log(Level.WARNING, null, ex);
   }
   return params;
 }
  public void initParameters(
      final AffineTransform2D objToDisp,
      final CanvasMonitor monitor,
      final Shape paintingDisplayShape,
      final Shape paintingObjectiveShape,
      final Shape canvasDisplayShape,
      final Shape canvasObjectiveShape,
      final double dpi) {
    this.canvasObjectiveBBox = canvas.getController().getVisibleEnvelope();
    this.objectiveCRS = canvasObjectiveBBox.getCoordinateReferenceSystem();
    this.objectiveCRS2D = canvas.getObjectiveCRS2D();
    this.displayCRS = canvas.getDisplayCRS();
    this.objectiveToDisplay = objToDisp;
    try {
      this.displayToObjective = (AffineTransform2D) objToDisp.inverse();
    } catch (NoninvertibleTransformException ex) {
      Logging.getLogger(DefaultRenderingContext2D.class).log(Level.WARNING, null, ex);
    }
    this.monitor = monitor;

    this.labelRenderer = null;

    this.coeffs.clear();
    // set the Pixel coeff = 1
    this.coeffs.put(NonSI.PIXEL, 1f);

    // calculate canvas shape/bounds values ---------------------------------
    this.canvasDisplayShape = canvasDisplayShape;
    final Rectangle2D canvasDisplayBounds = canvasDisplayShape.getBounds2D();
    this.canvasDisplaybounds = canvasDisplayBounds.getBounds();
    this.canvasObjectiveShape = canvasObjectiveShape;

    final Rectangle2D canvasObjectiveBounds = canvasObjectiveShape.getBounds2D();

    // calculate the objective bbox with there temporal and elevation parameters ----
    this.canvasObjectiveBBox2D = new Envelope2D(objectiveCRS2D, canvasObjectiveBounds);

    // calculate the resolution -----------------------------------------------
    this.dpi = dpi;
    this.resolution = new double[canvasObjectiveBBox.getDimension()];
    this.resolution[0] = canvasObjectiveBounds.getWidth() / canvasDisplayBounds.getWidth();
    this.resolution[1] = canvasObjectiveBounds.getHeight() / canvasDisplayBounds.getHeight();
    for (int i = 2; i < resolution.length; i++) {
      // other dimension are likely to be the temporal and elevation one.
      // we set a hug resolution to ensure that only one slice of data will be retrived.
      resolution[i] = Double.MAX_VALUE;
    }
    adjustResolutionWithDPI(resolution);

    // calculate painting shape/bounds values -------------------------------
    this.paintingDisplayShape = paintingDisplayShape;
    final Rectangle2D paintingDisplayBounds = paintingDisplayShape.getBounds2D();
    this.paintingDisplaybounds = paintingDisplayBounds.getBounds();
    this.paintingObjectiveShape = paintingObjectiveShape;

    final Rectangle2D paintingObjectiveBounds = paintingObjectiveShape.getBounds2D();
    this.paintingObjectiveBBox2D = new Envelope2D(objectiveCRS2D, paintingObjectiveBounds);
    this.paintingObjectiveBBox = new GeneralEnvelope(canvasObjectiveBBox);
    ((GeneralEnvelope) this.paintingObjectiveBBox)
        .setRange(0, paintingObjectiveBounds.getMinX(), paintingObjectiveBounds.getMaxX());
    ((GeneralEnvelope) this.paintingObjectiveBBox)
        .setRange(1, paintingObjectiveBounds.getMinY(), paintingObjectiveBounds.getMaxY());

    try {
      geoScale = canvas.getController().getGeographicScale();
    } catch (TransformException ex) {
      // could not calculate the geographic scale.
      geoScale = 1;
      LOGGER.log(Level.WARNING, null, ex);
    }

    // set temporal and elevation range--------------------------------------
    final Date[] temporal = canvas.getController().getTemporalRange();
    if (temporal != null) {
      temporalRange[0] = temporal[0];
      temporalRange[1] = temporal[1];
    } else {
      Arrays.fill(temporalRange, null);
    }

    final Double[] elevation = canvas.getController().getElevationRange();
    if (elevation != null) {
      elevationRange[0] = elevation[0];
      elevationRange[1] = elevation[1];
    } else {
      Arrays.fill(elevationRange, null);
    }

    // calculate the symbology encoding scale -------------------------------
    seScale = GO2Utilities.computeSEScale(this);
  }