TransWikia.com

Labeling many Raster Tiles at once

Geographic Information Systems Asked on February 6, 2021

I got this 42 tiles that I’m trying to show each tiles layer name on top of it like a label.

enter image description here

So I can know each tiles name, any Ideas on how to do that?

I have searched the web and found nothing

One Answer

You can use PyQGIS. Add all raster layers (and no other layers) to the map and execute code below. It will create centroid points for all rasters with a field holding layer name.

rlyrs = [layer for layer in QgsProject.instance().mapLayers().values()]

#Create point layer
vl = QgsVectorLayer("Point?crs={}&index=yes".format(rlyrs[0].crs().authid()), "myLayer", "memory")
provider = vl.dataProvider()
provider.addAttributes([QgsField("label", QVariant.String)])
vl.updateFields()

#For each raster layer create a point feature from rl extents centroid,
#populate label field with rl name.
for r in rlyrs:
    f = QgsFeature()
    f.setGeometry(QgsGeometry.fromRect(r.extent()).centroid())
    f.setAttributes([r.name()])
    provider.addFeature(f)

QgsProject.instance().addMapLayer(vl)

enter image description here

Answered by BERA on February 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP