<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SpatialQueryFilter in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/spatialqueryfilter/m-p/841400#M3837</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah yes, that makes sense to me now.&amp;nbsp; Thanks for helping!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 21 Nov 2017 14:37:10 GMT</pubDate>
    <dc:creator>BrianBulla</dc:creator>
    <dc:date>2017-11-21T14:37:10Z</dc:date>
    <item>
      <title>SpatialQueryFilter</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/spatialqueryfilter/m-p/841398#M3835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to do a spatial query on a layer in my map.&amp;nbsp; In my code, I first check to see if the layer is there:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IEnumerable&amp;lt;Layer&amp;gt; gridLayer = map.GetLayersAsFlattenedList().Where(l =&amp;gt; l.Name.IndexOf("GISWRKS1.WORKS.LAND_Grid", StringComparison.CurrentCultureIgnoreCase) &amp;gt;= 0);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (gridLayer.Count() == 0)&lt;BR /&gt; {&lt;BR /&gt; ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Please add the GRID layer before proceeding.", "Missing Layer");&lt;BR /&gt; return;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Later in the code I want to use a point to intersect the gridLayer using this code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SpatialQueryFilter spatialFilter = new SpatialQueryFilter();&lt;BR /&gt; spatialFilter.FilterGeometry = intersectPoint;&lt;BR /&gt; spatialFilter.SpatialRelationship = SpatialRelationship.Intersects;&lt;BR /&gt; spatialFilter.SubFields = "GRIDNO";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FeatureLayer grid = (FeatureLayer)gridLayer;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;//This does not work.&amp;nbsp; &amp;nbsp;Null Reference Exception or sometimes an InvalidCast, depending on what I am doing.&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;EM&gt;&lt;STRONG&gt;How do I turn my gridLayer from above into something I can use to query??&amp;nbsp; I've tried many different things...FeatureLayer, BasicFeatureLayer, FeatureClass.....nothing works.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;RowCursor gridCursor = grid.Search(spatialFilter);&lt;BR /&gt; while (gridCursor.MoveNext())&lt;BR /&gt; {&lt;BR /&gt; using (Feature feature = (Feature)gridCursor.Current)&lt;BR /&gt; {&lt;BR /&gt; ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(feature[0].ToString());&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Nov 2017 19:58:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/spatialqueryfilter/m-p/841398#M3835</guid>
      <dc:creator>BrianBulla</dc:creator>
      <dc:date>2017-11-20T19:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: SpatialQueryFilter</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/spatialqueryfilter/m-p/841399#M3836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Brian,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first line of your code defines&amp;nbsp;gridLayer as a&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;IEnumerable&amp;lt;Layer&amp;gt;&amp;nbsp; ... you cannot cast an enumeration to a class that expects a single object.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;It would be better if the&amp;nbsp;line was something similar to this&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt; Layer gridLayer = map.GetLayersAsFlattenedList().Where(l =&amp;gt; l.Name.IndexOf("GISWRKS1.WORKS.LAND_Grid", StringComparison.CurrentCultureIgnoreCase) &amp;gt;= 0).FirstOrDefault();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;then you can check gridLayer against null to determine if it exists.&amp;nbsp; Finally you&amp;nbsp;can then do&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;BR /&gt; FeatureLayer grid = gridLayer as FeatureLayer;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Alternatively you could also do this&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt; FeatureLayer gridLayer = map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().Where(l =&amp;gt; l.Name.IndexOf("GISWRKS1.WORKS.LAND_Grid", StringComparison.CurrentCultureIgnoreCase) &amp;gt;= 0).FirstOrDefault();&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Nov 2017 23:50:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/spatialqueryfilter/m-p/841399#M3836</guid>
      <dc:creator>NarelleChedzey</dc:creator>
      <dc:date>2017-11-20T23:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: SpatialQueryFilter</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/spatialqueryfilter/m-p/841400#M3837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah yes, that makes sense to me now.&amp;nbsp; Thanks for helping!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Nov 2017 14:37:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/spatialqueryfilter/m-p/841400#M3837</guid>
      <dc:creator>BrianBulla</dc:creator>
      <dc:date>2017-11-21T14:37:10Z</dc:date>
    </item>
  </channel>
</rss>

