예제 #1
0
  @Override
  public GridCoverage2D read(GeneralParameterValue[] parameters)
      throws IllegalArgumentException, IOException {
    File baseDir = FileUtils.createTempDirectory();

    try {
      File file = readToFile(baseDir, "WcsCoverageReader", parameters);

      // since the requested format may be one of several we need to look
      // up the format object
      // for reading the coverage from the file
      Format format = GridFormatFinder.findFormat(file);

      if (format instanceof AbstractGridFormat && UnknownFormat.class != format.getClass()) {
        AbstractGridFormat gridFormat = (AbstractGridFormat) format;

        // Now we need to find the parameters provided by the caller for
        // reading the coverage from the file
        // See the format API for details
        GeneralParameterValue[] readParams = new GeneralParameterValue[0];
        try {
          ParameterValueGroup group = format.getReadParameters();
          List<GeneralParameterValue> list = new ArrayList<GeneralParameterValue>();
          for (GeneralParameterValue paramValue : group.values()) {
            list.addAll(find(paramValue, parameters));
          }
          LOG.debug("Reading coverage from file using parameters: " + list);
          readParams = list.toArray(new GeneralParameterValue[list.size()]);
        } catch (Exception e) {
          // if can't configure the parameters then try to read with
          // what we have been able to configure
          LOG.warn("Exception occurred while getting request params for reading coverage", e);
        }
        AbstractGridCoverage2DReader reader = gridFormat.getReader(file);
        GridCoverage2D coverage = reader.read(readParams);
        return coverage;
      }
      throw new IllegalArgumentException(
          "Current configuration is unable to read coverage of "
              + file.getName()
              + " format.  "
              + "Check that you have the correct geotools plugins");

    } finally {
      FileUtils.delete(baseDir);
    }
  }
예제 #2
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  @RequestMapping(value = "/{wsName}/{name}", method = RequestMethod.POST)
  public @ResponseBody JSONObj create(
      @PathVariable String wsName,
      @PathVariable String name,
      @RequestBody JSONObj obj,
      HttpServletRequest req)
      throws IOException {
    Catalog cat = geoServer.getCatalog();
    CatalogFactory factory = cat.getFactory();

    WorkspaceInfo workspace = findWorkspace(wsName);
    StoreInfo store = null;

    JSONObj params = obj.object("connection");
    if (params == null) {
      throw new IllegalArgumentException("connection parameters required");
    }
    if (params.has("raster")) {
      String url = params.str("raster");
      CoverageStoreInfo info = factory.createCoverageStore();
      info.setWorkspace(workspace);
      info.setType(name);

      // connect and defaults
      info.setURL(url);
      info.setType(obj.str("type"));
      try {
        GridCoverageReader reader = info.getGridCoverageReader(null, null);
        Format format = reader.getFormat();
        info.setDescription(format.getDescription());
        info.setEnabled(true);
      } catch (IOException e) {
        info.setError(e);
        info.setEnabled(false);
      }
      store = info;
    } else if (params.has("url")
        && params.str("url").toLowerCase().contains("Service=WMS")
        && params.str("url").startsWith("http")) {
      WMSStoreInfo info = factory.createWebMapServer();
      info.setWorkspace(workspace);
      info.setType(name);

      // connect and defaults
      info.setCapabilitiesURL(params.str("url"));
      try {
        WebMapServer service = info.getWebMapServer(new NullProgressListener());
        info.setDescription(service.getInfo().getDescription());
        info.setEnabled(true);
      } catch (Throwable e) {
        info.setError(e);
        info.setEnabled(false);
      }
      store = info;
    } else {
      HashMap map = new HashMap(params.raw());
      Map resolved = ResourcePool.getParams(map, cat.getResourceLoader());
      DataAccess dataStore = DataAccessFinder.getDataStore(resolved);
      if (dataStore == null) {
        throw new IllegalArgumentException(
            "Connection parameters incomplete (does not match an available data store, coverage store or wms store).");
      }
      DataStoreInfo info = factory.createDataStore();
      info.setWorkspace(workspace);
      info.setType(name);
      info.getConnectionParameters().putAll(map);
      try {
        info.setDescription(dataStore.getInfo().getDescription());
        info.setEnabled(true);
      } catch (Throwable e) {
        info.setError(e);
        info.setEnabled(false);
      }
      store = info;
    }
    boolean refresh = define(store, obj);
    if (refresh) {
      LOG.log(
          Level.FINE, "Inconsistent: default connection used for store creation required refresh");
    }
    cat.add(store);

    return storeDetails(new JSONObj(), store, req);
  }