Exemplo n.º 1
0
 /** Método de finalización del proceso. */
 private void tasseledCapFinalize(String fileName) {
   if (!new File(fileName).exists()) return;
   try {
     RasterToolsUtil.loadLayer(viewName, fileName, null);
   } catch (RasterNotLoadException e) {
     RasterToolsUtil.messageBoxError("error_load_layer", this, e);
   }
   if (externalActions != null) {
     externalActions.end(fileName);
   }
 }
Exemplo n.º 2
0
  /**
   * Acciones que se realizan al finalizar de crear los recortes de imagen. Este método es llamado
   * por el thread TailRasterProcess al finalizar.
   */
  public void loadLayerInToc(String fileName) {
    if (!getFilterPanel().getNewLayerPanel().isNewLayerSelected()) return;
    if (!new File(fileName).exists()) return;
    try {
      RasterToolsUtil.loadLayer(getFilterPanel().getViewName(), fileName, null);
    } catch (RasterNotLoadException e) {
      RasterToolsUtil.messageBoxError("error_cargar_capa", this, e);
    }

    if (filterPanel != null) filterPanel.updateNewLayerText();
  }
Exemplo n.º 3
0
  /**
   * Acciones que se realizan al finalizar de crear los recortes de imagen. Este método es llamado
   * por el thread TailRasterProcess al finalizar.
   */
  private void cutFinalize(String fileName, long milis) {
    if (!new File(fileName).exists()) return;

    if (viewName != null) {
      if (RasterToolsUtil.messageBoxYesOrNot("cargar_toc", this)) {

        try {
          FLayer lyr = RasterToolsUtil.loadLayer(viewName, fileName, null);
          if (lyr != null && lyr instanceof FLyrRasterSE)
            ((FLyrRasterSE) lyr).setRois(rasterSE.getRois());
        } catch (RasterNotLoadException e) {
          RasterToolsUtil.messageBoxError("error_load_layer", this, e);
        }
      }
    }

    if (showEndDialog && externalActions != null)
      externalActions.end(new Object[] {fileName, new Long(milis)});
  }
