<?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: AddLayer loads imagery with incorrect colors in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692654#M53706</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for your help Jason.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Scott&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 17 Oct 2013 19:28:10 GMT</pubDate>
    <dc:creator>ScottOatley</dc:creator>
    <dc:date>2013-10-17T19:28:10Z</dc:date>
    <item>
      <title>AddLayer loads imagery with incorrect colors</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692648#M53700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My arcpy script uses the arcpy.mapping.AddLayer() function to add imagery raster datasets to the TOC. However, the symbology is defaulted to blue stretched rather than the appropriate RGB or grey stretched for color or b&amp;amp;w images respectively.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This doesn't happen if I drag-and-drop from Arc Catalog, a windows folder, or use the add data button.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any idea why this happens?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Scott&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Oct 2013 21:38:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692648#M53700</guid>
      <dc:creator>ScottOatley</dc:creator>
      <dc:date>2013-10-16T21:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: AddLayer loads imagery with incorrect colors</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692649#M53701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Use the &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Make_Raster_Layer/00170000006t000000/"&gt;Make Raster Layer function&lt;/A&gt;&lt;SPAN&gt;, don't create &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;arcpy.mapping.Layer&lt;/SPAN&gt;&lt;SPAN&gt; objects directly from raster datasets. It will add them to the TOC with the correct symbology.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Oct 2013 22:13:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692649#M53701</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-10-16T22:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: AddLayer loads imagery with incorrect colors</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692650#M53702</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried replacing this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;field = 'FILENAME'
cursor = arcpy.SearchCursor(myRefLayer)
for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; path = row.getValue(field)
&amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.mapping.Layer(path)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, addLayer, 'TOP')
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;with this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;field = 'FILENAME'
cursor = arcpy.SearchCursor(myRefLayer)
for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; path = row.getValue(field)
&amp;nbsp;&amp;nbsp;&amp;nbsp; name = os.path.basename(path)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeRasterLayer_management(path, name)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The former loads the imagery with the weird colors; the latter doesn't load any images. Is there something additional required with the MakeRasterLayer function? It didn't seem so from the help pages. I did try adding a RefreshTOC(), but that didn't change the result.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Scott&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:08:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692650#M53702</guid>
      <dc:creator>ScottOatley</dc:creator>
      <dc:date>2021-12-12T05:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: AddLayer loads imagery with incorrect colors</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692651#M53703</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How are you running this code? As a script tool?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;field = 'FILENAME' cursor = arcpy.SearchCursor(myRefLayer) for row in cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp; fullpath = row.getValue(field) &amp;nbsp;&amp;nbsp;&amp;nbsp; path = os.path.dirname(fullpath) &amp;nbsp;&amp;nbsp;&amp;nbsp; name = os.path.basename(fullpath) &amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.management.MakeRasterLayer(path, name)[0] &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, addLayer, 'TOP')&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Oct 2013 17:43:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692651#M53703</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-10-17T17:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: AddLayer loads imagery with incorrect colors</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692652#M53704</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm running this as a script from a toolbox; sorry, forgot to mention that initially.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I made a slight change to your code, and the rasters load correctly as you said they would. I used the path including the file name as the first parameter to MakeRasterLayer rather than just the dir name. This also worked nicely to load mosaic datasets.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;field = 'FILENAME'
cursor = arcpy.SearchCursor(myRefLayer)
for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; path = row.getValue(field)
#&amp;nbsp;&amp;nbsp;&amp;nbsp; path = os.path.dirname(fullpath)
&amp;nbsp;&amp;nbsp;&amp;nbsp; name = os.path.basename(path)
&amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.management.MakeRasterLayer(path, name)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, addLayer, 'TOP')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A couple of follow-up questions...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When do I code using arcpy.management.&amp;lt;function&amp;gt;() versus arcpy.&amp;lt;function&amp;gt;_management() syntax?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Eventually I'll want to put this code in an one of my addIns. Should I expect it to work pretty much as is?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Scott&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:08:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692652#M53704</guid>
      <dc:creator>ScottOatley</dc:creator>
      <dc:date>2021-12-12T05:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: AddLayer loads imagery with incorrect colors</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692653#M53705</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN style="font-family:Courier New;"&gt;arcpy.management.&amp;lt;function&amp;gt;()&lt;/SPAN&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;arcpy.&amp;lt;function&amp;gt;_management()&lt;/SPAN&gt;&lt;SPAN&gt; are functionally equivalent, it's a matter of personal preference.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Once it's an add-in, just calling the tool should add it to the TOC without the AddLayer part.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Oct 2013 19:14:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692653#M53705</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-10-17T19:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: AddLayer loads imagery with incorrect colors</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692654#M53706</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for your help Jason.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Scott&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Oct 2013 19:28:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-loads-imagery-with-incorrect-colors/m-p/692654#M53706</guid>
      <dc:creator>ScottOatley</dc:creator>
      <dc:date>2013-10-17T19:28:10Z</dc:date>
    </item>
  </channel>
</rss>

