mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
[processing] added new options (alpha, quality, tile_size) to xyz alg
This commit is contained in:
parent
861c5115eb
commit
3a9b32d635
@ -129,6 +129,8 @@ class TilesXYZAlgorithmBase(QgisAlgorithm):
|
||||
ZOOM_MAX = 'ZOOM_MAX'
|
||||
DPI = 'DPI'
|
||||
TILE_FORMAT = 'TILE_FORMAT'
|
||||
ALPHA = 'ALPHA'
|
||||
QUALITY = 'QUALITY'
|
||||
|
||||
def initAlgorithm(self, config=None):
|
||||
self.addParameter(QgsProcessingParameterExtent(self.EXTENT, self.tr('Extent')))
|
||||
@ -152,6 +154,16 @@ class TilesXYZAlgorithmBase(QgisAlgorithm):
|
||||
self.tr('Tile format'),
|
||||
self.formats,
|
||||
defaultValue=0))
|
||||
self.addParameter(QgsProcessingParameterNumber(self.ALPHA,
|
||||
self.tr('Background transparency (applies to PNG only)'),
|
||||
minValue=0,
|
||||
maxValue=255,
|
||||
defaultValue=0))
|
||||
self.addParameter(QgsProcessingParameterNumber(self.QUALITY,
|
||||
self.tr('Quality (applies to JPG only)'),
|
||||
minValue=1,
|
||||
maxValue=100,
|
||||
defaultValue=75))
|
||||
|
||||
def prepareAlgorithm(self, parameters, context, feedback):
|
||||
project = context.project()
|
||||
@ -167,8 +179,14 @@ class TilesXYZAlgorithmBase(QgisAlgorithm):
|
||||
self.max_zoom = self.parameterAsInt(parameters, self.ZOOM_MAX, context)
|
||||
dpi = self.parameterAsInt(parameters, self.DPI, context)
|
||||
self.tile_format = self.formats[self.parameterAsEnum(parameters, self.TILE_FORMAT, context)]
|
||||
tile_width = 256
|
||||
tile_height = 256
|
||||
alpha = self.parameterAsInt(parameters, self.ALPHA, context)
|
||||
quality = self.parameterAsInt(parameters, self.QUALITY, context)
|
||||
try:
|
||||
tile_width = self.parameterAsInt(parameters, self.TILE_WIDTH, context)
|
||||
tile_height = self.parameterAsInt(parameters, self.TILE_HEIGHT, context)
|
||||
except AttributeError:
|
||||
tile_width = 256
|
||||
tile_height = 256
|
||||
|
||||
wgs_crs = QgsCoordinateReferenceSystem('EPSG:4326')
|
||||
dest_crs = QgsCoordinateReferenceSystem('EPSG:3857')
|
||||
@ -183,7 +201,9 @@ class TilesXYZAlgorithmBase(QgisAlgorithm):
|
||||
settings.setLayers(self.layers)
|
||||
settings.setOutputDpi(dpi)
|
||||
if self.tile_format == 'PNG':
|
||||
settings.setBackgroundColor(QColor(Qt.transparent))
|
||||
color = QColor()
|
||||
color.setAlpha(alpha)
|
||||
settings.setBackgroundColor(color)
|
||||
|
||||
self.wgs_extent = src_to_wgs.transformBoundingBox(extent)
|
||||
self.wgs_extent = [self.wgs_extent.xMinimum(), self.wgs_extent.yMinimum(), self.wgs_extent.xMaximum(),
|
||||
@ -201,7 +221,7 @@ class TilesXYZAlgorithmBase(QgisAlgorithm):
|
||||
|
||||
tile_params = {
|
||||
'format': self.tile_format,
|
||||
'quality': 75,
|
||||
'quality': quality,
|
||||
'width': tile_width,
|
||||
'height': tile_height,
|
||||
'min_zoom': self.min_zoom,
|
||||
@ -282,11 +302,10 @@ class MBTilesWriter:
|
||||
self.min_zoom = tile_params.get('min_zoom')
|
||||
self.max_zoom = tile_params.get('max_zoom')
|
||||
tile_format = tile_params['format']
|
||||
options = []
|
||||
if tile_format == 'JPG':
|
||||
tile_format = 'JPEG'
|
||||
options = ['QUALITY=%s' % tile_params.get('quality', 75)]
|
||||
else:
|
||||
options = ['ZLEVEL=8']
|
||||
driver = gdal.GetDriverByName('MBTiles')
|
||||
ds = driver.Create(self.filename, 1, 1, 1, options=['TILE_FORMAT=%s' % tile_format] + options)
|
||||
ds = None
|
||||
@ -458,9 +477,21 @@ class TilesXYZAlgorithmDirectory(TilesXYZAlgorithmBase):
|
||||
TMS_CONVENTION = 'TMS_CONVENTION'
|
||||
OUTPUT_DIRECTORY = 'OUTPUT_DIRECTORY'
|
||||
OUTPUT_HTML = 'OUTPUT_HTML'
|
||||
TILE_WIDTH = 'TILE_WIDTH'
|
||||
TILE_HEIGHT = 'TILE_HEIGHT'
|
||||
|
||||
def initAlgorithm(self, config=None):
|
||||
super(TilesXYZAlgorithmDirectory, self).initAlgorithm()
|
||||
self.addParameter(QgsProcessingParameterNumber(self.TILE_WIDTH,
|
||||
self.tr('Tile width'),
|
||||
minValue=1,
|
||||
maxValue=4096,
|
||||
defaultValue=256))
|
||||
self.addParameter(QgsProcessingParameterNumber(self.TILE_HEIGHT,
|
||||
self.tr('Tile height'),
|
||||
minValue=1,
|
||||
maxValue=4096,
|
||||
defaultValue=256))
|
||||
self.addParameter(QgsProcessingParameterBoolean(self.TMS_CONVENTION,
|
||||
self.tr('Use inverted tile Y axis (TMS convention)'),
|
||||
defaultValue=False,
|
||||
|
||||
@ -2134,7 +2134,10 @@ tests:
|
||||
ZOOM_MIN: 1
|
||||
ZOOM_MAX: 3
|
||||
TILE_FORMAT: 0 # png
|
||||
ALPHA: 0 # fully transparent
|
||||
TMS_CONVENTION: false
|
||||
TILE_WIDTH: 256
|
||||
TILE_HEIGHT: 256
|
||||
|
||||
results:
|
||||
OUTPUT_DIRECTORY:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user