title: Count points in polygons with WFS or WPS
body: <p>I'm having 2 separate layers in geoserver. One containing polygons and other one contains points. How can I count the number of points within each polygon using wfs or wps requests?</p>
  <p>QGIS describing <a href="https://jonathansoma.com/lede/foundations-2018/qgis/points-in-polygon/" rel="nofollow noreferrer">the exact functionality</a> I'm asking.</p>
  <p>I tried using <code>vec:InclusionFeatureCollection</code> WPS function but it only returns attributes from the first feature collection so I can't count them grouped by polygons:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;wps:Execute version=&quot;1.0.0&quot; service=&quot;WPS&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns=&quot;http://www.opengis.net/wps/1.0.0&quot; xmlns:wfs=&quot;http://www.opengis.net/wfs&quot; xmlns:wps=&quot;http://www.opengis.net/wps/1.0.0&quot; xmlns:ows=&quot;http://www.opengis.net/ows/1.1&quot; xmlns:gml=&quot;http://www.opengis.net/gml&quot; xmlns:ogc=&quot;http://www.opengis.net/ogc&quot; xmlns:wcs=&quot;http://www.opengis.net/wcs/1.1.1&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; xsi:schemaLocation=&quot;http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd&quot;&gt;
    &lt;ows:Identifier&gt;vec:InclusionFeatureCollection&lt;/ows:Identifier&gt;
    &lt;wps:DataInputs&gt;
      &lt;wps:Input&gt;
          &lt;ows:Identifier&gt;first&lt;/ows:Identifier&gt;
              &lt;wps:Reference mimeType=&quot;text/xml; subtype=wfs-collection/1.0&quot; xlink:href=&quot;http://geoserver/wfs&quot; method=&quot;POST&quot;&gt;
                  &lt;wps:Body&gt;
                      &lt;wfs:GetFeature service=&quot;WFS&quot; version=&quot;1.0.0&quot; outputFormat=&quot;GML2&quot;&gt;
                          &lt;wfs:Query typeName=&quot;osm:events&quot;/&gt;
                      &lt;/wfs:GetFeature&gt;
                  &lt;/wps:Body&gt;
          &lt;/wps:Reference&gt;
      &lt;/wps:Input&gt;
      &lt;wps:Input&gt;
          &lt;ows:Identifier&gt;second&lt;/ows:Identifier&gt;
              &lt;wps:Reference mimeType=&quot;text/xml; subtype=wfs-collection/1.0&quot; xlink:href=&quot;http://geoserver/wfs&quot; method=&quot;POST&quot;&gt;
                  &lt;wps:Body&gt;
                      &lt;wfs:GetFeature service=&quot;WFS&quot; version=&quot;1.0.0&quot; outputFormat=&quot;GML2&quot;&gt;
                          &lt;wfs:Query typeName=&quot;osm:administrative_4&quot;/&gt;
                      &lt;/wfs:GetFeature&gt;
               &lt;/wps:Body&gt;
          &lt;/wps:Reference&gt;
      &lt;/wps:Input&gt;
    &lt;/wps:DataInputs&gt;
    &lt;wps:ResponseForm&gt;
      &lt;wps:RawDataOutput mimeType=&quot;text/xml; subtype=wfs-collection/1.0&quot;&gt;
        &lt;ows:Identifier&gt;result&lt;/ows:Identifier&gt;
      &lt;/wps:RawDataOutput&gt;
    &lt;/wps:ResponseForm&gt;
  &lt;/wps:Execute&gt;
  </code></pre>