Exemplo n.º 1
0
  /**
   * @param style
   * @param gm
   * @param queries
   * @return a list of dimension warnings
   * @throws MissingDimensionValue
   * @throws InvalidDimensionValue
   */
  public LinkedList<String> collectQueries(Style style, final GetMap gm, LinkedList<Query> queries)
      throws MissingDimensionValue, InvalidDimensionValue {
    final Envelope bbox = gm.getBoundingBox();

    Set<Expression> exprs = new HashSet<Expression>();

    final ValueReference geomProp;

    exprs.addAll(Styles.getGeometryExpressions(style));

    if (exprs.size() == 1 && exprs.iterator().next() instanceof ValueReference) {
      geomProp = (ValueReference) exprs.iterator().next();
    } else {
      geomProp = null;
    }

    final Pair<Filter, LinkedList<String>> dimFilter = getDimensionFilter(gm.getDimensions());
    final Filter filter =
        gm.getFilterForLayer(this.getName(), dimFilter == null ? null : dimFilter.first, style);
    if (style != null) {
      QName ftName = style.getFeatureType();
      if (ftName != null && datastore.getSchema().getFeatureType(ftName) == null) {
        LOG.warn("FeatureType '" + ftName + "' from style is not known to the FeatureStore.");
        return new LinkedList<String>();
      }
    }

    QName featureType = style == null ? null : style.getFeatureType();
    final int maxFeatures = gm.getRenderingOptions().getMaxFeatures(getName());
    if (featureType == null && datastore != null) {
      queries.addAll(
          map(
              datastore.getSchema().getFeatureTypes(null, false, false),
              new Mapper<Query, FeatureType>() {
                @Override
                public Query apply(FeatureType u) {
                  Filter fil = Filters.addBBoxConstraint(bbox, filter, geomProp);
                  return new Query(
                      u.getName(), fil, round(gm.getScale()), maxFeatures, gm.getResolution());
                }
              }));
    } else {
      Query query =
          new Query(
              featureType,
              Filters.addBBoxConstraint(bbox, filter, geomProp),
              round(gm.getScale()),
              maxFeatures,
              gm.getResolution());
      queries.add(query);
    }
    return dimFilter == null ? new LinkedList<String>() : dimFilter.second;
  }
Exemplo n.º 2
0
  @Override
  public Envelope getBbox() {
    if (super.getBbox() != null) {
      return super.getBbox();
    }

    if (datastore == null || !datastore.isAvailable()) {
      return null;
    }

    // always use up-to-date envelope
    Envelope bbox = null;
    AppSchema schema = datastore.getSchema();

    List<Style> styles = service.registry.getAll(getName());
    List<QName> ftNames = new LinkedList<QName>();
    for (Style s : styles) {
      if (s.getFeatureType() != null) {
        ftNames.add(s.getFeatureType());
      }
    }
    if (ftNames.isEmpty()) {
      for (FeatureType t : schema.getFeatureTypes(null, false, false)) {
        ftNames.add(t.getName());
      }
    }

    for (QName t : ftNames) {
      Envelope thisBox = null;
      try {
        thisBox = datastore.getEnvelope(t);
      } catch (FeatureStoreException e) {
        LOG.error("Error retrieving envelope from FeatureStore: " + e.getMessage(), e);
      }
      if (bbox == null) {
        bbox = thisBox;
      } else {
        if (thisBox != null) {
          bbox = bbox.merge(thisBox);
        }
      }
    }
    return bbox;
  }
Exemplo n.º 3
0
  @Override
  public Pair<FeatureCollection, LinkedList<String>> getFeatures(
      final GetFeatureInfo fi, Style style) throws MissingDimensionValue, InvalidDimensionValue {

    try {
      final Pair<Filter, LinkedList<String>> dimFilter = getDimensionFilter(fi.getDimensions());

      final Envelope clickBox = fi.getClickBox();
      OperatorFilter filter = dimFilter == null ? null : (OperatorFilter) dimFilter.first;
      if (filter == null) {
        double scale =
            calcScaleWMS130(
                fi.getWidth(),
                fi.getHeight(),
                fi.getEnvelope(),
                fi.getCoordinateSystem(),
                DEFAULT_PIXEL_SIZE);
        filter = getStyleFilters(style, scale);
      } else {
        double scale =
            calcScaleWMS130(
                fi.getWidth(),
                fi.getHeight(),
                fi.getEnvelope(),
                fi.getCoordinateSystem(),
                DEFAULT_PIXEL_SIZE);
        OperatorFilter f = getStyleFilters(style, scale);
        if (f != null) {
          filter = new OperatorFilter(new And(filter.getOperator(), f.getOperator()));
        }
      }

      Set<Expression> exprs = new HashSet<Expression>();

      final ValueReference geomProp;

      exprs.addAll(Styles.getGeometryExpressions(style));

      if (exprs.size() == 1 && exprs.iterator().next() instanceof ValueReference) {
        geomProp = (ValueReference) exprs.iterator().next();
      } else {
        geomProp = null;
      }

      final Operator operator = filter == null ? null : filter.getOperator();

      QName featureType = style == null ? null : style.getFeatureType();

      LOG.debug("Querying the feature store(s)...");

      FeatureCollection col;
      if (featureType == null) {
        List<Query> queries =
            map(
                datastore.getSchema().getFeatureTypes(null, false, false),
                new Mapper<Query, FeatureType>() {
                  @Override
                  public Query apply(FeatureType u) {
                    return new Query(
                        u.getName(),
                        buildFilter(operator, u, clickBox, geomProp),
                        -1,
                        fi.getFeatureCount(),
                        -1);
                  }
                });
        clearNulls(queries);
        col = clearDuplicates(datastore.query(queries.toArray(new Query[queries.size()])));
      } else {
        FeatureType ft = datastore.getSchema().getFeatureType(featureType);
        Query query =
            new Query(
                featureType,
                buildFilter(operator, ft, clickBox, geomProp),
                -1,
                fi.getFeatureCount(),
                -1);
        col = clearDuplicates(datastore.query(query));
      }

      LOG.debug("Finished querying the feature store(s).");

      return new Pair<FeatureCollection, LinkedList<String>>(
          col, dimFilter == null ? new LinkedList<String>() : dimFilter.second);
    } catch (FilterEvaluationException e) {
      LOG.warn("A filter could not be evaluated. The error was '{}'.", e.getLocalizedMessage());
      LOG.trace("Stack trace:", e);
    } catch (FeatureStoreException e) {
      LOG.warn(
          "Data could not be fetched from the feature store. The error was '{}'.",
          e.getLocalizedMessage());
      LOG.trace("Stack trace:", e);
    }

    return new Pair<FeatureCollection, LinkedList<String>>(null, new LinkedList<String>());
  }