Skip to content

Commit

Permalink
[processing] tiles_xyz: get rid of unlabeled areas at the edges of me…
Browse files Browse the repository at this point in the history
…tatiles
  • Loading branch information
varmar05 authored and wonder-sk committed Jun 7, 2019
1 parent 4013925 commit 228040d
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions python/plugins/processing/algs/qgis/TilesXYZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
QgsMapSettings,
QgsCoordinateTransform,
QgsCoordinateReferenceSystem,
QgsMapRendererCustomPainterJob)
QgsMapRendererCustomPainterJob,
QgsLabelingEngineSettings)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm


Expand Down Expand Up @@ -196,6 +197,11 @@ def generate(self, writer, parameters, context, feedback):
if self.tile_format == 'PNG':
settings.setBackgroundColor(QColor(Qt.transparent))

# disable partial labels (they would be cut at the edge of tiles)
labeling_engine_settings = settings.labelingEngineSettings()
labeling_engine_settings.setFlag(QgsLabelingEngineSettings.UsePartialCandidates, False)
settings.setLabelingEngineSettings(labeling_engine_settings)

self.wgs_extent = src_to_wgs.transformBoundingBox(extent)
self.wgs_extent = [self.wgs_extent.xMinimum(), self.wgs_extent.yMinimum(), self.wgs_extent.xMaximum(),
self.wgs_extent.yMaximum()]
Expand Down Expand Up @@ -233,17 +239,6 @@ def generate(self, writer, parameters, context, feedback):
settings.setExtent(wgs_to_dest.transformBoundingBox(extent))
settings.setOutputSize(size)

if hasattr(settings, 'setLabelBoundaryGeometry'):
label_area = QgsRectangle(settings.extent())
lab_buffer = label_area.width() * (lab_buffer_px / size.width())
label_area.set(
label_area.xMinimum() + lab_buffer,
label_area.yMinimum() + lab_buffer,
label_area.xMaximum() - lab_buffer,
label_area.yMaximum() - lab_buffer
)
settings.setLabelBoundaryGeometry(QgsGeometry.fromRect(label_area))

image = QImage(size, QImage.Format_ARGB32_Premultiplied)
image.fill(Qt.transparent)
dpm = settings.outputDpi() / 25.4 * 1000
Expand Down

0 comments on commit 228040d

Please sign in to comment.