Coverage for gws-app/gws/plugin/raster_layer/grabber.py: 75%

16 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-05 13:35 +0200

1"""Raster layer grabber.""" 

2 

3import gws 

4import gws.base.grabber.box 

5import gws.lib.mapserver.core 

6 

7 

8class Object(gws.base.grabber.box.Object): 

9 """Grabber that renders boxes with an in-process MapServer map.""" 

10 

11 msOptions: gws.MapServerLayerOptions 

12 """MapServer layer options.""" 

13 

14 def __init__(self, opts: gws.base.grabber.Options, msOptions: gws.MapServerLayerOptions): 

15 """Create the grabber. 

16 

17 Args: 

18 opts: Grabber options. 

19 msOptions: MapServer layer options. 

20 """ 

21 super().__init__(opts) 

22 self.msOptions = msOptions 

23 self.sourceCrs = self.targetCrs 

24 self.maxRequestPixels = 9000 

25 

26 def fetch_box_as_image(self, bounds, w, h, params=None): 

27 ms_map = gws.lib.mapserver.core.new_map() 

28 ms_map.add_layer(self.msOptions) 

29 return ms_map.draw(bounds, (w, h)) 

30 

31 def fetch_box_as_bytes(self, bounds, w, h, params=None): 

32 return self.to_bytes(self.fetch_box_as_image(bounds, w, h, params))