gs.rst 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. .. _wps_gs_processes:
  2. GeoServer processes
  3. ===================
  4. GeoServer WPS includes a few processes created especially for use with GeoServer. These are usually GeoServer-specific functions, such as bounds and reprojection. They use an internal connection to the GeoServer WFS/WCS, not part of the WPS specification, for reading and writing data.
  5. As with the "geo" processes, the names and definitions of these processes are subject to change, so they have not been included here. For a full list of GeoServer-specific processes, please see the GeoServer :ref:`WPS capabilities document <wps_getcaps>` (or browse with the :ref:`wps_request_builder`.)
  6. Aggregation process
  7. -------------------
  8. The aggregation process is used to perform common aggregation functions (sum, average, count) on vector data. The available outputs formats for this process are `text/xml` and `application/json`.
  9. The process parameters are described in the table bellow:
  10. .. list-table::
  11. :widths: 10 80 5 5
  12. * - **Parameter**
  13. - **Description**
  14. - **Mandatory**
  15. - **Multiple**
  16. * - ``features``
  17. - Input feature collection.
  18. - yes
  19. - no
  20. * - ``aggregationAttribute``
  21. - Attribute on which to perform aggregation.
  22. - yes
  23. - no
  24. * - ``function``
  25. - An aggregate function to compute. Functions include Count, Average, Max, Median, Min, StdDev, and Sum.
  26. - yes
  27. - yes
  28. * - ``singlePass``
  29. - If TRUE computes all aggregation values in a single pass. This will defeat DBMS-specific optimizations. If a group by attribute is provided this parameter will be ignored.
  30. - yes
  31. - no
  32. * - ``groupByAttributes``
  33. - Group by attribute.
  34. - no
  35. - yes
  36. Follow some examples of the invocation of this process using GeoServer shipped `topp:states` layer.
  37. The examples can be tested with CURL:
  38. .. code-block:: bash
  39. curl -u admin:geoserver -H 'Content-type: xml' -XPOST -d@'wps-request.xml' http://localhost:8080/geoserver/wps
  40. where `wps-request.xml` is the file that contains the request.
  41. Aggregate Example
  42. '''''''''''''''''
  43. Counts the total number of states, sum all the number of persons, computes the average number of persons per state and give the maximum and minimum number of persons in a state.
  44. Request:
  45. .. literalinclude:: ../../../../../../../data/release/demo/WPS_aggregate_1.0.xml
  46. :language: xml
  47. The result:
  48. .. code-block:: json
  49. {
  50. "AggregationAttribute": "PERSONS",
  51. "AggregationFunctions": ["Max", "Min", "Average", "Sum", "Count"],
  52. "GroupByAttributes": [],
  53. "AggregationResults": [
  54. [29760021, 453588, 5038397.020408163, 246881454, 49]
  55. ]
  56. }
  57. The value of `AggregationResults` attribute should be read in a tabular way. The group by attributes come first in the order they appear in `GroupByAttributes` attribute. After comes the result of the aggregation functions in the order they appear in the `AggregationFunctions` attribute. In this case there is no group by attributes so the result only contains a row with the aggregation functions results. This is very similar to the result of an SQL query.
  58. This result should be interpreted like this:
  59. .. list-table::
  60. :widths: 20 20 20 20 20
  61. * - **Max**
  62. - **Min**
  63. - **Average**
  64. - **Sum**
  65. - **Count**
  66. * - 29760021
  67. - 453588
  68. - 5038397.020408163
  69. - 246881454
  70. - 49
  71. To obtain the result in the XML format the request `wps:ResponseForm` element needs to be changed to:
  72. .. code-block:: xml
  73. <wps:ResponseForm>
  74. <wps:RawDataOutput mimeType="text/xml">
  75. <ows:Identifier>result</ows:Identifier>
  76. </wps:RawDataOutput>
  77. </wps:ResponseForm>
  78. The result in XML format:
  79. .. code-block:: xml
  80. <?xml version="1.0" encoding="UTF-8"?>
  81. <AggregationResults>
  82. <Min>453588.0</Min>
  83. <Max>2.9760021E7</Max>
  84. <Average>5038397.020408163</Average>
  85. <Sum>2.46881454E8</Sum>
  86. <Count>49</Count>
  87. </AggregationResults>
  88. Aggregate GroupBy Example
  89. '''''''''''''''''''''''''
  90. This example count the number of states and the population average grouped by region.
  91. Request:
  92. .. literalinclude:: ../../../../../../../data/release/demo/WPS_aggregate_groupby_1.0.xml
  93. :language: xml
  94. The result:
  95. .. code-block:: json
  96. {
  97. "AggregationAttribute": "PERSONS",
  98. "AggregationFunctions": ["Average", "Count"],
  99. "GroupByAttributes": ["SUB_REGION"],
  100. "AggregationResults": [
  101. [ "N Eng", 2201157.1666666665, 6 ],
  102. [ "W N Cen", 2522812.8571428573, 7 ],
  103. [ "Pacific", 12489678, 3 ],
  104. [ "Mtn", 1690408.25, 8 ],
  105. [ "E S Cen", 3998821.25, 4 ],
  106. [ "S Atl", 4837695.666666667, 9 ],
  107. [ "Mid Atl", 12534095.333333334, 3 ],
  108. [ "E N Cen", 8209477.2, 5 ],
  109. [ "W S Cen", 6709575.75, 4 ]
  110. ]
  111. }
  112. Since there is a group by attribute the result contains a row for each different value of the group by attribute. Very similar to the result of an SQL query. If there is more that one group by attribute (which is not the case) their values will be in the order they appear in the `GroupByAttributes` attribute.
  113. This result should be interpreted like this:
  114. .. list-table::
  115. :widths: 34 33 33
  116. * - **Sub Region**
  117. - **Average**
  118. - **count**
  119. * - N Eng
  120. - 2201157.1666666665
  121. - 6
  122. * - W N Cen
  123. - 2522812.8571428573
  124. - 7
  125. * - Pacific
  126. - 12489678
  127. - 3
  128. * - Mtn
  129. - 1690408.25
  130. - 8
  131. * - E S Cen
  132. - 3998821.25
  133. - 4
  134. * - S Atl
  135. - 4837695.666666667
  136. - 9
  137. * - Mid Atl
  138. - 12534095.333333334
  139. - 3
  140. * - E N Cen
  141. - 8209477.2
  142. - 5
  143. * - W S Cen
  144. - 6709575.75
  145. - 4
  146. The result in XML format:
  147. .. code-block:: xml
  148. <?xml version="1.0" encoding="UTF-8"?>
  149. <AggregationResults>
  150. <GroupByResult>
  151. <object-array>
  152. <string>N Eng</string>
  153. <double>2201157.1666666665</double>
  154. <int>6</int>
  155. </object-array>
  156. <object-array>
  157. <string>W N Cen</string>
  158. <double>2522812.8571428573</double>
  159. <int>7</int>
  160. </object-array>
  161. <object-array>
  162. <string>Pacific</string>
  163. <double>1.2489678E7</double>
  164. <int>3</int>
  165. </object-array>
  166. <object-array>
  167. <string>Mtn</string>
  168. <double>1690408.25</double>
  169. <int>8</int>
  170. </object-array>
  171. <object-array>
  172. <string>E S Cen</string>
  173. <double>3998821.25</double>
  174. <int>4</int>
  175. </object-array>
  176. <object-array>
  177. <string>S Atl</string>
  178. <double>4837695.666666667</double>
  179. <int>9</int>
  180. </object-array>
  181. <object-array>
  182. <string>Mid Atl</string>
  183. <double>1.2534095333333334E7</double>
  184. <int>3</int>
  185. </object-array>
  186. <object-array>
  187. <string>E N Cen</string>
  188. <double>8209477.2</double>
  189. <int>5</int>
  190. </object-array>
  191. <object-array>
  192. <string>W S Cen</string>
  193. <double>6709575.75</double>
  194. <int>4</int>
  195. </object-array>
  196. </GroupByResult>
  197. </AggregationResults>