Thursday, 11 July 2019

qgis - Capitalizing The First Letter Of Each Word In Attribute Field



Does anyone know of a way to capitalize the first letter of each word in a field in an attribute table? I am doing this in QGIS. I know of field calculations to change all the words to Lower or Upper, but I would like to be able to have the first letter Capitalized of each word, and the remaining letters lower cased. I know how to do this manually, but I am looking for an automated way. Similar to the Proper command in Excel.


Thanks...



Answer



Using the python field calculator:


http://hub.qgis.org/wiki/17/Using_Python_to_calculate_attribute_values_with_'fieldpyculator'


You should be able to us the .title() method on your strings:


https://stackoverflow.com/questions/3728655/python-titlecase-a-string-with-exceptions


Edit:


Assuming the attribute field you want to change is "FIELD", the sintax to use is:


value = .title()

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