outputformats.rst 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. .. _wfs_output_formats:
  2. WFS output formats
  3. ==================
  4. WFS returns features and feature information in a number of formats. The syntax for specifying an output format is::
  5. outputFormat=<format>
  6. where ``<format>`` is one of the following options:
  7. .. list-table::
  8. :widths: 15 30 55
  9. :header-rows: 1
  10. * - Format
  11. - Syntax
  12. - Notes
  13. * - GML2
  14. - ``outputFormat=GML2``
  15. - Default option for WFS 1.0.0
  16. * - GML3
  17. - ``outputFormat=GML3``
  18. - Default option for WFS 1.1.0 and 2.0.0
  19. * - Shapefile
  20. - ``outputFormat=shape-zip``
  21. - ZIP archive will be generated containing the shapefile (see :ref:`wfs_outputformat_shapezip` below).
  22. * - JSON
  23. - ``outputFormat=application/json``
  24. - Returns a GeoJSON or a JSON output. Note ``outputFormat=json`` is only supported for getFeature (for backward compatibility).
  25. * - JSONP
  26. - ``outputFormat=text/javascript``
  27. - Returns a `JSONP <http://en.wikipedia.org/wiki/JSONP>`_ in the form: ``parseResponse(...json...)``. See :ref:`wms_vendor_parameters` to change the callback name. Note that this format is disabled by default (See :ref:`wms_global_variables`).
  28. * - CSV
  29. - ``outputFormat=csv``
  30. - Returns a CSV (comma-separated values) file
  31. .. note:: Some additional output formats (such as :ref:`Excel <excel_extension>`) are available with the use of an extension. The full list of output formats supported by a particular GeoServer instance can be found by performing a WFS :ref:`wfs_getcap` request.
  32. GeoServer provides the ``format_options`` vendor-specific parameter to specify parameters that are specific to each format. The syntax is:
  33. ::
  34. format_options=param1:value1;param2:value2;...
  35. .. _wfs_outputformat_shapezip:
  36. Shapefile output
  37. ----------------
  38. The shapefile format has a number of limitations that would prevent turning data sources into an equivalent shapefile. In order to abide with such limitations
  39. the shape-zip output format will automatically apply some transformations on the source data, and eventually split the single collection into multiple
  40. shapefiles. In particular, the shape-zip format will:
  41. * Reduce attribute names to the DBF accepted length, making sure there are not conflicts (counters being added at the end of the attribute name to handle this).
  42. * Fan out multiple geometry type into parallel shapefiles, named after the original feature type, plus the geometry type as a suffix.
  43. * Fan out multiple shapefiles in case the maximum size is reached
  44. The default max size for both .shp and .dbf file is 2GB, it's possible to modify those limits by setting the GS_SHP_MAX_SIZE and
  45. GS_DBF_MAX_SIZE system variables to a different value (as a byte count, the default value being 2147483647).
  46. Shapefile output ``format_options``:
  47. * ``format_option=filename:<zipfile>``: if a file name is provided, the name is used as the output file name. For example, ``format_options=filename:roads.zip``.
  48. Shapefile filename customization
  49. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  50. If a file name is not specified, the output file name is inferred from the requested feature type name. The shapefile output format output can be customized by preparing a :ref:`Freemarker template <tutorial_freemarkertemplate>` which will configure the file name of the archive (ZIP file) and the files it contains. The default template is:
  51. ::
  52. zip=${typename}
  53. shp=${typename}${geometryName}${geometryType}
  54. txt=wfsrequest
  55. The ``zip`` property is the name of the archive, the ``shp`` property is the name of the shapefile for a given feature type, and ``txt`` is the dump of the actual WFS request.
  56. The properties available in the template are:
  57. * ``typename``—Feature type name (for the ``zip`` property this will be the first feature type if the request contains many feature types)
  58. * ``geometryName``—Name of the geometry attribute. Used only if the original feature type has more than one geometry attribute.
  59. * ``geometryType``—Type of geometry contained in the shapefile. This is only used if the output geometry type is generic and the various geometries are stored in one shapefile per type.
  60. * ``workspace``—Workspace of the feature type
  61. * ``timestamp``—Date object with the request timestamp
  62. * ``iso_timestamp``—String (ISO timestamp of the request at GMT) in ``yyyyMMdd_HHmmss`` format
  63. JSON and JSONP output
  64. ---------------------
  65. The JSON output format (and JSONP if enabled) return feature content as a `GeoJSON <http://geojson.org/>`__ document. Here is an example of a simple GeoJSON file;
  66. .. code-block:: json
  67. { "type": "Feature",
  68. "geometry": {
  69. "type": "Point",
  70. "coordinates": [125.6, 10.1]
  71. },
  72. "properties": {
  73. "name": "Dinagat Islands"
  74. }
  75. }
  76. The output properties can include the use of lists and maps:
  77. .. code-block:: json
  78. {
  79. "type": "Feature",
  80. "id": "example.3",
  81. "geometry": {
  82. "type": "POINT",
  83. "coordinates": [ -75.70742, 38.557476 ],
  84. },
  85. "geometry_name": "geom",
  86. "properties": {
  87. "CONDITION": "Orange",
  88. "RANGE": {"min":"37","max":"93"}
  89. }
  90. }
  91. JSON output ``format_options``:
  92. * ``format_options=id_policy:<attribute name>=<attribute|true|false>`` is used to determine if the id values are included in the output.
  93. Use ``format_options=id_policy:reference_no`` for feature id generation using the reference_no attribute, or ``format_options=id_policy:reference_no=true`` for default feature id generation, or ``format_options=id_policy:reference_no=false`` to suppress feature id output.
  94. If id_policy is not specified the geotools default feature id generation is used.
  95. * ``format_options=callback:<parseResponse>`` applies only to the JSONP output format. See :ref:`wms_vendor_parameters` to change the callback name. Note that this format is disabled by default (See :ref:`wms_global_variables`).
  96. * ``format_option=filename:<file>``: if a file name is provided, the name is used as the output file name. The extension :file:`json` is optional, for example ``format_options=filename:export`` or ``format_options=features.json``
  97. JSON output ``system properties``:
  98. * ``json.maxDepth=<max_value>`` is used to determine the max number of allowed JSON nested objects on encoding phase. By default the value is 100.
  99. .. note:: Coordinates with a value equal to :math:`\pm \infty` will be encoded with their string representation ``"Infinity"`` or ``"-Infinity"``
  100. CSV output
  101. ----------------
  102. A Default CSV file uses a comma to separate values. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. The separator can be changed using format_options as specified below.
  103. csv file output ``format_options``:
  104. * ``format_option=filename:<file>``: if a file name is provided, the name is used as the output file name. For example, ``format_options=filename:roads.csv``.
  105. * ``format_option=csvseparator:<csvseparator>`` (default is ```,``` ): if a separator is provided, it is used to separate values in output csv file. For example, ``format_options=csvseparator:-`` is used to get dash separated file.
  106. Some special characters need to be handled using keywords as below:
  107. * space separated: ``format_options=csvseparator:space``
  108. * tab separated: ``format_options=csvseparator:tab``
  109. * semicolon separated: ``format_options=csvseparator:semicolon``