Coverage for gws-app/gws/plugin/mbtiles_layer/grabber.py: 0%

16 statements  

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

1"""MBTiles grabber.""" 

2 

3import gws 

4import gws.base.grabber.box 

5import gws.lib.mapserver.core 

6 

7 

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

9 """Box grabber that renders an MBTiles file with MapServer.""" 

10 

11 msOptions: gws.MapServerLayerOptions 

12 """MapServer layer options for the file.""" 

13 

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

15 """Create an MBTiles grabber. 

16 

17 The source CRS is set to the target CRS, since MapServer reprojects 

18 the raster. One source request is limited to 9000 pixels. 

19 

20 Args: 

21 opts: Grabber options. 

22 msOptions: MapServer layer options for the file. 

23 """ 

24 super().__init__(opts) 

25 self.msOptions = msOptions 

26 self.sourceCrs = self.targetCrs 

27 self.maxRequestPixels = 9000 

28 

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

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

31 ms_map.add_layer(self.msOptions) 

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

33 

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

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