@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>()); }
@Override public LinkedList<String> paintMap(Graphics2D g, GetMap gm, Style style) throws MissingDimensionValue, InvalidDimensionValue { LinkedList<Query> queries = new LinkedList<Query>(); LinkedList<String> warnings = collectQueries(style, gm, queries); Java2DRenderer renderer = new Java2DRenderer( g, gm.getWidth(), gm.getHeight(), gm.getBoundingBox(), gm.getPixelSize()); Java2DTextRenderer textRenderer = new Java2DTextRenderer(renderer); // TODO @SuppressWarnings({"rawtypes", "unchecked"}) XPathEvaluator<Feature> evaluator = (XPathEvaluator) new TypedObjectNodeXPathEvaluator(); if (queries.isEmpty()) { LOG.warn("No queries were generated. Is the configuration correct?"); return warnings; } FeatureInputStream rs = null; try { rs = datastore.query(queries.toArray(new Query[queries.size()])); // TODO Should this always be done on this level? What about min and maxFill values? rs = new ThreadedFeatureInputStream(rs, 100, 20); int max = gm.getRenderingOptions().getMaxFeatures(getName()); int cnt = 0; double resolution = gm.getResolution(); // TODO get rid of resolution handling on this code level completely // if ( !gm.getCoordinateSystem().equals( datastore.getStorageSRS() ) ) { // try { // Envelope b = new GeometryTransformer( datastore.getStorageSRS() ).transform( // gm.getBoundingBox() ); // resolution = Utils.calcResolution( b, gm.getWidth(), gm.getHeight() ); // } catch ( IllegalArgumentException e ) { // LOG.warn( "Calculating the resolution failed: '{}'", e.getLocalizedMessage() ); // LOG.trace( "Stack trace:", e ); // } catch ( TransformationException e ) { // LOG.warn( "Calculating the resolution failed: '{}'", e.getLocalizedMessage() ); // LOG.trace( "Stack trace:", e ); // } catch ( UnknownCRSException e ) { // LOG.warn( "Calculating the resolution failed: '{}'", e.getLocalizedMessage() ); // LOG.trace( "Stack trace:", e ); // } // } for (Feature f : rs) { try { render(f, evaluator, style, renderer, textRenderer, gm.getScale(), resolution); } catch (IllegalArgumentException e) { LOG.warn("Unable to render feature, probably a curve had multiple/non-linear segments."); LOG.warn("Error message was: {}", e.getLocalizedMessage()); LOG.trace("Stack trace:", e); } if (max > 0 && ++cnt == max) { LOG.debug("Reached max features of {} for layer '{}', stopping.", max, this); break; } } } 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); } finally { if (rs != null) { rs.close(); } } return warnings; }