Esempio n. 1
0
  private void handleSldFromStyleStore(
      File file,
      String namedLayer,
      Map<String, String> map,
      String layerName,
      Map<String, Pair<File, URL>> legends,
      Map<String, Boolean> glgUrls) {
    // already loaded from workspace
    String styleId = file.getName().substring(0, file.getName().length() - 4);
    StyleStore store = styleManager.get(styleId);

    if (store != null) {
      LOG.info("Using SLD file loaded from style store.");
      for (Style s : store.getAll(namedLayer)) {
        s.setName(map.get(s.getName()));
        registry.put(layerName, s, false);
        Pair<File, URL> p = legends.get(s.getName());
        if (p != null && p.first != null) {
          s.setLegendFile(p.first);
        } else if (p != null) {
          s.setLegendURL(p.second);
        }
        s.setPrefersGetLegendGraphicUrl(
            glgUrls.get(s.getName()) != null && glgUrls.get(s.getName()));
      }
      return;
    }
  }
Esempio n. 2
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;
  }
Esempio n. 3
0
  private void extractFromSld(
      SLDStyleType sty,
      XMLAdapter adapter,
      File stylesDir,
      String layerName,
      Map<String, Pair<File, URL>> legends,
      Map<String, Boolean> glgUrls,
      Map<String, String> map)
      throws Throwable {
    String name = null, lastName = null;
    for (JAXBElement<?> elem : sty.getNameAndUserStyleAndLegendConfigurationFile()) {
      if (elem.getName().getLocalPart().equals("Name")) {
        name = elem.getValue().toString();
      } else if (elem.getName().getLocalPart().equals("LegendConfigurationFile")) {
        File legendFile = new File(adapter.resolve(elem.getValue().toString()).toURI());
        Style style = findStyle(legendFile, stylesDir, layerName);

        if (style != null) {
          if (name != null) {
            style.setName(name);
          }
          registry.putLegend(layerName, style, false);
        }
      } else if (elem.getName().getLocalPart().equals("LegendGraphicFile")) {
        LegendGraphicFile lgf = (LegendGraphicFile) elem.getValue();
        URL url = adapter.resolve(lgf.getValue());
        if (url.toURI().getScheme().equals("file")) {
          File legend = new File(url.toURI());
          legends.put(lastName, new Pair<File, URL>(legend, null));
        } else {
          legends.put(lastName, new Pair<File, URL>(null, url));
        }
        glgUrls.put(lastName, lgf.isOutputGetLegendGraphicUrl());
      } else if (elem.getName().getLocalPart().equals("UserStyle")) {
        if (name == null) {
          name = elem.getValue().toString();
        }
        LOG.debug(
            "Will load user style with name '{}', it will be known as '{}'.",
            elem.getValue(),
            name);
        map.put(elem.getValue().toString(), name);
        lastName = name;
        name = null;
      }
    }
  }
Esempio n. 4
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;
  }
Esempio n. 5
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>());
  }