Select to view content in your preferred language

Failed on input OID

2279
2
Jump to solution
04-01-2014 08:06 AM
TonyAlmeida
MVP Regular Contributor
I have a layer in my TOC that has a joined table. When i run the following code it get Failed on input OID.  I believe it is because the layer "vector.DBO.Taxparcels" has a table joined but i am not sur.? According to the Arcgis help on ERROR 001156 it's because text values cannot be added to numeric fields, and text values cannot be added to text fields if the values are longer than the field length.The Solution Change the field type or increase the field length in the field map properties. I a not sure why I am getting an error on arcpy.MakeFeatureLayer_management(PL_Lyr, PL_Lyr2)?

Code:
####Select by location on parcels with created point Parcellyr = "vector.DBO.Taxparcels"  arcpy.MakeFeatureLayer_management(Parcellyr, "Parcel layer") entries = int(arcpy.GetCount_management(fc).getOutput(0))  for i in xrange(entries):     Sel_Point = arcpy.MakeFeatureLayer_management(fc, "point layer", "\"FID\"={}".format(str(i))) #FID     arcpy.SelectLayerByLocation_management("Parcel layer", "INTERSECT", Sel_Point, "", "NEW_SELECTION")  #### populates fields  add_fields = ["ACCOUNT","SiteNum","OwnerName","SiteAddres","SiteNumSfx","SiteStreet","predir","StreetType","SubName"]  # fix args if not isinstance(add_fields, list):     # from script tool     add_fields = add_fields.split(';')  # do not need this scratch file fcOutput = "temp_join" arcpy.SpatialJoin_analysis("Parcel layer", fc, fcOutput, 'JOIN_ONE_TO_MANY')   # grab oid field from points oid_t = arcpy.Describe(fc).OIDFieldName  # init rowW and rowR curR = arcpy.SearchCursor(fcOutput) join_dict = dict([(r.JOIN_FID,[r.getValue(f) for f in add_fields]) for r in curR]) del curR  # Now update the new target curW = arcpy.UpdateCursor(fc) for row in curW:     t_oid = row.getValue(oid_t)     if t_oid in join_dict:         for f in add_fields:             row.setValue(f, join_dict[t_oid][add_fields.index(f)])     curW.updateRow(row) del row, curW  arcpy.Delete_management("Parcel layer")



Error:
Traceback (most recent call last):   File "C:\GIS\Python Scripts\AddressPoints\Select by Location based on selected features_3a.py", line 61, in <module>     arcpy.SpatialJoin_analysis("Parcel layer", fc, fcOutput, 'JOIN_ONE_TO_MANY')   File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\analysis.py", line 480, in SpatialJoin     raise e ExecuteError: ERROR 001156: Failed on input OID 387502, could not write value 'LN      ' to output field StreetType_1 Failed to execute (SpatialJoin).



I have the following code with field mapping but i am getting an error.

