I'm trying to code a script who calculate id of vineyard lines and vines in these lines.

I code with temporary layers, just my final layer will be save. But I'm getting stuck on adding new fields, at line 39, I have an OUTPUT error, and QGIS log says no more. Can you help me ?

This is my code :

##Intervine_distance=number 1.5
##output_layer=output vector

import os, processing
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *

# Project Layer in L93

l93 = processing.runalg("qgis:reprojectlayer", point_layer, "EPSG:2154", None)

# Buffer


buffer = processing.runalg("qgis:fixeddistancebuffer", l93['OUTPUT'], 
Dbuf, 100, False, None )

# Dissolve

dissolve = processing.runalg("qgis:dissolve", buffer['OUTPUT'], True, '',  None) 

# Split

split = processing.runalg('qgis:multiparttosingleparts', dissolve['OUTPUT'], None)

#New Fields

rang = processing.runalg('qgis:addfieldtoattributestable', split['OUTPUT'], "Rang", 0, 3, 0, None)

pied = processing.runalg('qgis:addfieldtoattributestable', rang['OUTPUT'], "Pied", 0, 3, 0, None)

# Some steps remaind to code here

# Reproject Layer in WGS84

processing.runalg("qgis:reprojectlayer", pied, "EPSG:4326", output_layer)
  • What error are you getting? – BritishSteel Jun 12 '17 at 14:32
  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. – Midavalo Jun 12 '17 at 15:18

I think you need to replace rang['OUTPUT'] with rang['OUTPUT_LAYER'] instead as the parameters for the qgis:addfieldtoattributestable algorithm reads:

ALGORITHM: Add field to attributes table
    INPUT_LAYER <ParameterVector>
    FIELD_NAME <ParameterString>
    FIELD_TYPE <ParameterSelection>
    FIELD_LENGTH <ParameterNumber>
    FIELD_PRECISION <ParameterNumber>
    OUTPUT_LAYER <OutputVector>

So instead use:

pied = processing.runalg('qgis:addfieldtoattributestable', rang['OUTPUT_LAYER'], "Pied", 0, 3, 0, None)

Then when you reproject, use :

processing.runalg("qgis:reprojectlayer", pied['OUTPUT_LAYER'], "EPSG:4326", output_layer)
| improve this answer | |
  • 1
    Oh yes, that's it !! thank you for your help, and now I know where i have to search to solve these type of problems. I will be able to finish my script, or at least continue. – Tim C. Jun 12 '17 at 14:59
  • 2
    @TimothéeColas The best way to say "thank you" here is to upvote and accept the answer. See What should I do when someone answers my question? – Midavalo Jun 12 '17 at 15:18
  • 1
    Ok thank you for your advice, i'm a newbie on stackexchange ;) – Tim C. Jun 15 '17 at 9:54
  • @TimothéeColas - Most welcome, glad it helped! And don't worry, you will get quickly used to stackexchange :) – Joseph Jun 15 '17 at 9:59

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.