Esempio n. 1
0
 /**
  * Splits up a layer group in order to get a layer by name when there are layer groups
  *
  * <p>In <code>result</code> always will be at least one layer.
  *
  * @param layer the layer we are looking for
  * @param result an array list that will have the results of the search
  */
 private void splitLayerGroup(FLayer layer, ArrayList result) {
   int i;
   FLayers layerGroup;
   if (layer instanceof FLayers) {
     layerGroup = (FLayers) layer;
     for (i = 0; i < layerGroup.getLayersCount(); i++) {
       splitLayerGroup(layerGroup.getLayer(i), result);
     }
   } else {
     result.add(layer);
   }
 }
Esempio n. 2
0
 private boolean hasVectorLayers(FLayers layers) {
   for (int i = 0; i < layers.getLayersCount(); i++) {
     FLayer lyr = layers.getLayer(i);
     if (lyr instanceof FLayers) {
       if (hasVectorLayers((FLayers) lyr)) {
         return true;
       }
     } else if (lyr instanceof FLyrVect) {
       return true;
     }
   }
   return false;
 }
  /** Toma las Bandas de la imagen seleccionada en el combo Imagen */
  public void getBandas() {

    // Antes de insertar se borra lo anterior
    getModeloTabla().LimpiarLista();
    FLyrRasterSE rasterLayer =
        (FLyrRasterSE) layers.getLayer((String) getComboCapas().getSelectedItem());
    String bandas[] = new String[rasterLayer.getBandCount()];
    if (layers.getLayer((String) getComboCapas().getSelectedItem()) instanceof FLyrRasterSE) {
      for (int j = 0; j < rasterLayer.getBandCount(); j++) {
        String s = (PluginServices.getText(this, "banda")) + (j + 1);
        bandas[j] = s;
      }
    }
    // Insertar las bandas el la tabla
    for (int i = 0; i < bandas.length; i++) getModeloTabla().addRow(bandas[i], true);
    getTableBands().updateUI();
  }
  /** @return array de String con los nombre de las capas cargadas */
  private String[] getLayerNames() {

    int i, capasraster = 0;
    for (i = 0; i < layers.getLayersCount(); i++) {
      if (layers.getLayer(i) instanceof FLyrRasterSE) capasraster++;
    }
    // Solo se toman las capas raster.
    String[] sNames = new String[capasraster];
    capasraster = 0;
    for (i = 0; i < layers.getLayersCount(); i++) {
      if (layers.getLayer(i) instanceof FLyrRasterSE) {
        sNames[capasraster] = layers.getLayer(i).getName();
        capasraster++;
      }
    }
    return sNames;
  }
  public void accept() {

    if (getModeloTabla().getNumSelected() > 0) {
      FLyrRasterSE rasterLayer =
          (FLyrRasterSE) layers.getLayer((String) getComboCapas().getSelectedItem());
      PluginServices.getMDIManager().closeWindow(this);
      statisticsProcess = new PCStatisticsProcess();
      statisticsProcess.addParam("inputRasterLayer", rasterLayer);
      selectecBands = getModeloTabla().getSeleccionadas();
      statisticsProcess.addParam("selectedBands", selectecBands);

      statisticsProcess.setActions(this);
      statisticsProcess.start();
    } else {

      JOptionPane.showMessageDialog(
          null,
          PluginServices.getText(this, "no_bandas"),
          PluginServices.getText(this, "principal_components"),
          JOptionPane.WARNING_MESSAGE);
    }
  }
  public void execute(ITocItem item, FLayer[] selectedItems) {
    // ITocItem tocItem = (ITocItem) getNodeUserObject();
    ChangeName changename = new ChangeName(null);
    PluginServices.getMDIManager().addWindow(changename);
    if (!changename.isAccepted()) return;
    String nombre = changename.getName();

    if (nombre != null) {

      getMapContext().beginAtomicEvent();
      FLayers parent = selectedItems[0].getParentLayer();
      //			FLayers newGroup = new FLayers(getMapContext(),parent);
      FLayers newGroup = getMapContext().getNewGroupLayer(parent);
      newGroup.setName(nombre);
      int pos = 0;
      for (int i = 0; i < parent.getLayersCount(); i++) {
        if (parent.getLayer(i).equals(selectedItems[0])) {
          pos = i;
          continue;
        }
      }
      for (int j = 0; j < selectedItems.length; j++) {
        FLayer layer = selectedItems[j];
        parent.removeLayer(layer);
        newGroup.addLayer(layer);
      }
      parent.addLayer(pos, newGroup);

      getMapContext().endAtomicEvent();
      // TRUCO PARA REFRESCAR.
      getMapContext().invalidate();
      Project project =
          ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
      project.setModified(true);
    }
  }
