2

I'm writing a stand-alone script using no GUI. I cannot use the function Join Attributes by Location. I think that the problem might be with proper passing arguments to the function. There's a piece of the code:

from qgis.core import *
from qgis.utils import *
import os,sys
QgsApplication.setPrefixPath("'C:/OSGEO4~1/apps/qgis'", True)
qgs = QgsApplication([], False)
qgs.initQgis()
sys.path.append('C:/OSGEO4~1/apps/qgis/python/plugins')
print sys.path
from processing.algs.qgis.JoinAttributes import *
alg = JoinAttributes()
alg.setParameterValue('INPUT_LAYER',QgsVectorLayer("C:\Points.shp",'pkt','ogr')) #all of those layers exist
alg.setParameterValue('INPUT_LAYER_2',QgsVectorLayer("C:\Polygons.shp",'polygons','ogr'))
alg.setOutputValue('OUTPUT_LAYER', QgsVectorLayer("C:\Ewid.shp",'CadastralLayer','ogr'))
from processing.gui.SilentProgress import SilentProgress
progress = SilentProgress()
alg.processAlgorithm(progress)

The error is as follows:

Original exception was:
Traceback (most recent call last):
File "mainScript.py", line 33, in <module> aCD.addCadastralData(layers,parcelLayerPath)
File "Z:\Soft\AutomatyczneRaportowanie\AddingCadastralData\AddingCadastralData_main.py", line 36, in addCadastralData alg.processAlgorithm(progress)
File "C:/OSGEO4~1/apps/qgis/python/plugins\processing\algs\qgis\JoinAttributes.py", line 76, in processAlgorithm layer.crs())
File "C:/OSGEO4~1/apps/qgis/python/plugins\processing\core\outputs.py", line 308, in getVectorWriter crs, options)
File "C:/OSGEO4~1/apps/qgis/python/plugins\processing\tools\vector.py", line 550, in __init__ if self.destination.startswith(self.MEMORY_LAYER_PREFIX):
AttributeError: 'NoneType' object has no attribute 'startswith'

Could you help me to sort it out?

asked Oct 21, 2016 at 6:19
2
  • 1
    Do you not also have to set two additional parameters: TABLE_FIELD and TABLE_FIELD_2? Commented Oct 21, 2016 at 9:54
  • 1
    You've changed the context of the question from "What's wrong with this code" to "Provide an example of code", which kind of makes @Matte's answer moot even though he was correct about the slashes. Perhaps it would be better to rollback this question to the previous edit, accept the answer and post this revision as a new question? ;) Commented Oct 21, 2016 at 10:52

1 Answer 1

3

You use a backslash within quotes in your parameters. In python this is a escape character.

Use r"c:\" or use forward slashes "c:/" or double backslashes "c:\\" to avoid the escape charakter. And try to be consistent about it as you are mixing them in your code. (sys.path.append with forward slashes for example). Its also a good idea not to mix single and double quotes even when it does not matter here.

answered Oct 21, 2016 at 8:52
1
  • +1 Very useful, thanks for that! However, I'm still stuck with joining attributes Commented Oct 21, 2016 at 9:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.