private void traceContour(
      float[][] grid,
      int[] cell,
      double level,
      double west,
      double north,
      double cellSize,
      GeoSet levelGeoSet) {

    GeoPath geoPath = traceContour(grid, cell, level, west, north, cellSize);
    if (geoPath != null && geoPath.getPointsCount() > 1) {
      levelGeoSet.add(geoPath);
    }
  }
  public GeoObject operate(GeoGrid geoGrid, double firstContourLevel, double lastContourLevel) {
    flags = new boolean[geoGrid.getRows()][geoGrid.getCols()];

    GeoSet geoSet = new GeoSet();

    final int nlevels = (int) ((lastContourLevel - firstContourLevel) / interval) + 1;
    if (treatDegreeJump) {
      GeoSet levelGeoSet = new GeoSet();
      this.contourLevel(geoGrid, 0.f, levelGeoSet);
      levelGeoSet.setName(Float.toString(0.f));
      geoSet.add(levelGeoSet);
    }

    for (int i = 0; i < nlevels; ++i) {
      final double contourLevel = firstContourLevel + i * interval;
      GeoSet levelGeoSet = new GeoSet();
      this.contourLevel(geoGrid, contourLevel, levelGeoSet);
      levelGeoSet.setName(Double.toString(contourLevel));
      geoSet.add(levelGeoSet);
    }
    return geoSet;
  }
  /**
   * Exports map features to a file. The user is asked to select a file path to a new file. This is
   * designed for vector data.
   *
   * @param exporter The GeoSetExporter to export the exporterMap. If null, the user is asked to
   *     select a GeoSetExporter from a list.
   * @param geoSet The GeoSet to export.
   * @param fileName A default file name without extension. If null, the name of the GeoSet is used.
   * @param frame The Frame for which the dialog for selecting a file is displayed.
   * @param pageFormat The page format for exporting to vector graphics formats (not georeferenced
   *     formats). If null and the exporter is a VectorGraphicsExporter, the page format of the
   *     exporter is used. If this is also null, a default page format is used that includes the
   *     whole GeoSet to export.
   * @param askScale If true and if exporting to a vector graphics format (not a georeferenced GIS
   *     format), the user is asked for a scale that is applied to the data prior to export.
   */
  public static void export(
      GeoSetExporter exporter,
      GeoSet geoSet,
      String fileName,
      Frame frame,
      PageFormat pageFormat,
      boolean askScale,
      String applicationName,
      String documentName,
      String documentAuthor,
      String documentSubject,
      String documentKeyWords,
      ProgressIndicator progressIndicator) {

    try {
      if (exporter == null) {
        exporter = GeoExportGUI.askExporter(frame);
      }
      if (exporter == null) {
        return; // user cancelled
      }

      // construct a message for the file selection dialog
      exporter.setApplicationName(applicationName);
      exporter.setDocumentName(documentName);
      exporter.setDocumentAuthor(documentAuthor);
      exporter.setDocumentSubject(documentSubject);
      exporter.setDocumentKeyWords(documentKeyWords);

      String msg = "Save " + exporter.getFileFormatName() + " File";

      // construct a file name
      if (fileName == null) {
        fileName = geoSet.getName();
      }
      String ext = exporter.getFileExtension();
      fileName = FileUtils.forceFileNameExtension(fileName, ext);

      // ask the user for a file.
      String filePath = FileUtils.askFile(frame, msg, fileName, false, ext);
      if (filePath == null) {
        return; // user canceled
      }

      // ask the user for a scale for graphics file formats if the exporter
      // does not have a valid page format. Don't do this for georeferenced
      // GIS export formats.
      if (exporter instanceof VectorGraphicsExporter) {
        VectorGraphicsExporter gExporter = (VectorGraphicsExporter) exporter;
        if (pageFormat == null) {
          pageFormat = gExporter.getPageFormat();
        }
        if (pageFormat == null) {
          pageFormat = new PageFormat();
          pageFormat.setAutomatic(true);
          Rectangle2D box = geoSet.getBounds2D(GeoObject.UNDEFINED_SCALE);
          pageFormat.setPageWorldCoordinates(box);
        }
        if (askScale) {
          if (!GeoExportGUI.askScale(exporter, pageFormat, geoSet, frame)) {
            return;
          }
        } else {
          gExporter.setPageFormat(pageFormat);
        }
      } else if (exporter instanceof RasterImageExporter) {
        String rasterSizeMsg = "Please enter the width of the image in pixels:";
        String rasterTitle = "Image Width";
        String widthStr =
            (String)
                JOptionPane.showInputDialog(
                    frame,
                    rasterSizeMsg,
                    rasterTitle,
                    JOptionPane.QUESTION_MESSAGE,
                    null,
                    null,
                    new Integer(1000));
        if (widthStr == null) {
          return; // user canceled
        }
        try {
          int width = (int) Double.parseDouble(widthStr);
          ((RasterImageExporter) exporter).setImageWidth(width);
        } catch (NumberFormatException exc) {
          ErrorDialog.showErrorDialog("Please enter a valid number for the image width.");
          return;
        }
      }

      if (progressIndicator == null) {
        GeoExportGUI.export(exporter, geoSet, filePath, null);
      } else {
        new GeoExportTask(exporter, geoSet, filePath, progressIndicator).execute();
      }

    } catch (Exception e) {
      // show an error message.
      String msg = "The data could not be exported.";
      ika.utils.ErrorDialog.showErrorDialog(msg, "Export Error", e, frame);
      e.printStackTrace();
    }
  }