Пример #1
0
  protected void determineSourceResolution() {
    xResolution = reqBounds.getWidth() / reqWidth;
    yResolution = reqBounds.getHeight() / reqHeight;

    double tmpResolution;
    // We use the smallest one
    if (yResolution < xResolution) {
      tmpResolution = yResolution;
    } else {
      tmpResolution = xResolution;
    }

    log.debug(
        "x res: " + xResolution + " y res: " + yResolution + " tmpResolution: " + tmpResolution);

    // Cut ourselves 0.5% slack
    double compResolution = 1.005 * tmpResolution;

    double[] resArray = gridSubset.getResolutions();

    for (srcIdx = 0; srcIdx < resArray.length; srcIdx++) {
      srcResolution = resArray[srcIdx];
      if (srcResolution < compResolution) {
        break;
      }
    }

    if (srcIdx >= resArray.length) {
      srcIdx = resArray.length - 1;
    }

    log.debug("z: " + srcIdx + " , resolution: " + srcResolution + " (" + tmpResolution + ")");

    // At worst, we have the best resolution possible
  }
Пример #2
0
  protected void determineCanvasLayout() {
    // Find the spatial extent of the tiles needed to cover the desired extent
    srcRectangle = gridSubset.getCoverageIntersection(srcIdx, reqBounds);
    srcBounds = gridSubset.boundsFromRectangle(srcRectangle);

    // We now have the complete area, lets figure out our offsets
    // Positive means that there is blank space to the first tile,
    // negative means we will not use the entire tile
    boundOfs.left = srcBounds.getMinX() - reqBounds.getMinX();
    boundOfs.bottom = srcBounds.getMinY() - reqBounds.getMinY();
    boundOfs.right = reqBounds.getMaxX() - srcBounds.getMaxX();
    boundOfs.top = reqBounds.getMaxY() - srcBounds.getMaxY();

    canvasSize[0] = (int) Math.round(reqBounds.getWidth() / this.srcResolution);
    canvasSize[1] = (int) Math.round(reqBounds.getHeight() / this.srcResolution);

    PixelOffsets naiveOfs = new PixelOffsets();
    // Calculate the corresponding pixel offsets. We'll stick to sane,
    // i.e. bottom left, coordinates at this point
    naiveOfs.left = (int) Math.round(boundOfs.left / this.srcResolution);
    naiveOfs.bottom = (int) Math.round(boundOfs.bottom / this.srcResolution);
    naiveOfs.right = (int) Math.round(boundOfs.right / this.srcResolution);
    naiveOfs.top = (int) Math.round(boundOfs.top / this.srcResolution);

    // Find the offsets on the opposite sides.  This is dependent of how the first two were rounded.

    // First, find a tile boundary near the canvas edge, then make sure it's on the correct
    // side to match the corresponding boundOfs, then take the modulo of the naive rounding
    // based on the boundOfs, then subtract the two and apply the difference to the boundOfs.
    int tileWidth = this.gridSubset.getTileWidth();
    int tileHeight = this.gridSubset.getTileHeight();

    canvOfs.left = naiveOfs.left;
    canvOfs.bottom = naiveOfs.bottom;

    canvOfs.right = (canvasSize[0] - canvOfs.left) % tileWidth; // Find nearby tile boundary
    canvOfs.right =
        (Integer.signum(naiveOfs.right) * tileWidth + canvOfs.right)
            % tileWidth; // Ensure same sign as naive calculation
    canvOfs.right =
        canvOfs.right
            - (naiveOfs.right % tileWidth)
            + naiveOfs.right; // Find adjustment from naive and apply to naive calculation
    canvOfs.top = (canvasSize[1] - canvOfs.bottom) % tileHeight; // Find nearby tile boundary
    canvOfs.top =
        (Integer.signum(naiveOfs.top) * tileHeight + canvOfs.top)
            % tileHeight; // Ensure same sign as naive calculation
    canvOfs.top =
        canvOfs.top
            - (naiveOfs.top % tileHeight)
            + naiveOfs.top; // Find adjustment from naive and apply to naive calculation

    // postconditions
    assert Math.abs(canvOfs.left - naiveOfs.left) <= 1;
    assert Math.abs(canvOfs.bottom - naiveOfs.bottom) <= 1;
    assert Math.abs(canvOfs.right - naiveOfs.right) <= 1;
    assert Math.abs(canvOfs.top - naiveOfs.top) <= 1;

    if (log.isDebugEnabled()) {
      log.debug("intersection rectangle: " + Arrays.toString(srcRectangle));
      log.debug("intersection bounds: " + srcBounds + " (" + reqBounds + ")");
      log.debug(
          "Bound offsets: "
              + Arrays.toString(
                  new double[] {boundOfs.left, boundOfs.bottom, boundOfs.right, boundOfs.top}));
      log.debug(
          "Canvas size: " + Arrays.toString(canvasSize) + "(" + reqWidth + "," + reqHeight + ")");
      log.debug(
          "Canvas offsets: "
              + Arrays.toString(
                  new int[] {canvOfs.left, canvOfs.bottom, canvOfs.right, canvOfs.top}));
    }
  }