Select to view content in your preferred language

Field mapping syntax (python)

2804
10
04-22-2010 07:04 AM
ChrisMathers
Deactivated User
Ok so what is the syntax for field mapping? In tools that require fields to be mapped I have figured out what most of each field needs to be, but not all of it. In this example from a Spatial Join this is one field:

A1RENUM 'A1RENUM' true true false 15 Text 0 0 ,First,#,C:\\GIS Projects\\CRW\\TrakIt_Source_RS.gdb\\Target_Data\\parce_test_FeatureToPoint.shp,A1RENUM,-1,-1


The syntax is:
NewFieldName 'NewFieldAlias' ? ? ? NewFieldLength NewFieldType ? ?, MergeRule, MergeDelimeter, SourcePath, SourceFieldName, ? , ?

NewField is the field in the table created by the tool. MergeDelimeter is # if you arent using the Join merge rule. What I want to know is what True True False, 0 0 , and -1,-1 are doing.
0 Kudos
10 Replies
SimonWillis
Emerging Contributor
A little late but here I found some good info:

http://forums.esri.com/Thread.asp?c=93&f=1729&t=207100#678774
0 Kudos
ChrisMathers
Deactivated User
HA! Thanks. Its funny that someone else asked the exact same thing I did.
0 Kudos
SimonWillis
Emerging Contributor
Did you ever get it to work? I have also been using the fieldmapping/fieldmap object and I keep bombing in pywin... I even took a couple of steps back to make the fieldmapping example work in arctoolbox - Merge (Data Management).
It's similar to arcgis10 arcpy fieldmapping example:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/FieldMappings/000v0000008q000000/
I still can't get it to work!
0 Kudos
ChrisMathers
Deactivated User
I ended up using the tool in catalog to set it all up. I just went back and did a find-replace to change the file paths. Much quicker than typing all of it. I have a spatial join in one script that is 20685 characters long, most all of it is field mapping. I wrote papers shorter than that in college.
0 Kudos
SimonWillis
Emerging Contributor
I finally got the fieldmapping object to work and it works great to append a shp to SDE in pythonwin2.5 but attached as a script in arctoolbox it bombs out and complains about:

PYTHON ERRORS:
Traceback info:
  File "C:\temp\SplitProcessImport063010.py", line 266, in ?
    import2SDE(UpdWorkspace, outputUpdFC)

Error Info:
(-2147467259, 'Unspecified error', None, None)
Geoprocessing ERRORS:
Failed to execute. Parameters are not valid.
Inputs must be either all FeatureClasses, Tables or Rasters; not mixed
Failed to execute (Append).

So I think it may like:
...
        # Process: Append the value table (from shp) into the SDE feature class
        gp.Append_management(vt, outfc, "NO_TEST", fieldmappings)
...
in pythonwin but hate this statement in the arctoolbox script??? I know I am importing point features only - so not mixing different different datasets!
Any ideas?
0 Kudos
SimonWillis
Emerging Contributor
So it looks like this may be a bug that has existed since 2007 *gasp*
http://forums.esri.com/Thread.asp?c=93&f=1729&t=223204
ESRI / dear Jack, if you read this, are we moving on this or not? It seems the problem still exists in 931 ... do I dare ask about 10?

Well, at least Holland in the world cup final...
Hup Holland Hup!
0 Kudos
SimonWillis
Emerging Contributor
Update:
I have been corresponding with ESRI support. They said:
"...I also suspect the 9.2 script tool is not liking the value table for some yet unknown reason.  I couldn't find any bugs reported for this, so at least there is hope for us..."

gp.Append_management(vt, outfc, "NO_TEST", fieldmappings)

this worked in pythonwin using a valid argument but as a script in arctoolbox92 I got this error:
"Inputs must be either all FeatureClasses, Tables or Rasters; not mixed
Failed to execute (Append)."
Based on this error I found a solution (for 92 and python24). I removed any reference to value tables, while keeping fieldmappings and fieldmap and I just used my input featureclass for the Append so:

gp.Append_management(fc, outfc, "NO_TEST", fieldmappings) # this works
gp.Append_management(vt, outfc, "NO_TEST", fieldmappings) # see error above

I hope it helps others!
0 Kudos
KimOllivier
Honored Contributor
I ended up using the tool in catalog to set it all up. I just went back and did a find-replace to change the file paths. Much quicker than typing all of it. I have a spatial join in one script that is 20685 characters long, most all of it is field mapping. I wrote papers shorter than that in college.


That is how I create field maps too, but you can set the workspace to shorten the paths to fit the fieldmap string into one line.
0 Kudos
SimonWillis
Emerging Contributor
Another update. This comes from ESRI again

Another one of our analysts here previously had a similar issue and logged the following software bug:

[NIM002716; Some geoprocessing tools that take in a value table argument are not honoring gp.workspace command when run as script tools in ArcToolbox]

There is a possible workaround listed that I would like to you to please try at your convenience.  For the Append tool value table input, please try specifying the full paths to the data when adding rows to the value table.  According to the bug, this may allow it to work when added as a script tool.


This workaround worked for me!
So first I had:
vt.AddRow(fc)
and I changed it to:
bugfixfc = SHPworkspace + "\\" + fc
vt.AddRow(bugfixfc)

# back to using vt and append works!
gp.Append_management(vt, outfc, "NO_TEST", fieldmappings)
0 Kudos