2

I am new to Python for ArcGIS, but have been using ArcGIS a while. I have a large directory of tables with point data. For each file of each folder I want to create a kernel density layer. I have managed to write a script that finds all the files (using os.walk) and creates an event layer however the resulting kernel density raster is blank, i.e. all cells have the same value.

When I use the GUI to create the kernel density, using the event layers that I created with the script the kernel density layer comes out beautifully.

I think it is the file formats that I'm having issues?? I tried different types but only .tif creates anything at all. Here is my function to run the kernel density after the file has been found and the event layer created.

def RunKernel(feature):
inFeatures = feature
populationField = "NONE"
cellSize = 1.5E-3
searchRadius = 5000

exten = ".tif" # extention of output file
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Execute KernelDensity
try:
    outKernelDensity = KernelDensity(inFeatures, populationField, cellSize,
                              searchRadius, "SQUARE_MAP_UNITS")

    featureName = feature.replace(".lyr", exten)

    print(featureName)
# Save the output 
    outKernelDensity.save(featureName)

    print (feature, "done")
except Exception as err:
    print(err)

closed as off-topic by PolyGeo Nov 3 '16 at 0:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    GetCount returns a geoprocessing result object. print(str(arcpy.GetCount_management(out_layer).getOutput(0))) and use int() to make it a number see resources.arcgis.com/en/help/main/10.1/index.html#//…. You are setting them to MGA94 Zone 55 but you say geographic.. what's up with that? Seriously though, there's a lot of code there, please limit it to just the bit that's causing problems please. While you're at it please remove 'help please' from your question title - it could be misinterpreted as a statement of urgency, which are frowned on. – Michael Stimson Jun 20 '15 at 1:24
  • I think this may be the key point to focus on within your broad question: "When I use the GUI to create the kernel density, using the event layers that I created with the script the kernel density layer comes out beautifully" I recommend that you repeat those steps using the tool dialogs and then use the Geoprocessing | Results window to Copy As Python Snippet from their successful runs. Once pasted into a test script, you should be able to make comparisons between what works in your test code and what doesn't in your larger script. – PolyGeo Jun 20 '15 at 4:51
  • Hi @Michael, sorry about the mix-up between saying geographic but using MGA94, it was something I was trying but didn't change back before copying my script. I feel like a fool. . . I'm new to the forum thing thanks for your help – pythonNovice Jun 21 '15 at 2:23
  • @PolyGeo I didn't know that you could do that! the snippet thing is great! – pythonNovice Jun 21 '15 at 2:27
  • Don't feel bad pythonNovice, I've seen much worse. Everybody here 'donates' their spare time and not many of us often feel like reading long posts, so it's in your best interest to shorten you question (get to the point) and if there's a few things you're unsure of post multiple questions (and include a link to the related questions). I think you need look at your workspace (arcpy.env.workspace), it could be creating what you want, just not where you can find it. Also have a look at os.path.splitext fn,fe = os.path.splitext(inFeatures) featureName = fn + exten – Michael Stimson Jun 21 '15 at 22:36

Browse other questions tagged or ask your own question.