2

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

1
  • 1
    Usually this is done by creating polygon footprints of each raster that contains the attributes you want to label by. Commented Sep 21, 2020 at 18:23

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.