# Create Feature Layer from BLPU point gp.makeFeatureLayer_management(inputPoint, "point_lyr", "", "","UPRN UPRN VISIBLE; ADDRESS ADDRESS VISIBLE") print "1 - ", inputPoint, "is now a feature layer" # Export Joined Point layer gp.copyFeatures_management("point_lyr", "READY_FOR_SDE_test") print "14 - ", "Joined points has been exported to", datadump
fieldInfo = "" fieldList = gp.listfields(layerPath) for field in fieldList: if field.name == "PARCEL_SYST_ID": fieldInfo = fieldInfo + field.Name + " " + "PARCEL_ID" + " VISIBLE;" elif field.name == "SURFACE_TRUST_CD": fieldInfo = fieldInfo + field.Name + " " + "SUR_OWN_CD" + " VISIBLE;" elif field.name == "SURFACE_TRUST_NM": fieldInfo = fieldInfo + field.Name + " " + "SUR_OWN_NM" + " VISIBLE;" elif field.name == "TIMBER_TRUST_CD": fieldInfo = fieldInfo + field.Name + " " + "TIM_OWN_CD" + " VISIBLE;" elif field.name == "TIMBER_TRUST_NM": fieldInfo = fieldInfo + field.Name + " " + "TIM_OWN_NM" + " VISIBLE;" else: fieldInfo = fieldInfo + field.Name + " " + field.Name + " HIDDEN;" gp.MakeFeatureLayer_management(layerPath, "feature_layer", "", "", fieldInfo[:-1]); showGpMessage() gp.MultipartToSinglepart_management("feature_layer", fgdbPath + "\\" + layerName); showGpMessage()
keepFieldList = ("FIELD1","FIELD2") fieldInfo = "" fieldList = gp.listfields(layerPath) for field in fieldList: if field.name in keepFieldList: fieldInfo = fieldInfo + field.Name + " " + field.name + " VISIBLE;" else: fieldInfo = fieldInfo + field.Name + " " + field.Name + " HIDDEN;" gp.MakeFeatureLayer_management(layerPath, "feature_layer", "", "", fieldInfo[:-1]); showGpMessage()
>>> fc = r"C:\csny490\test.gdb\haul_routes_lt_flat_l_1_3" >>> arcpy.MakeFeatureLayer_management(fc,"fl") >>> dsc = arcpy.Describe("fl") >>> dsc.FieldInfo.exportToString () u'OBJECTID OBJECTID VISIBLE NONE;Shape Shape VISIBLE NONE;FacilityID FacilityID VISIBLE NONE;ALTERNATIVE ALTERNATIVE VISIBLE NONE;DECADE DECADE VISIBLE NONE;SPATIAL_ID SPATIAL_ID VISIBLE NONE;MBF MBF VISIBLE NONE;Shape_Length Shape_Length VISIBLE NONE' >>> dsc.FieldInfo.setFieldName(3, "ALT") #This should rename ALTERANTIVE to ALT >>> dsc.FieldInfo.setVisible(4, "HIDDEN") #This should make DECADE to HIDDEN >>> dsc.FieldInfo.exportToString () u'OBJECTID OBJECTID VISIBLE NONE;Shape Shape VISIBLE NONE;FacilityID FacilityID VISIBLE NONE;ALTERNATIVE ALTERNATIVE VISIBLE NONE;DECADE DECADE VISIBLE NONE;SPATIAL_ID SPATIAL_ID VISIBLE NONE;MBF MBF VISIBLE NONE;Shape_Length Shape_Length VISIBLE NONE' >>> arcpy.CopyFeatures_management("fl",r"C:\csny490\test.gdb\test333") <Result 'C:\\csny490\\test.gdb\\test333'>
I also couldn't get the fieldInfo() methods to work
This is what I used to get this working from the examples above. After modifying the fieldInfo for the previously created memorynet feature layer, I created another feature layer from that and then used the "in_memory//" to create yet another layer which had the correctly modified fields.
keepFieldList = ("Field1","Field2", "Field3", "Field4", "Field5")
fieldInfo = ""
fieldList = gp.listfields(memorynet)
for field in fieldList:
if field.name in keepFieldList:
print field.name
fieldInfo = fieldInfo + field.Name + " " + field.name + " VISIBLE;"
else:
fieldInfo = fieldInfo + field.Name + " " + field.Name + " HIDDEN;"
print fieldInfo
gp.MakeFeatureLayer_management(memorynet, "feature_layer", "", "", fieldInfo[:-1])
memfldNet = "in_memory//memfldNet"
arcpy.CopyFeatures_management("feature_layer", memfldNet)