I am working on a tool for my map but I’m running into some problems using gs:Clip. The user draws a line. All the polygons from a certain layer that intersects the drawn feature have an attribute that is supposed to be calculated (the total sum is wanted). So, for instance, the user might draw a line that crosses two polygons with attribute values of 2 and 4, thus the code should return 6.
It works by saving the user drawn line in an OpenLayers vector layer. The feature drawn is then used (in WKT format) in a chained WPS request. A gs:Clip request (WKT used for clipping) is used as the input for a gs:Aggregate request. Complete code for the WPS request can be found here. The problem is that polygons that do not intersect the drawn line but are close to it are also part of the calculation. See the picture below, it might illustrate the problem somewhat better.
Below is part of the code from the response of gs:Clip (an unwanted feature). No boundedBy coordinates nor any coordinates after the feature:the_geom tag. All the features that should be clipped (corresponding to the drawn lines in the picture above) contains coordinates, but for some reason features that are not within the clipping area gets added to the wfs-FeatureCollection and are consequently part of the gs:Aggregate calculation, causing the end result to be incorrect.
//This is a feature that is unwanted in the response
<gml:featureMember>
<feature:IR_Y fid="IR_Y.1295">
<gml:boundedBy>
<gml:null>unknown</gml:null>
</gml:boundedBy>
<feature:the_geom>
<gml:MultiPolygon srsName="http://www.opengis.net/gml/srs/epsg.xml#3010">
<gml:polygonMember />
</gml:MultiPolygon>
</feature:the_geom>
<feature:BT>5</feature:BT>
</feature:IR_Y>
</gml:featureMember>