Coverage for gws-app/gws/base/exporter/core.py: 92%
36 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"""Base exporter."""
3from typing import Optional
5import gws
8class Config(gws.ConfigWithAccess):
9 """Exporter configuration."""
11 title: str
12 """Exporter title, shown in the client."""
13 target: gws.ExportTarget
14 """Where the export result goes."""
15 targetPath: Optional[str]
16 """Target export path (if applicable)."""
17 withNoGeometry: bool = False
18 """Export features without geometry instead of skipping them."""
19 withMixedGeometry: bool = False
20 """Allow different geometry types in one layer instead of skipping features."""
21 withMixedCrs: bool = False
22 """Allow different CRS in one layer instead of skipping features."""
23 withMultiLayer: bool = False
24 """Write all layers to one file if the format supports it."""
25 options: dict = {}
26 """Format-specific options, passed to the GDAL driver."""
29class Props(gws.Props):
30 """Exporter properties."""
32 title: str
33 """Exporter title."""
34 supportsVector: bool
35 """Whether exporter supports vector features."""
36 supportsRaster: bool
37 """Whether exporter supports raster features."""
40class Object(gws.Exporter):
41 """Base exporter.
43 Writes features to files in one format. Provides subclasses with the
44 common export options, the client props and event notification.
46 Subclasses set ``supportsVector``, ``supportsRaster`` and
47 ``supportsMultiLayer`` and implement ``run``.
48 """
50 def configure(self):
51 self.title = self.cfg('title')
52 self.targetType = self.cfg('targetType')
53 self.targetPath = self.cfg('targetPath')
54 self.withNoGeometry = self.cfg('withNoGeometry')
55 self.withMixedGeometry = self.cfg('withMixedGeometry')
56 self.withMixedCrs = self.cfg('withMixedCrs')
57 self.withMultiLayer = self.cfg('withMultiLayer') and self.supportsMultiLayer
58 self.options = gws.u.to_dict(self.cfg('options')) or {}
59 self.supportedAttributeTypes = []
61 def props(self, user) -> Props:
62 return Props(
63 uid=self.uid,
64 title=self.title,
65 supportsVector=self.supportsVector,
66 supportsRaster=self.supportsRaster,
67 )
69 def notify(self, ea: 'ExportArgs', event: str):
70 """Pass an export event to the notification callback of the export arguments.
72 Args:
73 ea: Export arguments.
74 event: Event name.
75 """
76 if ea.notify:
77 ea.notify(event)