rendering Kernel Density raster

2578
5
05-26-2014 08:17 AM
RyanClancy
Occasional Contributor
I have written a Python toolbox tool which among other things generates a raster via the Kernel Density tool. I have a .lyr file which is applied by the tool to the output. The .lyr sets the color palette and specifies an 8-class Natural Breaks classification. I've noticed that when the symbology is applied by the Python toolbox tool the resulting raster is very pixelated and generally looks pretty bad in ArcMap, but when I manually (ie. right-click, properties, apply symbology from .lyr) take that same output and apply that very same symbology using the exact same .lyr file, the raster is rendered very smoothly and looks quite nice.

Does geoprocessing use a different renderer than the layer properties dialog? Is there a way I can control how smoothly the raster is drawn via my Python code or via Geoprocessing options? The whole point is to automatically create a visually appealing result for the user but the way the surface is being rendered looks terrible unless I manually change it.
Tags (2)
0 Kudos
5 Replies
JimCousins
MVP Regular Contributor
I suspect that the interpolation is Natural neighbor, and the smoothed one is bilinear interpolation. I have applied symbology via a lyr file through a script successfully (using bilinear). It is possible that you have bilinear interpolation set as the default for raster data in ArcMap, and the python script is applying a lyr file that specifies natural neighbor. Recreate the lyr file, and be certain to set the display to bilinear, and try applying that.
Best Regards,
Jim
0 Kudos
RyanClancy
Occasional Contributor
Thanks for you response Jim.

The issue is indeed related to the display interpolation setting. My .lyr file has the display method saved as bilinear but for some reason the resulting raster layer always ends up with Nearest Neighbor. The resulting raster inherits all of the other parameters from the .lyr file -- color palette, number of classes, etc, but not the display interpolation method.

Aside from verifying the resampling method saved in the .lyr file, I've also tested the various environment settings:

1. Customize --> ArcMap Options --> Raster --> Raster Layer --> Enable Custom Rendering Defaults --> Display resampling = bilinear

2. Geoprocessing --> Environment Settings --> Raster Storage --> Build Pyramids --> Pyramid resampling technique = bilinear

I even added two lines to my Python code:

arcpy.env.resample = "BILINEAR"


and

arcpy.Resample_management(input, output, "#", "BILINEAR")


....no matter what I do I always end up with nearest neighbor. I must be missing something, I just can't see what it is.
0 Kudos
JimCousins
MVP Regular Contributor
Ryan, you seem to have covered all the possible settings, and I do not believe you have missed any. Perhaps it is time to use that annual maintenance fee, and try ESRI tech support.
Best Regards and good luck,
Jim
0 Kudos
RyanClancy
Occasional Contributor
Yep, I think you're right. If I get a solution from ESRI I'll post it here.

I found one option I hadn't tried yet but it didn't work either. For the record, it was SetRasterProperties_management. Apparently ArcMap will apply bilinear interpolation by default if it thinks it's got an elevation raster. So I tried using the SetRasterProperties method to change my raster from "generic" to "elevation". No dice though..... not only did I not get bilinear interpolation, the tool completed successfully but the raster Source Type was unchanged.
0 Kudos
RyanClancy
Occasional Contributor

No actual solution yet, but an acknowledgement of a bug. Progress!

Recent email from Tech Support:

This is just an update that in short, confirms that this issue is reproducible in-house.

arcpy.ApplySymbologyFromLayer_management faces the same issues as the Apply Symbology From Layer (Data Management) tool. Items in the Symbology tab are applied, and some items from the Display tab (like transparency) are applied, but 'Resample during display using:' is not applied. Furthermore, using the tool or code, the 'Resample during display using:' parameter is reset to Nearest Neighbor if the raster was originally set to Bilinear Interpolation (and the .lyr was set to Bilinear Interpolation as well). This happens for some raster datasets (i.e. those produced from Kernel Density - Spatial Analyst). As a result of this ticket, the following bug has been logged:

[#NIM103676  Apply Symbology From Layer (Data Management) sets 'Resample during display using:' in the Display tab to Nearest Neighbor. ]

0 Kudos