Hi. I'm creating a series of MapTools to sketch a line on the map that will represent a new feature. A criteria of the sketch is that the first node of the sketch must intersect a line feature. So for example, to create a hydrant lateral the first click must intersect a watermain....the second click will represent the hydrant valve and the last the hydrant.
I have created a routine for checking for the intersection of the first click to a given layer, but I am getting mixed results. With certain layers it works (ie. my sewer layer for my sewer connection tool), but other layers (ie. my watermain layer for my hydrant tool). Here is the code:
<SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">static</SPAN> <SPAN class="keyword token">bool</SPAN> <SPAN class="token function">IntersectsLayer</SPAN><SPAN class="punctuation token">(</SPAN>MapPoint point<SPAN class="punctuation token">,</SPAN> FeatureLayer layer<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">try</SPAN>
<SPAN class="punctuation token">{</SPAN>
SpatialQueryFilter spatialFilter <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">SpatialQueryFilter</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
spatialFilter<SPAN class="punctuation token">.</SPAN>FilterGeometry <SPAN class="operator token">=</SPAN> point<SPAN class="punctuation token">;</SPAN>
spatialFilter<SPAN class="punctuation token">.</SPAN>SpatialRelationship <SPAN class="operator token">=</SPAN> SpatialRelationship<SPAN class="punctuation token">.</SPAN>Intersects<SPAN class="punctuation token">;</SPAN>
RowCursor theCursor <SPAN class="operator token">=</SPAN> layer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Search</SPAN><SPAN class="punctuation token">(</SPAN>spatialFilter<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
Feature feature<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">while</SPAN> <SPAN class="punctuation token">(</SPAN>theCursor<SPAN class="punctuation token">.</SPAN><SPAN class="token function">MoveNext</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">using</SPAN> <SPAN class="punctuation token">(</SPAN>feature <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>Feature<SPAN class="punctuation token">)</SPAN>theCursor<SPAN class="punctuation token">.</SPAN>Current<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">Exception</SPAN> ex<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
ArcGIS<SPAN class="punctuation token">.</SPAN>Desktop<SPAN class="punctuation token">.</SPAN>Framework<SPAN class="punctuation token">.</SPAN>Dialogs<SPAN class="punctuation token">.</SPAN>MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>ex<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToString</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>And here is the code that calls it:
<SPAN class="keyword token">protected</SPAN> <SPAN class="keyword token">override</SPAN> Task<SPAN class="operator token"><</SPAN><SPAN class="keyword token">bool</SPAN><SPAN class="operator token">></SPAN> <SPAN class="token function">OnSketchCompleteAsync</SPAN><SPAN class="punctuation token">(</SPAN>Geometry geometry<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//use the sketch geometry to create the connectionPoint, valve and hydrant</SPAN>
<SPAN class="keyword token">var</SPAN> pointCollection <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>Multipart<SPAN class="punctuation token">)</SPAN>geometry<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>Points<SPAN class="punctuation token">;</SPAN>
MapPoint connectionPoint <SPAN class="operator token">=</SPAN> pointCollection<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN>
MapPoint hydrantPoint <SPAN class="operator token">=</SPAN> pointCollection<SPAN class="punctuation token">[</SPAN>pointCollection<SPAN class="punctuation token">.</SPAN>Count <SPAN class="operator token">-</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN>
MapPoint valvePoint <SPAN class="operator token">=</SPAN> pointCollection<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//start creating the features</SPAN>
QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>Global<SPAN class="punctuation token">.</SPAN><SPAN class="token function">IntersectsLayer</SPAN><SPAN class="punctuation token">(</SPAN>connectionPoint<SPAN class="punctuation token">,</SPAN> waterMainLayer<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
ArcGIS<SPAN class="punctuation token">.</SPAN>Desktop<SPAN class="punctuation token">.</SPAN>Framework<SPAN class="punctuation token">.</SPAN>Dialogs<SPAN class="punctuation token">.</SPAN>MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>connectionPoint<SPAN class="punctuation token">.</SPAN>X<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToString</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">", "</SPAN> <SPAN class="operator token">+</SPAN> connectionPoint<SPAN class="punctuation token">.</SPAN>Y<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToString</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Error"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
ArcGIS<SPAN class="punctuation token">.</SPAN>Desktop<SPAN class="punctuation token">.</SPAN>Framework<SPAN class="punctuation token">.</SPAN>Dialogs<SPAN class="punctuation token">.</SPAN>MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"The starting point must intersect the WaterMain or Water Service layer."</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Error"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Can anyone see anything wrong in the code? For some reason it always returns false when using the watermain layer. I have snapping turned on, and it always works when using my similarly coded sewer connection tool.
Any ideas are appreciated.