<?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: How to stop raster loading from stopping arcpy script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-stop-raster-loading-from-stopping-arcpy/m-p/317047#M24649</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should really show the whole script&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;out_raster&amp;nbsp; &amp;nbsp;is a variable&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;today ... is it a string or date?&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;root .... what is root? a path to a folder?&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;"out_raster" .... where did you make a layer called out_raster? or are you referring to the previous variable?&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;"Density"&amp;nbsp; .... ditto, where do you make layers called "Density"&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;Getting hard to follow now.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 18 May 2020 23:53:55 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2020-05-18T23:53:55Z</dc:date>
    <item>
      <title>How to stop raster loading from stopping arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-raster-loading-from-stopping-arcpy/m-p/317046#M24648</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey all.&lt;/P&gt;&lt;P&gt;First question here and relatively new to arcpy, so please&amp;nbsp;bear with me.&lt;/P&gt;&lt;P&gt;I'm automating some mapping processes for my team (in this case kernel density generation, symbology changes, and layout exporting) and the last issue that has me confused is when running kernel density maps, the script stops running&amp;nbsp;&lt;STRONG&gt;a little after&amp;nbsp;&lt;/STRONG&gt;finishing the raster. This means it can run some more simple code (like print statements) before the script stops. There's no error message and pasting in the remaining code into the python window completes the process as it should have.I think that the script stops when the raster is actually loaded onto the map, which would explain the slight delay before stopping the script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #cc7832;"&gt;import &lt;/SPAN&gt;arcpy
&lt;SPAN style="color: #cc7832;"&gt;import &lt;/SPAN&gt;datetime
arcpy.env.workspace = &lt;SPAN style="color: #6a8759;"&gt;r"W:\Analytical Products\Austin Glass\Reports\2D\MVT TFA\MVT TFA Report.gdb"
&lt;/SPAN&gt;aprx = arcpy.mp.ArcGISProject(&lt;SPAN style="color: #6a8759;"&gt;"CURRENT"&lt;/SPAN&gt;)
map = aprx.listMaps(&lt;SPAN style="color: #6a8759;"&gt;"Map"&lt;/SPAN&gt;)[&lt;SPAN style="color: #6897bb;"&gt;0&lt;/SPAN&gt;]
lyt = aprx.listLayouts("Layout")[0]

