<?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: Help with IFeatureLayer in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745561#M19813</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I wasn't going to reply, because it seemed more of a nitpick and me being somewhat rude.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, why would you mark a previous reply as the answer and still not have a solution to your problem?&amp;nbsp; Doesn't seem right.&amp;nbsp; I'm just saying what most people are probably thinking.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 18 Jun 2012 16:07:27 GMT</pubDate>
    <dc:creator>LeoDonahue</dc:creator>
    <dc:date>2012-06-18T16:07:27Z</dc:date>
    <item>
      <title>Help with IFeatureLayer</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745557#M19809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Iâ??m trying to create a simple Query, with VS2010. All I want to do is have a Selection by Attribute, using a Geodatabase Feature Class in the ActiveView. Iâ??m using the &lt;/SPAN&gt;&lt;STRONG&gt;SelectMapFeaturesByAttributeQuery&lt;/STRONG&gt;&lt;SPAN&gt; Snippet, but the code is a little unclear as to how I invoke the Feature Class by it's &lt;/SPAN&gt;&lt;STRONG&gt;name&lt;/STRONG&gt;&lt;SPAN&gt;, and not by order (Layer(0)) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Carto
Public Class Button1
&amp;nbsp; Inherits ESRI.ArcGIS.Desktop.AddIns.Button

&amp;nbsp; Public Sub New()

&amp;nbsp; End Sub

&amp;nbsp; Protected Overrides Sub OnClick()

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelectMapFeaturesByAttributeQuery(My.ArcMap.Document.ActiveView, ??????, "PID = '00000000'")

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; My.ArcMap.Application.CurrentTool = Nothing
&amp;nbsp; End Sub

&amp;nbsp; Protected Overrides Sub OnUpdate()
&amp;nbsp;&amp;nbsp;&amp;nbsp; Enabled = My.ArcMap.Application IsNot Nothing
&amp;nbsp; End Sub


