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.

3
  • 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. Jul 30, 2020 at 7:31
  • I am sorry what is unclear here? I am talking about the property information here. A moment I will send a screenshot. Jul 30, 2020 at 8:03
  • I have sent a screenshot, should be clear now. I should have said Layer Property Information. Jul 30, 2020 at 8:05

1 Answer 1

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

5
  • 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. Jul 30, 2020 at 8:34
  • Yes gis.stackexchange.com/questions/118862/…
    – BERA
    Jul 30, 2020 at 8: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. Jul 30, 2020 at 9:33
  • Put some own effort in it and you can solve your question.
    – BERA
    Jul 30, 2020 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. Jul 30, 2020 at 10:34

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.