-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrename.py
More file actions
29 lines (23 loc) · 853 Bytes
/
rename.py
File metadata and controls
29 lines (23 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#To rename all Admin1 names contain foreign characters to ENG
#Created by Christopher Gabris
#04/05/2016
import unicodedata
import arcpy
import os
def strip_accents(s):
return ''.join(c for c in unicodedata.normalize('NFD', s)
if unicodedata.category(c) != 'Mn')
arcpy.env.workspace = r"P:\Data\global_admin_boundaries\gadm27_levels_1.gdb"
workspace = arcpy.env.workspace
in_fc = os.path.join(workspace,"Admin1")
fields = ["NAME_1","NAME_1_ENG"]
with arcpy.da.UpdateCursor(in_fc,fields) as upd_cursor:
for row in upd_cursor:
row[1] = strip_accents(u"{0}".format(row[0]))
upd_cursor.updateRow(row)
print 'done'
#afterwards, in Field Calculator manually replace the following:"
# ` , ' , -
#ex: Replace( [NAME_1_ENG], "-", " " )
#ex: Replace( [NAME_1_ENG], "`", "" )
#ex: Replace( [NAME_1_ENG], "'", "" )