Skip to main content
10 of 14
updated question, error, and script based on SQL integer/string issue

How to fix this Heatmap script from failing SQL expression (integer/string?) using arcpy (ArcMap 10.5)?

I have a heatmap script that will eventually print 10 PDF maps. At the moment it is failing at the SQL expression in the Make Feature Layer right before Kernel Density Raster creation because the column datatype is string. I'm having trouble changing it to an integer in the loop.

Traceback (most recent call last): File "\coacd.org\dfs\SWS\Code Enforcement\ACD Admin Operations\GIS\Operations\Council District Analysis Reporting\Auto_HeatMap_WIP\test.py", line 58, in int(stringA) ValueError: invalid literal for int() with base 10: '%d'

Here is the part of the script that is failing:

arcpy.CheckOutExtension('Spatial')
#use 'CURRENT' if running from arcmap, when published use MXD on disk
mxd = arcpy.mapping.MapDocument(workspace+"\\working_environment.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0] # address location data frame and turn on select layers
df.zoomToSelectedFeatures()



arcpy.env.extent = df.extent #set extent to current one
arcpy.env.overwriteOutput = True #overwrite existing files

my_point_features = autoLayerGDB +"\\coded_xy_points_FIPS4203"
scratch_output = workspace+"scratch"
    

#Select each district via script

or i in range(1, 11): stringA = '%d' int(stringA) my_clause = 'COUNCILDISTRICT =' + stringA % i my_filename = "kden_d%d" % i arcpy.MakeFeatureLayer_management(my_point_features, 'templyr', where_clause=my_clause,) outKDens = KernelDensity("templyr", "None", cell_size=100) outKDens.save(autoLayerGDB+"\"+my_filename) print("\tRaster created for District %d" % i)