I have some trauma related to regular expressions from my university days. Yes, they are super useful. Do I enjoy using them? Does anyone?
I routinely modify and create new instances of the AMIS GIS data model. Depending on the client and the type of assets they have, there can be 4 feature datasets, containing about 5 feature classes each, or 9 feature datasets with up to 50 feature classes spread across the database.
Inevitably at some point in the process of losing my mind, I will forget that the alias is lost when creating a new feature class, or randomly copying it over or whatever. I then end up with dozens of feature classes with really ugly looking abbreviated layer names in CamelCase. So for posterity, and so that I will never ever forget this ridiculously easy thing again:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# @date 05/10/2017 | |
# @author Cindy Jayakumar | |
# | |
# Change the alias of feature classes to the | |
# title case version of the CamelCase name | |
# | |
# e.g. WaterPumpStation => Water Pump Station | |
import arcpy | |
import re | |
gdb = r"C:\Some\Arb\Folder\test.gdb" | |
def alterFCAlias(name): | |
return re.sub(r"\B([A-Z])", r" \1", name) | |
for root, _, fcs in arcpy.da.Walk(gdb): | |
for fc in fcs: | |
alias = alterFCAlias(fc) | |
arcpy.AlterAliasName(fc, alias ) | |
print("{0} => {1}".format(fc, alias)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @credit https://stackoverflow.com/a/199215 | |
import re | |
text = "ThisIsATest" | |
re.sub(r"\B([A-Z])", r" \1", text) |
One thing I’ve omitted from the script is that I usually store the feature class names with a prefix, e.g. fc_name = wps_WaterPumpStation
. In this case, I would use split on the feature class name before passing it to the alterFCAlias
function i.e. fc_name.split("_")[1]
.
Link for mobile users is here.
Aaaaaaand I’ve just realised that I’ve forgotten this basic task so many times over the last few years that I actually already have a blog post about it, except for some reason I was updating the layer names in ArcMap every time instead of resetting it once on the feature classes themselves.