/** * Salva la tabla de color al fichero rmf. * * @param fName * @throws IOException */ private void saveToRmf(String fileName) { RasterDataset rds = null; int limitNumberOfRequests = 20; while (rds == null && limitNumberOfRequests > 0) { try { rds = rasterSE.getDataSource().getDataset(0)[0]; } catch (IndexOutOfBoundsException e) { // En ocasiones, sobre todo con servicios remotos al pedir un // datasource da una excepción de este tipo // se supone que es porque hay un refresco en el mismo momento // de la petición por lo que como es más lento de // gestionar pilla a la capa sin datasources asociados ya que // está reasignandolo. Si volvemos a pedirlo debe // haberlo cargado ya. try { Thread.sleep(200); } catch (InterruptedException e1) { } } limitNumberOfRequests--; } if (rds == null) { // RasterToolsUtil.messageBoxError("error_load_layer", this, new // Exception("Error writing RMF. limitNumberOfRequests=" + // limitNumberOfRequests)); return; } RasterFilterList rasterFilterList = rasterSE.getRenderFilterList(); // Guardamos en el RMF el valor NoData if (Configuration.getValue("nodata_transparency_enabled", Boolean.FALSE).booleanValue()) { try { RasterDataset.saveObjectToRmfFile( fileName, NoData.class, new NoData( rasterSE.getNoDataValue(), rasterSE.getNoDataType(), rasterSE.getDataType()[0])); } catch (RmfSerializerException e) { RasterToolsUtil.messageBoxError("error_salvando_rmf", this, e); } } // Guardamos en el RMF la tabla de color ColorTableFilter colorTableFilter = (ColorTableFilter) rasterFilterList.getByName(ColorTableFilter.names[0]); if (colorTableFilter != null) { GridPalette gridPalette = new GridPalette((ColorTable) colorTableFilter.getColorTable().clone()); try { RasterDataset.saveObjectToRmfFile(fileName, ColorTable.class, (ColorTable) gridPalette); } catch (RmfSerializerException e) { RasterToolsUtil.messageBoxError("error_salvando_rmf", this, e); } } }
/* * (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); }