Пример #1
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)});
  }
Пример #2
0
  /*
   * (non-Javadoc)
   *
   * @see org.gvsig.raster.gui.wizards.IFileOpen#post(java.io.File[])
   */
  public File post(File file) throws LoadLayerException {

    // Si el fichero es raw lanzamos el dialogo de parámetros de raw
    if (RasterUtilities.getExtensionFromFileName(file.getAbsolutePath()).equals("raw")) {
      OpenRawFileDefaultView view = new OpenRawFileDefaultView(file.getAbsolutePath());
      file = view.getImageFile();
    }

    if (file == null || file.getAbsoluteFile() == null) return null;

    // Si el fichero es vrt chequeamos que sea correcto
    if (RasterUtilities.getExtensionFromFileName(file.getAbsolutePath()).equals("vrt")) {
      try {
        checkFileVRT(file);
      } catch (FileOpenVRTException e) {
        RasterToolsUtil.messageBoxError(
            PluginServices.getText(this, "error_abrir_fichero")
                + " "
                + file.getName()
                + "\n\n"
                + PluginServices.getText(this, "informacion_adicional")
                + ":\n\n  "
                + e.getMessage(),
            this,
            e);
        return null;
      }
    }

    try {
      FLyrRasterSE lyrRaster = null;

      String lyr_name = RasterToolsUtil.getLayerNameFromFile(file);
      lyrRaster = FLyrRasterSE.createLayer(lyr_name, file, null);

      // Si hay que generar las overviews por el panel de preferencias
      // if (Configuration.getValue("overviews_ask_before_loading",
      // Boolean.FALSE).booleanValue() == true) {
      // try {
      // boolean generate = false;
      // for (int i = 0; i < lyrRaster.getFileCount(); i++) {
      // if
      // (lyrRaster.getDataSource().getDataset(i)[0].getOverviewCount(0)
      // == 0) {
      // generate = true;
      // break;
      // }
      // }
      // if (generate) {
      // if (firstTaskOverview) {
      // execOverview =
      // RasterToolsUtil.messageBoxYesOrNot("generar_overviews", this);
      // firstTaskOverview = false;
      // }
      //
      // if (execOverview) {
      // RasterProcess process = new OverviewsProcess();
      // process.setCancelable(false);
      // process.addParam("layer", (FLyrRasterSE) lyrRaster);
      // UniqueProcessQueue.getSingleton().add(process);
      // }
      // }
      // } catch (Exception e) {
      // // Si no se puede generar la overview no hacemos nada
      // }
      // }

      // Mostramos el cuadro que pide la georreferenciación si la capa no
      // tiene y si la opción está activa en preferencias
      if (RasterModule.askCoordinates) {
        if (lyrRaster.getFullExtent().getMinX() == 0
            && lyrRaster.getFullExtent().getMinY() == 0
            && lyrRaster.getFullExtent().getMaxX() == ((FLyrRasterSE) lyrRaster).getPxWidth()
            && lyrRaster.getFullExtent().getMaxY() == ((FLyrRasterSE) lyrRaster).getPxHeight()) {
          if (RasterToolsUtil.messageBoxYesOrNot(
              lyrRaster.getName() + "\n" + PluginServices.getText(this, "layer_without_georref"),
              null)) {
            GeoLocationOpeningRasterDialog gld = new GeoLocationOpeningRasterDialog(lyrRaster);
            PluginServices.getMDIManager().addWindow(gld);
          }
        }
      }

      // Opciones de proyección
      boolean compareProj =
          Configuration.getValue("general_ask_projection", Boolean.valueOf(false)).booleanValue();
      if (compareProj) compareProjections(lyrRaster);
      else actionList.add(new Integer(defaultActionLayer));

      lyrsRaster.add(lyrRaster);
    } catch (LoadLayerException e) {
      RasterToolsUtil.messageBoxError("error_carga_capa", this, e);
      throw new LoadLayerException("error_carga_capa", e);
    }

    return super.post(file);
  }
Пример #3
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;
    }
  }