Sunday 11 June 2017

spatial etl - Permanently reorder fields in data (shp, gdb)


If I have a shapefile or geodatabase featureclass that has fields that I want to permanently reorder, is there a tool, script, or utility that will help me quickly accomplish this task?


Generally I know you have to create a new field, then populate it with the old values, then delete the old field. I am hoping there is something already created out there that will help with this. Assuming you don't have FME or another ETL tool available, what is the next best suggestion?


This is NOT a view level change (ie- drag/drop the fields in order), but rather write out to a new shapefile or featureclass. Thanks.



Answer



I'm pretty sure you can do this with Feature Class to Feature Class by re-ordering fields in the field map section of the tool.



Edit: FC2FC doesn't do this but...ogr to the rescue.


I just confirmed that ogr2ogr can do this. Specify your field name order on the -select switch. For instance, if I have a shapefile with two fields, "Name" and "FolderPath" (in that order), but I want a new shapefile with "FolderPath" first I would do this:


C:\Temp>ogr2ogr -f "ESRI Shapefile" re_order_ogr.shp re_order1.shp -select "FolderPath,Name"

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...