Example #1
0
 private void buildLocations() {
   guiLogger.info("Building Locations from ERDDAP Dataset: " + this.getTitle());
   try {
     ClientConfig clientConfig = new DefaultClientConfig();
     clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
     Client c = Client.create(clientConfig);
     guiLogger.info(
         "Request: "
             + this.getTabledap()
             + ".json?"
             + this.getX().getName()
             + ","
             + this.getY().getName()
             + "&distinct()");
     WebResource wr =
         c.resource(
             this.getTabledap()
                 + ".json?"
                 + this.getX().getName()
                 + ","
                 + this.getY().getName()
                 + "&distinct()");
     JSONObject result = wr.get(JSONObject.class);
     JSONArray ar = result.getJSONObject("table").getJSONArray("rows");
     locations = new ArrayList<SensorContainer>(ar.length());
     SensorContainer senc;
     double[] loc = new double[4];
     for (int i = 0; i < ar.length(); i++) {
       senc = new SensorContainer();
       loc[0] = ar.getJSONArray(i).getDouble(1);
       loc[1] = ar.getJSONArray(i).getDouble(0);
       loc[2] = ar.getJSONArray(i).getDouble(1);
       loc[3] = ar.getJSONArray(i).getDouble(0);
       senc.setNESW(loc.clone());
       senc.setName("");
       locations.add(senc);
     }
   } catch (Exception e) {
     guiLogger.error("Exception", e);
   }
 }
Example #2
0
  public void buildVariables() {
    guiLogger.info("Building Variables from ERDDAP Dataset: " + this.getTitle());
    try {
      ClientConfig clientConfig = new DefaultClientConfig();
      clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
      Client c = Client.create(clientConfig);
      guiLogger.info("Request: " + this.getInfo());
      WebResource wr = c.resource(this.getInfo());
      JSONObject result = wr.get(JSONObject.class);
      JSONArray ar = result.getJSONObject("table").getJSONArray("rows");
      variables = new ArrayList<ErddapVariable>();
      ErddapVariable edv = null;
      String[] subsetVars = null;
      Double frst, scnd;
      for (int i = 0; i < ar.length(); i++) {
        if (ar.getJSONArray(i).getString(2).equals("subsetVariables")) {
          subsetVars = ar.getJSONArray(i).getString(4).split(",");
          for (int j = 0; j < subsetVars.length; j++) {
            subsetVars[j] = subsetVars[j].trim();
          }
          continue;
        }

        if (ar.getJSONArray(i).getString(2).equals("cdm_data_type")) {
          cdm_data_type = ar.getJSONArray(i).getString(4);
          continue;
        }

        if (ar.getJSONArray(i).getString(0).equals("variable")) {
          if (edv != null) {
            setAxis(edv);
            variables.add(edv);
          }
          edv =
              new ErddapVariable(
                  this,
                  ar.getJSONArray(i).getString(1),
                  ar.getJSONArray(i).getString(3),
                  Arrays.asList(subsetVars).contains(ar.getJSONArray(i).getString(1).trim()));
          continue;
        }

        if (ar.getJSONArray(i).getString(0).equals("attribute")) {
          if (ar.getJSONArray(i).getString(2).equals("actual_range")) {
            // The range is not always going to be in the correct order
            frst = Double.parseDouble(ar.getJSONArray(i).getString(4).split(",")[0].trim());
            scnd = Double.parseDouble(ar.getJSONArray(i).getString(4).split(",")[1].trim());
            edv.setMin(String.valueOf(Math.min(frst, scnd)));
            edv.setMax(String.valueOf(Math.max(frst, scnd)));
          } else if (ar.getJSONArray(i).getString(2).equals("long_name")) {
            edv.setLongname(ar.getJSONArray(i).getString(4).trim());
          } else if (ar.getJSONArray(i).getString(2).equals("units")) {
            edv.setUnits(ar.getJSONArray(i).getString(4).trim());
          } else if (ar.getJSONArray(i).getString(2).equals("cf_role")) {
            edv.setAxis(ar.getJSONArray(i).getString(4).trim());
          } else if (ar.getJSONArray(i).getString(2).equalsIgnoreCase("description")) {
            edv.setDescription(ar.getJSONArray(i).getString(4).trim());
          }
        }
      }
      // Get the last iteration's edv variable
      if (edv != null) {
        variables.add(edv);
      }

      // Does this dataset have points we can strip out?
      // latitude and longitude also need to be subsetVariables or
      // this might be a long and hard query (from Bob Simmons).
      if (hasX() && hasY() && !getX().getValues().isEmpty() && !getX().getValues().isEmpty()) {
        buildLocations();
      }

    } catch (Exception e) {
      guiLogger.error("Exception", e);
    }
  }