1

I am trying to make Employment Distribution of map of a given area in ArcGIS. All the employment information is in this one point shapefile from Census. Different fields show different number of employment for different industries. The Fields Now I want to use each field as population field input in Kernel Density tool. There are like 18 fields so I am wondering how I could use iterator or some other way to do it more efficiently.

The model I used is shown as below:

Model

What shall I do to finish this job?

This was marked as duplicated by Mods, which I understand. But I am just wondering if this could be done merely in ModelBuilder.

Bowen Liu
  • 663
  • 8
  • 18

1 Answers1

1

I dont think it is possible unless you use some coding. Either as a standalone script or imported into Modelbuilder. I Think you should use a standalone script which you can execute in the Python window:

import arcpy, os
from arcpy.sa import *

#Change to match your data:
input_fc=r'C:\TEST.gdb\polygon567'
out_folder=r'C:\TEST'

#List all fields that starts with c. Or you can specify them manually for example ['ce01','ce02']
fieldlist=[f.name for f in arcpy.ListFields(input_fc) if f.name.startswith('c')]

#Execute kernel density for each listed field
for field in fieldlist:
    outKernelDensity=KernelDensity(in_features=input_fc, population_field=field)
    outKernelDensity.save(os.path.join(out_folder,'Outraster_{0}.tif'.format(field)))

The outputs will for example be named

Outraster_ce01.tif

BERA
  • 72,339
  • 13
  • 72
  • 161
  • Thank you so much, but I couldn't get it through. The last step is the problem: Output raster: L:...\Distribution Maps\SaveTRY.gdb\Outraster_{0}.tif\cns01's workspace is an invalid output workspace. ERROR 000875. I have tried folder or file geodatabase. It just doesn't work. What shall I do to fix this? Thanks. – Bowen Liu Oct 19 '17 at 20:07
  • @AndrewLebron : I have changed the last line. I had a comma where there should be a dot (.format) – BERA Oct 19 '17 at 20:29
  • 1
    Thank you so much sir. That comma took me like 3 hours, but I still couldn't fix it haha. Rudimentary understanding of Arcpy. Couldn't do this without you. THANK YOU SO MUCH sir! BTW I don't know who downvoted you, this is like perfect. – Bowen Liu Oct 19 '17 at 20:44
  • Hi sir it's me again. Not sure if you can see this still. I've been learning Python a little bit so now I came back to see the Python code that helped me before. I don't quite get the part in your code with for loop and if statement: [f.name for f in arcpy.ListFields(input_fc) if f.name.startswith('c')] could you share a link where I can read or learn more on this please? Thanks a lot – Bowen Liu May 24 '18 at 13:38
  • Google list comprehension – BERA May 24 '18 at 19:49