Code:
####Select by location on parcels with created point Parcellyr = "vector.DBO.Taxparcels"  ParLyr = arcpy.MakeFeatureLayer_management(Parcellyr, "Parcel layer") entries = int(arcpy.GetCount_management(fc).getOutput(0))  for i in xrange(entries):     Sel_Point = arcpy.MakeFeatureLayer_management(fc, "point layer", "\"FID\"={}".format(str(i) + ""))     PL_Lyr = arcpy.SelectLayerByLocation_management(ParLyr, "INTERSECT", Sel_Point, "", "NEW_SELECTION")     #if arcpy.Exists(pt_lyr): arcpy.Delete_management(pt_lyr)  Sel_PT = "Sel_PTT" arcpy.MakeFeatureLayer_management(Sel_Point, Sel_PT) PL_Lyr2 = "PL_Layer" arcpy.MakeFeatureLayer_management(PL_Lyr, PL_Lyr2)  fcOutput = r"C:\Temp\default.gdb\temp_join"   #Field Mapping def Layers(PL_Lyr2, Sel_PT):     FieldMapString = "" \                 + """ACCOUNT "ACCOUNT" true true false 11 Text 0 0 ,First,#,""" + PL_Lyr2 + """,ACCOUNT,-1,-1;"""\                 + """SiteNum "SiteNum" true true false 10 Double 0 0 ,First,#,""" + PL_Lyr2 + """,SiteNum,-1,-1;"""\                 + """OwnerName "OwnerName" true true false 100 Text 0 0 ,First,#,""" + PL_Lyr2 + """,OwnerName,-1,-1;"""\                 + """SiteAddress "SiteAddress" true true false 106 Text 0 0 ,First,#,""" + PL_Lyr2 + """,SiteAddress,-1,-1;"""\                 + """SiteNumSfx "SiteNumSfx" true true false 6 Text 0 0 ,First,#,""" + PL_Lyr2 + """,SiteNumSfx,-1,-1;"""\                 + """SiteStreet "SiteStreet" true true false 64 Text 0 0 ,First,#,""" + PL_Lyr2 + """,SiteStreet,-1,-1;"""\                 + """Predir "Predir" true true false 2 Text 0 0 ,First,#,""" + PL_Lyr2 + """,Predir,-1,-1;"""\                 + """StreetType "StreetType" true true false 8 Text 0 0 ,First,#,""" + PL_Lyr2+ """,StreetType,-1,-1;"""\                 + """SubName "SubName" true true false 20 Text 0 0 ,First,#,""" + PL_Lyr2 + """,SubName,-1,-1;"""\       fieldmappings = arcpy.FieldMappings()     fieldmappings.loadFromString(FieldMapString)     return fieldmappings  def main(args=None):         if args is None:                 args = sys.argv  arcpy.SpatialJoin_analysis(PL_Lyr2, Sel_PT, fcOutput,                            "JOIN_ONE_TO_MANY", "KEEP_ALL", Layers(PL_Lyr2, Sel_PT), "INTERSECT")  #### populates fields  add_fields = ["ACCOUNT","SiteNum","OwnerName","SiteAddres","SiteNumSfx","SiteStreet","Predir","StreetType","SubName"]  # fix args if not isinstance(add_fields, list):     # from script tool     add_fields = add_fields.split(';') # do not need this scratch file #fcOutput = "temp_join" #'temp_join' when using workspace = r"C:\Temp\default.gdb" #arcpy.SpatialJoin_analysis("Parcel layer", fc, fcOutput, 'JOIN_ONE_TO_MANY')  # grab oid field from points oid_t = arcpy.Describe(fc).OIDFieldName  # init rowW and rowR curR = arcpy.SearchCursor(fcOutput) join_dict = dict([(r.JOIN_FID,[r.getValue(f) for f in add_fields]) for r in curR]) del curR  # Now update the new target curW = arcpy.UpdateCursor(fc) for row in curW:     t_oid = row.getValue(oid_t)     if t_oid in join_dict:         for f in add_fields:             row.setValue(f, join_dict[t_oid][add_fields.index(f)])     curW.updateRow(row) del row, curW


Error with filed mapping:
Traceback (most recent call last):   File "C:\GIS\Python Scripts\AddressPoints\Create_Point_2_a.py", line 66, in <module>     arcpy.MakeFeatureLayer_management(PL_Lyr, PL_Lyr2)   File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 5748, in MakeFeatureLayer     raise e ExecuteError: ERROR 999999: Error executing function. The table does not have an OID Field. Failed to execute (MakeFeatureLayer).
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
AdamCox1
Deactivated User
When you write:
ParLyr = arcpy.MakeFeatureLayer_management(Parcellyr, "Parcel layer") #result object

ParLyr is a result object, not a string or feature class object.  Try using the getOutput method to make ParLyr a layer object.  Then, later on, you can get the layer's name by using ParLyr.name.  That will be a string.
ParLyr = arcpy.MakeFeatureLayer_management(Parcellyr, "Parcel layer").getOutput(0) #layer object ParLyr_name = ParLyr.name #string object


Here's some more info http://resources.arcgis.com/en/help/main/10.1/index.html#//018z00000046000000

