Hi
I am trying to perform a summary on a poly line dataset. This data contains an attribute for the year the section was laid and the diameter of the section. I want to sum the length of these sections group them by both year and band. However I want to group the bands and years e.g year laid 2000-2010 and diameter 150-300 mm. I have created a model which does what I want but I was wondering if there was an easier way to carry out this task. I was also wondering if there was a way to modify the model so that the user could can the year bands and diameters in a table of spreadsheet. I am new to the model builder. Maybe there is a better way to do what I am trying to do. See attached images.
Thanks
Ciaran
You can make an model input variable a multi value list, one variable for each of your classify variables.
Then you can use that multi value list in Calculate Field, inside the code block splitting it into a Python list with “;”.split().
Here is a Calculate Field expression I came up with that seems to do what you want. Dan Patterson numpy is pretty handy!
<SPAN class="comment token"># Calculate Field expression, specifying to update field "class"</SPAN> <SPAN class="comment token"># Source field is the name of the field we want to classify</SPAN> classify<SPAN class="punctuation token">(</SPAN>!<SPAN class="operator token">%</SPAN>Source field<SPAN class="operator token">%</SPAN>!<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># Code block </SPAN> <SPAN class="comment token"># breaks is a multivalue model variable I created of type Double</SPAN> <SPAN class="keyword token">import</SPAN> numpy <SPAN class="keyword token">as</SPAN> np breaks <SPAN class="operator token">=</SPAN> sorted<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>float<SPAN class="punctuation token">(</SPAN>k<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> k <SPAN class="keyword token">in</SPAN> <SPAN class="string token">"%breaks%"</SPAN><SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">";"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> breaklab <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"<{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>breaks<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> breaklab <SPAN class="operator token">+=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"{} up to {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>breaks<SPAN class="punctuation token">[</SPAN>k<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> breaks<SPAN class="punctuation token">[</SPAN>k<SPAN class="operator token">+</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> k <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN>len<SPAN class="punctuation token">(</SPAN>breaks<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> breaklab <SPAN class="operator token">+=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">">={}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>breaks<SPAN class="punctuation token">[</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> breaks <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>array<SPAN class="punctuation token">(</SPAN>breaks<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">classify</SPAN><SPAN class="punctuation token">(</SPAN>vv<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> p <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>searchsorted<SPAN class="punctuation token">(</SPAN>breaks<SPAN class="punctuation token">,</SPAN> vv<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'right'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> breaklab<SPAN class="punctuation token">[</SPAN>p<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>
Hi @curtvprice
i know this is an old post but i am doing something similar, but instead of multivalue variable i am using Table of Values variable. and i need to split the variables so that i could use in them for field calculation.
I have posted a question here in communities would love to pick your brains on the topic
Hussain
I have got this working now thanks.
I didn't realise the coulmn that is being updated has to be of datatype text/string.
Thanks again
Curtis,
Thanks for the information but i must be doing something stupid. I have tried to simplify this to test. So i created a new feature class with the same structure as your example and with the same names. When i try to run the model i get an error about value type. I have set the to type double. See attached images which will hopefulyl help.
Regards
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.