Example #1
0
        /// <summary>
        /// Applies the Stretch colorizer to the basic raster layer.
        /// </summary>
        /// <param name="basicRasterLayer">The basic raster layer is either a raster or image service layer, or the image sub-layer of the mosaic layer.</param>
        /// <returns></returns>
        public static async Task SetToStretchColorizer(BasicRasterLayer basicRasterLayer)
        {
            // Defines parameters in colorizer definition.
            int bandIndex = 0;
            RasterStretchType stretchType    = RasterStretchType.MinimumMaximum;
            double            gamma          = 2.0;
            string            colorRampStyle = "ArcGIS Colors";
            string            colorRampName  = "Aspect";

            await QueuedTask.Run(async() =>
            {
                // Gets a color ramp from a style.
                IList <ColorRampStyleItem> rampList = GetColorRampsFromStyleAsync(Project.Current, colorRampStyle, colorRampName);
                CIMColorRamp colorRamp = rampList[0].ColorRamp;

                // Creates a new Stretch Colorizer Definition with defined parameters.
                StretchColorizerDefinition stretchColorizerDef = new StretchColorizerDefinition(bandIndex, stretchType, gamma, colorRamp);

                // Creates a new stretch colorizer using the colorizer definition created above.
                CIMRasterStretchColorizer newColorizer = await basicRasterLayer.CreateColorizerAsync(stretchColorizerDef) as CIMRasterStretchColorizer;

                // Sets the newly created colorizer on the layer.
                basicRasterLayer.SetColorizer(newColorizer);
            });
        }
Example #2
0
        public static async Task DisplayRasterAsync(Uri rasterUri, string displayName, int transparency)
        {
            // parse the uri for the folder and file
            string strFileName   = null;
            string strFolderPath = null;

            if (rasterUri.IsFile)
            {
                strFileName   = System.IO.Path.GetFileName(rasterUri.LocalPath);
                strFolderPath = System.IO.Path.GetDirectoryName(rasterUri.LocalPath);
            }
            await QueuedTask.Run(() =>
            {
                RasterDataset rDataset = null;
                // Opens a file geodatabase. This will open the geodatabase if the folder exists and contains a valid geodatabase.
                using (Geodatabase geodatabase =
                           new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(strFolderPath))))
                {
                    // Use the geodatabase.
                    try
                    {
                        rDataset = geodatabase.OpenDataset <RasterDataset>(strFileName);
                    }
                    catch (GeodatabaseTableException e)
                    {
                        Debug.WriteLine("DisplayRasterAsync: Unable to open raster " + strFileName);
                        Debug.WriteLine("DisplayRasterAsync: " + e.Message);
                        return;
                    }
                }
                // Create a new colorizer definition using default constructor.
                StretchColorizerDefinition stretchColorizerDef = new StretchColorizerDefinition();
                RasterLayer rasterLayer = (RasterLayer)LayerFactory.Instance.CreateLayer(rasterUri, MapView.Active.Map);
                if (rasterLayer != null)
                {
                    rasterLayer.SetTransparency(transparency);
                    rasterLayer.SetName(displayName);
                }
            });
        }