Thursday, 29 October 2015

python - QGIS Field Pyculator Reclass


I'm new to the QGIS Pyculator and need to reclass a field ('AP') based on another field ('Mag'). What I have so far, from the ArcGIS field calculator:


def Reclass(Mag,AP):
if Mag>= 2000:
return "M"
elif Mag>80 and Vector_Mag<2000:
return "L"
elif Mag<=80 :
return "S"

else:
return "UNCLASS"

With the expression as:


Reclass(!Mag!,!AP!)

How does this translate into the QGIS Field Pyculator?



Answer



In the FieldPyculator, you will need to:




  • Insert your function as a Global expression and remove the AP parameter as you can choose from the GUI which field you want updated.

  • Slightly change your Field expression by specifying fields using instead of !Mag!.




This is the global expression I used (not sure what Vector_Mag was so changed these to Mag):


def Reclass(Mag):
if Mag >= 2000:
return "M"
elif Mag > 80 and Mag < 2000:
return "L"

elif Mag <= 80:
return "S"
else:
return "UNCLASS"

This is the field expression:


value = Reclass()

FieldPyculator


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...