2

I'm working with the model builder in ArcMap 10.4.1 and I need to do some geometry calculation using the fields ArcMap creates. I am doing this with the tool 'calculate field' and my expression is:

[SHAPE_Length] / [SHAPE_Area]

But some of my feature classes have the geometry fields named as SHAPE_Length and SHAPE_Area and other feature classes as GEOM_LENGTH and GEOM_AREA. Because of the different names I cannot use an iterator to go through all my different feature classes because it will give an error when the geometry is stored as GEOM_Length rather then SHAPE_Length. Arcmap keeps naming the geometry field as GEOM_Length as in the original feature class even after altering the data or making a copy. I am working from a file geodatabase.

How can I force Arcmap to name all the geometry fields in the same way?

2
  • Is there a SHAPE field? Or is this different too?
    – Midavalo
    Mar 30, 2017 at 17:37
  • That is also called GEOM* instead of SHAPE. Mar 31, 2017 at 7:29

2 Answers 2

2

You could use an UpdateCursor instead of Field Calculator but it will require som python coding. With the cursor you can use tokens for the geometry fields, for example SHAPE@AREA and SHAPE@LENGTH. This will work on all inputs.

For example code below will calculate the existing field 'LengthDividedByArea':

import arcpy

feature=r'C:\path\to\data.gdb\polygon'

with arcpy.da.UpdateCursor(feature,['SHAPE@AREA','SHAPE@LENGTH','LengthDividedByArea']) as cursor:
    for row in cursor:
        row[2]=row[1]/row[0] #'LengthDividedByArea'='SHAPE@LENGTH'/'SHAPE@AREA'
        cursor.updateRow(row)

You can execute the code in the Python window or add to a Modelbuilder model: Integrating scripts within a model

2
  • Thank you for the answer. The feature class I am doing the calculation on is actually created in the model. Will I be able to use this script in my spatial model? I'm not exactly python hero but I can do some very (very) basic scripting. Mar 30, 2017 at 15:04
  • 1
    Thank you so much, that makes my model work. I have noticed that when I do an intersect with a layer that does use SHAPE as field names the new layer also uses SHAPE instead of GEOM. But why Arcmap uses different names for geometry fields is still a bit of a mistery... Mar 31, 2017 at 7:54
0

Found another solution, which isn't very efficient but does do the trick.

If another dataset does display geometry fields as SHAPE you can perform an intersect with this layer. Make sure the layer with 'SHAPE' is the first input. The dataset that is created will copy the geometry fields from the first input layer.

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.