2

Currently we are trying to extract the layer property information from our vector layers and raster layers (inside some geopackages). More specifically the property information. However though it is very easy to do this with vector layer with Rasters it is a different story. While a work around would be to "vectorise" and do the attribute table part, we are looking for another way.

I know the information in the Raster is there because when I click on Properties on my raster i get this:

[![enter image description here][1]][1]

This is something we also want to run as batch process to process many layers at the same time. Note we are not trying to store the information inside the raster layer but outside of it in a table without geometry.

BERA
  • 72,339
  • 13
  • 72
  • 161
ThunderSpark
  • 929
  • 4
  • 13
  • We are not trying to store the information inside the Raster but outside it of in a different table. Kind of catalog or meta data table we can use. – ThunderSpark Jul 30 '20 at 07:31
  • I am sorry what is unclear here? I am talking about the property information here. A moment I will send a screenshot. – ThunderSpark Jul 30 '20 at 08:03
  • I have sent a screenshot, should be clear now. I should have said Layer Property Information. – ThunderSpark Jul 30 '20 at 08:05

1 Answers1

2

You can use pyqgis, example:

#Create empty memory table
vl = QgsVectorLayer("None", "Rasterinfo", "memory")
pr = vl.dataProvider()

with edit(vl): #Add fields pr.addAttributes([QgsField("Name", QVariant.String),QgsField("Source", QVariant.String),QgsField("crs", QVariant.String)]) vl.updateFields() for lyr in QgsProject.instance().mapLayers().values(): #For each raster layer added to the map write data to table if type(lyr) == qgis._core.QgsRasterLayer: info = [lyr.name(), lyr.source(), lyr.crs().authid()] f = QgsFeature() f.setAttributes(info) (res, outFeats) = pr.addFeatures([f])

#Add table to map QgsProject.instance().addMapLayer(vl)

enter image description here

BERA
  • 72,339
  • 13
  • 72
  • 161
  • Any chance this can be done as script/model that then can be run as a batch? Because 1: we have so many rasters in different geopackages and 2 it just needs to remain simple where my colleague just needs to select the layers his map and then just run the script. – ThunderSpark Jul 30 '20 at 08:34
  • Yes https://gis.stackexchange.com/questions/118862/getting-list-of-layer-names-using-pyqgis – BERA Jul 30 '20 at 08:35
  • I am gonna post an edit and update to Illustrate what I exacly want, thx for the script not only does it work so far for Rasters but this also kind of helps us with Vector data at the same time. There are still a two things though but I can solve them later on. A moment gonna give you an update with an illustation of how I want this script to work. – ThunderSpark Jul 30 '20 at 09:33
  • Put some own effort in it and you can solve your question. – BERA Jul 30 '20 at 10:31
  • 1
    Nevermind this update for now this sollution is the best so far to get done with one layer per name. I will mark this as a solution and go on from here. – ThunderSpark Jul 30 '20 at 10:34