I am attempting to use Spatial Join to combine tax parcels and zoning information, such that the parcels contain the designation of the underlying zone. However, I only want to take the "esmZONE" attribute from the zoning feature class, without any of the other information. The following script will copy the info from "esmZONE" into "TEST" in the joined feature class, but it also transfers the rest of the attributes from the zoning FC. Can anyone provide some direction as to how I'd remedy this?
import arcpy import os base_gdb = r"\\Esm8\gis\python_practice\bellevueBaseData.gdb" arcpy.env.workspace = base_gdb target = os.path.join(base_gdb, "inputData", "bellevueParcelsBase") join = os.path.join(base_gdb, "inputData", "bellevueZoning") outfc = os.path.join(base_gdb, "outputData", "bellevueTest1") ##good_fields = ["esmZONE"] ## ##field_names = [f.name for f in arcpy.Describe(zoning).Fields if not ## (f.type in ["OID","Geometry"] or ## f.name in ["Shape_Length","Shape_Area"] or ## f.name in good_fields)] ## ##if field_names: ## arcpy.DeleteField_management(zoning, field_names) #Create FieldMap and FieldMappings objects fieldmappings = arcpy.FieldMappings() fieldmappings.addTable(join) fieldmappings.addTable(target) zonefield = fieldmappings.findFieldMapIndex("esmZONE") fieldmap = fieldmappings.getFieldMap(zonefield) parcel_field = fieldmap.outputField parcel_field.name = "TEST" parcel_field.aliasName = "TEST" fieldmap.outputField = parcel_field fieldmappings.mergeRule = "Join" fieldmappings.replaceFieldMap(zonefield, fieldmap) arcpy.SpatialJoin_analysis(target, join, outfc, "", "KEEP_COMMON", fieldmappings, "WITHIN")