Example #1
0
        private void OnUpdateRendererClicked(object sender, RoutedEventArgs e)
        {
            // Define the RasterLayer that will be used to display in the map
            RasterLayer rasterLayer_ForDisplayInMap;

            // Define the ColorRamp that will be used by the BlendRenderer
            ColorRamp myColorRamp;

            // Based on ColorRamp type chosen by the user, create a different
            // RasterLayer and define the appropriate ColorRamp option
            if (ColorRamps.SelectedValue.ToString() == "None")
            {
                // The user chose not to use a specific ColorRamp, therefore
                // need to create a RasterLayer based on general imagery (ie. Shasta.tif)
                // for display in the map and use null for the ColorRamp as one of the
                // parameters in the BlendRenderer constructor

                // Load the raster file using a path on disk
                Raster raster_Imagery = new Raster(GetRasterPath_Imagery());

                // Create the raster layer from the raster
                rasterLayer_ForDisplayInMap = new RasterLayer(raster_Imagery);

                // Set up the ColorRamp as being null
                myColorRamp = null;
            }
            else
            {
                // The user chose a specific ColorRamp (options: are Elevation, DemScreen, DemLight),
                // therefore create a RasterLayer based on an imagery with elevation
                // (ie. Shasta_Elevation.tif) for display in the map. Also create a ColorRamp
                // based on the user choice, translated into an Enumeration, as one of the parameters
                // in the BlendRenderer constructor

                // Load the raster file using a path on disk
                Raster raster_Elevation = new Raster(GetRasterPath_Elevation());

                // Create the raster layer from the raster
                rasterLayer_ForDisplayInMap = new RasterLayer(raster_Elevation);

                // Create a ColorRamp based on the user choice, translated into an Enumeration
                PresetColorRampType myPresetColorRampType = (PresetColorRampType)Enum.Parse(typeof(PresetColorRampType), ColorRamps.SelectedValue.ToString());
                myColorRamp = ColorRamp.Create(myPresetColorRampType, 256);
            }


            // Define the parameters used by the BlendRenderer constructor
            Raster raster_ForMakingBlendRenderer   = new Raster(GetRasterPath_Elevation());
            IEnumerable <double> myOutputMinValues = new List <double> {
                9
            };
            IEnumerable <double> myOutputMaxValues = new List <double> {
                255
            };
            IEnumerable <double> mySourceMinValues = new List <double>();
            IEnumerable <double> mySourceMaxValues = new List <double>();
            IEnumerable <double> myNoDataValues    = new List <double>();
            IEnumerable <double> myGammas          = new List <double>();
            SlopeType            mySlopeType       = (SlopeType)Enum.Parse(typeof(SlopeType), SlopeTypes.SelectedValue.ToString());

            BlendRenderer myBlendRenderer = new BlendRenderer(
                raster_ForMakingBlendRenderer, // elevationRaster - Raster based on a elevation source
                myOutputMinValues,             // outputMinValues - Output stretch values, one for each band
                myOutputMaxValues,             // outputMaxValues - Output stretch values, one for each band
                mySourceMinValues,             // sourceMinValues - Input stretch values, one for each band
                mySourceMaxValues,             // sourceMaxValues - Input stretch values, one for each band
                myNoDataValues,                // noDataValues - NoData values, one for each band
                myGammas,                      // gammas - Gamma adjustment
                myColorRamp,                   // colorRamp - ColorRamp object to use, could be null
                Altitude_Slider.Value,         // altitude - Altitude angle of the light source
                Azimuth_Slider.Value,          // azimuth - Azimuth angle of the light source, measured clockwise from north
                1,                             // zfactor - Factor to convert z unit to x,y units, default is 1
                mySlopeType,                   // slopeType - Slope Type
                1,                             // pixelSizeFactor - Pixel size factor, default is 1
                1,                             // pixelSizePower - Pixel size power value, default is 1
                8);                            // outputBitDepth - Output bit depth, default is 8-bi

            // Set the RasterLayer.Renderer to be the BlendRenderer
            rasterLayer_ForDisplayInMap.Renderer = myBlendRenderer;

            // Set the new base map to be the RasterLayer with the BlendRenderer applied
            MyMapView.Map.Basemap = new Basemap(rasterLayer_ForDisplayInMap);
        }
