Dear All,
I created a fishnet in ArcMap. I want to give 1 value to the lowest row then 2 to next row when go up and again 1 to upper and repeat this in my whole grid. As I have lot of feature I want any Python Script for automation of process.
Thanks
Hi,
I put this together quickly using Pro but I'm pretty sure it should run from the Python window in ArcMap too:
fishnet <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN> <SPAN class="comment token">#layer name goes here</SPAN> fieldname <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN> <SPAN class="comment token">#name of field storing new value (1, 2)</SPAN> fields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"SHAPE@Y"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>fieldname<SPAN class="punctuation token">)</SPAN> ys <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>fishnet<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SHAPE@Y"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> ysDict <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN> uniqueys <SPAN class="operator token">=</SPAN> sorted<SPAN class="punctuation token">(</SPAN>list<SPAN class="punctuation token">(</SPAN>set<SPAN class="punctuation token">(</SPAN>ys<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> y <SPAN class="keyword token">in</SPAN> luniqueys<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> luniqueys<SPAN class="punctuation token">.</SPAN>index<SPAN class="punctuation token">(</SPAN>y<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">%</SPAN> <SPAN class="number token">2</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN> ysDict<SPAN class="punctuation token">[</SPAN>y<SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> ysDict<SPAN class="punctuation token">[</SPAN>y<SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="number token">2</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>fish<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"SHAPE@Y"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"val"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> ucur<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> ucur<SPAN class="punctuation token">:</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> valueDict<SPAN class="punctuation token">[</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> ucur<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<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>
Just enter in the name of the layer and the field name that stores the values (1 or 2) in there. Also make sure that field is an integer field. Basically this script finds all the features unique y values, lays them out in order and assigns them a 1 or 2 depending on if its index is odd or even, then adds that value back to the feature.
Thanks alot Joshua it works
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.