grid_code now gridcode!?!

4657
9
Jump to solution
10-28-2014 02:25 PM
ChrisSnyder
Regular Contributor III

Seems now in v10.2 the 'grid_code' field (field automatically generated when converting raster layers to vector layers) is now named 'gridcode' (no underscore).

...not that this ^%$#s up all my scripts or anything... Oh wait, it does!

0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

Yes, I know it's a pain but before the change shapefile output for these tools used the field name "gridcode" and gdb feature class output used "grid_code". In the long run I'm glad they changed it so these tools always generate a field with a consistent name, regardless of output feature class format.

View solution in original post

0 Kudos
9 Replies
curtvprice
MVP Esteemed Contributor

Yes, I know it's a pain but before the change shapefile output for these tools used the field name "gridcode" and gdb feature class output used "grid_code". In the long run I'm glad they changed it so these tools always generate a field with a consistent name, regardless of output feature class format.

0 Kudos
DuncanHornby
MVP Notable Contributor

I'm sure I have read in the T&C of the software that it states that subtle changes are made to any tool so as to make unnecessary work for you... It's the standard contractual agreement we all willingly entered into.

0 Kudos
ChrisSnyder
Regular Contributor III

Good point Curtis - I wasn't aware of that.

As I recall, long ago it also used to be 'GRID_CODE' in caps... Maybe that flavor was for coverages.

0 Kudos
ChrisSnyder
Regular Contributor III

OK - Thought I was imagining stuff for a while but:

In v10.2.2, the StreamToFeature tool still pumps out 'grid_code' field (or 'GRID_CODE' if using a shapefile. Thus. now with the advent of the 'gridcode' flavor in v10.2,  the problem is actually worse now in that there are now three different flavors: 'gridcode', 'grid_code', and 'GRID_CODE' .... Right after I did a blanker find='grid_code' and replace='gridcode'.

*&(^(^^%!!!!!   I can't win...

Note the StreamToFeature tool in v10.2 returns a schema of:

For shapefile format: 'ARCID', 'GRID_CODE', 'FROM_NODE', 'TO_NODE'

For FGDB format: 'arcid', 'grid_code', 'from_node', 'to_node'

0 Kudos
curtvprice
MVP Esteemed Contributor

Thank goodness field names are case insensitive everywhere but INFO (unless you set $CASE-FLAG haha)

0 Kudos
ChrisSnyder
Regular Contributor III

Yet in Python:

>>> 'grid_code' == 'gridcode' == 'GRID_CODE'

False

0 Kudos
curtvprice
MVP Esteemed Contributor

So much pain in the world....

def GetGridCode(tbl):

    """Get grid code from table"""

    gc = arcpy.ListFields(tbl, "GRID_CODE")

    if not gc:

        gc = arcpy.ListFields(tbl, "GRIDCODE")

    else:

        raise Exception("No GRIDCODE field in " + tbl)

    return gc.upper()

0 Kudos
ChrisSnyder
Regular Contributor III

Curtis, I agree with you. And I feel your pain...but we will march on!

Hopefully someone on the ESRI Dev team notices this one... Too late for 10.3 though.

0 Kudos
ChrisSnyder
Regular Contributor III

Okay - someone's probably made one of these already, but I'll stick it here incase I need it again.
Untitled.jpg

0 Kudos