raster.rst 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. .. _tutorials_getfeatureinfo_raster:
  2. Raster GetFeatureInfo Response Customization
  3. ============================================
  4. The default output for a ``GetFeatureInfo`` request on a raster layer contains just the value of the selected pixel, one for each band of the image.
  5. For instance, in case of an ``application/json`` output format:
  6. .. code-block:: json
  7. {
  8. "type": "FeatureCollection",
  9. "features": [
  10. {
  11. "type": "Feature",
  12. "id": "",
  13. "geometry": null,
  14. "properties": {
  15. "GRAY_INDEX": 124,
  16. }
  17. }
  18. ],
  19. "totalFeatures": "unknown",
  20. "numberReturned": 1,
  21. "timeStamp": "2021-03-19T11:33:52.587Z",
  22. "crs": null
  23. }
  24. If the raster layer is associated with a Style based on a ``ColorMap``, GeoServer allows to include in the output the labels of each ``ColorMapEntry`` matching the pixel. This is controlled by a ``VendorOption``, that needs to be added inside the ``RasterSymbolizer`` holding the ``ColorMap``.
  25. .. code-block:: xml
  26. <sld:RasterSymbolizer>
  27. <sld:ColorMap>
  28. <sld:ColorMapEntry color="#0000FF" quantity="1.0" label="low"/>
  29. <sld:ColorMapEntry color="#FFFF00" quantity="124.81173566700335" label="mid"/>
  30. <sld:ColorMapEntry color="#FF7F00" quantity="559.2041949413946" label="high"/>
  31. <sld:ColorMapEntry color="#FF0000" quantity="55537.0" label="veryhigh"/>
  32. </sld:ColorMap>
  33. <sld:ContrastEnhancement/>
  34. <VendorOption name="labelInFeatureInfo">add</VendorOption>
  35. </sld:RasterSymbolizer>
  36. The output produced by the above ``RasterSymbolizer`` looks as follows:
  37. .. code-block:: json
  38. {
  39. "type": "FeatureCollection",
  40. "features": [
  41. {
  42. "type": "Feature",
  43. "id": "",
  44. "geometry": null,
  45. "properties": {
  46. "GRAY_INDEX": 124,
  47. "Label_GRAY_INDEX": "mid"
  48. }
  49. }
  50. ],
  51. "totalFeatures": "unknown",
  52. "numberReturned": 1,
  53. "timeStamp": "2021-03-19T11:33:52.587Z",
  54. "crs": null
  55. }
  56. As it's possible to see, the label's value has been added to the output with attribute name ``Label_GRAY_INDEX``.
  57. The ``VendorOption labelInFeatureInfo`` supports the following values:
  58. * ``add`` the label value is added to the normal GetFeatureInfo output.
  59. * ``replace`` the label value replaces the pixel value in the output.
  60. * ``none`` no label is added to the output. We obtain a normal ``GetFeatureInfo`` response.
  61. Additionally, it is possible to customize the attribute name of the label value, by means of a second ``VendorOption``:
  62. ``<VendorOption name="labelAttributeName">your custom name</VendorOption>``.
  63. Assuming to have a ``RasterSymbolizer`` like this
  64. .. code-block:: xml
  65. <sld:RasterSymbolizer>
  66. <sld:ColorMap>
  67. <sld:ColorMapEntry color="#0000FF" quantity="1.0" label="low"/>
  68. <sld:ColorMapEntry color="#FFFF00" quantity="124.81173566700335" label="mid"/>
  69. <sld:ColorMapEntry color="#FF7F00" quantity="559.2041949413946" label="high"/>
  70. <sld:ColorMapEntry color="#FF0000" quantity="55537.0" label="very high"/>
  71. </sld:ColorMap>
  72. <sld:ContrastEnhancement/>
  73. <VendorOption name="labelInFeatureInfo">add</VendorOption>
  74. <VendorOption name="labelAttributeName">custom name</VendorOption>
  75. </sld:RasterSymbolizer>
  76. we would obtain the following output, where the attribute name of the label value has been replaced by the one specified in the labelAttributeName ``VendorOption``:
  77. .. code-block:: json
  78. {
  79. "type": "FeatureCollection",
  80. "features": [
  81. {
  82. "type": "Feature",
  83. "id": "",
  84. "geometry": null,
  85. "properties": {
  86. "GRAY_INDEX": 159,
  87. "custom name": "mid"
  88. }
  89. }
  90. ],
  91. "totalFeatures": "unknown",
  92. "numberReturned": 1,
  93. "timeStamp": "2021-03-19T11:50:32.433Z",
  94. "crs": null
  95. }
  96. We have been using the ``JSON`` output format for the example above, but the two ``VendorOptions`` work for all other GetFeatureInfo output formats.