1

I am editing attribute tables of multiple shapefiles for a future project. I need the field data types to be very specific and uniform among all the shapefiles. I am running into the problem that the majority of these shapefiles's attribute tables are all different in terms of field name and field data type.

I have been adding a new field, then using field calculator to copy the data from the old field column into the new one. However, one field (StationID) has been giving me trouble because copying station id with letters and numbers (example 113a) will not copy into a float in the new added field. And that is fine, I can manually fix that and include the information in a separate Notes column, but not when there over 1,000 entries in which this occurs.

Is there any command, or tool or function, that could "easily" change the field data type from string/text to float?

Chris W
  • 15,720
  • 2
  • 29
  • 47
Katie
  • 19
  • 1

1 Answers1

3

For ArcGIS:

I'm not aware of any method to change a field definition or length in place. I would probably look at bringing the shapefiles into a , and then edit the field definitions with MS Access. Be careful though, hacking with Access is completely unsupported by Esri (but still very effective when used correctly).

For the StationID problem, you will never be able to cast an alphanumeric string like 113a into a float, because the a makes the value illegal (in any database and for any software).

You could dive into a pre-processing python expression using string.translate() and strip the letters, leaving you with 113. The related How to remove comma from combined fields which should be null? will help construct the expression.

>>> import string
>>> s = '1123h34523j'
>>> s.translate(None, string.letters)
'112334523'

Sources:

matt wilkie
  • 28,176
  • 35
  • 147
  • 280