@Override
  public boolean performFinish() {
    // TODO create a nice workspace with the properties
    for (String m : props.mapsets) {
      System.out.println(m);
    }
    System.out.println(props.locationPath);
    System.out.println(props.north);
    System.out.println(props.xres);
    System.out.println(props.crs.getName().toString());

    try {
      JGrassRegion window =
          new JGrassRegion(
              props.west, props.east, props.south, props.north, props.xres, props.yres);
      JGrassCatalogUtilities.createLocation(props.locationPath, props.crs, window);
      for (String mapset : props.mapsets) {
        JGrassCatalogUtilities.createMapset(props.locationPath, mapset, null, null);
        // set the WIND file
        String mapsetPath = props.locationPath + File.separator + mapset;
        JGrassRegion.writeWINDToMapset(mapsetPath, window);
      }

      JGrassCatalogUtilities.addServiceToCatalog(
          props.locationPath + File.separator + JGrassCatalogUtilities.JGRASS_WORKSPACE_FILENAME,
          new NullProgressMonitor());
    } catch (IOException e) {
      JGrassPlugin.log(
          "JGrassPlugin problem: eu.hydrologis.udig.catalog.workspacecreation.wizard#NewJGrassLocationWizard#performFinish",
          e); //$NON-NLS-1$
      e.printStackTrace();
    }

    return true;
  }
예제 #2
0
  public static void copyToNewMapset(String mapsetName, String... maps) {
    String originalMapsetPath = p_locationPath + File.separator + p_mapsetName;
    String mapsetPath = p_locationPath + File.separator + mapsetName;

    File f = new File(mapsetPath);
    if (f.exists()) {
      p_err.println(
          "The mapset already exists. Can't export to an existing mapset. Choose a different name.");
      return;
    }

    boolean createdMapset =
        JGrassCatalogUtilities.createMapset(p_locationPath, mapsetName, null, null);
    if (!createdMapset) {
      p_err.println(
          "An error occurred while creating the new mapset structure. Check your permissions.");
    }

    StringBuilder warnings = new StringBuilder();
    monitor.beginTask("Copy maps...", maps.length);
    for (String mapName : maps) {
      monitor.worked(1);
      String[] originalMapsPath = JGrassUtilities.filesOfRasterMap(originalMapsetPath, mapName);
      String[] copiedMapsPath = JGrassUtilities.filesOfRasterMap(mapsetPath, mapName);

      for (int i = 0; i < originalMapsPath.length; i++) {
        File orig = new File(originalMapsPath[i]);
        if (!orig.exists()) {
          warnings.append("\nWarning: The following file didn't exist: " + originalMapsPath[i]);
          continue;
        }
        if (orig.isDirectory()) {
          continue;
        }
        File copiedParent = new File(copiedMapsPath[i]).getParentFile();
        if (!copiedParent.exists()) {
          copiedParent.mkdirs();
        }
        FileUtilities.copyFile(originalMapsPath[i], copiedMapsPath[i]);
      }
    }
    monitor.done();
    p_out.println(warnings.toString());
  }