[GIS] Using Python in the Field Calculator, how to refer to a field in another shapefile

arcgis-10.0field-calculatorpython

I want to compare the changes in geometry between two shapefiles (of election districts in NYC. One is from 2001 and the other 2005). I am attempting to calculate a new field in the 2005 shapefile that shows the change in AREA from the 2001 shapefile to the 2005 shapefile, using the districts common IDs.

What I can't seem to figure out is how to refer to a field name in ANOTHER shapefile in my field calculator definition.

Here's what I have so far:

Pre-Logic Script Code:

def areaChg(shpOrig, areaOrig, shpNew, areaNew):
    origRows = arcpy.SearchCursor(shpOrig)
    for origRow in origRows:
        newRows = arcpy.SearchCursor(shpNew)
        for newRow in newRows:
            if origRow.ED == newRow.ED:
                return newRow.ED - origRow.ED
            else: pass

AreaChg =

areaChg("nyed_01bav", areaOrig, "nyed_05", !Area!)

It's the "areaOrig" in that last part of code, which is the place-holder for the field in the other shapefile, which I'm having a hard time with. How do I point to a field in another shapefile in field calculator? For the field in the shapefile from within which I'm doing the calculation, the correct format is "!Area!", but what about for a field from another shapefile?

Thanks!

Best Answer

Short Answer: Directly You can't.

Long Answer: Join the layer that contains the inputfield, to the layer that contains the field your want to calculate. After this, you can definetly use the input field in your Python Code.

Related Question