Hi all -
I keep getting:
Runtime error
Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
File <SPAN class="string token">"<string>"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">26</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN>
RuntimeError<SPAN class="punctuation token">:</SPAN> workspace already <SPAN class="keyword token">in</SPAN> transaction mode<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
when I run my script. I can't sort out why.
Here's my code. (Not loving how the formatting works here.)
<SPAN class="comment token"># Move points based up current lat/lon</SPAN>
<SPAN class="comment token">#grab stuff you need</SPAN>
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> os
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Imported Libraries."</SPAN>
<SPAN class="comment token"># Set variablesfilepath = r'S:\AGR\AGR-Shared\AGR-GIS\AGR_Data\Connection to cloud.agriculture.vermont.gov.sde'</SPAN>
fc <SPAN class="operator token">=</SPAN> <SPAN class="string token">"AGRGISDATA.DBO.ApiariesWGS"</SPAN>
fc_path <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>filepath<SPAN class="punctuation token">,</SPAN> fc<SPAN class="punctuation token">)</SPAN>
fields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'Longtitude'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'Latitude'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'SHAPE@XY'</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">#arcpy.env.workspace = fc_path #I don't think this is needed. </SPAN>
workspace <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>dirname<SPAN class="punctuation token">(</SPAN>fc_path<SPAN class="punctuation token">)</SPAN>
editor <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> <SPAN class="comment token">#this one throws "RuntimeError: workspace already in transaction mode"</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Set vars."</SPAN>
editor<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>
editor<SPAN class="punctuation token">.</SPAN>startOperation<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Editor Commands."</SPAN>
<SPAN class="comment token">#create curser on fc</SPAN>
<SPAN class="comment token">#try: </SPAN>
<SPAN class="comment token">#print "Trying"</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>fc_path<SPAN class="punctuation token">,</SPAN>fields<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"With"</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"for row in cursor"</SPAN>
x <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
y <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
xy <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>x<SPAN class="punctuation token">,</SPAN>y<SPAN class="punctuation token">)</SPAN>
pnt <SPAN class="operator token">=</SPAN> xy
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> pnt
cursor<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Updated Rows."</SPAN>
<SPAN class="comment token">#finally: </SPAN>
editor<SPAN class="punctuation token">.</SPAN>stopOperation<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
editor<SPAN class="punctuation token">.</SPAN>stopEditing<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> editor
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"It worked!"</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>
My code is indented properly, I just couldn't make it do so with the syntax highlighter here. I'm sure there's a way, but I haven't figured it out.
Anyway, I've been trying different things to get this code running again, and I'm out of ideas. Would love some help.
Thx
JG