today = &lt;SPAN style="color: #8888c6;"&gt;str&lt;/SPAN&gt;(datetime.date.today())
today = today.replace(&lt;SPAN style="color: #6a8759;"&gt;"-"&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6a8759;"&gt;"_"&lt;/SPAN&gt;)

in_table = &lt;SPAN style="color: #6a8759;"&gt;r"W:/Analytical Products/Austin Glass/Reports/2D/MVT TFA/" &lt;/SPAN&gt;+ today + &lt;SPAN style="color: #6a8759;"&gt;r".csv"
&lt;/SPAN&gt;out_feature_class = &lt;SPAN style="color: #6a8759;"&gt;'MVTTFA_' &lt;/SPAN&gt;+ today
x_coords = &lt;SPAN style="color: #6a8759;"&gt;"Offense Location GEOX"
&lt;/SPAN&gt;y_coords = &lt;SPAN style="color: #6a8759;"&gt;"Offense Location GEOY"

&lt;/SPAN&gt;arcpy.management.XYTableToPoint(in_table&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;out_feature_class&lt;SPAN style="color: #cc7832;"&gt;,
&lt;/SPAN&gt;                               x_coords&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;y_coords&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6a8759;"&gt;''&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;arcpy.SpatialReference(&lt;SPAN style="color: #6897bb;"&gt;26985&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6897bb;"&gt;115700&lt;/SPAN&gt;))

arcpy.env.extent = arcpy.Extent(&lt;SPAN style="color: #6897bb;"&gt;388004&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6897bb;"&gt;130267&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6897bb;"&gt;400000&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6897bb;"&gt;149167&lt;/SPAN&gt;)
out_raster = arcpy.sa.KernelDensity(&lt;SPAN style="color: #6a8759;"&gt;"MVTTFA_" &lt;/SPAN&gt;+ today&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6a8759;"&gt;"NONE"&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6897bb;"&gt;5&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6897bb;"&gt;500&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6a8759;"&gt;"SQUARE_METERS"&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6a8759;"&gt;"DENSITIES"&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6a8759;"&gt;"PLANAR"&lt;/SPAN&gt;); out_raster.save(&lt;SPAN style="color: #6a8759;"&gt;r"W:\Analytical Products\Austin Glass\Reports\2D\MVT TFA\MVT TFA Report.gdb\HM_" &lt;/SPAN&gt;+ today)
kernel = map.listLayers(&lt;SPAN style="color: #6a8759;"&gt;"out_raster"&lt;/SPAN&gt;)[&lt;SPAN style="color: #6897bb;"&gt;0&lt;/SPAN&gt;]
Density = map.listLayers(&lt;SPAN style="color: #6a8759;"&gt;"Density"&lt;/SPAN&gt;)[&lt;SPAN style="color: #6897bb;"&gt;0&lt;/SPAN&gt;]
arcpy.management.ApplySymbologyFromLayer(kernel&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;Density&lt;SPAN style="color: #cc7832;"&gt;, None, &lt;/SPAN&gt;&lt;SPAN style="color: #6a8759;"&gt;"UPDATE"&lt;/SPAN&gt;)

lyt.exportToJPEG(&lt;SPAN style="color: #6a8759;"&gt;r"W:/Analytical Products/Austin Glass/Reports/2D/MVT TFA/AutoMaps/" &lt;/SPAN&gt;+ today + &lt;SPAN style="color: #6a8759;"&gt;"_Density"&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6897bb;"&gt;300&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know if I need to provide additional info. I appreciate the help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:04:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-raster-loading-from-stopping-arcpy/m-p/317046#M24648</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-11T15:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop raster loading from stopping arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-raster-loading-from-stopping-arcpy/m-p/317047#M24649</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should really show the whole script&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;out_raster&amp;nbsp; &amp;nbsp;is a variable&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;today ... is it a string or date?&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;root .... what is root? a path to a folder?&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;"out_raster" .... where did you make a layer called out_raster? or are you referring to the previous variable?&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;"Density"&amp;nbsp; .... ditto, where do you make layers called "Density"&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;Getting hard to follow now.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2020 23:53:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-raster-loading-from-stopping-arcpy/m-p/317047#M24649</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2020-05-18T23:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop raster loading from stopping arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-raster-loading-from-stopping-arcpy/m-p/317048#M24650</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the feedback, Dan. The whole script is 150 lines long and only about 10% of it has any relevance to the issue, so I was reluctant to just drop the&amp;nbsp;whole thing. I've recreated the error with a smaller script and edited the original post to hopefully make it more legible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;out_raster is created by the kernel density tool in the line that it is first mentioned.&lt;/P&gt;&lt;P&gt;Density is the layer that I am importing the symbology from (color scheme and class count with class breaks being updated), and it is already present in the project.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 May 2020 11:39:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-raster-loading-from-stopping-arcpy/m-p/317048#M24650</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-05-19T11:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop raster loading from stopping arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/how-to-stop-raster-loading-from-stopping-arcpy/m-p/317049#M24651</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I found a workaround for this issue. By disabling arcpy.env.addOutputsToMap and manually saving+adding the raster to the map, the script stopping issue is avoided. At the end of the script, the original out_raster is still added to the map in addition to the one added via the addDataFromPath method, but this is not a concern for my current use case and so I'm not terribly concerned with it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've bolded the changes to the original code below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.env.extent = arcpy.Extent(388004, 130267, 400000, 149167)&lt;BR /&gt;&lt;STRONG&gt;arcpy.env.addOutputsToMap = 0&lt;/STRONG&gt;&lt;BR /&gt;out_raster = arcpy.sa.KernelDensity("MVTTFA_" + today, "NONE", 5, 500, "SQUARE_METERS", "DENSITIES", "PLANAR"); out_raster.save(r"W:\Analytical Products\Austin Glass\Reports\2D\MVT TFA\MVT TFA Report.gdb\HM_" + today)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;map.addDataFromPath(r"W:\Analytical Products\Austin Glass\Reports\2D\MVT TFA\MVT TFA Report.gdb\HM_" + today)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;arcpy.env.addOutputsToMap = 1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;kernel = map.listLayers("Kernel*")[0]&lt;/P&gt;&lt;P&gt;Density = map.listLayers("Density")[0]&lt;BR /&gt;arcpy.management.ApplySymbologyFromLayer(kernel, Density, None, "UPDATE")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2020 17:16:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-stop-raster-loading-from-stopping-arcpy/m-p/317049#M24651</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-07-31T17:16:25Z</dc:date>
    </item>
  </channel>
</rss>

