Arcpy append not appending all features

1498
7
Jump to solution
10-15-2018 02:42 PM
StuartMoore
Occasional Contributor III

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

0 Kudos
1 Solution

Accepted Solutions
MatthewDobson
Occasional Contributor

And is the geometry valid? 

Matthew

View solution in original post

7 Replies
DarrenWiens2
MVP Honored Contributor

Can you post your script?

0 Kudos
StuartMoore
Occasional Contributor III

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

0 Kudos
DanPatterson_Retired
MVP Emeritus

can you format the code?

/blogs/dan_patterson/2016/08/14/script-formatting 

print(Polys)   …. some sample output

0 Kudos
DanPatterson_Retired
MVP Emeritus

what did the print statement print?

0 Kudos
curtvprice
MVP Esteemed Contributor

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.

MatthewDobson
Occasional Contributor

And is the geometry valid? 

Matthew

StuartMoore
Occasional Contributor III

Forgot to post back, it looks like it didn’t work due to the geometry being corrupted for some of the polygons 

stu