Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Could someone tell me how to classify/populate fields with QGIS FieldPyculator Plugin?

In the Attribute Table, I have a field named POPULACAO with population data:

enter image description here

I want to apply a weight to classify these fields. I've installed QGIS FieldPyculator Plugin via repository. Below the Python code to complete this task in ArcGIS 10:


def reclass(POP):

if (POP <= 10000):
return 1
elif (POP > 10001 and POP <= 30000):
return 2
elif (POP > 30001 and POP <= 50000):
return 3
elif (POP > 50001 and POP <= 100000):
return 4
elif (POP > 100001 and POP <= 200000):
return 5
elif (POP > 200001 and POP <= 500000):
return 6
elif (POP > 500001 and POP <= 1000000):
return 7
else:
return 8

In the box below:

reclass( !POPULACAO! )

The ArcGIS 10 Python code works like a charm. Data shapefile: http://bit.ly/xBW8Pz | In FieldPyculator, I did wrong, I know:

enter image description here

Please help me. Jorge Santos

share|improve this question

2 Answers 2

Well, the error message says that the indentation is wrong. The code is not correctly indented at all. In Python, indentation matters and everything after the first line would have to be indented, as well as all the loops etc.

share|improve this answer

Standard Python indentation is two or four spaces.
Try using the following indented code:

def reclass(POP):
  if (POP <= 10000):
    return 1
  elif (POP > 10001 and POP <= 30000):
    return 2
  elif (POP > 30001 and POP <= 50000):
    return 3
  elif (POP > 50001 and POP <= 100000):
    return 4
  elif (POP > 100001 and POP <= 200000):
    return 5
  elif (POP > 200001 and POP <= 500000):
    return 6
  elif (POP > 500001 and POP <= 1000000):
    return 7
  else:
    return 8

share|improve this answer
    
Ei!!! Kisses for Anita "@underdarkgis" Graser, hugs for Fezter! Python need to insert more spaces... Sorry for all, boys and girls. In the box below: reclass( !POPULACAO! ) exchange for reclass ( <POPULACAO> ) –  Jorge Santos May 28 '12 at 23:23
    
Now the FieldPyculator rocks: goo.gl/Zbe5Q Thanks for all, Jorge Santos –  Jorge Santos May 29 '12 at 1:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.