Wednesday, July 8, 2009

Changing Field types in File Geodatabases

Ever tried changing the data type of a field in a feature class or table in a File Geodatabase? If you haven't, then believe me, it is not as easy as you would think. The only way of doing it is to actually create a new field and copy the values across.

As an example, let's say we want to change Field1 from an integer to a double field

  1. Close ArcCatalog (it will almost definitely have a lock on the database that you can't get rid of any other way)
  2. Rename Field1 to Field2
  3. Create a new field called Field1 (type=double)
  4. Copy any values across using the field calculator
  5. Delete Field2

From this point on, you have to put up with Field1 being the last field in the table, which can be pretty annoying if you have spent the time setting up your feature classes in a logical order, with similar attributes situated near one another.

What is the alternative I hear you ask?

  1. Export your table/feature class to a Personal Geodatabase
  2. Open the database in Microsoft Access
  3. Open the table in Design View
  4. Alter the field format
  5. Copy your table/feature class back to the file Geodatabase

You can also use this same method for renaming fields.

Warning! Be very cautious when doing this. Things can go wrong if you are not careful. Do not change any of the special fields (ObjectID, Shape etc.) as your table will become corrupt. You should always create a backup copy of your data before playing around with the schema of any databases.

No comments: