5

I have an xyz file that I want to convert negative field values in the z column to positive values. How do I do this with field calculator?

1
  • Thanks that does indeed change the values to positive but what I didn't make clear was that I want to keep them as the original values but without the minus symbol (effectively multiplying all negative values by -1)
    – mtsini
    Commented Mar 22, 2015 at 9:23

2 Answers 2

8

In QGIS you can use abs("fieldname") to turn them into always positive values.

1
  • And -abs("fieldname") to go from positive to negative which just helped me :)
    – JohnGIS
    Commented Mar 12, 2019 at 10:03
1

In ArcGIS desktop you could use the following python script in the field calculator, where you would create a new field (say, FIELDNAME2) and calculate the following (where FIELDNAME1 is your original values):

Pre-Logic script

def values(n):
    if n < 0:
        return n * -1
    else:
        return n

bottom window

values(!FIELDNAME1!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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