input1 = r'G:\Data\Geodatabase\Cedar_County.mdb\ADDRESS\Addresses' input2 = r'G:\Data\Geodatabase\Cedar_County.mdb\CADASTRAL\PARCEL' try: lista = [f.name for f in arcpy.ListFields(input1)] listb = [fb.name for fb in arcpy.ListFields(input2)] # print lista print listb for fielda in lista: for fieldb in listb: if fielda == fieldb: fieldb = fieldb + '_1' print fieldb else: pass
[u'OBJECTID', u'Shape', u'PID', u'HOUSENUM', u'ADDRESS', u'CITY', u'GID', u'UNIT', u'Verify_add', u'Add', u'Type', u'Need_GPS', u'Business', u'Prefix', u'Street', u'Suffix', u'FULL_ADD', u'Full_Str', u'POINT_X', u'POINT_Y', u'BLUE_TAG', u'NOTES', u'ESN', u'ZIP', u'SOL_PID'] [u'OBJECTID', u'PID', u'GIS_ACRES', u'SOL_PID', u'SHAPE', u'SHAPE_Length', u'SHAPE_Area'] OBJECTID_1 PID_1 SOL_PID_1
# Get User Input Parameters Input_Table_Data = str(sys.argv[1]) Input_Table_Join_Field = str(sys.argv[2]) Input_GIS = str(sys.argv[3]) GIS_Join_Field = str(sys.argv[4]) Output_Location = str(sys.argv[5]) Output_Data_Name = str(sys.argv[6]) Keep_Type = str(sys.argv[7]) Keep_Matching = str(sys.argv[8])
def dup_field_name_list(fc_path, table_path): # For every field in the Input_GIS_Dataset, loop through the Input_Table and write out the matching table fields to a list GIS_fieldlist = arcpy.ListFields(fc_path) Table_fieldlist = arcpy.ListFields(table_path) Plist = list() for field in GIS_fieldlist: GIS_field_name = str(field.name) GIS_field_name_upper = GIS_field_name.upper() for field in Table_fieldlist: Table_field_name = str(field.name) Table_field_name_upper = Table_field_name.upper() if Table_field_name_upper == GIS_field_name_upper: Plist.append(Table_field_name) return Plist
def rename_field(fc_path, dup_item): field = dup_item field_name_tab = field + "_tab" field_name_tab_len = len(field_name_tab) if field_name_tab_len > 10: field_name_tab = field_name_tab[:6] field_name_tab = field_name_tab + "_tab" fieldlist = arcpy.ListFields(fc_path) for field in fieldlist: field_name = str(field.name) field_type = str(field.type) field_length = str(field.length) if (field_name == dup_item): # Case handling; Returned type of "String" uses the type of "text" and also uses length as an AddField parameter. if (field_type == "String"): field_type = "TEXT" messages("Adding field: " + field_name_tab + ". The field type is: " + field_type + " and The length is: " + field_length) arcpy.AddField_management(fc_path, field_name_tab, field_type, "", "", field_length, "", "NULLABLE", "NON_REQUIRED", "") arcpy.CalculateField_management(fc_path, field_name_tab, "[" + field_name + "]") if not field_name_tab.endswith("_tab"): messages("Deleting: " + field_name) arcpy.DeleteField_management(fc_path, field_name) else: # Case handling; Returned type of "Integer" converted to a type of "long" for use as AddField parameter. if (field_type == "Integer"): field_type = "LONG" messages("Adding field: " + field_name_tab + ". The field type is: " + field_type + " and The length is: " + field_length) arcpy.AddField_management(fc_path, field_name_tab, field_type, "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.CalculateField_management(fc_path, field_name_tab, "[" + field_name + "]") if not field_name_tab.endswith("_tab"): messages("Deleting: " + field_name) arcpy.DeleteField_management(fc_path, field_name) # Case handling; Returned type of "SmallInteger" converted to a type of "short" for use as AddField parameter. elif (field_type == "SmallInteger"): field_type = "SHORT" messages("Adding field: " + field_name_tab + ". The field type is: " + field_type + " and The length is: " + field_length) arcpy.AddField_management(fc_path, field_name_tab, field_type, "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.CalculateField_management(fc_path, field_name_tab, "[" + field_name + "]") if not field_name_tab.endswith("_tab"): messages("Deleting: " + field_name) arcpy.DeleteField_management(fc_path, field_name) # Case handling; Returned type of "Single" converted to a type of "Float" for use as AddField parameter. elif (field_type == "Single"): field_type = "FLOAT" messages("Adding field: " + field_name_tab + ". The field type is: " + field_type + " and The length is: " + field_length) arcpy.AddField_management(fc_path, field_name_tab, field_type, "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.CalculateField_management(fc_path, field_name_tab, "[" + field_name + "]") if not field_name_tab.endswith("_tab"): messages("Deleting: " + field_name) arcpy.DeleteField_management(fc_path, field_name) # Case handling; Returned type other than "String", "Integer", "SmallInteger", or "Single" handled normally. else: messages("Adding field: " + field_name_tab + ". The field type is: " + field_type + " and The length is: " + field_length) arcpy.AddField_management(fc_path, field_name_tab, field_type, "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.CalculateField_management(fc_path, field_name_tab, "[" + field_name + "]") if not field_name_tab.endswith("_tab"): messages("Deleting: " + field_name) arcpy.DeleteField_management(fc_path, field_name) # Reset variables field_type = "" field_length = "" field_name = "" field_name_tab = "" dup_item = ""
#################################################################################################### #Call Rename Field function if the user wants to preserve matching fields in the output GIS dataset# #################################################################################################### if Keep_Matching == "YES": # Call function that detects duplicate field names between Input_GIS_Dataset and Input_Table, output a list of duplicates duplicate_item_list = dup_field_name_list(Input_GIS_Dataset, Input_Table) # Loop through list of duplicates to preserve duplicate items in the output dataset for item in duplicate_item_list: messages("Duplicate field name detected: " + item) messages("Retaining Original Input Fields...") rename_field(Input_Table, item) # Call rename field function
for fielda in arcpy.GetParameterAsText(0).split(';'): # Assuming you have the multi-value parameter??? for fieldb in arcpy.GetParameterAsText(1).split(';'): if fielda == fieldb: fieldb = fieldb +'_1' else: pass
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.