Select to view content in your preferred language

Field calc not working on old Miles Hitchen Code Create Sorted Ids

828
2
07-29-2010 03:25 PM
TomMagdaleno
Frequent Contributor
I am working on labeling parcels with an ID number.  I am trying to create sorted Ids based on their location.  I have this old code from an old thread by Miles Hitchen.  It worked great, but now the field calculator in step 2 will give me an error in ArcGIS 10.  Is there a way to fix this, or a better way to do this process in Modelbuilder or Python?

Thanks,
Tom

Process below...


1. Create two fields in you layer, "MaxY" as Double and "Id" as Long (this one may already exist).

2. Use the field calculator with the following advanced expression to populate the "MaxY" field:

Dim dMaxY As Double
Dim pGeom As IGeometry
Set pGeom = [Shape]
dMaxY = pGeom.Envelope.YMax
' Now use dMaxY as the expression for the field

3. Copy the code below into a new module of the VBA Editor, close the editor and run the macro "CreateSortedIDs"

This will give you unique ID's starting at 0 for the northern most feature, incrementing for subsequent southerly features.
0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus
see examples at
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Calculate_Field_examples/005s0000002m0...
look for the section
Parser:
Python

Expression:
!shape.extent.XMax!

and there are other properties for the shape field that can be accessed
0 Kudos
TomMagdaleno
Frequent Contributor
Thanks for the reply Dan. I realize it would be easy if I knew the syntax, but I do not. I have a field named MaxY that is a double. Can you tell me how I would enter the code to calculate this field in the field calculator window? If I just enter !shape.extent.YMax! into the code window I get an error. Do I need to put something in pre-logic?  Like def Reclass(MaxY):
!shape.extent.YMax!

Thanks
0 Kudos