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

Failed on input OID

$
0
0
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:
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:
Code:

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:
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:
Code:

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).


Viewing all articles
Browse latest Browse all 2485

Trending Articles