4

I have two fields, "P_Area" and "PC_Area", whose sizes I'd like to compare in a third field, "Areas_Equal". The "Areas_Equal" field should contain a "Yes" if the other two are equal and a "No" if they aren't.

How can I do this with Field Calculator and its Python Parser?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Mar 19, 2012 at 8:32

2 Answers 2

7

If you're using Python in ArcGIS you may be using an = for comparison instead of an ==

Your code should be similar to the below, if you use Python:

Pre-Logic Script Code - Check "Show Codeblock"

def ifBlock(pArea,pcArea):
 if pArea == pcArea:
 return 1
 else:
 return 0

Then in the actual code:

ifBlock(!P_AreaFieldName!,!PC_AreaFieldName!)
answered Mar 19, 2012 at 9:54
2
  • 6
    And, of course, if he wants "Yes" and "No" instead of 1 and 0, he should use return "Yes" and return "No". Commented Mar 19, 2012 at 13:44
  • 1
    Another way to write this in Python (that doesn't require the code block) is this... 1 if !P_Area! == !PC_Area! else 0 Commented Aug 12, 2014 at 2:35
2

Please always mention which tool you are using. I will explain how to do this in QGIS because it's free.

Open your shapefile. Open the attributes table. At the bottom create a new columon, call it 'test' or whatever. Now click on advanced search. Type 'P_Area = PC_Area' (without quotes) in SQL where clause. Hit OK.

Now click on 'Open field calculator' (ctrl+I). On the top check 'update existing field' and 'only update selected features'. In field calculator, type '1'. Hit ok.

Now, go back to advanced search, this time search for 'P_Area != PC_Area'. Do same steps as above, except input '0' in field calculator instead of '1'.

I am sure you can do it in a smarter way, but hey, this works. :)

Stev_k
6,7892 gold badges36 silver badges48 bronze badges
answered Mar 19, 2012 at 9:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.