Wednesday 18 December 2019

Re-ordering fields permanently using ArcGIS Make Query Table tool?


In the Answer to Reordering fields (permanently) in file geodatabase using ArcGIS Desktop? it was stated that the Make Query Table tool could be used to re-order fields in tables and feature classes permanently.


However, when I open the dialog for that tool I cannot see anywhere that enables re-ordering of fields. All I can see is that fields can be carried through or dropped using checkboxes but in the same order.


Assuming that it is possible can someone describe the steps in more detail, please?


Make Query Table tool dialog




Answer



I figured out how to do this by using the Make Query Table tool, Copy As Python Snippet, the Python window and the Copy Features tool.


After running the Make Query Table tool to pull through just the fields I wanted to appear in the output I was able to Copy As Python Snippet this code from the Geoprocessing | Results window into the Python window of ArcMap.


arcpy.MakeQueryTable_management("'C:/avhome/data/WAregional/wa regional.mdb/schools'","QueryTable","USE_KEY_FIELDS","#","schools.OBJECTID #;schools.Shape #;schools.CODE #;schools.NAME #;schools.TYPE #;schools.Y11STUDENT #;schools.Y12STUDENT #;schools.COORDGEOCO #;schools.ID #","#")

and edit it to become:


arcpy.MakeQueryTable_management("'C:/avhome/data/WAregional/wa regional.mdb/schools'","QueryTable2","USE_KEY_FIELDS","#","schools.OBJECTID #;schools.Shape #;schools.Y12STUDENT #;schools.Y11STUDENT #;schools.NAME #","#")

Note that the new QueryTable2 retains the Shape field (so I can CopyFeatures it) and I have reordered the NAME,YR11STUDENT & YR12STUDENT fields. I also used the opportunity to drop out a few more fields.


The last step is to use the Copy Features tool on QueryTable2 which I did via its tool dialog to create a new feature class with the fields re-ordered permanently.



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...