Coverage for gws-app/gws/plugin/mbtiles_layer/layer.py: 0%
42 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 23:09 +0200
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 23:09 +0200
1"""MBTiles based layer."""
3from typing import Optional
5import gws
6import gws.base.layer
7import gws.config.util
8import gws.gis.gdalx
9import gws.gis.ms
10import gws.gis.ms.util
11import gws.gis.zoom
12import gws.lib.bounds
14from . import provider
16gws.ext.new.layer('mbtiles')
19class Config(gws.base.layer.Config):
20 """MBTiles layer"""
22 provider: provider.Config
23 """Provider configuration."""
24 processing: Optional[list[str]]
25 """Processing directives."""
26 transparentColor: Optional[str]
27 """Color to treat as transparent in the layer."""
30class Object(gws.base.layer.image.Object):
31 msOptions: gws.gis.ms.LayerOptions
32 serviceProvider: provider.Object
34 def configure(self):
35 self.msOptions = gws.gis.ms.LayerOptions(
36 type=gws.gis.ms.LayerType.raster,
37 processing=self.cfg('processing', default=[]),
38 transparentColor=self.cfg('transparentColor', default=None),
39 )
40 self.configure_layer()
42 def configure_provider(self):
43 gws.config.util.configure_service_provider_for(self, provider.Object)
44 self.msOptions.path = self.serviceProvider.path
46 def configure_bounds(self):
47 if super().configure_bounds():
48 return True
49 with gws.gis.gdalx.open_raster(self.msOptions.path) as gd:
50 self.bounds = gws.lib.bounds.transform(gd.bounds(), self.mapCrs)
51 self.msOptions.crs = self.bounds.crs
52 return True
54 def configure_grid(self):
55 p = self.cfg('grid', default=gws.Config())
57 self.grid = gws.TileGrid(
58 origin=p.origin or gws.Origin.nw,
59 tileSize=p.tileSize or 256,
60 bounds=self.bounds,
61 )
63 if p.resolutions:
64 self.grid.resolutions = p.resolutions
65 else:
66 self.grid.resolutions = gws.gis.zoom.resolutions_from_bounds(self.grid.bounds, self.grid.tileSize)
68 ##
70 def render(self, lri):
71 return gws.gis.ms.util.raster_render(self, lri)