Select to view content in your preferred language

silverlight image service display errors

1242
4
01-25-2012 05:32 AM
RyanKoehnen
Occasional Contributor
I have a couple of issues that I can't figure out when trying to control how and image service is displayed.

The first being, setting ArcGISImageServiceLayer.ImageFormat to anything but JPGPNG does not seem to have any effect. I know this because I have an image/raster with nodata values. JPG doesn't support transparency, and the silverlight app will not display nodata as transparent when using PNG8 or PNG24.

The second issue I'm having is with setting a colormap on a ArcGISImageServiceLayer that has negative values in the raster. Even though I am populating the colormap array with the proper values, all but the negative values are being displayed correctly. The negative values are being display as random colors or black. The negative values in this example are from -808 to 0. The image being served is an integer raster.

Anybody have a clue? Am I doing something incorrectly?

Sample code below and image attached-

    public class DisplayRaster : ICommand
    {

        #region ICommand members
        public void Execute(object parameter)
        {
            ArcGISImageServiceLayer aglLayer = new ArcGISImageServiceLayer()
            {
                Url = "https://gis.projectportal.net/ArcGIS/rest/services/2028-0001/CAG_Surface_Height_AGL/ImageServer",
                ProxyURL = "http://gis.projectportal.net/apps/cag_demo/proxy.ashx",
                ID = "HeightAGLLayer",
                ImageFormat = ArcGISImageServiceLayer.ImageServiceImageFormat.JPGPNG,
                NoData = 32767,
                Interpolation = ArcGISImageServiceLayer.ImageServiceInterpolation.NearestNeighbor,
                Visible = true
            };

            aglLayer.SetValue(MapApplication.LayerNameProperty, "Height AGL");

            aglLayer.Initialized += new EventHandler<EventArgs>(aglLayer_Initialized);

            MapApplication.Current.Map.Layers.Add(aglLayer);
        }

        void aglLayer_Initialized(object sender, EventArgs e)
        {
            ArcGISImageServiceLayer aglLayer = (ArcGISImageServiceLayer) MapApplication.Current.Map.Layers["HeightAGLLayer"];

            int[][] colormap = CreateColorMap(aglLayer);

            Dictionary<string, object> rasterParams = new Dictionary<string, object>();
            rasterParams.Add("Colormap", colormap);

            RenderingRule rr = new RenderingRule()
            {
                RasterFunctionName = "Colormap",
                VariableName = "Raster",
                RasterFunctionArguments = rasterParams
            };

            aglLayer.RenderingRule = rr;
            aglLayer.Refresh();
        }

        public bool CanExecute(object parameter)
        {
            // Return true so that the command can always be executed
            return true;
        }

        public event EventHandler CanExecuteChanged;

        #endregion

        private int[][] CreateColorMap(ArcGISImageServiceLayer aglLayer)
        {
            int maxValue = System.Convert.ToInt32(aglLayer.MaxValues[0]);
            //minValue in this example ends up being -808
            int minValue = System.Convert.ToInt32(aglLayer.MinValues[0]);
            int span = maxValue - minValue;

            int[][] colorMap = new int[span][];

            //set everything below 1000 to red, above 1000 to green
            for (int i = 0; i < span; i++)
            {
                if (minValue + i < 1000)
                    colorMap = new int[] { minValue + i, 255, 0, 0 };
                else
                    colorMap = new int[] { minValue + i, 0, 255, 0 };
            }

            return colorMap;
        }
    }
0 Kudos
4 Replies
RyanKoehnen
Occasional Contributor
Ok, to elaborate on this a little more, the part of the problem seems to be at the Rest export image request level. When I export the image directly through the Rest API web interface, two things are apparent, 1) export type of PNG does not honor the value I set for nodata to be transparent and 2) The only type that does work is tiff and when exported to tiff, I get the same erroneous pixels in the output. Sample from Rest export attached. Forum won't let me upload tiff, but png equivalent attached.

Any help would be appreciated.

-Ryan
0 Kudos
JenniferNery
Esri Regular Contributor
You can post to RESThttp://forums.arcgis.com/forums/11-ArcGIS-Server-REST-API. I will also forward your question to ImageServer team.
0 Kudos
RyanKoehnen
Occasional Contributor
You can post to RESThttp://forums.arcgis.com/forums/11-ArcGIS-Server-REST-API. I will also forward your question to ImageServer team.


I tested the service directly through the rest api and found that the problem was two fold. A) The nodata values were only being displayed correctly when I chose the JPGPNG or tiff option. In either of those two options it would give me a signed 16bit tiff. Otherwise if I chose PNG explicitly, it would give me a png but the nodata was not set to transparent. B) The tiff had the correct values and transparency in it, but it wasn't being displayed correctly. There's some range of negative values somewhere between 0 and -600 that don't play well with most imaging software including image previewers on Windows and Mac, Photoshop, and Gimp. Why this is, I have no idea. When I tested the values on the tiff in ArcMap they were correct. Regardless, rendering software outside of ArcMap would not display them correctly.

I did post to the Rest API forums, no one has spoke up over there yet. I also entered a support request directly. It would be helpful to get some feedback from the ImageServer team. We have some client commitments to meet that hinge on ImageServer working correctly in this scenario.
0 Kudos
WenxueJu
Esri Contributor
Ryan,

Thanks for providing more details, I posted some workarounds on REST API forum: http://forums.arcgis.com/threads/48593-Image-service-display-errors, could you check that out?

Wenxue
0 Kudos