コード例 #1
0
  /**
   * Adds a map to the catalog into the right Mapset.
   *
   * <p>Note: this doesn't add the file. The file adding has to be done separately
   *
   * @param locationPath the path to the Location folder.
   * @param mapsetName the name of the Mapset into which to put the map.
   * @param mapName the name of the map to add.
   * @param mapType the format of the map to add.
   * @return the resource that has been added.
   */
  public static synchronized JGrassMapGeoResource addMapToCatalog(
      String locationPath, String mapsetName, String mapName, String mapType) {
    // URL mapsetId = JGrassMapsetGeoResource.createId(locationPath, mapsetName);

    JGrassMapsetGeoResource mapset = null;
    try {
      File locationFile = new File(locationPath);

      ID locationId = new ID(locationFile.toURI().toURL());
      URL mapsetUrl = JGrassMapsetGeoResource.createId(locationFile.getAbsolutePath(), mapsetName);
      ID mapsetId = new ID(mapsetUrl);
      ICatalog localCatalog = CatalogPlugin.getDefault().getLocalCatalog();
      mapset =
          localCatalog.getById(
              JGrassMapsetGeoResource.class, mapsetId, ProgressManager.instance().get());
      if (mapset == null) {
        // try with the service
        // URL locationId = JGrassService.createId(locationPath);
        JGrassService locationService =
            localCatalog.getById(JGrassService.class, locationId, ProgressManager.instance().get());
        mapset = locationService.getMapsetGeoresourceByName(mapsetName);
      }
    } catch (MalformedURLException e) {
      e.printStackTrace();
      String message = "An error occurred while adding the map to the catalog";
      ExceptionDetailsDialog.openError(null, message, IStatus.ERROR, JGrassPlugin.PLUGIN_ID, e);
    }
    if (mapset == null) return null;
    return mapset.addMap(mapName, mapType);
  }
コード例 #2
0
  /**
   * Remove a map from the mapset in the catalog.
   *
   * <p>Note: this doesn't remove the file. The file removal has to be done separately
   *
   * @param locationPath the path to the Location folder.
   * @param mapsetName the name of the Mapset from which to remove the map.
   * @param mapName the name of the map to remove.
   * @param mapType the format of the map to remove.
   */
  public static synchronized void removeMapFromCatalog(
      String locationPath, String mapsetName, String mapName, String mapType) {
    // URL mapsetId = JGrassMapsetGeoResource.createId(locationPath, mapsetName);
    File locationFile = new File(locationPath);
    URL mapsetUrl = JGrassMapsetGeoResource.createId(locationFile.getAbsolutePath(), mapsetName);
    ID mapsetId = new ID(mapsetUrl);

    JGrassMapsetGeoResource mapset =
        CatalogPlugin.getDefault()
            .getLocalCatalog()
            .getById(JGrassMapsetGeoResource.class, mapsetId, ProgressManager.instance().get());
    mapset.removeMap(mapName, mapType);
  }