2

I'm using the python console of QGIS 2.8.1-Wien. I have a shapefile with many fields in the table that I want to remove them. I tried to use this geoalgoritm as:

processing.runalg('qgis:deletecolumn', myshapefile.shp, "myfield", myoutput.shp) 

This works perfectly and the field I want is removed. My question is: if I want to remove more than one fields how should I write this formula? Or there are any other way to write a python script?


I used your 1st method, just for one shapefile as:

output_0=processing.runalg('qgis:deletecolumn', "D:/PATRICIA/ECMWF/Test/TPrecip_20140628_VERAO_join9.shp", "Lat_dec", None) output_1=processing.runalg('qgis:deletecolumn', output_0, "Lon_dec", None) output_2=processing.runalg('qgis:deletecolumn', output_1, "Altitude", "D:/PATRICIA/ECMWF/Test/TPrecip_20140628_VERAO_join12.shp")

The result was:"Error: Wrong parameter value: None"

I tried to use the 2nd method for 3 similar shapefiles (with same fields) activated in the table of contentes but just occured de removal of the fields in the 1st shapefile :

layer = qgis.utils.iface.activeLayer()
res = layer.dataProvider().deleteAttributes([1, 2, 3, 4, 5, 6, 7, 8])
layer.updateFields()

In this case it's impossible to use 8000 shapefiles activated in map canvas.

Any help?

underdark
  • 84,148
  • 21
  • 231
  • 413
  • I've edited my post, I think the None error was my mistake as I forgot to add a bit more to the code. Apologies for that! The edit includes a script to run on multiple shapefiles. You should probably edit your title as you want it for multiple shapefiles and not for a single one. Currently, your question is being flagged as a duplicate. – Joseph Jun 30 '15 at 14:12

0 Answers0