Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

FieldInfo fails when using SpatialJoin

$
0
0
I am trying to do a point-in-polygon overlay using SpatialJoin and at the same time suppress most of the fields and rename the ones I want to keep.

Theoretically all possible with a layer and a fieldInfo object.
However if I attempt to rename the field in the fieldInfo object, then Spatial Join gets confused.

The field is added, but the contents are empty.
If I change back to leave the alias the same as the field name it works correctly.

Is there a way around this? Do I have to write out an intermediate featureclass first?
Code:


import arcpy
from datetime import datetime
import sys
try:
    ws = sys.argv[1]
except:
    ws = "path/mydb.gdb"
arcpy.env.workspace = ws
arcpy.env.overwriteOutput = True
# make a view to suppress unwanted fields
hidemap = []
lstFields = arcpy.ListFields("locality")
dKeep = {'SUBURB_ID':'SUBURB_ID','SUBURB_4TH':'SUBURB','MAJOR_NAME':'CITY'}
# Create a fieldinfo object
fieldinfo = arcpy.FieldInfo()
# Iterate through the fields and set them to fieldinfo
for field in lstFields:
    if field.name in dKeep.keys() :
        fieldinfo.addField(field.name, dKeep[field.name], "VISIBLE", "")
    else:
        fieldinfo.addField(field.name, field.name, "HIDDEN", "")
arcpy.management.MakeFeatureLayer("locality","locality_lay",field_info=fieldinfo)
arcpy.SpatialJoin_analysis("refAdd2",
                          "locality_lay",
                          "refAdd3",
                          "JOIN_ONE_TO_ONE",
                          "KEEP_ALL")
print "big fail"

Version 10.1 SP1

Viewing all articles
Browse latest Browse all 2485

Latest Images

Trending Articles



Latest Images