The goal is to find the angle at each vertex. My current computation which started with the clue I got here, isn't giving me the expected vertex angle values. By expected values, I mean angles at vertex measured using ArcMap10 COGO tool.
inFC (input feature class) are polylines which were a result of polygon split operation.
I am also not getting it right with regards to pushing those angle values to the field "Angle"
Alternate approaches are welcome.
<SPAN class="comment token"># get the vertex angle</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">getVertexAngle</SPAN><SPAN class="punctuation token">(</SPAN>inFC<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddField_management<SPAN class="punctuation token">(</SPAN>inFC<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"Angle"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"DOUBLE"</SPAN><SPAN class="punctuation token">)</SPAN>
pointer <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</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>inFC<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Angle'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> uCur<SPAN class="punctuation 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>inFC<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'SHAPE@'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> sCur<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> sCur<SPAN class="punctuation token">:</SPAN>
orient <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
Geom <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
Parts <SPAN class="operator token">=</SPAN> range<SPAN class="punctuation token">(</SPAN>Geom<SPAN class="punctuation token">.</SPAN>partCount<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> part <SPAN class="keyword token">in</SPAN> Parts<SPAN class="punctuation token">:</SPAN>
currPart <SPAN class="operator token">=</SPAN> Geom<SPAN class="punctuation token">.</SPAN>getPart<SPAN class="punctuation token">(</SPAN>part<SPAN class="punctuation token">)</SPAN>
pointCount <SPAN class="operator token">=</SPAN> currPart<SPAN class="punctuation token">.</SPAN>count
qPointsRange <SPAN class="operator token">=</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> pointCount <SPAN class="operator token">-</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> point <SPAN class="keyword token">in</SPAN> qPointsRange<SPAN class="punctuation token">:</SPAN>
currPnt <SPAN class="operator token">=</SPAN> currPart<SPAN class="punctuation token">.</SPAN>getObject<SPAN class="punctuation token">(</SPAN>point<SPAN class="punctuation token">)</SPAN>
X <SPAN class="operator token">=</SPAN> currPnt<SPAN class="punctuation token">.</SPAN>X
Y <SPAN class="operator token">=</SPAN> currPnt<SPAN class="punctuation token">.</SPAN>Y
prevPnt <SPAN class="operator token">=</SPAN> currPart<SPAN class="punctuation token">.</SPAN>getObject<SPAN class="punctuation token">(</SPAN>point <SPAN class="operator token">-</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
nxtPnt <SPAN class="operator token">=</SPAN> currPart<SPAN class="punctuation token">.</SPAN>getObject<SPAN class="punctuation token">(</SPAN>point <SPAN class="operator token">+</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
radian <SPAN class="operator token">=</SPAN> math<SPAN class="punctuation token">.</SPAN>atan2<SPAN class="punctuation token">(</SPAN>Y <SPAN class="operator token">-</SPAN> prevPnt<SPAN class="punctuation token">.</SPAN>Y<SPAN class="punctuation token">,</SPAN> X <SPAN class="operator token">-</SPAN> prevPnt<SPAN class="punctuation token">.</SPAN>X<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">-</SPAN> math<SPAN class="punctuation token">.</SPAN>atan2<SPAN class="punctuation token">(</SPAN>nxtPnt<SPAN class="punctuation token">.</SPAN>Y <SPAN class="operator token">-</SPAN> prevPnt<SPAN class="punctuation token">.</SPAN>Y<SPAN class="punctuation token">,</SPAN> nxtPnt<SPAN class="punctuation token">.</SPAN>X <SPAN class="operator token">-</SPAN> prevPnt<SPAN class="punctuation token">.</SPAN>X<SPAN class="punctuation token">)</SPAN>
degrees <SPAN class="operator token">=</SPAN> <SPAN class="number token">90</SPAN> <SPAN class="operator token">-</SPAN> math<SPAN class="punctuation token">.</SPAN>degrees <SPAN class="punctuation token">(</SPAN> math<SPAN class="punctuation token">.</SPAN>radians<SPAN class="punctuation token">(</SPAN> radian <SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">)</SPAN>
orient<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>degrees<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> degrees
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"orientations are: "</SPAN><SPAN class="punctuation token">,</SPAN> orient
<SPAN class="keyword token">return</SPAN> orient<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>