private static void doSetup() throws Exception {
    String fwAndamiDriverPath = TestProperties.driversPath;
    File baseDriversPath = new File(fwAndamiDriverPath);
    if (!baseDriversPath.exists()) {
      throw new Exception("Can't find drivers path: " + fwAndamiDriverPath);
    }

    LayerFactory.setDriversPath(baseDriversPath.getAbsolutePath());
    if (LayerFactory.getDM().getDriverNames().length < 1) {
      throw new Exception("Can't find drivers in path: " + fwAndamiDriverPath);
    }
  }
 private IEditableSource getIEditableSourceFromFile(String filePath)
     throws ReadDriverException, DriverLoadException, NoSuchTableException {
   LayerFactory.getDataSourceFactory()
       .addFileDataSource("gdbms dbf driver", "countries", filePath);
   SelectableDataSource sds2 =
       new SelectableDataSource(
           LayerFactory.getDataSourceFactory()
               .createRandomDataSource("countries", DataSourceFactory.MANUAL_OPENING));
   EditableAdapter ea2 = new EditableAdapter();
   ea2.setOriginalDataSource(sds2);
   return ea2;
 }
  private String[] getDriverNames() {
    Class[] classes = new Class[] {IVectorialDatabaseDriver.class};

    ArrayList ret = new ArrayList();
    String[] driverNames = LayerFactory.getDM().getDriverNames();

    for (int i = 0; i < driverNames.length; i++) {
      for (int j = 0; j < classes.length; j++) {
        if (LayerFactory.getDM().isA(driverNames[i], classes[j])) {
          ret.add(driverNames[i]);
        }
      }
    }

    return (String[]) ret.toArray(new String[0]);
  }
