Example #1
0
  /** Read the configuration information from individual layers from the config file. */
  private void readLayerConfig() {
    for (Layer layer : this.getLayers()) // all the layers, scalars and vectors
    {
      // Load the Variable object from the config file or create a new
      // one if it doesn't exist.
      Variable var = this.getVariables().get(layer.getId());
      if (var == null) {
        var = new Variable();
        var.setId(layer.getId());
        this.addVariable(var);
      }

      // If there is no title set for this layer in the config file, we
      // use the title that was read by the DataReader.
      if (var.getTitle() == null) var.setTitle(layer.getTitle());

      // Set the colour scale range.  If this isn't specified in the
      // config information, load an "educated guess" at the scale range
      // from the source data.
      if (var.getColorScaleRange() == null) {
        this.appendLoadingProgress("Reading min-max data for layer " + layer.getName());
        Range<Float> valueRange;
        try {
          valueRange = WmsUtils.estimateValueRange(layer);
          if (valueRange.isEmpty()) {
            // We failed to get a valid range.  Just guess at a scale
            valueRange = Ranges.newRange(-50.0f, 50.0f);
          } else if (valueRange.getMinimum().equals(valueRange.getMaximum())) {
            // This happens occasionally if the above algorithm happens
            // to hit an area of uniform data.  We make sure that
            // the max is greater than the min.
            valueRange = Ranges.newRange(valueRange.getMinimum(), valueRange.getMaximum() + 1.0f);
          } else {
            // Set the scale range of the layer, factoring in a 10% expansion
            // to deal with the fact that the sample data we read might
            // not be representative
            float diff = valueRange.getMaximum() - valueRange.getMinimum();
            valueRange =
                Ranges.newRange(
                    valueRange.getMinimum() - 0.05f * diff, valueRange.getMaximum() + 0.05f * diff);
          }
        } catch (Exception e) {
          logger.error(
              "Error reading min-max from layer " + layer.getId() + " in dataset " + this.id, e);
          valueRange = Ranges.newRange(-50.0f, 50.0f);
        }
        var.setColorScaleRange(valueRange);
      }
    }
  }
Example #2
0
 private static Range<Float> getRange(Element parentElement, String childName)
     throws WmsConfigException {
   String str = parentElement.getChildTextTrim(childName);
   if (str == null) return null;
   String[] els = str.split(" ");
   if (els.length != 2) {
     throw new WmsConfigException("Invalid range format");
   }
   try {
     float min = Float.parseFloat(els[0]);
     float max = Float.parseFloat(els[1]);
     return Ranges.newRange(min, max);
   } catch (NumberFormatException nfe) {
     throw new WmsConfigException("Invalid floating-point value in range");
   }
 }
Example #3
0
 LayerSettings(Element parentElement) throws WmsConfigException {
   if (parentElement == null) return; // Create a set of layer settings with all-null fields
   this.allowFeatureInfo = getBoolean(parentElement, "allowFeatureInfo");
   this.defaultColorScaleRange = getRange(parentElement, "defaultColorScaleRange");
   this.defaultPaletteName = parentElement.getChildTextTrim("defaultPaletteName");
   // If the default palette name tag is used, it must be populated
   // TODO: can we check this against the installed palettes?
   if (this.defaultPaletteName != null && this.defaultPaletteName.isEmpty()) {
     throw new WmsConfigException("defaultPaletteName must contain a value");
   }
   this.defaultNumColorBands =
       getInteger(
           parentElement,
           "defaultNumColorBands",
           Ranges.newRange(5, ColorPalette.MAX_NUM_COLOURS));
   this.logScaling = getBoolean(parentElement, "logScaling");
 }