コード例 #1
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);
    }
  }
コード例 #2
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);
    }
  }
コード例 #3
0
  public boolean launchGeoprocess() {
    FLyrVect inputLayer = geoProcessingConvexHullPanel.getInputLayer();
    FLayers layers = geoProcessingConvexHullPanel.getFLayers();
    File outputFile = null;
    try {
      outputFile = geoProcessingConvexHullPanel.getOutputFile();
    } catch (FileNotFoundException e3) {
      String error = PluginServices.getText(this, "Error_entrada_datos");
      String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado");
      geoProcessingConvexHullPanel.error(errorDescription, error);
      return false;
    }
    if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) {
      String error = PluginServices.getText(this, "Error_entrada_datos");
      String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado");
      geoProcessingConvexHullPanel.error(errorDescription, error);
      return false;
    }
    if (outputFile.exists()) {
      if (!geoProcessingConvexHullPanel.askForOverwriteOutputFile(outputFile)) {
        return false;
      }
    }
    ConvexHullGeoprocess convexHull = new ConvexHullGeoprocess();
    convexHull.setFirstOperand(inputLayer);

    SHPLayerDefinition definition = (SHPLayerDefinition) convexHull.createLayerDefinition();
    definition.setFile(outputFile);
    ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
    IWriter writer = null;
    try {
      writer = getShpWriter(definition);
    } catch (Exception e1) {
      String error = PluginServices.getText(this, "Error_escritura_resultados");
      String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados");
      geoProcessingConvexHullPanel.error(errorDescription, error);
      return false;
    }
    convexHull.setResultLayerProperties(writer, schemaManager);
    HashMap params = new HashMap();
    boolean onlySelected = geoProcessingConvexHullPanel.isConvexHullOnlySelected();
    params.put("layer_selection", new Boolean(onlySelected));
    try {
      convexHull.setParameters(params);
      convexHull.checkPreconditions();
      IMonitorableTask task1 = convexHull.createTask();
      if (task1 == null) {
        return false;
      }
      AddResultLayerTask task2 = new AddResultLayerTask(convexHull);
      task2.setLayers(layers);
      MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1, task2);
      if (globalTask.preprocess()) PluginServices.cancelableBackgroundExecution(globalTask);

    } catch (GeoprocessException e) {
      String error = PluginServices.getText(this, "Error_ejecucion");
      String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso");
      errorDescription = "<html>" + errorDescription + ":<br>" + e.getMessage() + "</html>";
      geoProcessingConvexHullPanel.error(errorDescription, error);
      return false;
    }
    return true;
  }