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,136
  • 29
  • 109
  • 338
jay
  • 337
  • 2
  • 4
  • 8

2 Answers2

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!)
Stev_k
  • 6,689
  • 2
  • 34
  • 46
  • 6
    And, of course, if he wants "Yes" and "No" instead of 1 and 0, he should use return "Yes" and return "No". – nmpeterson Mar 19 '12 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 – Jason Miller Aug 12 '14 at 02: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,689
  • 2
  • 34
  • 46
Naresh
  • 677
  • 4
  • 14