public List<FeatureCollection> getFeature() { // alias return getFeatures(); }
/** Helper method that checks if the results feature collections contain complex features. */ protected static boolean isComplexFeature(FeatureCollectionResponse results) { for (FeatureCollection featureCollection : results.getFeatures()) { if (!(featureCollection.getSchema() instanceof SimpleFeatureType)) { // this feature collection contains complex features return true; } } // all features collections contain only simple features return false; }
private Set<FeatureType> getFeatureTypes(FeatureCollectionResponse collections) { Set<FeatureType> result = new HashSet<FeatureType>(); for (FeatureCollection<FeatureType, Feature> fc : collections.getFeatures()) { result.add(fc.getSchema()); } return result; }
@Override public Object operationExecuted(Request request, Operation operation, Object result) { TimeoutVerifier timeoutVerifier = TIMEOUT_VERIFIER.get(); if (timeoutVerifier != null) { // check before encode timeoutVerifier.checkTimeout(); // wrap if needed if (result instanceof FeatureCollectionResponse) { FeatureCollectionResponse featureCollectionResponse = (FeatureCollectionResponse) result; List<FeatureCollection> collections = featureCollectionResponse.getFeatures(); List<FeatureCollection> wrappers = collections .stream() .map(fc -> TimeoutFeatureCollection.wrap(timeoutVerifier, fc)) .collect(Collectors.toList()); featureCollectionResponse.setFeatures(wrappers); } } return result; }
@Override public String getAttachmentFileName(Object value, Operation operation) { try { FeatureCollectionResponse featureCollections = (FeatureCollectionResponse) value; TransformInfo info = locateTransformation(featureCollections, operation); // concatenate all feature types requested StringBuilder sb = new StringBuilder(); for (FeatureCollection<FeatureType, Feature> fc : featureCollections.getFeatures()) { sb.append(fc.getSchema().getName().getLocalPart()); sb.append("_"); } sb.setLength(sb.length() - 1); String extension = info.getFileExtension(); if(extension == null) { extension = ".txt"; sb.append(extension); } if(!extension.startsWith(".")) { sb.append("."); } sb.append(extension); return sb.toString(); } catch(IOException e) { throw new WFSException("Failed to locate the XSLT transformation", e); } }
private List<SimpleFeatureCollection> getFeatureCollections(FeatureCollectionResponse featureCollection) { List<FeatureCollection> inputs = featureCollection.getFeatures(); List<SimpleFeatureCollection> result = new ArrayList<SimpleFeatureCollection>(); for (FeatureCollection fc : inputs) { if (!(fc instanceof SimpleFeatureCollection)) { throw new ServiceException( "The KML output format can only be applied to simple features"); } // KML is defined only over wgs84 in lon/lat order, ignore what the WFS thinks the output // crs should be SimpleFeatureCollection sfc = (SimpleFeatureCollection) fc; CoordinateReferenceSystem sourceCRS = sfc.getSchema().getCoordinateReferenceSystem(); if(sourceCRS != null && !CRS.equalsIgnoreMetadata(sourceCRS, DefaultGeographicCRS.WGS84)) { sfc = new ReprojectingFeatureCollection(sfc, DefaultGeographicCRS.WGS84); } result.add(sfc); } return result; }
/** * Writes a single feature using the facilities provided by the base class * * @param value * @param output * @param operation * @throws UnsupportedEncodingException */ private void writeSingleFeature( FeatureCollectionResponse value, OutputStream output, Operation operation) throws IOException { OutputStreamWriter osw = new OutputStreamWriter(output, gs.getGlobal().getSettings().getCharset()); BufferedWriter outWriter = new BufferedWriter(osw); FeatureCollectionResponse featureCollection = value; boolean isComplex = isComplexFeature(featureCollection); GeoJSONBuilder jsonWriter = getGeoJSONBuilder(featureCollection, outWriter); writeFeatures(featureCollection.getFeatures(), operation, isComplex, jsonWriter); outWriter.flush(); }
@Override public Object operationExecuted(Request request, Operation operation, Object result) { if (delaySeconds > 0 && result instanceof FeatureCollectionResponse) { FeatureCollectionResponse featureCollectionResponse = (FeatureCollectionResponse) result; List<FeatureCollection> collections = featureCollectionResponse.getFeatures(); List<FeatureCollection> wrappers = collections .stream() .map(fc -> new DelayFeatureCollection((SimpleFeatureCollection) fc)) .collect(Collectors.toList()); featureCollectionResponse.setFeatures(wrappers); } return super.operationExecuted(request, operation, result); }
@Override protected void encode(FeatureCollectionResponse results, OutputStream output, Encoder encoder) throws IOException { // evil behavior... if the query was a GetFeatureById then we have to write out a single // feature // without the feature collection wrapper if (results.isGetFeatureById()) { List<FeatureCollection> features = results.getFeatures(); Feature next = DataUtilities.first(features.get(0)); if (next == null) { throw new WFSException( (EObject) null, "No feature matching the requested id found", WFSException.NOT_FOUND); } else { encoder.encode(next, GML.AbstractFeature, output); } } else { encoder.encode( results.unadapt(FeatureCollectionType.class), WFS.FeatureCollection, output); } }