My conundrum is, is it possible to calculate fields based on other fields in a stand-alone python script. An example would be a group of values bases on two fields dictates what gets calculated in two other fields such as GeneralConcern = 1 (subytype) and SpecificConcern = "Pothole" and ContactDept IS NULL and DeptInfo IS NULL, calculate ContactDept = "Street Dept" and calculates DeptInfo = "715-555-5555".?
This is what I have come up with so far, but I am having a hard time wrapping my head around it.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token"># Set workspaces</SPAN>
workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\ESRITest\GeoReportingSystem\Testing9116\Testing9116.gdb'</SPAN>
outWorkspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\ESRITest\GeoReportingSystem\Testing9116\Scratch.gdb'</SPAN>
<SPAN class="comment token"># Set feature classes</SPAN>
tbl <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\ESRITest\GeoReportingSystem\Testing9116\Testing9116.gdb\GeoReporting'</SPAN>
<SPAN class="comment token"># Set other variables</SPAN>
pContact <SPAN class="operator token">=</SPAN> <SPAN class="string token">"PrimaryContact"</SPAN>
contactInfo <SPAN class="operator token">=</SPAN> <SPAN class="string token">"PrimaryInformation"</SPAN>
sql <SPAN class="operator token">=</SPAN> <SPAN class="string token">"""{} is NULL AND {} IS NULL"""</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>pContact<SPAN class="punctuation token">,</SPAN> contactInfo<SPAN class="punctuation token">)</SPAN>
specificCon1 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'Commercial Signage Concern'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'Temporary Signage Concern'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Building Maintenance Issue'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'Fence Concern'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Land Use Concern'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Property Maintenance Concern'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Setback or Property Concern'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Other'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># Mulitple General Concern Numbers</SPAN>
specificCon2 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'Athletic Field Issue'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Fairgrounds Issue'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Park Maintenance Issue'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Pool Issue'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Restroom Issue'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Shelter Issue'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Skate Park Issue'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Trail Maintenance Issue'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Unsafe or Downed Tree'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Zoo Issue'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Other'</SPAN> <SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Starting an Edit Session - DMB</SPAN>
edit <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>Editor<SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">)</SPAN>
edit<SPAN class="punctuation token">.</SPAN>startEditing<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
edit<SPAN class="punctuation token">.</SPAN>startOperation<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># What I am trying to do is update the Null PrimaryContact and PrimaryInformation fields based on a General Concern (subtype number) and a specific concern.</SPAN>
<SPAN class="comment token">#Example would be General Concern = 6 and Specific Concern = Pool Issue then PrimaryContact = Parks and Recreation and PrimaryInformation = 715-555-5555</SPAN>
<SPAN class="comment token"># See specificCon1. That variable will be a mix of several General Concern numbers like</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>tbl<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'PrimaryContact'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'PrimaryInformation'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">,</SPAN> where_clause <SPAN class="operator token">=</SPAN> sql<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>
<SPAN class="keyword token">if</SPAN> value <SPAN class="operator token">==</SPAN> specificCon1<SPAN class="punctuation token">:</SPAN>
row<SPAN class="punctuation token">.</SPAN>setValue<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"PrimaryContact"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Development Services"</SPAN>
row<SPAN class="punctuation token">.</SPAN>setValue<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"PrimaryInformation"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"715-555-5555"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">elif</SPAN> value <SPAN class="operator token">==</SPAN> specificCon2<SPAN class="punctuation token">:</SPAN>
row<SPAN class="punctuation token">.</SPAN>setValue<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"PrimaryContact"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Parks and Recreation"</SPAN>
row<SPAN class="punctuation token">.</SPAN>setValue<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"PrimaryInformation"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"715-555-5555"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"??????"</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># Closing the Edit Session - DMB</SPAN>
edit<SPAN class="punctuation token">.</SPAN>stopOperation<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
edit<SPAN class="punctuation token">.</SPAN>stopEditing<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">True</SPAN><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>