@Test public void testIntersection() throws ProcessException, NoSuchIdentifierException { // Inputs final FeatureCollection<?> featureList = buildFeatureList(); final FeatureCollection<?> featureUnionList = buildFeatureUnionList(); // Process ProcessDescriptor desc = ProcessFinder.getProcessDescriptor("vector", "union"); ParameterValueGroup in = desc.getInputDescriptor().createValue(); in.parameter("feature_in").setValue(featureList); in.parameter("feature_union").setValue(featureUnionList); in.parameter("input_geometry_name").setValue("geom1"); org.geotoolkit.process.Process proc = desc.createProcess(in); // Features out final FeatureCollection<?> featureListOut = (FeatureCollection<?>) proc.call().parameter("feature_out").getValue(); // Expected Features out final FeatureCollection<?> featureListResult = buildResultList(); assertEquals(featureListOut.getFeatureType(), featureListResult.getFeatureType()); assertEquals(featureListOut.getID(), featureListResult.getID()); assertEquals(featureListOut.size(), featureListResult.size()); assertTrue(featureListOut.containsAll(featureListResult)); }
/** * @param featureCollection * @param writer * @param fragment : true if we write in a stream, dont write start and end elements * @throws DataStoreException */ public Element writeFeatureCollection( final FeatureCollection featureCollection, final boolean fragment, final boolean wfs) throws DataStoreException, ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // then we have to create document-loader: factory.setNamespaceAware(false); DocumentBuilder loader = factory.newDocumentBuilder(); // creating a new DOM-document... Document document = loader.newDocument(); // the XML header if (!fragment) { document.setXmlVersion("1.0"); // writer.writeStartDocument("UTF-8", "1.0"); } // the root Element final Element rootElement; if (wfs) { rootElement = document.createElementNS("http://www.opengis.net/wfs", "FeatureCollection"); rootElement.setPrefix("wfs"); } else { rootElement = document.createElementNS("http://www.opengis.net/gml", "FeatureCollection"); rootElement.setPrefix("gml"); } document.appendChild(rootElement); String collectionID = ""; if (featureCollection.getID() != null) { collectionID = featureCollection.getID(); } final Attr idAttribute = document.createAttributeNS(Namespaces.GML, "id"); idAttribute.setValue(collectionID); idAttribute.setPrefix("gml"); rootElement.setAttributeNodeNS(idAttribute); if (schemaLocation != null && !schemaLocation.equals("")) { rootElement.setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", schemaLocation); } /*FeatureType type = featureCollection.getFeatureType(); if (type != null && type.getName() != null) { String namespace = type.getName().getNamespaceURI(); if (namespace != null && !namespace.equals(Namespaces.GML)) { Prefix prefix = getPrefix(namespace); writer.writeNamespace(prefix.prefix, namespace); } }*/ /* * The boundedby part */ final Element boundElement = writeBounds(featureCollection.getEnvelope(), document); if (boundElement != null) { rootElement.appendChild(boundElement); } // we write each feature member of the collection FeatureIterator iterator = featureCollection.iterator(); try { while (iterator.hasNext()) { final Feature f = iterator.next(); final Element memberElement = document.createElementNS(Namespaces.GML, "featureMember"); memberElement.setPrefix("gml"); memberElement.appendChild(writeFeature(f, document, true)); rootElement.appendChild(memberElement); } } finally { // we close the stream iterator.close(); } return rootElement; }