@Test public void testExecute() throws Exception { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.setName("featureType"); tb.add("geometry", Polygon.class); tb.add("integer", Integer.class); GeometryFactory gf = new GeometryFactory(); SimpleFeatureBuilder b = new SimpleFeatureBuilder(tb.buildFeatureType()); DefaultFeatureCollection features = new DefaultFeatureCollection(null, b.getFeatureType()); DefaultFeatureCollection secondFeatures = new DefaultFeatureCollection(null, b.getFeatureType()); Polygon[] firstArrayGeometry = new Polygon[1]; Polygon[] secondArrayGeometry = new Polygon[1]; for (int numFeatures = 0; numFeatures < 1; numFeatures++) { Coordinate array[] = new Coordinate[5]; array[0] = new Coordinate(0, 0); array[1] = new Coordinate(1, 0); array[2] = new Coordinate(1, 1); array[3] = new Coordinate(0, 1); array[4] = new Coordinate(0, 0); LinearRing shell = gf.createLinearRing(new CoordinateArraySequence(array)); b.add(gf.createPolygon(shell, null)); b.add(0); firstArrayGeometry[0] = gf.createPolygon(shell, null); features.add(b.buildFeature(numFeatures + "")); } for (int numFeatures = 0; numFeatures < 1; numFeatures++) { Coordinate array[] = new Coordinate[5]; Coordinate centre = ((Polygon) features.features().next().getDefaultGeometry()) .getCentroid() .getCoordinate(); array[0] = new Coordinate(centre.x, centre.y); array[1] = new Coordinate(centre.x + 1, centre.y); array[2] = new Coordinate(centre.x + 1, centre.y + 1); array[3] = new Coordinate(centre.x, centre.y + 1); array[4] = new Coordinate(centre.x, centre.y); LinearRing shell = gf.createLinearRing(new CoordinateArraySequence(array)); b.add(gf.createPolygon(shell, null)); b.add(0); secondArrayGeometry[0] = gf.createPolygon(shell, null); secondFeatures.add(b.buildFeature(numFeatures + "")); } SimpleFeatureCollection output3 = process.execute(features, secondFeatures, null, null, null, false, false); assertTrue(output3.size() == 1); SimpleFeatureIterator iterator = output3.features(); GeometryCollection firstCollection = null; GeometryCollection secondCollection = null; firstCollection = new GeometryCollection(firstArrayGeometry, new GeometryFactory()); secondCollection = new GeometryCollection(secondArrayGeometry, new GeometryFactory()); for (int i = 0; i < firstCollection.getNumGeometries() && iterator.hasNext(); i++) { Geometry expected = (Geometry) firstCollection .getGeometryN(i) .intersection(secondCollection.getGeometryN(i)); SimpleFeature sf = iterator.next(); assertTrue(expected.equals((Geometry) sf.getDefaultGeometry())); } }
@DescribeResult(description = "Output feature collection") public SimpleFeatureCollection execute( @DescribeParameter( name = "first feature collection", description = "First feature collection" ) SimpleFeatureCollection firstFeatures, @DescribeParameter( name = "second feature collection", description = "Second feature collection" ) SimpleFeatureCollection secondFeatures, @DescribeParameter( name = "first attributes to retain", collectionType = String.class, min = 0, description = "First feature collection attribute to include" ) List<String> firstAttributes, @DescribeParameter( name = "second attributes to retain", collectionType = String.class, min = 0, description = "Second feature collection attribute to include" ) List<String> sndAttributes, @DescribeParameter( name = "intersectionMode", min = 0, description = "Specifies geometry computed for intersecting features. INTERSECTION (default) computes the spatial intersection of the inputs. FIRST copies geometry A. SECOND copies geometry B.", defaultValue = "INTERSECTION" ) IntersectionMode intersectionMode, @DescribeParameter( name = "percentagesEnabled", min = 0, description = "Indicates whether to output feature area percentages (attributes percentageA and percentageB)" ) Boolean percentagesEnabled, @DescribeParameter( name = "areasEnabled", min = 0, description = "Indicates whether to output feature areas (attributes areaA and areaB)" ) Boolean areasEnabled) { logger.fine("INTERSECTION FEATURE COLLECTION WPS STARTED"); if (percentagesEnabled == null) { percentagesEnabled = false; } if (areasEnabled == null) { areasEnabled = false; } if (intersectionMode == null) { intersectionMode = IntersectionMode.INTERSECTION; } Class firstGeomType = firstFeatures.getSchema().getGeometryDescriptor().getType().getBinding(); Class secondGeomType = secondFeatures.getSchema().getGeometryDescriptor().getType().getBinding(); if ((percentagesEnabled || areasEnabled) && (!isGeometryTypeIn(firstGeomType, MultiPolygon.class, Polygon.class) || !isGeometryTypeIn(secondGeomType, MultiPolygon.class, Polygon.class))) { throw new IllegalArgumentException( "In case of opMode or areaMode are true, the features in the first and second collection must be polygonal"); } if (!isGeometryTypeIn( firstGeomType, MultiPolygon.class, Polygon.class, MultiLineString.class, LineString.class)) { throw new IllegalArgumentException( "First feature collection must be polygonal or linear"); } return new IntersectedFeatureCollection( firstFeatures, firstAttributes, secondFeatures, sndAttributes, intersectionMode, percentagesEnabled, areasEnabled); }
IntersectionFeatureCollection implements VectorProcess { @DescribeResult(description = "Output feature collection") public SimpleFeatureCollection execute( @DescribeParameter( name = "first feature collection", description = "First feature collection" ) SimpleFeatureCollection firstFeatures, @DescribeParameter( name = "second feature collection", description = "Second feature collection" ) SimpleFeatureCollection secondFeatures, @DescribeParameter( name = "first attributes to retain", collectionType = String.class, min = 0, description = "First feature collection attribute to include" ) List<String> firstAttributes, @DescribeParameter( name = "second attributes to retain", collectionType = String.class, min = 0, description = "Second feature collection attribute to include" ) List<String> sndAttributes, @DescribeParameter( name = "intersectionMode", min = 0, description = "Specifies geometry computed for intersecting features. INTERSECTION (default) computes the spatial intersection of the inputs. FIRST copies geometry A. SECOND copies geometry B.", defaultValue = "INTERSECTION" ) IntersectionMode intersectionMode, @DescribeParameter( name = "percentagesEnabled", min = 0, description = "Indicates whether to output feature area percentages (attributes percentageA and percentageB)" ) Boolean percentagesEnabled, @DescribeParameter( name = "areasEnabled", min = 0, description = "Indicates whether to output feature areas (attributes areaA and areaB)" ) Boolean areasEnabled) { logger.fine("INTERSECTION FEATURE COLLECTION WPS STARTED"); if (percentagesEnabled == null) { percentagesEnabled = false; } if (areasEnabled == null) { areasEnabled = false; } if (intersectionMode == null) { intersectionMode = IntersectionMode.INTERSECTION; } Class firstGeomType = firstFeatures.getSchema().getGeometryDescriptor().getType().getBinding(); Class secondGeomType = secondFeatures.getSchema().getGeometryDescriptor().getType().getBinding(); if ((percentagesEnabled || areasEnabled) && (!isGeometryTypeIn(firstGeomType, MultiPolygon.class, Polygon.class) || !isGeometryTypeIn(secondGeomType, MultiPolygon.class, Polygon.class))) { throw new IllegalArgumentException( "In case of opMode or areaMode are true, the features in the first and second collection must be polygonal"); } if (!isGeometryTypeIn( firstGeomType, MultiPolygon.class, Polygon.class, MultiLineString.class, LineString.class)) { throw new IllegalArgumentException( "First feature collection must be polygonal or linear"); } return new IntersectedFeatureCollection( firstFeatures, firstAttributes, secondFeatures, sndAttributes, intersectionMode, percentagesEnabled, areasEnabled); } }
IntersectionFeatureCollection implements VectorProcess { @DescribeResult(description = "Output feature collection") public SimpleFeatureCollection execute( @DescribeParameter( name = "first feature collection", description = "First feature collection" ) SimpleFeatureCollection firstFeatures, @DescribeParameter( name = "second feature collection", description = "Second feature collection" ) SimpleFeatureCollection secondFeatures, @DescribeParameter( name = "first attributes to retain", collectionType = String.class, min = 0, description = "First feature collection attribute to include" ) List<String> firstAttributes, @DescribeParameter( name = "second attributes to retain", collectionType = String.class, min = 0, description = "Second feature collection attribute to include" ) List<String> sndAttributes, @DescribeParameter( name = "intersectionMode", min = 0, description = "Specifies geometry computed for intersecting features. INTERSECTION (default) computes the spatial intersection of the inputs. FIRST copies geometry A. SECOND copies geometry B.", defaultValue = "INTERSECTION" ) IntersectionMode intersectionMode, @DescribeParameter( name = "percentagesEnabled", min = 0, description = "Indicates whether to output feature area percentages (attributes percentageA and percentageB)" ) Boolean percentagesEnabled, @DescribeParameter( name = "areasEnabled", min = 0, description = "Indicates whether to output feature areas (attributes areaA and areaB)" ) Boolean areasEnabled) { logger.fine("INTERSECTION FEATURE COLLECTION WPS STARTED"); if (percentagesEnabled == null) { percentagesEnabled = false; } if (areasEnabled == null) { areasEnabled = false; } if (intersectionMode == null) { intersectionMode = IntersectionMode.INTERSECTION; } Class firstGeomType = firstFeatures.getSchema().getGeometryDescriptor().getType().getBinding(); Class secondGeomType = secondFeatures.getSchema().getGeometryDescriptor().getType().getBinding(); if ((percentagesEnabled || areasEnabled) && (!isGeometryTypeIn(firstGeomType, MultiPolygon.class, Polygon.class) || !isGeometryTypeIn(secondGeomType, MultiPolygon.class, Polygon.class))) { throw new IllegalArgumentException( "In case of opMode or areaMode are true, the features in the first and second collection must be polygonal"); } if (!isGeometryTypeIn( firstGeomType, MultiPolygon.class, Polygon.class, MultiLineString.class, LineString.class)) { throw new IllegalArgumentException( "First feature collection must be polygonal or linear"); } return new IntersectedFeatureCollection( firstFeatures, firstAttributes, secondFeatures, sndAttributes, intersectionMode, percentagesEnabled, areasEnabled); }  }
IntersectionFeatureCollection implements VectorProcess { @DescribeResult(description = "Output feature collection") public SimpleFeatureCollection execute( @DescribeParameter( name = "first feature collection", description = "First feature collection" ) SimpleFeatureCollection firstFeatures, @DescribeParameter( name = "second feature collection", description = "Second feature collection" ) SimpleFeatureCollection secondFeatures, @DescribeParameter( name = "first attributes to retain", collectionType = String.class, min = 0, description = "First feature collection attribute to include" ) List<String> firstAttributes, @DescribeParameter( name = "second attributes to retain", collectionType = String.class, min = 0, description = "Second feature collection attribute to include" ) List<String> sndAttributes, @DescribeParameter( name = "intersectionMode", min = 0, description = "Specifies geometry computed for intersecting features. INTERSECTION (default) computes the spatial intersection of the inputs. FIRST copies geometry A. SECOND copies geometry B.", defaultValue = "INTERSECTION" ) IntersectionMode intersectionMode, @DescribeParameter( name = "percentagesEnabled", min = 0, description = "Indicates whether to output feature area percentages (attributes percentageA and percentageB)" ) Boolean percentagesEnabled, @DescribeParameter( name = "areasEnabled", min = 0, description = "Indicates whether to output feature areas (attributes areaA and areaB)" ) Boolean areasEnabled) { logger.fine("INTERSECTION FEATURE COLLECTION WPS STARTED"); if (percentagesEnabled == null) { percentagesEnabled = false; } if (areasEnabled == null) { areasEnabled = false; } if (intersectionMode == null) { intersectionMode = IntersectionMode.INTERSECTION; } Class firstGeomType = firstFeatures.getSchema().getGeometryDescriptor().getType().getBinding(); Class secondGeomType = secondFeatures.getSchema().getGeometryDescriptor().getType().getBinding(); if ((percentagesEnabled || areasEnabled) && (!isGeometryTypeIn(firstGeomType, MultiPolygon.class, Polygon.class) || !isGeometryTypeIn(secondGeomType, MultiPolygon.class, Polygon.class))) { throw new IllegalArgumentException( "In case of opMode or areaMode are true, the features in the first and second collection must be polygonal"); } if (!isGeometryTypeIn( firstGeomType, MultiPolygon.class, Polygon.class, MultiLineString.class, LineString.class)) { throw new IllegalArgumentException( "First feature collection must be polygonal or linear"); } return new IntersectedFeatureCollection( firstFeatures, firstAttributes, secondFeatures, sndAttributes, intersectionMode, percentagesEnabled, areasEnabled); }  @DescribeResult(description = "Output feature collection") SimpleFeatureCollection execute(
            @DescribeParameter(
                        name = "first feature collection",
                        description = "First feature collection"
                    )
                    SimpleFeatureCollection firstFeatures,
            @DescribeParameter(
                        name = "second feature collection",
                        description = "Second feature collection"
                    )
                    SimpleFeatureCollection secondFeatures,
            @DescribeParameter(
                        name = "first attributes to retain",
                        collectionType = String.class,
                        min = 0,
                        description = "First feature collection attribute to include"
                    )
                    List<String> firstAttributes,
            @DescribeParameter(
                        name = "second attributes to retain",
                        collectionType = String.class,
                        min = 0,
                        description = "Second feature collection attribute to include"
                    )
                    List<String> sndAttributes,
            @DescribeParameter(
                        name = "intersectionMode",
                        min = 0,
                        description =
                                "Specifies geometry computed for intersecting features.  INTERSECTION (default) computes the spatial intersection of the inputs. FIRST copies geometry A.  SECOND copies geometry B.",
                        defaultValue = "INTERSECTION"
                    )
                    IntersectionMode intersectionMode,
            @DescribeParameter(
                        name = "percentagesEnabled",
                        min = 0,
                        description =
                                "Indicates whether to output feature area percentages (attributes percentageA and percentageB)"
                    )
                    Boolean percentagesEnabled,
            @DescribeParameter(
                        name = "areasEnabled",
                        min = 0,
                        description =
                                "Indicates whether to output feature areas (attributes areaA and areaB)"
                    )
                    Boolean areasEnabled); }
