<?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 How do I determine the type of data referenced in a layer file? in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-i-determine-the-type-of-data-referenced-in/m-p/258810#M6647</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to determine the type of data that is referenced in a layer file.&amp;nbsp; For example, I open a layer file that is referencing a raster dataset.&amp;nbsp; In code how do you determine that the layer file is referencing a raster dataset?&amp;nbsp; Right now I first use a 'try' block and QI to the IFeatureLayer interface.&amp;nbsp; If this fails then in the 'catch' block I QI to IRasterLayer.&amp;nbsp; I would rather first determine that the layer is pointing to a raster dataset and then use a 'switch/case' block to work with the appropriate interface.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My current method:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;string LayerFileLocation = "C:\SomeLayerFile.lyr";&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ILayerFile layerFile = new ESRI.ArcGIS.Carto.LayerFileClass();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;layerFile.Open(LayerFileLocation);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ILayer pLayer = layerFile.Layer;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IFeatureLayer2 pFeatureLayer2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IRasterLayer pRasterLayer;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;try&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; pFeatureLayer2 = (IFeatureLayer2)pLayer;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;catch&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; pRasterLayer = (IRasterLayer)pLayer;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dennis Geasan&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;GIS Technolgies&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 Oct 2010 22:46:58 GMT</pubDate>
    <dc:creator>DennisGeasan</dc:creator>
    <dc:date>2010-10-05T22:46:58Z</dc:date>
    <item>
      <title>How do I determine the type of data referenced in a layer file?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-i-determine-the-type-of-data-referenced-in/m-p/258810#M6647</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to determine the type of data that is referenced in a layer file.&amp;nbsp; For example, I open a layer file that is referencing a raster dataset.&amp;nbsp; In code how do you determine that the layer file is referencing a raster dataset?&amp;nbsp; Right now I first use a 'try' block and QI to the IFeatureLayer interface.&amp;nbsp; If this fails then in the 'catch' block I QI to IRasterLayer.&amp;nbsp; I would rather first determine that the layer is pointing to a raster dataset and then use a 'switch/case' block to work with the appropriate interface.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My current method:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;string LayerFileLocation = "C:\SomeLayerFile.lyr";&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ILayerFile layerFile = new ESRI.ArcGIS.Carto.LayerFileClass();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;layerFile.Open(LayerFileLocation);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ILayer pLayer = layerFile.Layer;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IFeatureLayer2 pFeatureLayer2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IRasterLayer pRasterLayer;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;try&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; pFeatureLayer2 = (IFeatureLayer2)pLayer;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;catch&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; pRasterLayer = (IRasterLayer)pLayer;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dennis Geasan&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;GIS Technolgies&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Oct 2010 22:46:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-i-determine-the-type-of-data-referenced-in/m-p/258810#M6647</guid>
      <dc:creator>DennisGeasan</dc:creator>
      <dc:date>2010-10-05T22:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine the type of data referenced in a layer file?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-i-determine-the-type-of-data-referenced-in/m-p/258811#M6648</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You just need to check the type using Is in C#:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If (layer Is IFeatureLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;// do something&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ElseIf (layer Is IRasterLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;// do something&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It would be nice if you could use a Switch block to do this instead of a bunch of Else/ElseIfs but I don't think you can do that.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Oct 2010 13:23:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-i-determine-the-type-of-data-referenced-in/m-p/258811#M6648</guid>
      <dc:creator>NeilClemmons</dc:creator>
      <dc:date>2010-10-06T13:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine the type of data referenced in a layer file?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-i-determine-the-type-of-data-referenced-in/m-p/258812#M6649</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So that's what Is is!&amp;nbsp; Thanks Neil.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Oct 2010 22:38:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-i-determine-the-type-of-data-referenced-in/m-p/258812#M6649</guid>
      <dc:creator>DennisGeasan</dc:creator>
      <dc:date>2010-10-12T22:38:18Z</dc:date>
    </item>
  </channel>
</rss>

