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
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
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.
what did the print statement print?
can you format the code?
/blogs/dan_patterson/2016/08/14/script-formatting
print(Polys) …. some sample output
this is the code:
<SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">import</SPAN> sys <SPAN class="keyword token">import</SPAN> os <SPAN class="keyword token">import</SPAN> time <SPAN class="keyword token">import</SPAN> datetime FromRange <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> ToRange <SPAN class="operator token">=</SPAN> FromRange <SPAN class="operator token">+</SPAN> <SPAN class="number token">11</SPAN> <SPAN class="comment token">#Latest polygon Data</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"C:/polygonedata.gdb/Poly"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Poly_lyr"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#Target Data</SPAN> Target_FC <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"C:/TargetPoly.gdb/Poly"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Target_lyr"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#Polygon table select</SPAN> QueryStr <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"OBJECTID > %s and OBJECTID < %s"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">%</SPAN><SPAN class="punctuation token">(</SPAN>FromRange<SPAN class="punctuation token">,</SPAN> ToRange<SPAN class="punctuation token">)</SPAN> tableList <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:/PolyTable.gdb/tbl_Poly"</SPAN> lyrName <SPAN class="operator token">=</SPAN> <SPAN class="string token">"tbl_Poly"</SPAN> keyField <SPAN class="operator token">=</SPAN> <SPAN class="string token">"tbl_Unique_Polys.OBJECTID"</SPAN> fieldList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"OBJECTID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'OBJECTID'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Poly_ID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Poly_ID'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeQueryTable_management<SPAN class="punctuation token">(</SPAN>tableList<SPAN class="punctuation token">,</SPAN> lyrName<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"USE_KEY_FIELDS"</SPAN><SPAN class="punctuation token">,</SPAN> keyField<SPAN class="punctuation token">,</SPAN> fieldList<SPAN class="punctuation token">,</SPAN> QueryStr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MakeQueryTable"</SPAN><SPAN class="punctuation token">)</SPAN> Polys <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"tbl_Poly"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"OBJECTID"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"Poly_ID"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN> Polys <SPAN class="operator token">=</SPAN> Polys <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN> <SPAN class="operator token">+</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"',"</SPAN> Polys <SPAN class="operator token">=</SPAN> Polys<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>Polys<SPAN class="punctuation token">)</SPAN> PolySel <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Poly_lyr"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NEW_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"Poly_ID in ({})"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>Polys<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> schemaType <SPAN class="operator token">=</SPAN> <SPAN class="string token">'NO_TEST'</SPAN> fm_type <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>FieldMap<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> fms <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>FieldMappings<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> fm_type<SPAN class="punctuation token">.</SPAN>addInputField<SPAN class="punctuation token">(</SPAN>PolySel<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Poly_ID"</SPAN><SPAN class="punctuation token">)</SPAN> type_name <SPAN class="operator token">=</SPAN> fm_type<SPAN class="punctuation token">.</SPAN>outputField type_name<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Poly_IDENT'</SPAN> fm_type<SPAN class="punctuation token">.</SPAN>outputField <SPAN class="operator token">=</SPAN> type_name fms<SPAN class="punctuation token">.</SPAN>addFieldMap<SPAN class="punctuation token">(</SPAN>fm_type<SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Append_management<SPAN class="punctuation token">(</SPAN>PolySel<SPAN class="punctuation token">,</SPAN> Target_FC<SPAN class="punctuation token">,</SPAN> schemaType<SPAN class="punctuation token">,</SPAN> fms<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
thanks
Stu
Can you post your script?
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.