&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Sub SelectMapFeaturesByAttributeQuery(ByVal activeView As IActiveView, ByVal featureLayer As IFeatureLayer, ByVal whereClause As System.String)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If activeView Is Nothing OrElse featureLayer Is Nothing OrElse whereClause Is Nothing Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim featureSelection As IFeatureSelection = TryCast(featureLayer, IFeatureSelection) ' Dynamic Cast

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Set up the query
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim queryFilter As IQueryFilter = New QueryFilterClass
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryFilter.WhereClause = whereClause

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Invalidate only the selection cache. Flag the original selection
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Perform the selection
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; featureSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, False)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Flag the new selection
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:52:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745557#M19809</guid>
      <dc:creator>DaveCouture</dc:creator>
      <dc:date>2021-12-12T16:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Help with IFeatureLayer</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745558#M19810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;First off there is a difference between featureclass and featurelayer.&amp;nbsp; The featureclass is the data source (like a table) and the featurelayer is the representation of the data (like a report.)&amp;nbsp; The featurelayer may or may not have the same name as the featureclass.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You still have to loop through the layers of the map using the layer index and look for the layer name.&amp;nbsp; If you need to compare the featureclass name and get the featureclass from the featurelayer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jun 2012 14:21:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745558#M19810</guid>
      <dc:creator>AlexanderGray</dc:creator>
      <dc:date>2012-06-18T14:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Help with IFeatureLayer</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745559#M19811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Alexander. I understand what you are saying, but I have no idea how to do it (yet). I just started to learn VS2010 and ArcGIS 10. I'm familiar with VBA , but I'm not familiar with ArcGIS Development kit.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'll try to get it to work, nontheless!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let's assume there's only one layer (Feature Class), loaded in ArcMap. What would be the argument, then?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pMap = My.ArcMap.Document&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SelectMapFeaturesByAttributeQuery(pMap.ActiveView, pMap.Layer(0), "PID = '00000000'")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jun 2012 14:27:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745559#M19811</guid>
      <dc:creator>DaveCouture</dc:creator>
      <dc:date>2012-06-18T14:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help with IFeatureLayer</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745560#M19812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;No takers, eh?&amp;nbsp; I just need to know how to select the first layer, then I'm done!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jun 2012 16:04:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745560#M19812</guid>
      <dc:creator>DaveCouture</dc:creator>
      <dc:date>2012-06-18T16:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: Help with IFeatureLayer</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745561#M19813</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I wasn't going to reply, because it seemed more of a nitpick and me being somewhat rude.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, why would you mark a previous reply as the answer and still not have a solution to your problem?&amp;nbsp; Doesn't seem right.&amp;nbsp; I'm just saying what most people are probably thinking.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jun 2012 16:07:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745561#M19813</guid>
      <dc:creator>LeoDonahue</dc:creator>
      <dc:date>2012-06-18T16:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: Help with IFeatureLayer</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745562#M19814</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry, but he did give me a valid answer, but it wasn't the solution to my problem.&amp;nbsp; I just make a difference between the two, but I guess this forum works differently.&amp;nbsp; I can remove it, if that's the reason why I don';t get replies.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jun 2012 16:11:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745562#M19814</guid>
      <dc:creator>DaveCouture</dc:creator>
      <dc:date>2012-06-18T16:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: Help with IFeatureLayer</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745563#M19815</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm not saying remove Alexander's points, I'm just asking why mark a thread as answered when you still don't have the answer you need?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jun 2012 16:25:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745563#M19815</guid>
      <dc:creator>LeoDonahue</dc:creator>
      <dc:date>2012-06-18T16:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: Help with IFeatureLayer</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745564#M19816</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I made a mistake and I tried to change the Checkmark, but it didn't allowed me.&amp;nbsp; What was I suppose to do?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jun 2012 16:33:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745564#M19816</guid>
      <dc:creator>DaveCouture</dc:creator>
      <dc:date>2012-06-18T16:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: Help with IFeatureLayer</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745565#M19817</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, there a lot of things kind of strange with this forum...&amp;nbsp; People posting questions and then posting an answer and marking their own post as the answer post.&amp;nbsp; However, the points are browny points anyway and the value comes from the users not from the points.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As far as getting the correct layer, yes the code you posted should work as long as you have the option strict off (which I don't recommend.)&amp;nbsp; Option strict forces you to explicit cast (type conversion) to the specific type before you pass in an argument to a method.&amp;nbsp; In your case, your method signature calls for an IFeatureLayer.&amp;nbsp; Your method passes in an ILayer.&amp;nbsp; That works fine as long as the ILayer happens to be a FeatureLayer.&amp;nbsp; All FeatureLayers implement ILayer but lots of other types of layers implement ILayer such as grouplayer, rasterlayer, etc. and don't implement IFeatureLayer.&amp;nbsp; Explicitly casting your ILayer to IFeatureLayer is a better practice.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Dim fLayer as IfeatureLayer = ctype(pMap.Layer(0), IFeatureLayer) SelectMapFeaturesByAttributeQuery(pMap.ActiveView, flayer, "PID = '00000000'")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now there is always the chance the first layer in the map is not a featurelayer, in which case the first line would fail&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;if typeof pMap.Layer(0) is IFeatureLayer then &amp;nbsp; Dim fLayer as IfeatureLayer = ctype(pMap.Layer(0), IFeatureLayer) &amp;nbsp; SelectMapFeaturesByAttributeQuery(pMap.ActiveView, flayer, "PID = '00000000'") End if&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or better yet, trycast returns nothing if the cast fails&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Dim fLayer as IfeatureLayer = trycast(pMap.Layer(0), IFeatureLayer) if fLayer isnot Nothing then &amp;nbsp; SelectMapFeaturesByAttributeQuery(pMap.ActiveView, flayer, "PID = '00000000'") end if&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can write a for loop to go from 0 to pMap.LayerCount -1 and look at the layer of featureclass name.&amp;nbsp; However, if you hit a group layer, it will be skipped and you will never look at the sub layers and also the code will crash if your map is empty (you can check the layercount before calling.)&amp;nbsp; I prefer to use the IMap.Layers method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Dim featLayerUid As New UIDClass featLayerUid.Value = "{40A9E885-5533-11D0-98BE-00805F7CED21}" 'IFeatureLayer Dim enumLayer As IEnumLayer = pMap.Layers(featLayerUid , True)&amp;nbsp; 'True argument looks at sub layers in a group enumLayer.Reset() Dim layer As ILayer = enumLayer.Next Do While Not (layer Is Nothing) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dim fLayer as IFeatureLayer = CType(layer, IFeatureLayer) 'Guaranteed to work since only querying IFeatureLayers. &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ctype(fLayer.FeatureClass, IDataset).Name = "Name_I_am_looking_for" then &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelectMapFeaturesByAttributeQuery(pMap.ActiveView, fLayer, "PID = '00000000'") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit do &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end if &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer = enumLayer.Next() Loop&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jun 2012 16:34:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745565#M19817</guid>
      <dc:creator>AlexanderGray</dc:creator>
      <dc:date>2012-06-18T16:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Help with IFeatureLayer</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745566#M19818</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks a bunch - it's working!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jun 2012 17:10:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/help-with-ifeaturelayer/m-p/745566#M19818</guid>
      <dc:creator>DaveCouture</dc:creator>
      <dc:date>2012-06-18T17:10:33Z</dc:date>
    </item>
  </channel>
</rss>

