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.
So I can know each tiles name, any Ideas on how to do that?
I have searched the web and found nothing
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)
Answered by BERA on February 6, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP