Select to view content in your preferred language

Error - Calculating the Extent of a Geo-Database feature (polygon)

3277
9
05-20-2013 06:31 AM
D__SamuelRajasekhar
Deactivated User
Hello All,

I have polygons in a geo-databases - WGS84

I want to calculate the extent (XMin, ...)

I have added a field XMin_Test (double)

In the field calculator I added the Python expression !extent.XMin!

I am getting the following error:

ERROR 000539: Invalid field extent.XMin
Failed to execute (Calculate Field).

I have tried the field as text, changed the expression to !extent.shape.YMin!

Same error.
0 Kudos
9 Replies
RichardFairhurst
MVP Honored Contributor
Hello All,

I have polygons in a geo-databases - WGS84

I want to calculate the extent (XMin, ...)

I have added a field XMin_Test (double)

In the field calculator I added the Python expression !extent.XMin!

I am getting the following error:

ERROR 000539: Invalid field extent.XMin
Failed to execute (Calculate Field).

I have tried the field as text, changed the expression to !extent.shape.YMin!

Same error.


The syntax in the Field Calculator should !Shape.extent.XMin!

The name of shape field in the feature class has to come first in the expression before accessing the properties of the shape field with the dot property operator.
0 Kudos
D__SamuelRajasekhar
Deactivated User
Thanks.

I am getting the same error.

however when I use the expression: !test!extent.XMin

It runs but no values are added to the field. All are NULL
0 Kudos
RichardFairhurst
MVP Honored Contributor
Thanks.

I am getting the same error.

however when I use the expression: !test!extent.XMin

It runs but no values are added to the field. All are NULL


No my syntax is essentially correct, since I just tested it, but perhaps the capitalization is wrong (Python at 10.1 is case sensitive).  First double click the Shape field in the pick list so that it has the exact same capitalization and name spelling for your shape field as you see in the table and then capitalize .Extent.XMin exactly like that.  For my successful calculation my shape field is in all caps, so my expression read:

!SHAPE.Extent.XMin!
0 Kudos
D__SamuelRajasekhar
Deactivated User
Thanks,

Below is the result:

Executing (Add Field): AddField Geo_Index_All_test test DOUBLE # # # # NULLABLE NON_REQUIRED #
Start Time: Mon May 20 12:00:04 2013
Adding test to Geo_Index_All_test...
Succeeded at Mon May 20 12:00:05 2013 (Elapsed Time: 1.00 seconds)
Executing (Calculate Field): CalculateField Geo_Index_All_test test !TEST.Extent.XMin! PYTHON #
Start Time: Mon May 20 12:00:05 2013
ERROR 000539: Invalid field TEST.Extent.XMin
Failed to execute (Calculate Field).
Failed at Mon May 20 12:00:05 2013 (Elapsed Time: 0.00 seconds)

However,
Below are the results when with different expression (runs - but all NULL)
Geo_Index_All_test test DOUBLE # # # # NULLABLE NON_REQUIRED #
Start Time: Mon May 20 12:02:19 2013
Adding test to Geo_Index_All_test...
Succeeded at Mon May 20 12:02:20 2013 (Elapsed Time: 1.00 seconds)
Executing (Calculate Field): CalculateField Geo_Index_All_test test !TEST!.Extent.XMin PYTHON #
Start Time: Mon May 20 12:02:20 2013
Succeeded at Mon May 20 12:03:22 2013 (Elapsed Time: 1 minutes 2 seconds)
0 Kudos
RichardFairhurst
MVP Honored Contributor
Thanks,

Below is the result:

Executing (Add Field): AddField Geo_Index_All_test test DOUBLE # # # # NULLABLE NON_REQUIRED #
Start Time: Mon May 20 12:00:04 2013
Adding test to Geo_Index_All_test...
Succeeded at Mon May 20 12:00:05 2013 (Elapsed Time: 1.00 seconds)
Executing (Calculate Field): CalculateField Geo_Index_All_test test !TEST.Extent.XMin! PYTHON #
Start Time: Mon May 20 12:00:05 2013
ERROR 000539: Invalid field TEST.Extent.XMin
Failed to execute (Calculate Field).
Failed at Mon May 20 12:00:05 2013 (Elapsed Time: 0.00 seconds)

However,
Below are the results when with different expression (runs - but all NULL)
Geo_Index_All_test test DOUBLE # # # # NULLABLE NON_REQUIRED #
Start Time: Mon May 20 12:02:19 2013
Adding test to Geo_Index_All_test...
Succeeded at Mon May 20 12:02:20 2013 (Elapsed Time: 1.00 seconds)
Executing (Calculate Field): CalculateField Geo_Index_All_test test !TEST!.Extent.XMin PYTHON #
Start Time: Mon May 20 12:02:20 2013
Succeeded at Mon May 20 12:03:22 2013 (Elapsed Time: 1 minutes 2 seconds)


Test is not the name of a shape field and no field you have created can be used in the field calculator expression to do this type of calculation (Test could be the name of an output field only, but not part of the calculation expression).  The shape field is a built in field for a feature class or shapefile and would always contain the word Shape in the name, so your expression tests above are meaningless.

Copy and paste the exact expression below into the field calculator (don't change anything) and run it so that it outputs to your test field or whatever field you have set up as a double for the calculation output:

!SHAPE.Extent.XMin!
0 Kudos
D__SamuelRajasekhar
Deactivated User
Thanks once gain for your efforts and the information.

I did know the inner workings and now I am glad I know some.

Here are the results:

1st the model builder:
CalculateField Geo_Index_All_test test !Shape!.extent.XMin! PYTHON #
Start Time: Mon May 20 12:34:20 2013
ERROR 000539: Error running expression: GPVARIANTOBJECT0.extent.XMin
Traceback (most recent call last):
  File "<expression>", line 1, in <module>
AttributeError: 'str' object has no attribute 'XMin'

Failed to execute (Calculate Field).

But

When I used the same expression (!Shape!.extent.XMin!) in the field calculator of the table:

The results were produced.

[ATTACH=CONFIG]24512[/ATTACH]

Does the model builder need different syntax?
0 Kudos
D__SamuelRajasekhar
Deactivated User
Thanks a lot.

The syntax that works in model builder is as follows:

!SHAPE!.extent.ymin

Obviously the shape field needs to be capitalized and surprisingly the xmin field need not be.
0 Kudos
RichardFairhurst
MVP Honored Contributor
Thanks a lot.

The syntax that works in model builder is as follows:

!SHAPE!.extent.ymin

Obviously the shape field needs to be capitalized and surprisingly the xmin field need not be.


The expression above works in the Desktop environment and so does my expression (I tested both).  But apparently only one syntax is supported by the geoprocessing environment.  Whatever works is all that matters in the end.  But the syntax support should be consistent between Desktop and ModelBuilder.  ModelBuilder should add support for the alternate syntax and not drop the alternate from Desktop, since Desktop gets used so much more often than the ModelBuilder tool.

Differences like this definitely can and do exist between Desktop and ModelBuilder tools.  It is annoying, since it is confusing when something works in one and not the other.
0 Kudos
D__SamuelRajasekhar
Deactivated User
Thanks once again.

I wanted to create a simple Python script to do this.

That is why I used the model syntax. Worked well.


import arcpy
import os
from arcpy import env

# Set the current work Space - the input feature folder
arcpy.env.workspace = r'Y:\USGS_HiRes\Appended_Polygons_BK\Test_Join.gdb\Placemarks_Join'

# Select the input feature
inputFeature = r'Y:\USGS_HiRes\Appended_Polygons_BK\Test_Join.gdb\Placemarks_Join\Geo_Index_All_test'
inputFilename = os.path.basename(inputFeature)
print 'The input feature is ...'
print inputFilename

# Process: Add all 4 Fields
arcpy.AddField_management(inputFeature, "X_Min", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(inputFeature, "Y_Min", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(inputFeature, "X_Max", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(inputFeature, "Y_Max", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

print ''
addedFields = arcpy.ListFields(inputFeature)
for addedFields in addedFields:
    print ("Fields-Present:{0}".format(addedFields.name))

#Process: Calculate all 4 Fields
arcpy.CalculateField_management(inputFeature, "X_Min", "!SHAPE!.extent.XMin", "PYTHON_9.3", "")
    
arcpy.CalculateField_management(inputFeature, "Y_Min", "!SHAPE!.extent.YMin", "PYTHON_9.3", "")
  
arcpy.CalculateField_management(inputFeature, "X_Max", "!SHAPE!.extent.XMax", "PYTHON_9.3", "") 
 
arcpy.CalculateField_management(inputFeature, "Y_Max", "!SHAPE!.extent.YMax", "PYTHON_9.3", "") 
0 Kudos