Coverage for gws-app/gws/base/exporter/core.py: 93%

42 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-24 12:46 +0200

1from typing import Optional 

2 

3import gws 

4 

5 

6class Config(gws.ConfigWithAccess): 

7 """Exporter configuration.""" 

8 

9 title: str 

10 """Exporter title.""" 

11 target: gws.ExportTarget 

12 """Target export type.""" 

13 targetPath: Optional[str] 

14 """Target export path (if applicable).""" 

15 withNoGeometry: bool = False 

16 """Allow features with no geometry.""" 

17 withMixedGeometry: bool = False 

18 """Allow features with different geometries in the same layer.""" 

19 withMixedCrs: bool = False 

20 """Allow features with different CRS in the same layer.""" 

21 withMultiLayer: bool = False 

22 """Store multiple layers in a single file.""" 

23 options: dict = {} 

24 """Additional exporter-specific options.""" 

25 

26 

27class Props(gws.Props): 

28 """Exporter properties.""" 

29 

30 title: str 

31 """Exporter title.""" 

32 supportsVector: bool 

33 """Whether exporter supports vector features.""" 

34 supportsRaster: bool 

35 """Whether exporter supports raster features.""" 

36 

37 

38class Object(gws.Exporter): 

39 """Exporter object.""" 

40 

41 def configure(self): 

42 self.title = self.cfg('title') 

43 self.targetType = self.cfg('targetType') 

44 self.targetPath = self.cfg('targetPath') 

45 self.withNoGeometry = self.cfg('withNoGeometry') 

46 self.withMixedGeometry = self.cfg('withMixedGeometry') 

47 self.withMixedCrs = self.cfg('withMixedCrs') 

48 self.withMultiLayer = self.cfg('withMultiLayer') and self.supportsMultiLayer 

49 self.options = gws.u.to_dict(self.cfg('options')) or {} 

50 self.supportedAttributeTypes = [] 

51 

52 def props(self, user) -> Props: 

53 """Return exporter properties.""" 

54 return Props( 

55 uid=self.uid, 

56 title=self.title, 

57 supportsVector=self.supportsVector, 

58 supportsRaster=self.supportsRaster, 

59 ) 

60 

61 def notify(self, ea: 'ExportArgs', event: str): 

62 """Notify exporter of export events.""" 

63 if ea.notify: 

64 ea.notify(event)