2

Reference taken: https://www.bradley365.com/qgis/split-layer-by-attribute.html

I took reference from above mentioned site and wrote:

import processing
input = 'D:\Geo_Data\maps-master-Saikat\maps-master\States'
field= 'State_Name'
operator = 0
value = 'Goa'
output = 'C:\Users\rpatro\Desktop\osm\Output'

processing.runalg('qgis:extractbyattribute',input,field,operator,value,output)

But its showing:

enter image description here

Can anyone help me to solve this error?

I am a bit new to scripting and all.

  • 1
    Which QGIS version are you using? Also, you should escape your paths with r if using backward slashes (i.e. r'C:\Users\rpatro\Desktop\osm\Output') – Joseph Jul 27 '18 at 10:28
  • Using Version 2.18 – Rashmita Jul 27 '18 at 10:30
  • 2
    The input needs to be vector data such as a shapefile, you have defined it as a directory. – Joseph Jul 27 '18 at 10:32
2

As Joseph noted with the input variable needs to be a vector layer (shapefile or some other vector layer), in addition the output needs to point to a vector format file too:

import processing
input = r'D:\Geo_Data\maps-master-Saikat\maps-master\States\inputShpName.shp'
field= 'State_Name'
operator = 0
value = 'Goa'
output = r'C:\Users\rpatro\Desktop\osm\Output\outputShpName.shp'

processing.runalg('qgis:extractbyattribute',input,field,operator,value,output)
  • Thanks, It works but again I am stuck in batch processing.Here the code which I am using: import processing import os input = 'D:/Geo_Data/maps-master-Saikat/maps-master/States/India_states.shp' field= 'State_Name' operator = 0 output = 'C:/Users/rpatro/Desktop/osm/Output/' unique = processing.runalg('qgis:listuniquevalues', input, field, None) values = unique['UNIQUE_VALUES'].split(';') for value in values: layer = os.path.join(output,value+'.shp') processing.runalg('qgis:extractbyattribute',input,field,operator,value,layer) – Rashmita Jul 31 '18 at 6:27
  • Your output variable needs to point to a file that the process will create, currently you have it only pointing to a directory, change output = 'C:/Users/rpatro/Desktop/osm/Output/' to output = 'C:/Users/rpatro/Desktop/osm/Output/outputShpName.shp' – artwork21 Jul 31 '18 at 15:32

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.