Пример #4
0
  /**
   * DOCUMENT ME!
   *
   * @param mapContext DOCUMENT ME!
   * @param layer DOCUMENT ME!
   * @param duplicate DOCUMENT ME!
   * @throws ReadDriverException
   * @throws EditionException DOCUMENT ME!
   * @throws DriverIOException DOCUMENT ME!
   */
  public void saveToShp(MapContext mapContext, Annotation_Layer layer, String duplicate)
      throws ReadDriverException {
    try {
      JFileChooser jfc = new JFileChooser();
      SimpleFileFilter filterShp =
          new SimpleFileFilter("shp", PluginServices.getText(this, "shp_files"));
      jfc.setFileFilter(filterShp);

      if (jfc.showSaveDialog((Component) PluginServices.getMainFrame())
          == JFileChooser.APPROVE_OPTION) {
        File newFile = jfc.getSelectedFile();
        String path = newFile.getAbsolutePath();

        if (newFile.exists()) {
          int resp =
              JOptionPane.showConfirmDialog(
                  (Component) PluginServices.getMainFrame(),
                  PluginServices.getText(this, "fichero_ya_existe_seguro_desea_guardarlo"),
                  PluginServices.getText(this, "guardar"),
                  JOptionPane.YES_NO_OPTION);

          if (resp != JOptionPane.YES_OPTION) {
            return;
          }
        }

        if (!(path.toLowerCase().endsWith(".shp"))) {
          path = path + ".shp";
        }

        newFile = new File(path);

        SelectableDataSource sds = layer.getRecordset();
        FieldDescription[] fieldsDescrip = sds.getFieldsDescription();

        ShpWriter writer = (ShpWriter) LayerFactory.getWM().getWriter("Shape Writer");
        Driver driver = null;

        SHPLayerDefinition lyrDefPoint = new SHPLayerDefinition();
        lyrDefPoint.setFieldsDesc(fieldsDescrip);

        File filePoints = new File(path);
        lyrDefPoint.setFile(filePoints);
        lyrDefPoint.setName(filePoints.getName());
        lyrDefPoint.setShapeType(FShape.POINT);
        writer.setFile(filePoints);
        writer.initialize(lyrDefPoint);
        driver = getOpenAnnotationDriver(filePoints);
        writeFeatures(mapContext, layer, writer, driver, duplicate);
      }
    } catch (InitializeWriterException e) {
      throw new ReadDriverException(layerAnnotation.getName(), e);
    } catch (DriverLoadException e) {
      throw new ReadDriverException(layerAnnotation.getName(), e);
    } catch (IOException e) {
      throw new ReadDriverException(layerAnnotation.getName(), e);
    }
  }
  public void execute(String actionCommand) {
    if (actionCommand.compareToIgnoreCase("NEW_ORACLE_SPATIAL") == 0) {

      IWindow w = PluginServices.getMDIManager().getActiveWindow();
      if (w instanceof View) {
        try {
          String _file = createResourceUrl("images/new_geodb_table.png").getFile();
          ImageIcon iicon = new ImageIcon(_file);

          DriverManager writerManager = LayerFactory.getDM();
          WizardAndami wizard = new WizardAndami(iicon);
          RepeatedChooseGeometryTypePanel panelChoose =
              new RepeatedChooseGeometryTypePanel(wizard.getWizardComponents());
          RepeatedFieldDefinitionPanel panelFields =
              new RepeatedFieldDefinitionPanel(wizard.getWizardComponents());
          NewVectorDBConnectionPanel connPanel =
              new NewVectorDBConnectionPanel(
                  wizard.getWizardComponents(),
                  OracleSpatialDriver.NAME,
                  OracleSpatialDriver.MAX_ID_LENGTH);

          wizard.getWizardComponents().addWizardPanel(panelChoose);
          wizard.getWizardComponents().addWizardPanel(panelFields);
          wizard.getWizardComponents().addWizardPanel(connPanel);

          Driver driver = new OracleSpatialDriver();
          panelFields.setWriter(((IWriteable) driver).getWriter());
          panelChoose.setDriver(driver);

          View theView = (View) w;
          MapContext mc = theView.getMapControl().getMapContext();

          NewOracleSpatialTableFinishAction action =
              new NewOracleSpatialTableFinishAction(
                  wizard.getWizardComponents(), wizard, connPanel, mc);

          wizard.getWizardComponents().setFinishAction(action);
          wizard.getWizardComponents().getFinishButton().setEnabled(false);
          wizard.getWindowInfo().setWidth(640);
          wizard.getWindowInfo().setHeight(350);
          wizard.getWindowInfo().setTitle(PluginServices.getText(this, "new_layer"));
          PluginServices.getMDIManager().addWindow(wizard);

        } catch (Exception ex) {
          logger.error("While showing new oracle spatial table wizard: " + ex.getMessage());
        }
      }
    }
  }
