protected List<Feature> setNextFeature(String fId, List<Object> foreignIdValues)
      throws IOException {
    List<Feature> features = new ArrayList<Feature>();
    features.add(curSrcFeature);
    curSrcFeature = null;

    while (getSourceFeatureIterator().hasNext()) {
      Feature next = getSourceFeatureIterator().next();
      if (extractIdForFeature(next).equals(fId) && checkForeignIdValues(foreignIdValues, next)) {
        // HACK HACK HACK
        // evaluate filter that applies to this list as we want a subset
        // instead of full result
        // this is a temporary solution for Bureau of Meteorology
        // requirement for timePositionList
        if (listFilter != null) {
          if (listFilter.evaluate(next)) {
            features.add(next);
          }
          // END OF HACK
        } else {
          features.add(next);
        }
        // HACK HACK HACK
        // evaluate filter that applies to this list as we want a subset
        // instead of full result
        // this is a temporary solution for Bureau of Meteorology
        // requirement for timePositionList
      } else if (listFilter == null || listFilter.evaluate(next)) {
        // END OF HACK
        curSrcFeature = next;
        break;
      }
    }
    return features;
  }
Exemplo n.º 2
0
  /**
   * Filters the rules of <code>featureTypeStyle</code> returnting only those that apply to <code>
   * feature</code>.
   *
   * <p>This method returns rules for which:
   *
   * <ol>
   *   <li><code>rule.getFilter()</code> matches <code>feature</code>, or:
   *   <li>the rule defines an "ElseFilter", and the feature matches no other rules.
   * </ol>
   *
   * This method returns an empty array in the case of which no rules match.
   *
   * @param featureTypeStyle The feature type style containing the rules.
   * @param feature The feature being filtered against.
   */
  public static Rule[] filterRules(
      FeatureTypeStyle featureTypeStyle, SimpleFeature feature, double scaleDenominator) {
    Rule[] rules = featureTypeStyle.getRules();

    if ((rules == null) || (rules.length == 0)) {
      return new Rule[0];
    }

    ArrayList filtered = new ArrayList(rules.length);

    // process the rules, keep track of the need to apply an else filters
    boolean match = false;
    boolean hasElseFilter = false;

    for (int i = 0; i < rules.length; i++) {
      Rule rule = rules[i];
      LOGGER.finer(new StringBuffer("Applying rule: ").append(rule.toString()).toString());

      // does this rule have an else filter
      if (rule.hasElseFilter()) {
        hasElseFilter = true;

        continue;
      }

      // is this rule within scale?
      if (!isWithInScale(rule, scaleDenominator)) {
        continue;
      }

      // does this rule have a filter which applies to the feature
      Filter filter = rule.getFilter();

      if ((filter == null) || filter.evaluate(feature)) {
        match = true;

        filtered.add(rule);
      }
    }

    // if no rules mached the feautre, re-run through the rules applying
    // any else filters
    if (!match && hasElseFilter) {
      // loop through again and apply all the else rules
      for (int i = 0; i < rules.length; i++) {
        Rule rule = rules[i];

        // is this rule within scale?
        if (!isWithInScale(rule, scaleDenominator)) {
          continue;
        }

        if (rule.hasElseFilter()) {
          filtered.add(rule);
        }
      }
    }

    return (Rule[]) filtered.toArray(new Rule[filtered.size()]);
  }
Exemplo n.º 3
0
 /** {@inheritDoc } */
 @Override
 public boolean evaluate(final Object object) {
   for (Filter filter : filterArray) {
     if (!filter.evaluate(object)) {
       return false;
     }
   }
   return true;
 }
  @Override
  public boolean hasNext() {
    boolean exists = !isNextSourceFeatureNull();

    if (!isHasNextCalled()) {
      if (featureCounter < maxFeatures) {
        if (!exists && getSourceFeatureIterator() != null && getSourceFeatureIterator().hasNext()) {
          this.curSrcFeature = getSourceFeatureIterator().next();
          exists = true;
        }
        if (exists && filteredFeatures != null) {
          // get the next one if this row has already been added to the target
          // feature from setNextFilteredFeature
          while (exists && filteredFeatures.contains(extractIdForFeature(this.curSrcFeature))) {
            if (getSourceFeatureIterator() != null && getSourceFeatureIterator().hasNext()) {
              this.curSrcFeature = getSourceFeatureIterator().next();
              exists = true;
            } else {
              exists = false;
            }
          }
        }
        // HACK HACK HACK
        // evaluate filter that applies to this list as we want a subset
        // instead of full result
        // this is a temporary solution for Bureau of Meteorology
        // requirement for timePositionList
        if (listFilter != null) {
          while (exists && !listFilter.evaluate(curSrcFeature)) {
            // only add to subset if filter matches value
            if (getSourceFeatureIterator() != null && getSourceFeatureIterator().hasNext()) {
              this.curSrcFeature = getSourceFeatureIterator().next();
              exists = true;
            } else {
              exists = false;
            }
          }
        }
        // END OF HACK
      } else {
        exists = false;
      }
    }

    if (!exists) {
      LOGGER.finest("no more features, produced " + featureCounter);
      close();
      curSrcFeature = null;
    }

    setHasNextCalled(true);

    return exists;
  }
Exemplo n.º 5
0
 /**
  * @see org.geotools.data.AbstractDataStore#getCount(java.lang.String, org.geotools.data.Query)
  */
 protected int getCount(Query query) throws IOException {
   String featureTypeName = query.getTypeName();
   if (!featureType.getTypeName().equals(featureTypeName)) {
     throw new SchemaNotFoundException(featureTypeName);
   }
   int count = 0;
   FeatureIterator<SimpleFeature> iterator = collection.features();
   try {
     Filter filter = query.getFilter();
     while (iterator.hasNext() && (count < query.getMaxFeatures())) {
       if (filter.evaluate(iterator.next())) {
         count++;
       }
     }
   } finally {
     iterator.close();
   }
   return count;
 }
Exemplo n.º 6
0
  /** @param query */
  protected ReferencedEnvelope getBoundsInternal(Query query) {
    ReferencedEnvelope envelope =
        new ReferencedEnvelope(featureType.getCoordinateReferenceSystem());

    FeatureIterator<SimpleFeature> iterator = collection.features();
    try {
      if (iterator.hasNext()) {
        int count = 1;
        Filter filter = query.getFilter();

        while (iterator.hasNext() && (count < query.getMaxFeatures())) {
          SimpleFeature feature = iterator.next();
          if (filter.evaluate(feature)) {
            count++;
            envelope.expandToInclude(
                ((Geometry) feature.getDefaultGeometry()).getEnvelopeInternal());
          }
        }
      }
    } finally {
      iterator.close();
    }
    return envelope;
  }
Exemplo n.º 7
0
 @Override
 public boolean evaluate(Object object) {
   return filter.evaluate(object);
 }