I am trying to measure the distance between two points using the arcgis.geometry.distance function.
However, I get this error:
RuntimeError: Unable to complete operation. The operation cannot be performed on a non-simple geometry. (Error Code: 400)
My code is:
<SPAN class="comment token"># Calculate distance</SPAN>
<SPAN class="keyword token">for</SPAN> index<SPAN class="punctuation token">,</SPAN> values <SPAN class="keyword token">in</SPAN> cc_df<SPAN class="punctuation token">.</SPAN>iterrows<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
cap_point <SPAN class="operator token">=</SPAN> values<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'SHAPE'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># A point object</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>type<SPAN class="punctuation token">(</SPAN>cap_point<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">" geometry 1 type"</SPAN><SPAN class="punctuation token">)</SPAN>
cap_stid <SPAN class="operator token">=</SPAN> values<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'Study_ID'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># (string)</SPAN>
<SPAN class="keyword token">for</SPAN> c <SPAN class="keyword token">in</SPAN> dist_clm<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># A list of columns</SPAN>
moi <SPAN class="operator token">=</SPAN> c<SPAN class="punctuation token">[</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># The specific column</SPAN>
moi <SPAN class="operator token">=</SPAN> moi<SPAN class="punctuation token">[</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># A part of the column name used to acess the 'SHAPE' value in a dictionary</SPAN>
r_shp <SPAN class="operator token">=</SPAN> rel_dict<SPAN class="punctuation token">[</SPAN>cap_stid<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN>moi<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">'shp'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># the 'SHAPE' column of a data frame</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>type<SPAN class="punctuation token">(</SPAN>r_shp<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">" geometry 2 type"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># Printing the data type as part of testing</SPAN>
r_wkid <SPAN class="operator token">=</SPAN> rel_dict<SPAN class="punctuation token">[</SPAN>cap_stid<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN>moi<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">'shp'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">'spatialReference'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">'wkid'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># The WKID (spatial refrence)</SPAN>
d <SPAN class="operator token">=</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>geometry<SPAN class="punctuation token">.</SPAN>distance<SPAN class="punctuation token">(</SPAN>r_wkid<SPAN class="punctuation token">,</SPAN> cap_point<SPAN class="punctuation token">,</SPAN> r_shp<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"METERS"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</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>It is basically extracting a point geometry from a dictionary and measuring the distance to another point geometry in a SPED. (Or that is what it is supposed to do)
The output is:
<class 'arcgis.geometry._types.Point'> geometry 1 type <class 'arcgis.geometry._types.Point'> geometry 2 type
Unable to complete operation. The operation cannot be performed on a non-simple geometry.
Are point objects not simple geometry?
The documentation on this is very sparse and I can't find any examples.
Here is a link to the documentation: arcgis.geometry module — arcgis 1.6.0 documentation
Any insight would be helpful. Thanks
arcgis 1.5.3
pandas 0.24.2