IntersectionFeatureCollection implements VectorProcess { @DescribeResult(description = "Output feature collection") public SimpleFeatureCollection execute( @DescribeParameter( name = "first feature collection", description = "First feature collection" ) SimpleFeatureCollection firstFeatures, @DescribeParameter( name = "second feature collection", description = "Second feature collection" ) SimpleFeatureCollection secondFeatures, @DescribeParameter( name = "first attributes to retain", collectionType = String.class, min = 0, description = "First feature collection attribute to include" ) List<String> firstAttributes, @DescribeParameter( name = "second attributes to retain", collectionType = String.class, min = 0, description = "Second feature collection attribute to include" ) List<String> sndAttributes, @DescribeParameter( name = "intersectionMode", min = 0, description = "Specifies geometry computed for intersecting features. INTERSECTION (default) computes the spatial intersection of the inputs. FIRST copies geometry A. SECOND copies geometry B.", defaultValue = "INTERSECTION" ) IntersectionMode intersectionMode, @DescribeParameter( name = "percentagesEnabled", min = 0, description = "Indicates whether to output feature area percentages (attributes percentageA and percentageB)" ) Boolean percentagesEnabled, @DescribeParameter( name = "areasEnabled", min = 0, description = "Indicates whether to output feature areas (attributes areaA and areaB)" ) Boolean areasEnabled) { logger.fine("INTERSECTION FEATURE COLLECTION WPS STARTED"); if (percentagesEnabled == null) { percentagesEnabled = false; } if (areasEnabled == null) { areasEnabled = false; } if (intersectionMode == null) { intersectionMode = IntersectionMode.INTERSECTION; } Class firstGeomType = firstFeatures.getSchema().getGeometryDescriptor().getType().getBinding(); Class secondGeomType = secondFeatures.getSchema().getGeometryDescriptor().getType().getBinding(); if ((percentagesEnabled || areasEnabled) && (!isGeometryTypeIn(firstGeomType, MultiPolygon.class, Polygon.class) || !isGeometryTypeIn(secondGeomType, MultiPolygon.class, Polygon.class))) { throw new IllegalArgumentException( "In case of opMode or areaMode are true, the features in the first and second collection must be polygonal"); } if (!isGeometryTypeIn( firstGeomType, MultiPolygon.class, Polygon.class, MultiLineString.class, LineString.class)) { throw new IllegalArgumentException( "First feature collection must be polygonal or linear"); } return new IntersectedFeatureCollection( firstFeatures, firstAttributes, secondFeatures, sndAttributes, intersectionMode, percentagesEnabled, areasEnabled); }  @DescribeResult(description = "Output feature collection") SimpleFeatureCollection execute(
            @DescribeParameter(
                        name = "first feature collection",
                        description = "First feature collection"
                    )
                    SimpleFeatureCollection firstFeatures,
            @DescribeParameter(
                        name = "second feature collection",
                        description = "Second feature collection"
                    )
                    SimpleFeatureCollection secondFeatures,
            @DescribeParameter(
                        name = "first attributes to retain",
                        collectionType = String.class,
                        min = 0,
                        description = "First feature collection attribute to include"
                    )
                    List<String> firstAttributes,
            @DescribeParameter(
                        name = "second attributes to retain",
                        collectionType = String.class,
                        min = 0,
                        description = "Second feature collection attribute to include"
                    )
                    List<String> sndAttributes,
            @DescribeParameter(
                        name = "intersectionMode",
                        min = 0,
                        description =
                                "Specifies geometry computed for intersecting features.  INTERSECTION (default) computes the spatial intersection of the inputs. FIRST copies geometry A.  SECOND copies geometry B.",
                        defaultValue = "INTERSECTION"
                    )
                    IntersectionMode intersectionMode,
            @DescribeParameter(
                        name = "percentagesEnabled",
                        min = 0,
                        description =
                                "Indicates whether to output feature area percentages (attributes percentageA and percentageB)"
                    )
                    Boolean percentagesEnabled,
            @DescribeParameter(
                        name = "areasEnabled",
                        min = 0,
                        description =
                                "Indicates whether to output feature areas (attributes areaA and areaB)"
                    )
                    Boolean areasEnabled);  }