Exemplo n.º 4
0
  /** Tarea de recorte */
  public void process() throws InterruptedException {
    IRasterDataSource dsetCopy = null;
    if (rasterSE != null) rasterSE.setReadingData(Thread.currentThread().toString());

    try {
      long t2;
      long t1 = new java.util.Date().getTime();

      insertLineLog(RasterToolsUtil.getText(this, "leyendo_raster"));

      dsetCopy = rasterSE.getDataSource().newDataset();
      BufferFactory bufferFactory = new BufferFactory(dsetCopy);
      bufferFactory.setDrawableBands(drawableBands);

      if (interpolationMethod != BufferInterpolation.INTERPOLATION_Undefined) {
        try {
          if (pValues != null) {
            if (RasterBuffer.isBufferTooBig(
                new double[] {pValues[0], pValues[3], pValues[2], pValues[1]},
                drawableBands.length)) bufferFactory.setReadOnly(true);
            bufferFactory.setAreaOfInterest(
                pValues[0], pValues[3], pValues[2] - pValues[0], pValues[1] - pValues[3]);
          } else if (wcValues != null) {
            // if (RasterBuffer.isBufferTooBig(new double[] {
            // wcValues[0], wcValues[3], wcValues[2], wcValues[1] },
            // rasterSE.getCellSize(), drawableBands.length))
            if (!rasterSE.isActionEnabled(IRasterLayerActions.REMOTE_ACTIONS))
              bufferFactory.setReadOnly(true);
            bufferFactory.setAreaOfInterest(
                wcValues[0],
                wcValues[1],
                Math.abs(wcValues[0] - wcValues[2]),
                Math.abs(wcValues[1] - wcValues[3]));
          }
        } catch (InvalidSetViewException e) {
          RasterToolsUtil.messageBoxError(
              "No se ha podido asignar la vista al inicial el proceso de recorte.", this, e);
        }
        buffer = bufferFactory.getRasterBuf();

        insertLineLog(RasterToolsUtil.getText(this, "interpolando"));

        if (buffer != null)
          buffer =
              ((RasterBuffer) buffer)
                  .getAdjustedWindow(resolutionWidth, resolutionHeight, interpolationMethod);
        else {
          RasterToolsUtil.messageBoxError(
              "El proceso de recorte ha fallado porque el buffer no contenía datos.",
              this,
              new NullPointerException());
          return;
        }
      } else {
        try {
          if (RasterBuffer.isBufferTooBig(
              new double[] {0, 0, resolutionWidth, resolutionHeight}, drawableBands.length))
            bufferFactory.setReadOnly(true);
          if (pValues != null)
            bufferFactory.setAreaOfInterest(
                pValues[0],
                pValues[3],
                Math.abs(pValues[2] - pValues[0]) + 1,
                Math.abs(pValues[1] - pValues[3]) + 1,
                resolutionWidth,
                resolutionHeight);
          else if (wcValues != null)
            bufferFactory.setAreaOfInterest(
                wcValues[0],
                wcValues[1],
                wcValues[2],
                wcValues[3],
                resolutionWidth,
                resolutionHeight);
          buffer = bufferFactory.getRasterBuf();
          if (buffer == null) {
            RasterToolsUtil.messageBoxError(
                "El proceso de recorte ha fallado porque el buffer no contenía datos.",
                this,
                new NullPointerException());
            return;
          }
        } catch (InvalidSetViewException e) {
          RasterToolsUtil.messageBoxError(
              "No se ha podido asignar la vista al inicial el proceso de recorte.", this, e);
        }
      }
      // TODO: FUNCIONALIDAD: Poner los getWriter con la proyección del
      // fichero fuente

      if ((selectedRois != null) && (!bufferFactory.isReadOnly())) {
        if (selectedRois.size() > 0) {
          int despX = 0;
          int despY = 0;
          if (pValues != null) {
            despX = pValues[0];
            despY = pValues[1];
          } else if (wcValues != null) {
            despX =
                (int) dsetCopy.worldToRaster(new Point2D.Double(wcValues[0], wcValues[1])).getX();
            despY =
                (int) dsetCopy.worldToRaster(new Point2D.Double(wcValues[0], wcValues[1])).getY();
          }
          drawOnlyROIs(buffer, selectedRois, despX, despY);
        }
      }

      insertLineLog(RasterToolsUtil.getText(this, "salvando_imagen"));

      String finalFileName = "";
      if (oneLayerPerBand) {
        long[] milis = new long[drawableBands.length];
        String[] fileNames = new String[drawableBands.length];
        for (int i = 0; i < drawableBands.length; i++) {
          fileNames[i] = fileName + "_B" + drawableBands[i] + ".tif";
          writerBufferServer.setBuffer(buffer, i);
          Params p = null;
          if (params == null) p = GeoRasterWriter.getWriter(fileNames[i]).getParams();
          else p = params;
          grw =
              GeoRasterWriter.getWriter(
                  writerBufferServer,
                  fileNames[i],
                  1,
                  affineTransform,
                  buffer.getWidth(),
                  buffer.getHeight(),
                  buffer.getDataType(),
                  p,
                  null);
          grw.setColorBandsInterpretation(new String[] {DatasetColorInterpretation.GRAY_BAND});
          grw.setWkt(dsetCopy.getWktProjection());
          grw.setCancellableRasterDriver(cancellableObj);
          grw.dataWrite();
          grw.writeClose();
          saveToRmf(fileNames[i]);
          t2 = new java.util.Date().getTime();
          milis[i] = (t2 - t1);
          t1 = new java.util.Date().getTime();
        }
        if (incrementableTask != null) {
          incrementableTask.processFinalize();
          incrementableTask = null;
        }
        if (viewName != null) {
          if (RasterToolsUtil.messageBoxYesOrNot("cargar_toc", this)) {
            try {
              for (int i = 0; i < drawableBands.length; i++) {
                FLayer lyr = RasterToolsUtil.loadLayer(viewName, fileNames[i], null);
                if (lyr != null && lyr instanceof FLyrRasterSE)
                  ((FLyrRasterSE) lyr).setRois(rasterSE.getRois());
              }
            } catch (RasterNotLoadException e) {
              RasterToolsUtil.messageBoxError("error_load_layer", this, e);
            }
          }
        }
        for (int i = 0; i < drawableBands.length; i++) {
          if (externalActions != null)
            externalActions.end(
                new Object[] {fileName + "_B" + drawableBands[i] + ".tif", new Long(milis[i])});
        }
      } else {
        if (isUsingFile(fileName)) {
          incrementableTask.hideWindow();
          RasterToolsUtil.messageBoxError("error_opened_file", this);
          return;
        }
        File f = new File(fileName);
        if (f.exists()) {
          f.delete();
        }
        f = null;
        writerBufferServer.setBuffer(buffer, -1);
        if (params == null) {
          finalFileName = fileName + ".tif";
          params = GeoRasterWriter.getWriter(finalFileName).getParams();
        } else finalFileName = fileName;
        grw =
            GeoRasterWriter.getWriter(
                writerBufferServer,
                finalFileName,
                buffer.getBandCount(),
                affineTransform,
                buffer.getWidth(),
                buffer.getHeight(),
                buffer.getDataType(),
                params,
                null);
        if (colorInterp != null) grw.setColorBandsInterpretation(colorInterp.getValues());
        grw.setWkt(dsetCopy.getWktProjection());
        grw.setCancellableRasterDriver(cancellableObj);
        grw.dataWrite();
        grw.writeClose();
        saveToRmf(finalFileName);
        t2 = new java.util.Date().getTime();
        if (incrementableTask != null) {
          incrementableTask.processFinalize();
          incrementableTask = null;
        }
        // Damos tiempo a parar el Thread del incrementable para que no
        // se cuelgue la ventana
        // El tiempo es como mínimo el de un bucle del run de la tarea
        // incrementable
        Thread.sleep(600);
        cutFinalize(finalFileName, (t2 - t1));
      }

    } catch (NotSupportedExtensionException e) {
      RasterToolsUtil.messageBoxError("error_not_suported_extension", this, e);
    } catch (RasterDriverException e) {
      RasterToolsUtil.messageBoxError("error_writer", this, e);
    } catch (IOException e) {
      RasterToolsUtil.messageBoxError("error_georasterwriter", this, e);
    } finally {
      if (rasterSE != null) rasterSE.setReadingData(null);
      if (dsetCopy != null) dsetCopy.close();
      buffer = null;
    }
  }