View solution in original post

0 Kudos
2 Replies
TonyAlmeida
MVP Regular Contributor
I made some modifications to my code. I am still having a hard time understand my it error's out.
any help would be gratefully appreciated.

modified code
ParLyr = arcpy.MakeFeatureLayer_management(Parcellyr, "Parcel layer")
entries = int(arcpy.GetCount_management(fc).getOutput(0))

for i in xrange(entries):
    Pt_sel = arcpy.MakeFeatureLayer_management(fc, "point layer", "\"FID\"={}".format(str(i) + ""))
    arcpy.SelectLayerByLocation_management(ParLyr, "INTERSECT", Pt_sel, "", "NEW_SELECTION")
    #if arcpy.Exists(pt_lyr): arcpy.Delete_management(pt_lyr)


fcOutput = r"C:\Temp\default.gdb\temp_join" 

#Field Mapping
def Layers(ParLyr, Pt_sel):
    FieldMapString = "" \
                + """ACCOUNT "ACCOUNT" true true false 11 Text 0 0 ,First,#,""" + ParLyr + """,ACCOUNT,-1,-1;"""\
                + """SiteNum "SiteNum" true true false 10 Double 0 0 ,First,#,""" + ParLyr + """,SiteNum,-1,-1;"""\
                + """OwnerName "OwnerName" true true false 100 Text 0 0 ,First,#,""" + ParLyr + """,OwnerName,-1,-1;"""\
                + """SiteAddress "SiteAddress" true true false 106 Text 0 0 ,First,#,""" + ParLyr + """,SiteAddress,-1,-1;"""\
                + """SiteNumSfx "SiteNumSfx" true true false 6 Text 0 0 ,First,#,""" + ParLyr + """,SiteNumSfx,-1,-1;"""\
                + """SiteStreet "SiteStreet" true true false 64 Text 0 0 ,First,#,""" + ParLyr + """,SiteStreet,-1,-1;"""\
                + """Predir "Predir" true true false 2 Text 0 0 ,First,#,""" + ParLyr + """,Predir,-1,-1;"""\
                + """StreetType "StreetType" true true false 8 Text 0 0 ,First,#,""" + ParLyr+ """,StreetType,-1,-1;"""\
                + """SubName "SubName" true true false 20 Text 0 0 ,First,#,""" + ParLyr + """,SubName,-1,-1;"""\


    fieldmappings = arcpy.FieldMappings()
    fieldmappings.loadFromString(FieldMapString)
    return fieldmappings

def main(args=None):
        if args is None:
                args = sys.argv

arcpy.SpatialJoin_analysis(ParLyr, Pt_sel, fcOutput,
                           "JOIN_ONE_TO_MANY", "", Layers(ParLyr, Pt_sel), "INTERSECT")


Error:
Traceback (most recent call last):
  File "C:\GIS\Python Scripts\AddressPoints\Create_Point_2_a.py", line 94, in <module>
    "JOIN_ONE_TO_MANY", "", Layers(ParLyr, Pt_sel), "INTERSECT")
  File "C:\GIS\Python Scripts\AddressPoints\Create_Point_2_a.py", line 82, in Layers
    + """SubName "SubName" true true false 20 Text 0 0 ,First,#,""" + ParLyr + """,SubName,-1,-1;"""\
TypeError: cannot concatenate 'str' and 'Result' objects
0 Kudos
AdamCox1
Deactivated User
When you write:
ParLyr = arcpy.MakeFeatureLayer_management(Parcellyr, "Parcel layer") #result object

ParLyr is a result object, not a string or feature class object.  Try using the getOutput method to make ParLyr a layer object.  Then, later on, you can get the layer's name by using ParLyr.name.  That will be a string.
ParLyr = arcpy.MakeFeatureLayer_management(Parcellyr, "Parcel layer").getOutput(0) #layer object ParLyr_name = ParLyr.name #string object


Here's some more info http://resources.arcgis.com/en/help/main/10.1/index.html#//018z00000046000000
0 Kudos