Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

What I need to do is change data type of a field of a table or feature class. If there are some data, then I need to transfer it, if its possible, if not possible then just set null for that data. I need to do it using python script.

Problems:

  1. Because of before and after changing the data type, field name is same, I can not add new field with same name using arcpy.AddField_management method.
  2. Because of I need to transfer field values from first field to second one, I need to map both data types.

It will be good for me if I can find any arcpy procedure similar to artwork21's answer.

Thanks.

share|improve this question
    
You might want to vote for this ArcGIS Idea (as if it hasn't gotten enough votes already). –  blah238 Feb 22 '13 at 3:44
    
Does your data happen to be stored in Oracle? –  blah238 Feb 22 '13 at 3:46
    
@blah238: My data is stored in a table/feature class. And the idea is for reordering the fields not changing the data type. –  Emi Feb 22 '13 at 3:55
    
You misunderstood me. What is your underlying DBMS: Oracle, SQL Server, PostgreSQL, file geodatabase, personal geodatabase, shapefile, etc.? –  blah238 Feb 22 '13 at 3:57
2  
I did not downvote it, but the question does not show much research effort (reads like a "do my homework for me" type question, sorry to say), and could use some minor grammar cleanup. –  blah238 Feb 22 '13 at 4:08

2 Answers 2

up vote 6 down vote accepted

There are essentially three options for making field schema changes in ArcGIS.

  1. Dropping the whole feature class/table and replacing it completely
  2. Dropping the field/column and replacing it -- this always puts the new column at the end, so not good if field order is important to you.
  3. Modifying column definitions in the underlying DBMS (dangerous, may cause corruption). This last one I wouldn't even go near unless you are in Oracle, and even then you have to be very careful (see this post).

It sounds like you want to go with option 2. The simplest way I can think of to do that is to add an intermediate/temporary column and calculate it from your original column. Then delete the original column, add a new column with the desired field type, calculate the new column from the intermediate column and finally delete the intermediate column.

share|improve this answer
    
May be I will go with your 2nd idea. I need to read about it some more. thanks for the idea –  Emi Feb 22 '13 at 4:03

You could do a simple "Feature Class to Feature Class" conversion. During this you can change field names and types, after that delete the original FC.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.