2

I am trying to use Processing tool to automate refactoring for several tables: here is the code I am trying to use

import processing
input = 'C:\\Users\\Ehsan\\Desktop\\CIS WORK\\Sample 
files\\GeoJason\\cable.geojson'
output = 'C:\\Users\\Ehsan\\Desktop\\CIS WORK\\Temp\\'+'cable'+'.geojson'

processing.run("qgis:refactorfields",
                  input,
                  [{'name': 'id',
                    'type': 10,
                    'length': 10,
                    'precision': 0,
                    'expression': 'Value'
                   }],
                  output)   

When I run this program I get the following error:

Traceback (most recent call last):
File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "<string>", line 14, in <module>
File "C:/PROGRA~1/QGIS3~1.2/apps/qgis/./python/plugins\processing\tools\general.py", line 96, in run
return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
File "C:/PROGRA~1/QGIS3~1.2/apps/qgis/./python/plugins\processing\core\Processing.py", line 128, in runAlgorithm
context = dataobjects.createContext(feedback)
File "C:/PROGRA~1/QGIS3~1.2/apps/qgis/./python/plugins\processing\tools\dataobjects.py", line 72, in createContext
context.setFeedback(feedback)
TypeError: QgsProcessingContext.setFeedback(): argument 1 has unexpected type 'str'
  • Please edit this question and add the complete trace back of this error. – Asad Abbas Nov 10 '18 at 5:55
  • 3
    Run the tool manually and go to processing history (Ctrl+Alt+H) to see correct syntax. For example processing.run("qgis:refactorfields", {'INPUT':'/home/bera/GIS/Testdata/Polygons123.shp','FIELDS_MAPPING':[{'expression': '"id"', 'length': 10, 'name': 'id', 'precision': 0, 'type': 4}, {'expression': '"someid"', 'length': 100, 'name': 'someid', 'precision': 0, 'type': 10}],'OUTPUT':'/home/bera/GIS/Testdata/Polygons123_refactor.shp'}) Input should be inside curly brackets etc. – BERA Nov 10 '18 at 7:57
  • Thanks alot BERA . it did work for me .if you submit this as an answer I will accept it – Ehsan Aliverdi Nov 11 '18 at 0:13

Your Answer

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

Browse other questions tagged or ask your own question.