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?

  • 2
    what software are you using? – DPSSpatial Jul 9 '15 at 18:27
  • Could you give some more examples. I think with QGIS field calculator expression engine and some Python magic- this should be easy to implement. – PKG Jul 9 '15 at 19:22
  • Please include the GIS software and version that you are using by using the edit button beneath your question. – PolyGeo Jul 9 '15 at 19:52
  • Are you obtaining data directly from shapefiles or another data source such as CSV? – Simbamangu Jul 10 '15 at 5:08

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)


| improve this answer | |

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