9

It seems that processing.getObject() is no longer available in QGIS.

from PyQt5.QtCore import *
from qgis.core import *
#...
layer = processing.getObject(layer)

# -> ...module 'processing' has no attribute 'getObject'

Is there a new way to use get.Object?

  • Method 'processing.getObject()' is still available in QGIS. – xunilk Jul 30 '17 at 14:31
  • 1
    Don't port to qgis 3 yet - the API has not frozen, so you'll be making extra work for yourself when the release is made! If you want to cause work for yourself, the work in progress processing porting guide is at github.com/qgis/QGIS/pull/4841/files – ndawson Jul 31 '17 at 3:43
4

I have a copy of the QGIS github project locally, it's a few months old but I was able to find where this changed.

It's worth checking the list of API changes, which mentions this

dataobjects.getLayerFromString() was removed. Use QgsProcessingUtils.mapLayerFromString() instead.

Using git line annotations I was able to trace this back to a change made a few months ago...

it looks as if a few methods (including getObject) were refactored out and replaced with a single getLayerFromString() method

def getLayerFromString(string, forceLoad=True):
    """Returns an object (layer/table) given a source definition.

    if forceLoad is true, it tries to load it if it is not currently open
    Otherwise, it will return the object only if it is loaded in QGIS.
    """
    ...

But since then it's been moved to QgsProcessingUtils.

So you could try using QgsProcessingUtils.mapLayerFromString()

If using QGIS 2.x, you should still be able to use getObject() as before (can check using print(processing.__dict__['getObject'])

0

Method 'processing.getObject()' is still available in QGIS. It can be observed at net image:

enter image description here

So, the workaround is as follow:

>>>import processing
>>>layer =  processing.getObject("/home/zeito/pyqgis_data/polygon8.shp")
>>>layer
<qgis._core.QgsVectorLayer object at 0x9a9c0104>
  • 1
    processing.getObject() is not available in current master, which will be QGIS v3.0 in months. – Germán Carrillo Jul 30 '17 at 14:57
  • i was going to tag this question qgis-3.0 but noticed there isn't a tag for this. Out of interest what plugin were you using there? – Steven Kay Jul 30 '17 at 16:19
  • @StevenKay, there is, just tagged it. – Germán Carrillo Jul 30 '17 at 17:37
  • @GermánCarrillo I know that. Sorry, but I didn't see number 3 because I focus in that he used in his question a layer reference instead a uri as parameter (possible cause of error). – xunilk Jul 30 '17 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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