Coverage for gws-app/gws/base/exporter/__init__.py: 100%
2 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
1"""Feature export.
3Exports features selected in the client to files, such as Shapefile, GeoJSON,
4GML, KML or CSV. Exports run as background jobs. Concrete exporters, one per
5format, live in ``gws.plugin.exporter``.
7Submodules
8----------
10- ``core`` - the base exporter object with its configuration and props.
11 Subclasses declare which kinds of data they support and implement ``run``.
12 ``withMultiLayer`` is only enabled if the subclass supports multiple layers.
13- ``manager`` - the exporter manager (``root.app.exporterMgr``). It lists the
14 exporters available to a user, starts export jobs and runs exports directly
15 from the command line.
16- ``worker`` - the job worker. It loads the requested features, finds the
17 exporter and calls its ``run`` method, reporting progress to the job.
18- ``action`` - the ``exporter`` action with the API commands to start, poll,
19 cancel and download an export, and the ``gws exporter export`` command line
20 command.
21- ``util`` - helpers for exporters: grouping features by model with consistent
22 columns, geometry type and CRS, and a complete export with a GDAL vector driver.
24Exporters are configured on projects and on the application (``exporters``).
25For a project, the exporters of the project and of the application that the
26user can use are offered; of several exporters with the same title, only the
27first one is used.
29Export flow
30-----------
321. The client sends ``exporterStart`` with a ``gws.ExportRequest`` (exporter
33 uid and feature props). The manager creates a job for the worker and
34 schedules it. The request is passed to the worker through a pickled file
35 in the ephemeral directory.
362. The worker loads the features. Depending on the ``exportStrategy`` of
37 their model, features are read from the model by uid or built from the
38 props sent by the client.
393. The exporter writes the files and fills the ``gws.ExportResult``: the path
40 of the result file, its mime type and counts. The GDAL helper in ``util``
41 zips the files if there is more than one.
424. The client polls ``exporterStatus``. When the job is complete, the status
43 contains the counts and a URL for ``exporterOutput``, which returns the file.
45In the ``util`` helpers, a feature that does not fit its group (no geometry, a different geometry type
46or a different CRS) is skipped with an error in the result, unless the
47exporter allows it with ``withNoGeometry``, ``withMixedGeometry`` or
48``withMixedCrs``.
50Example::
52 actions+ {
53 type "exporter"
54 }
56 exporters+ {
57 type "geojson"
58 title "GeoJSON"
59 target "download"
60 access "allow all"
61 }
63 exporters+ {
64 type "gml"
65 title "GML (one file)"
66 target "download"
67 withMultiLayer true
68 access "allow all"
69 }
71From the command line, with a request stored as JSON::
73 gws exporter export --request request.json --output export.zip
75Implementing an exporter::
77 @gws.ext.object.exporter('myformat')
78 class Object(gws.base.exporter.Object):
79 supportsVector = True
80 supportsRaster = False
81 supportsMultiLayer = False
83 def run(self, ea, er):
84 gws.base.exporter.util.run_gdal_vector_export('MyDriver', 'application/x-my', ea, er)
85"""
87from .core import Config, Object, Props
88from . import manager, util