/** @param file */
 public void export(File file) {
   LOG.debug("Writing index file for directory...");
   ObjectOutputStream out = null;
   try {
     out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
     out.writeObject(qtree);
     out.writeObject(createEnvelope(envelope));
     out.writeObject(rasterDataInfo);
     out.writeObject(rasterGeoReference.getOriginLocation());
     out.writeDouble(rasterGeoReference.getResolutionX());
     out.writeDouble(rasterGeoReference.getResolutionY());
     out.writeDouble(rasterGeoReference.getRotationX());
     out.writeDouble(rasterGeoReference.getRotationY());
     out.writeDouble(rasterGeoReference.getOriginEasting());
     out.writeDouble(rasterGeoReference.getOriginNorthing());
     out.writeObject(rasterGeoReference.getCrs());
     out.writeObject(resolutionInfo);
     out.writeObject(options);
     LOG.debug("Done.");
   } catch (IOException e) {
     LOG.debug(
         "Raster pyramid file '{}' could not be written: '{}'.", file, e.getLocalizedMessage());
     LOG.trace("Stack trace:", e);
   } finally {
     if (out != null) {
       try {
         out.close();
       } catch (IOException e) {
         LOG.debug(
             "Raster pyramid file '{}' could not be closed: '{}'.", file, e.getLocalizedMessage());
         LOG.trace("Stack trace:", e);
       }
     }
   }
 }
예제 #2
0
  /**
   * Merge two Raster references. Returns a new RasterReference where the upper-left corner is set
   * to the values of the smallest upper and smallest left ordinate. The resolution is set to the
   * minimum value (i.e. the highest resolution [unit/pixel]). Some assumptions are made (not
   * checked):
   *
   * <ul>
   *   <li>The pixel location (center/outer) of the origin are equal, if not, the location of the
   *       first reference will be used (translated origin of second)
   *   <li>Crs is identical
   *   <li>rotation around axis are equal
   * </ul>
   *
   * @param geoRef1
   * @param geoRef2
   * @return new RasterReference
   */
  public static RasterGeoReference merger(RasterGeoReference geoRef1, RasterGeoReference geoRef2) {

    if (geoRef1 == null) {
      return geoRef2;
    }
    if (geoRef2 == null) {
      return geoRef1;
    }
    RasterGeoReference geoRef2Copy = geoRef2;
    if (geoRef1.location != geoRef2.location) {
      double[] orig = geoRef2.getOrigin(geoRef1.location);
      geoRef2Copy =
          new RasterGeoReference(
              geoRef1.location,
              geoRef2.getResolutionX(),
              geoRef2.getResolutionY(),
              geoRef2.getRotationX(),
              geoRef2.getRotationY(),
              orig[0],
              orig[1],
              geoRef2.crs);
    }
    double[] origin1 = geoRef1.getOrigin();
    double[] origin2 = geoRef2Copy.getOrigin();

    double res1x = geoRef1.getResolutionX();
    double res1y = geoRef1.getResolutionY();

    double res2x = geoRef2Copy.getResolutionX();
    double res2y = geoRef2Copy.getResolutionY();

    double nResx = (res1x < 0) ? max(res1x, res2x) : min(res1x, res2x);
    double nResy = (res1y < 0) ? max(res1y, res2y) : min(res1y, res2y);

    double nOrigx = (res1x < 0) ? max(origin1[0], origin2[0]) : min(origin1[0], origin2[0]);
    double nOrigy = (res1y < 0) ? max(origin1[1], origin2[1]) : min(origin1[1], origin2[1]);

    return new RasterGeoReference(
        geoRef1.location,
        nResx,
        nResy,
        geoRef1.getRotationX(),
        geoRef1.getRotationY(),
        nOrigx,
        nOrigy,
        geoRef1.crs);
  }