Esempio n. 7
0
  /**
   * Adds the layer with the information in an XML entity and the specified name, to this collection
   * of layers.
   *
   * <p>This method really executes the addition, considering the kind of layer (<code>FLyrVect
   * </code>, <code>FLyrAnnotation</code>, <code>FLyrRaster</code>, a collection of layers (<code>
   * FLayers</code>), or another kind of layer (<code>FLayer</code>)), and the driver in the layer.
   *
   * @param xml tree-node structure with information about layers
   * @param name name of the layer to add
   * @throws LoadLayerException if fails loading this layer.
   */
  private void addLayerFromXML(XMLEntity xml, String name) throws LoadLayerException {
    FLayer layer = null;

    try {
      if (name == null) {
        name = xml.getName();
      }

      String className = xml.getStringProperty("className");
      Class clase = Class.forName(className);
      layer = (FLayer) clase.newInstance();
      if (FLayers.class.isAssignableFrom(clase)) {
        ((FLayers) layer).setMapContext(getMapContext());
        ((FLayers) layer).setParentLayer(this);
        //			layer = new FLayers(getMapContext(),this);
        layer.setXMLEntity(xml);
      } else {
        // Capas Nuevas (externas)
        layer.setName(name);
        layer.setXMLEntity(xml);
        layer.load();
      }

      //		//TODO VCN FLyrAnnotation es un parche para no tener que duplicar todo el código de aqí y
      // de los diferentes métodos de LayerFactory,
      //		//ya que los drivers de una FLyrAnnotation no sabemos cual es puede ser cualquier Driver
      // Vectorial.
      //		if (className.equals(FLyrVect.class.getName())){// ||
      // className.equals(FLyrAnnotation.class.getName())) {
      //			String type = xml.getStringProperty("type");
      //			if ("vectorial".equals(type)){
      //				//String recordsetName = xml.getChild(i).getStringProperty("recordset-name");
      //				IProjection proj = null;
      //				if (xml.contains("proj")) {
      //					proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
      //				}
      //				else
      //				{
      //					proj = this.getMapContext().getViewPort().getProjection();
      //				}
      //				if (xml.contains("file")) {
      //					Driver d;
      //					try {
      //						d = LayerFactory.getDM().getDriver(xml.getStringProperty("driverName"));
      //					} catch (DriverLoadException e1) {
      //						throw new DriverLayerException(name,e1);
      //					}
      //					layer = LayerFactory.createLayer(name, (VectorialFileDriver) d,
      //							new File(xml.getStringProperty("file")),
      //							proj);
      //
      //
      //				}
      //				if (xml.contains("db")) {
      //
      //					String driverName = xml.getStringProperty("db");
      //					IVectorialDatabaseDriver driver;
      //					try {
      //						driver = (IVectorialDatabaseDriver) LayerFactory.getDM().getDriver(driverName);
      //						//Hay que separar la carga de los datos del XMLEntity del load.
      //						driver.setXMLEntity(xml.getChild(2));
      //
      //						boolean loadOk = false;
      //						((DefaultJDBCDriver)driver).load();
      //						if (((DefaultJDBCDriver)driver).getConnection() != null) {
      //							loadOk = true;
      //						}
      //						layer = LayerFactory.createDBLayer(driver, name, proj);
      //						if (!loadOk) {
      //							layer.setAvailable(false);
      //						}
      //
      //					} catch (DriverLoadException e) {
      //						throw new DriverLayerException(name,e);
      //					} catch (XMLException e) {
      //						throw new DriverLayerException(name,e);
      //					} catch (ReadException e) {
      //						throw new DriverLayerException(name,e);
      //					}
      //
      //				}
      //				// Clases con algun driver genérico creado por otro
      //				// programador
      //				if (xml.contains("other")) {
      //
      //					String driverName = xml.getStringProperty("other");
      //					VectorialDriver driver = null;
      //					try {
      //						driver = (VectorialDriver) LayerFactory.getDM().getDriver(driverName);
      //					} catch (DriverLoadException e) {
      //						// Si no existe ese driver, no pasa nada.
      //						// Puede que el desarrollador no quiera que
      //						// aparezca en el cuadro de diálogo y ha metido
      //						// el jar con sus clases en nuestro directorio lib.
      //						// Intentamos cargar esa clase "a pelo".
      //						if (xml.getChild(2).contains("className"))
      //						{
      //							String className2 = xml.getChild(2).getStringProperty("className");
      //							try {
      //								driver = (VectorialDriver) Class.forName(className2).newInstance();
      //							} catch (Exception e1) {
      //								throw new DriverLayerException(name,e);
      //							}
      //						}
      //					} catch (NullPointerException npe) {
      //						// Si no existe ese driver, no pasa nada.
      //						// Puede que el desarrollador no quiera que
      //						// aparezca en el cuadro de diálogo y ha metido
      //						// el jar con sus clases en nuestro directorio lib.
      //						// Intentamos cargar esa clase "a pelo".
      //						if (xml.getChild(2).contains("className"))
      //						{
      //							String className2 = xml.getChild(2).getStringProperty("className");
      //							try {
      //								driver = (VectorialDriver) Class.forName(className2).newInstance();
      //							} catch (Exception e1) {
      //								throw new DriverLayerException(name,e1);
      //							}
      //						}
      //					}
      //					if (driver instanceof IPersistence)
      //					{
      //						IPersistence persist = (IPersistence) driver;
      //						persist.setXMLEntity(xml.getChild(2));
      //					}
      //					layer = LayerFactory.createLayer(name, driver, proj);
      //				}
      //
      //			}
      //
      //			//TODO VCN FLyrAnnotation es un parche para no tener que duplicar todo el código de aqí y
      // de los diferentes métodos de LayerFactory,
      //			//ya que los drivers de una FLyrAnnotation no sabemos cual es puede ser cualquier Driver
      // Vectorial.
      //			if (className.equals(FLyrAnnotation.class.getName())){
      //				layer=FLyrAnnotation.createLayerFromVect((FLyrVect)layer);
      //			}
      //
      //
      //			layer.setXMLEntity(xml);
      //
      //		} else {
      //			Class clase = LayerFactory.getLayerClassForLayerClassName(className);
      //			layer = (FLayer) clase.newInstance();
      //			if (clase.isAssignableFrom(FLayers.class)) {
      //				((FLayers)layer).setMapContext(getMapContext());
      //				((FLayers)layer).setParentLayer(this);
      ////				layer = new FLayers(getMapContext(),this);
      //				layer.setXMLEntity(xml);
      //			} else {
      //				// Capas Nuevas (externas)
      //				layer.setName(name);
      //				layer.setXMLEntity(xml);
      //				layer.load();
      //			}
      //		}
      this.addLayer(layer);
      logger.debug("layer: " + layer.getName() + " loaded");
      // Comprobar que la proyección es la misma que la de FMap
      // Si no lo es, es una capa que está reproyectada al vuelo
      IProjection proj = layer.getProjection();
      if ((proj != null)) {
        if (!proj.getFullCode().equals(getMapContext().getProjection().getFullCode())) {
          ICoordTrans ct = proj.getCT(getMapContext().getProjection());
          // TODO: REVISAR CON LUIS
          // Se lo fijamos a todas, luego cada una que se reproyecte
          // si puede, o que no haga nada

          layer.setCoordTrans(ct);
        }
      }
    } catch (XMLException e) {
      fmap.addLayerError(xml.getStringProperty("name"));
      throw new LoadLayerException(name, e);
    } catch (ClassNotFoundException e) {
      fmap.addLayerError(xml.getStringProperty("name"));
      throw new LoadLayerException(name, e);
    } catch (InstantiationException e) {
      fmap.addLayerError(xml.getStringProperty("name"));
      throw new LoadLayerException(name, e);
    } catch (IllegalAccessException e) {
      fmap.addLayerError(xml.getStringProperty("name"));
      throw new LoadLayerException(name, e);
    } catch (LoadLayerException e) {
      fmap.addLayerError(xml.getStringProperty("name"));
      throw e;
    }
  }