Example #2
0
        private async void OnUpdateRendererClicked(object sender, EventArgs e)
        {
            try
            {
                // Define the RasterLayer that will be used to display in the map
                RasterLayer rasterLayer_ForDisplayInMap;

                // Define the ColorRamp that will be used by the BlendRenderer
                ColorRamp myColorRamp;

                // Get the user choice for the ColorRamps
                UITableViewSource myUITableViewSource_ColorRamp = _ColorRamps.Source;
                TableSource       myTableSource_ColorRamp       = (TableSource)myUITableViewSource_ColorRamp;
                string            myColorRampChoice;

                if (myTableSource_ColorRamp.SelectedValue == null)
                {
                    // If the user does not click on a choice in the table but just clicks the
                    // button, the selected value will be null so use the initial ColorRamp option
                    myColorRampChoice = "Elevation";
                }
                else
                {
                    // The user clicked on an option in the table and thus the selected value
                    // will contain a valid choice
                    myColorRampChoice = myTableSource_ColorRamp.SelectedValue;
                }

                // Based on ColorRamp type chosen by the user, create a different
                // RasterLayer and define the appropriate ColorRamp option
                if (myColorRampChoice == "None")
                {
                    // The user chose not to use a specific ColorRamp, therefore
                    // need to create a RasterLayer based on general imagery (ie. Shasta.tif)
                    // for display in the map and use null for the ColorRamp as one of the
                    // parameters in the BlendRenderer constructor

                    // Load the raster file using a path on disk
                    Raster raster_Imagery = new Raster(await GetRasterPath_Imagery());

                    // Create the raster layer from the raster
                    rasterLayer_ForDisplayInMap = new RasterLayer(raster_Imagery);

                    // Set up the ColorRamp as being null
                    myColorRamp = null;
                }
                else
                {
                    // The user chose a specific ColorRamp (options: are Elevation, DemScreen, DemLight),
                    // therefore create a RasterLayer based on an imagery with elevation
                    // (ie. Shasta_Elevation.tif) for display in the map. Also create a ColorRamp
                    // based on the user choice, translated into an Enumeration, as one of the parameters
                    // in the BlendRenderer constructor

                    // Load the raster file using a path on disk
                    Raster raster_Elevation = new Raster(await GetRasterPath_Elevation());

                    // Create the raster layer from the raster
                    rasterLayer_ForDisplayInMap = new RasterLayer(raster_Elevation);

                    // Create a ColorRamp based on the user choice, translated into an Enumeration
                    PresetColorRampType myPresetColorRampType = (PresetColorRampType)Enum.Parse(typeof(PresetColorRampType), myColorRampChoice);
                    myColorRamp = ColorRamp.Create(myPresetColorRampType, 256);
                }


                // Define the parameters used by the BlendRenderer constructor
                Raster raster_ForMakingBlendRenderer   = new Raster(await GetRasterPath_Elevation());
                IEnumerable <double> myOutputMinValues = new List <double> {
                    9
                };
                IEnumerable <double> myOutputMaxValues = new List <double> {
                    255
                };
                IEnumerable <double> mySourceMinValues = new List <double> {
                };
                IEnumerable <double> mySourceMaxValues = new List <double> {
                };
                IEnumerable <double> myNoDataValues    = new List <double> {
                };
                IEnumerable <double> myGammas          = new List <double> {
                };

                // Get the user choice for the SlopeType
                UITableViewSource myUITableViewSource_SlopeType = _SlopeTypes.Source;
                TableSource       myTableSource_SlopeType       = (TableSource)myUITableViewSource_SlopeType;
                string            mySlopeTypeChoice;

                if (myTableSource_SlopeType.SelectedValue == null)
                {
                    // If the user does not click on a choice in the table but just clicks the
                    // button, the selected value will be null so use the initial SlopeType option
                    mySlopeTypeChoice = "Degree";
                }
                else
                {
                    // The user clicked on an option in the table and thus the selected value
                    // will contain a valid choice
                    mySlopeTypeChoice = myTableSource_SlopeType.SelectedValue;
                }

                SlopeType mySlopeType = (SlopeType)Enum.Parse(typeof(SlopeType), mySlopeTypeChoice);

                BlendRenderer myBlendRenderer = new BlendRenderer(
                    raster_ForMakingBlendRenderer, // elevationRaster - Raster based on a elevation source
                    myOutputMinValues,             // outputMinValues - Output stretch values, one for each band
                    myOutputMaxValues,             // outputMaxValues - Output stretch values, one for each band
                    mySourceMinValues,             // sourceMinValues - Input stretch values, one for each band
                    mySourceMaxValues,             // sourceMaxValues - Input stretch values, one for each band
                    myNoDataValues,                // noDataValues - NoData values, one for each band
                    myGammas,                      // gammas - Gamma adjustment
                    myColorRamp,                   // colorRamp - ColorRamp object to use, could be null
                    _Altitude_Slider.Value,        // altitude - Altitude angle of the light source
                    _Azimuth_Slider.Value,         // azimuth - Azimuth angle of the light source, measured clockwise from north
                    1,                             // zfactor - Factor to convert z unit to x,y units, default is 1
                    mySlopeType,                   // slopeType - Slope Type
                    1,                             // pixelSizeFactor - Pixel size factor, default is 1
                    1,                             // pixelSizePower - Pixel size power value, default is 1
                    8);                            // outputBitDepth - Output bit depth, default is 8-bi

                // Set the RasterLayer.Renderer to be the BlendRenderer
                rasterLayer_ForDisplayInMap.Renderer = myBlendRenderer;

                // Set the new base map to be the RasterLayer with the BlendRenderer applied
                _myMapView.Map.Basemap = new Basemap(rasterLayer_ForDisplayInMap);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }