コード例 #1
0
ファイル: WMS.java プロジェクト: roarbra/geoserver
  /**
   * Returns the list of elevation values for the specified typeInfo based on the dimension
   * representation: all values for {@link DimensionPresentation#LIST}, otherwise min and max
   *
   * @param typeInfo
   * @return
   * @throws IOException
   */
  public TreeSet<Double> getFeatureTypeElevations(FeatureTypeInfo typeInfo) throws IOException {
    // grab the time metadata
    DimensionInfo elevation =
        typeInfo.getMetadata().get(ResourceInfo.ELEVATION, DimensionInfo.class);
    if (elevation == null || !elevation.isEnabled()) {
      throw new ServiceException(
          "Layer " + typeInfo.getPrefixedName() + " does not have elevation support enabled");
    }

    FeatureCollection collection = getDimensionCollection(typeInfo, elevation);

    TreeSet<Double> result = new TreeSet<Double>();
    if (elevation.getPresentation() == DimensionPresentation.LIST
        || (elevation.getPresentation() == DimensionPresentation.DISCRETE_INTERVAL
            && elevation.getResolution() == null)) {
      final UniqueVisitor visitor = new UniqueVisitor(elevation.getAttribute());
      collection.accepts(visitor, null);

      @SuppressWarnings("unchecked")
      Set<Object> values = visitor.getUnique();
      if (values.size() <= 0) {
        result = null;
      } else {
        for (Object value : values) {
          result.add(((Number) value).doubleValue());
        }
      }
    } else {
      final MinVisitor min = new MinVisitor(elevation.getAttribute());
      collection.accepts(min, null);
      // check calcresult first to avoid potential IllegalStateException if no features are in
      // collection
      CalcResult calcResult = min.getResult();
      if (calcResult != CalcResult.NULL_RESULT) {
        result.add(((Number) min.getMin()).doubleValue());
        final MaxVisitor max = new MaxVisitor(elevation.getAttribute());
        collection.accepts(max, null);
        result.add(((Number) max.getMax()).doubleValue());
      }
    }

    return result;
  }
コード例 #2
0
ファイル: WMS.java プロジェクト: roarbra/geoserver
  /**
   * Returns the list of time values for the specified typeInfo based on the dimension
   * representation: all values for {@link DimensionPresentation#LIST}, otherwise min and max
   *
   * @param typeInfo
   * @return
   * @throws IOException
   */
  public TreeSet<Date> getFeatureTypeTimes(FeatureTypeInfo typeInfo) throws IOException {
    // grab the time metadata
    DimensionInfo time = typeInfo.getMetadata().get(ResourceInfo.TIME, DimensionInfo.class);
    if (time == null || !time.isEnabled()) {
      throw new ServiceException(
          "Layer " + typeInfo.getPrefixedName() + " does not have time support enabled");
    }

    FeatureCollection collection = getDimensionCollection(typeInfo, time);

    TreeSet<Date> result = new TreeSet<Date>();
    if (time.getPresentation() == DimensionPresentation.LIST) {
      final UniqueVisitor visitor = new UniqueVisitor(time.getAttribute());
      collection.accepts(visitor, null);

      @SuppressWarnings("unchecked")
      Set<Date> values = visitor.getUnique();
      if (values.size() <= 0) {
        result = null;
      } else {
        // we might get null values out of the visitor, strip them
        values.remove(null);
        result.addAll(values);
      }
    } else {
      final MinVisitor min = new MinVisitor(time.getAttribute());
      collection.accepts(min, null);
      CalcResult minResult = min.getResult();
      // check calcresult first to avoid potential IllegalStateException if no features are in
      // collection
      if (minResult != CalcResult.NULL_RESULT) {
        result.add((Date) min.getMin());
        final MaxVisitor max = new MaxVisitor(time.getAttribute());
        collection.accepts(max, null);
        result.add((Date) max.getMax());
      }
    }

    return result;
  }
コード例 #3
0
    /**
     * Set the timeDomain metadata in case the dimensionsHelper instance has a timeDimension
     *
     * @param helper
     * @throws IOException
     */
    private void handleTimeMetadata(WCSDimensionsHelper helper) throws IOException {
      Utilities.ensureNonNull("helper", helper);
      final DimensionInfo timeDimension = helper.getTimeDimension();
      if (timeDimension != null) {
        start(initStartMetadataTag(TAG.TIME_DOMAIN, null, timeDimension, helper));
        final DimensionPresentation presentation = timeDimension.getPresentation();
        final String id = helper.getCoverageId();
        switch (presentation) {
          case CONTINUOUS_INTERVAL:
            encodeTimePeriod(helper.getBeginTime(), helper.getEndTime(), id + "_tp_0", null, null);
            break;
          case DISCRETE_INTERVAL:
            encodeTimePeriod(
                helper.getBeginTime(),
                helper.getEndTime(),
                id + "_tp_0",
                helper.getTimeResolutionUnit(),
                helper.getTimeResolutionValue());
            break;
          default:
            // TODO: check if we are in the list of instants case, or in the list of periods case

            // list case
            final TreeSet<Object> domain = helper.getTimeDomain();
            int i = 0;
            for (Object item : domain) {
              // gml:id is mandatory for time instant...
              if (item instanceof Date) {
                encodeDate((Date) item, helper, id + "_td_" + i);
              } else if (item instanceof DateRange) {
                encodeDateRange((DateRange) item, helper, id + "_td_" + i);
              }
              i++;
            }
            break;
        }
        end(TAG.TIME_DOMAIN);
      }
    }
コード例 #4
0
    /**
     * Set the elevationDomain metadata in case the dimensionsHelper instance has an
     * elevationDimension
     *
     * @param helper
     * @throws IOException
     */
    private void handleElevationMetadata(WCSDimensionsHelper helper) throws IOException {
      // Null check has been performed in advance
      final DimensionInfo elevationDimension = helper.getElevationDimension();
      if (elevationDimension != null) {
        start(initStartMetadataTag(TAG.ELEVATION_DOMAIN, null, elevationDimension, helper));
        final DimensionPresentation presentation = elevationDimension.getPresentation();
        switch (presentation) {
            // Where _er_ means elevation range
          case CONTINUOUS_INTERVAL:
            encodeInterval(helper.getBeginElevation(), helper.getEndElevation(), null, null);
            break;
          case DISCRETE_INTERVAL:
            encodeInterval(
                helper.getBeginElevation(),
                helper.getEndElevation(),
                helper.getElevationResolutionUnit(),
                helper.getElevationResolutionValue());
            break;
          default:
            // TODO: check if we are in the list of instants case, or in the list of periods case

            // list case
            final TreeSet<Object> domain = helper.getElevationDomain();
            for (Object item : domain) {
              if (item instanceof Number) {
                element(TAG.SINGLE_VALUE, item.toString());
              } else if (item instanceof NumberRange) {
                NumberRange range = (NumberRange) item;
                encodeInterval(
                    range.getMinValue().toString(), range.getMaxValue().toString(), null, null);
              }
            }
            break;
        }
        end(TAG.ELEVATION_DOMAIN);
      }
    }