예제 #1
0
  /*
   * (non-Javadoc)
   *
   * @see org.gvsig.raster.gui.wizards.IFileOpen#execute(java.io.File[])
   */
  public Rectangle2D createLayer(File file, MapControl mapControl, CoordinateReferenceSystem crs) {
    this.mapControl = mapControl;
    FLyrRasterSE lyr = null;

    String layerName = RasterToolsUtil.getLayerNameFromFile(file);
    int nLayer = -1;

    // Si hay capas en la lista la buscamos allí
    if (lyrsRaster.size() != 0) {
      for (int i = 0; i < lyrsRaster.size(); i++) {
        if (((FLyrRasterSE) lyrsRaster.get(i)).getName().equals(layerName)) {
          lyr = (FLyrRasterSE) lyrsRaster.get(i);
          lyr.setCrs(crs);
          nLayer = i;
        }
      }
    }

    // Si no hay capa la cargamos
    if (lyr == null) {
      try {
        lyr = FLyrRasterSE.createLayer(layerName, file, crs);
        layerActions(defaultActionLayer, lyr);
      } catch (LoadLayerException e) {
        RasterToolsUtil.messageBoxError("error_carga_capa", this, e);
      }
    }

    if (lyr != null) {
      boolean actionsAdded = false;
      if ((nLayer >= 0) && (nLayer < actionList.size())) {
        Object obj = actionList.get(nLayer);
        if (obj != null && obj instanceof Integer) {
          actionsAdded = true;
          layerActions(((Integer) obj).intValue(), lyr);
        }
      }
      if (!actionsAdded) layerActions(defaultActionLayer, lyr);
      return lyr.getFullExtent();
    }

    return null;
  }
예제 #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);
  }