public void testMin() throws Exception {
    FilterFactory ff = dataStore.getFilterFactory();
    PropertyName p = ff.property(aname("doubleProperty"));

    MinVisitor v = new MyMinVisitor(p);
    dataStore.getFeatureSource(tname("ft1")).accepts(Query.ALL, v, null);
    assertFalse(visited);
    assertEquals(0.0, v.getResult().toDouble(), 0.01);
  }
  public void testMinWithFilter() throws Exception {
    FilterFactory ff = dataStore.getFilterFactory();
    PropertyName p = ff.property(aname("doubleProperty"));

    MinVisitor v = new MyMinVisitor(p);

    Filter f = ff.greater(ff.property(aname("doubleProperty")), ff.literal(1));
    Query q = new DefaultQuery(tname("ft1"), f);
    dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null);
    assertFalse(visited);
    assertEquals(1.1, v.getResult().toDouble(), 0.01);
  }
  public void testMinWithLimitOffset() throws Exception {
    if (!dataStore.getSQLDialect().isLimitOffsetSupported()) {
      return;
    }
    FilterFactory ff = dataStore.getFilterFactory();
    PropertyName p = ff.property(aname("doubleProperty"));

    MinVisitor v = new MyMinVisitor(p);

    DefaultQuery q = new DefaultQuery(tname("ft1"));
    q.setStartIndex(0);
    q.setMaxFeatures(2);
    dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null);

    assertFalse(visited);
    assertEquals(0.0, v.getResult().toDouble(), 0.01);
  }
    /**
     * Collects features domain to be exposed as metadata
     *
     * @param filePath
     * @param aggregate
     * @param firstFeature
     * @return
     */
    private Map<String, Object> computeGroupMetadata(
        String filePath, boolean aggregate, SimpleFeature firstFeature) {
      Map<String, Object> metadataMap = null;
      List<DimensionDescriptor> dimensionDescriptors = rasterManager.getDimensionDescriptors();
      // extract metadata for the available domains
      if (dimensionDescriptors != null && !dimensionDescriptors.isEmpty()) {
        Filter filter = FF.equals(FF.property("location"), FF.literal(filePath));
        metadataMap = new HashMap<String, Object>();
        try {
          // scan dimensions
          for (DimensionDescriptor descriptor : dimensionDescriptors) {
            String attribute = descriptor.getStartAttribute();
            String name = descriptor.getName();
            Comparable max = null;
            Comparable min = null;
            if (aggregate) {
              Query query = new Query(typeName);
              query.setFilter(filter);
              query.setPropertyNames(Arrays.asList(attribute));
              // Repeat the queries to avoid using a in-Memory
              // featureCollection
              // We may consider caching the features in case
              // the collection size isn't too big

              final MaxVisitor maxVisitor = new MaxVisitor(attribute);
              granuleCatalog.computeAggregateFunction(query, maxVisitor);
              max = maxVisitor.getMax();
              MinVisitor minVisitor = new MinVisitor(attribute);
              granuleCatalog.computeAggregateFunction(query, minVisitor);
              min = minVisitor.getMin();
            } else {
              max = min = (Comparable) firstFeature.getAttribute(attribute);
            }
            addMetadaElement(name, min, max, metadataMap);
          }

          addBBOX(aggregate, filter, firstFeature, metadataMap);
        } catch (IOException e) {
          throw new RuntimeException("Exception occurred while parsing the feature domains", e);
        }
      }
      return metadataMap;
    }
Пример #5
0
  /**
   * 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;
  }
Пример #6
0
  /**
   * 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;
  }
 /**
  * Calculate minimum (using FeatureCalc) - only one parameter is used.
  *
  * @param collection collection to calculate the minimum
  * @param expression Single Expression argument
  * @return An object containing the minimum value of the attributes
  * @throws IllegalFilterException
  * @throws IOException
  */
 static CalcResult calculateMin(SimpleFeatureCollection collection, Expression expression)
     throws IllegalFilterException, IOException {
   MinVisitor minVisitor = new MinVisitor(expression);
   collection.accepts(minVisitor, null);
   return minVisitor.getResult();
 }
 public void visit(SimpleFeature feature) {
   super.visit(feature);
   visited = true;
 }