so I’ve got a script that selects 20 polygons and appends them to a new feature class , but it only works for 15 of the 20 polygons , it does the first and the last 14. If I change the number of selected polygons it still skips some
any ideas
Solved! Go to Solution.
Can you post your script?
this is the code:
import arcpy
import sys
import os
import time
import datetime
FromRange = 0
ToRange = FromRange + 11
#Latest polygon Data
arcpy.MakeFeatureLayer_management("C:/polygonedata.gdb/Poly", "Poly_lyr")
#Target Data
Target_FC = arcpy.MakeFeatureLayer_management("C:/TargetPoly.gdb/Poly", "Target_lyr")
#Polygon table select
QueryStr = ("OBJECTID > %s and OBJECTID < %s") %(FromRange, ToRange)
tableList = "C:/PolyTable.gdb/tbl_Poly"
lyrName = "tbl_Poly"
keyField = "tbl_Unique_Polys.OBJECTID"
fieldList = [["OBJECTID", 'OBJECTID'],["Poly_ID", 'Poly_ID']]
arcpy.MakeQueryTable_management(tableList, lyrName,"USE_KEY_FIELDS", keyField, fieldList, QueryStr)
print("MakeQueryTable")
Polys = ""
with arcpy.da.SearchCursor("tbl_Poly", ["OBJECTID","Poly_ID"]) as cursor:
for row in cursor:
Polys = Polys + "'" + row[1] + "',"
Polys = Polys[:-1]
print(Polys)
PolySel = arcpy.SelectLayerByAttribute_management ("Poly_lyr", "NEW_SELECTION","Poly_ID in ({})".format(Polys))
schemaType = 'NO_TEST'
fm_type = arcpy.FieldMap()
fms = arcpy.FieldMappings()
fm_type.addInputField(PolySel, "Poly_ID")
type_name = fm_type.outputField
type_name.name = 'Poly_IDENT'
fm_type.outputField = type_name
fms.addFieldMap(fm_type)
arcpy.Append_management(PolySel, Target_FC, schemaType, fms)
thanks
Stu
can you format the code?
/blogs/dan_patterson/2016/08/14/script-formatting
print(Polys) …. some sample output
what did the print statement print?
OBJECTID is not guaranteed to start from one and be sequential. (It's also not guaranteed to be named "OBJECTID"!) I suggest trying some other method to do your selecting.
And is the geometry valid?
Matthew
Forgot to post back, it looks like it didn’t work due to the geometry being corrupted for some of the polygons
stu