Пример #6
0
  @Override
  public void export(MapContext mapContext, FLyrVect layer) {
    try {
      JFileChooser jfc = new JFileChooser(lastPath);
      SimpleFileFilter filterShp =
          new SimpleFileFilter("dxf", PluginServices.getText(this, "dxf_files"));
      jfc.setFileFilter(filterShp);
      if (jfc.showSaveDialog((Component) PluginServices.getMainFrame())
          == JFileChooser.APPROVE_OPTION) {
        File newFile = jfc.getSelectedFile();
        String path = newFile.getAbsolutePath();
        if (!(path.toLowerCase().endsWith(".dxf"))) {
          path = path + ".dxf";
        }
        newFile = new File(path);

        DxfWriter writer = (DxfWriter) LayerFactory.getWM().getWriter("DXF Writer");
        SHPLayerDefinition lyrDef = new SHPLayerDefinition();
        SelectableDataSource sds = layer.getRecordset();
        FieldDescription[] fieldsDescrip = sds.getFieldsDescription();
        lyrDef.setFieldsDesc(fieldsDescrip);
        lyrDef.setFile(newFile);
        lyrDef.setName(newFile.getName());
        lyrDef.setShapeType(layer.getShapeType());
        writer.setFile(newFile);
        writer.initialize(lyrDef);
        writer.setProjection(layer.getProjection());
        DxfFieldsMapping fieldsMapping = new DxfFieldsMapping();
        // TODO: Recuperar aqu� los campos del cuadro de di�logo.
        writer.setFieldMapping(fieldsMapping);
        DXFMemoryDriver dxfDriver = new DXFMemoryDriver();
        dxfDriver.open(newFile);
        writeFeatures(mapContext, layer, writer, dxfDriver);
        String fileName = newFile.getAbsolutePath();
        lastPath = fileName.substring(0, fileName.lastIndexOf(File.separatorChar));
      }

    } catch (ReadDriverException e) {
      NotificationManager.addError(e.getMessage(), e);
    } catch (InitializeWriterException e) {
      NotificationManager.addError(e.getMessage(), e);
    } catch (DriverLoadException e) {
      NotificationManager.addError(e.getMessage(), e);
    }
  }
  public void actionPerformed(ActionEvent arg0) {
    Object src = arg0.getSource();

    if (src == connectedCheckBox) {
      if (connectedCheckBox.isSelected()) {
        passwordField.setEnabled(true);
        passwordField.setBackground(Color.WHITE);
      } else {
        passwordField.setText("");
        passwordField.setEnabled(false);
        passwordField.setBackground(Color.LIGHT_GRAY);
      }
    }

    if (src == okButton) {
      okPressed = true;
      PluginServices.getMDIManager().closeWindow(this);

      return;
    }

    if (src == cancelButton) {
      okPressed = false;
      PluginServices.getMDIManager().closeWindow(this);

      return;
    }

    if (src == driverComboBox) {
      String driverName = driverComboBox.getSelectedItem().toString();
      IVectorialDatabaseDriver driver;

      try {
        driver = (IVectorialDatabaseDriver) LayerFactory.getDM().getDriver(driverName);
        portTextField.setText("" + driver.getDefaultPort());
      } catch (DriverLoadException e1) {
        portTextField.setText("");
      }

      return;
    }
  }
  /**
   * Creating dbf format file with the statistics
   *
   * @param valores - Pairs String name (key) + Double value
   * @param endFile - File to write the information
   */
  private void exportToDBFFile(List<MyObjectStatistics> valores, File endFile) {

    try {
      FileDriver driver = null;
      try {
        driver = (FileDriver) LayerFactory.getDM().getDriver("gdbms dbf driver");
      } catch (DriverLoadException e1) {
        logger.error("Error Creando el driver dbf");
      }

      try {
        if (!endFile.exists()) {
          try {
            driver.createSource(
                endFile.getAbsolutePath(), new String[] {"0"}, new int[] {Types.DOUBLE});
          } catch (ReadDriverException e) {
            logger.error("Error en createSource");
          }
          endFile.createNewFile();
        }

        try {
          driver.open(endFile);
        } catch (OpenDriverException e) {
          logger.error("Error abriendo el fichero de destino");
        }
      } catch (IOException e) {
        try {
          throw new Exception("Error creando el fichero de destino", e);
        } catch (Exception e1) {
          logger.error("Error creando el fichero de destino");
        }
      }

      IWriter writer = ((IWriteable) driver).getWriter();
      ITableDefinition orgDef = new TableDefinition();
      try {
        // Preparing the total rows in the new dbf file, in this case
        // two rows : Name Value
        FieldDescription[] fields = new FieldDescription[2];
        fields[0] = new FieldDescription();
        fields[0].setFieldType(Types.VARCHAR);
        fields[0].setFieldName(PluginServices.getText(this, "Nombre"));
        fields[0].setFieldLength(50);
        fields[1] = new FieldDescription();
        fields[1].setFieldType(Types.DOUBLE);
        fields[1].setFieldName(PluginServices.getText(this, "Valor"));
        fields[1].setFieldLength(50);
        fields[1].setFieldDecimalCount(25);
        fields[1].setFieldLength(100);
        orgDef.setFieldsDesc(fields);
        writer.initialize(orgDef);
      } catch (InitializeWriterException e) {
        logger.error("Error en la inicialización del writer");
      }
      try {
        writer.preProcess();
      } catch (StartWriterVisitorException e) {
        logger.error("Error en el preProcess del writer");
      }
      try {
        int index = 0;
        Value[] value = new Value[2];
        IFeature feat = null;

        Iterator<MyObjectStatistics> iterador = valores.listIterator();

        while (iterador.hasNext()) {
          MyObjectStatistics data = (MyObjectStatistics) iterador.next();
          value[0] = ValueFactory.createValue(data.getKey());
          value[1] = ValueFactory.createValue(data.getValue());
          feat = new DefaultFeature(null, value, "" + index++);
          write(writer, feat, index);
        }
      } catch (Exception e) {
        logger.error("Error en el write");
      }
      try {
        writer.postProcess(); // Operation finished
        JOptionPane.showMessageDialog(
            null,
            PluginServices.getText(this, "fichero_creado_en") + " " + endFile.getAbsolutePath(),
            PluginServices.getText(this, "fichero_creado_en_formato") + " dbf",
            JOptionPane.INFORMATION_MESSAGE); // Informing the user
      } catch (StopWriterVisitorException e) {
        logger.error("Error en el postProcess del writer");
      }
    } catch (Exception e) { // Informing the user
      logger.error("Error exportando a formato dbf");
      JOptionPane.showMessageDialog(
          null,
          PluginServices.getText(this, "Error_exportando_las_estadisticas")
              + " "
              + endFile.getAbsolutePath(),
          PluginServices.getText(this, "Error"),
          JOptionPane.ERROR_MESSAGE);
    }
  }
  public void testExtendDangleFix() throws BaseException {

    GeneralPathX gpx = new GeneralPathX();
    gpx.moveTo(190, 200);
    gpx.lineTo(260, 130);
    gpx.lineTo(360, 140);
    gpx.lineTo(420, 180);
    gpx.lineTo(470, 220);
    gpx.lineTo(530, 240);
    FGeometry geometry = (FGeometry) ShapeFactory.createPolyline2D(gpx);

    GeneralPathX gpx2 = new GeneralPathX();
    gpx2.moveTo(860, 70);
    gpx2.lineTo(970, 120);
    gpx2.lineTo(1000, 220);
    gpx2.lineTo(920, 300);
    // gpx2.lineTo(470, 220); Cuando varios rectangulos contienen un mismo
    // punto,
    // el operador NNearest solo devuelve el primero que se insertara en el
    // indice
    gpx2.lineTo(1000, 370);
    FGeometry geometry2 = (FGeometry) ShapeFactory.createPolyline2D(gpx2);

    double searchRadius = 400d;

    Value[] values1 = new Value[1];
    values1[0] = ValueFactory.createValue(5d);

    Value[] values2 = new Value[1];
    values2[0] = ValueFactory.createValue(199d);

    DefaultFeature f1 = new DefaultFeature(geometry, values1, "0");
    DefaultFeature f2 = new DefaultFeature(geometry2, values2, "1");

    List<IFeature> features = new ArrayList<IFeature>();
    features.add(f1);
    features.add(f2);
    LayerDefinition def =
        new LayerDefinition() {
          public int getShapeType() {
            return FShape.LINE;
          }
        };
    def.setFieldsDesc(new FieldDescription[] {});
    FeatureCollectionMemoryDriver driver = new FeatureCollectionMemoryDriver("", features, def);
    FLyrVect lyr =
        (FLyrVect) com.iver.cit.gvsig.fmap.layers.LayerFactory.createLayer("", driver, null);

    Topology topo = new Topology(null, null, 0.2d, 0, new SimpleTopologyErrorContainer());

    LineMustNotHaveDangles violatedRule = new LineMustNotHaveDangles(topo, lyr, 0.1d);

    FGeometry dangleGeometry = (FGeometry) ShapeFactory.createPoint2D(530, 240);
    TopologyError error = new TopologyError(dangleGeometry, violatedRule, f1, topo);
    topo.addTopologyError(error);

    new ExtendDangleToNearestVertexFix(searchRadius).fix(error);

    assertTrue(topo.getNumberOfErrors() == 0);

    f1.setGeometry(geometry);
    topo.addTopologyError(error);

    new ExtendDangleToNearestBoundaryPointFix(searchRadius).fix(error);

    assertTrue(topo.getNumberOfErrors() == 0);
  }