AnsweredAssumed Answered

How to stop raster loading from stopping arcpy script

Question asked by austin.glass@dc.gov_DCGIS on May 18, 2020
Latest reply on Jul 31, 2020 by austin.glass@dc.gov_DCGIS

Hey all.

First question here and relatively new to arcpy, so please bear with me.

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 a little after 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.

 

 

 

import arcpy
import datetime
arcpy.env.workspace = r"W:\Analytical Products\Austin Glass\Reports\2D\MVT TFA\MVT TFA Report.gdb"
aprx = arcpy.mp.ArcGISProject("CURRENT")
map = aprx.listMaps("Map")[0]
lyt = aprx.listLayouts("Layout")[0]

today = str(datetime.date.today())
today = today.replace("-", "_")

in_table = r"W:/Analytical Products/Austin Glass/Reports/2D/MVT TFA/" + today + r".csv"
out_feature_class = 'MVTTFA_' + today
x_coords = "Offense Location GEOX"
y_coords = "Offense Location GEOY"

arcpy.management.XYTableToPoint(in_table, out_feature_class,
                               x_coords, y_coords, '', arcpy.SpatialReference(26985, 115700))

arcpy.env.extent = arcpy.Extent(388004, 130267, 400000, 149167)
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)
kernel = map.listLayers("out_raster")[0]
Density = map.listLayers("Density")[0]
arcpy.management.ApplySymbologyFromLayer(kernel, Density, None, "UPDATE")

lyt.exportToJPEG(r"W:/Analytical Products/Austin Glass/Reports/2D/MVT TFA/AutoMaps/" + today + "_Density", 300)

 

Let me know if I need to provide additional info. I appreciate the help.

Outcomes