Ejemplo n.º 1
0
        /// <summary>
        /// Renders a feature layer using graduated symbols and natural breaks to draw quantities.
        /// ![cb-symbols.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/cb-symbols.png "Graduated symbols with natural breaks renderer.")
        /// </summary>
        /// <returns>
        /// </returns>
        internal static Task CBRendererGraduatedSymbols()
        {
            //Check feature layer name
            //Code works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data
            var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(f => f.Name == "USDemographics");

            if (featureLayer == null)
            {
                MessageBox.Show("This renderer works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data", "Data missing");
                return(Task.FromResult(0));
            }
            return(QueuedTask.Run(() =>
            {
                GraduatedSymbolsRendererDefinition gsDef = new GraduatedSymbolsRendererDefinition()
                {
                    ClassificationField = SDKHelpers.GetNumericField(featureLayer), //getting the first numeric field
                    ClassificationMethod = ClassificationMethod.NaturalBreaks,
                    MinimumSymbolSize = 4,
                    MaximumSymbolSize = 50,
                    BreakCount = 5,
                    ColorRamp = SDKHelpers.GetColorRamp(), //getting a color ramp
                };
                CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(gsDef);
                featureLayer?.SetRenderer(renderer);
            }));
        }
        /// <summary>
        /// Renders a feature layer using an unclassed color gradient.
        /// ![cb-unclassed.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/cb-unclassed.png "Class breaks unclassed renderer.")
        /// </summary>
        /// <returns>
        /// </returns>
        internal static Task UnclassedRenderer()
        {
            //Check feature layer name
            //Code works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data
            var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(f => f.Name == "U.S. National Transportation Atlas Interstate Highways");

            if (featureLayer == null)
            {
                MessageBox.Show("This renderer works with the U.S. National Transportation Atlas Interstate Highways feature layer available with the ArcGIS Pro SDK Sample data", "Data missing");
                return(Task.FromResult(0));
            }
            return(QueuedTask.Run(() =>
            {
                //Gets the first numeric field of the feature layer
                var firstNumericFieldOfFeatureLayer = SDKHelpers.GetNumericField(featureLayer);
                //Gets the min and max value of the field
                var labels = SDKHelpers.GetFieldMinMax(featureLayer, firstNumericFieldOfFeatureLayer);
                UnclassedColorsRendererDefinition ucDef = new UnclassedColorsRendererDefinition()
                {
                    Field = firstNumericFieldOfFeatureLayer,
                    ColorRamp = SDKHelpers.GetColorRamp(),
                    LowerColorStop = Convert.ToDouble(labels.Item1),
                    UpperColorStop = Convert.ToDouble(labels.Item2),
                    UpperLabel = labels.Item2,
                    LowerLabel = labels.Item1,
                };
                CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(ucDef);
                featureLayer?.SetRenderer(renderer);
            }));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Renders a feature layer using graduated colors and manual intervals to draw quantities.
        ///  ![cb-colors-manual-breaks.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/cb-colors-manual-breaks.png "Graduated colors with manual intervals renderer.")
        /// </summary>
        /// <returns></returns>
        internal static Task CBGraduatedColorsManualBreaks()
        {
            //Check feature layer name
            //Code works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data
            var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(f => f.Name == "USDemographics");

            if (featureLayer == null)
            {
                MessageBox.Show("This renderer works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data", "Data missing");
                return(Task.FromResult(0));
            }
            //Change these class breaks to be appropriate for your data. These class breaks defined below apply to the US States feature class
            List <CIMClassBreak> listClassBreaks = new List <CIMClassBreak>
            {
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB).MakeSymbolReference(),
                    UpperBound = 24228
                },
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreenRGB).MakeSymbolReference(),
                    UpperBound = 67290
                },
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlueRGB).MakeSymbolReference(),
                    UpperBound = 121757
                },
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreyRGB).MakeSymbolReference(),
                    UpperBound = 264435
                },
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.WhiteRGB).MakeSymbolReference(),
                    UpperBound = 576594
                }
            };

            return(QueuedTask.Run(() =>
            {
                CIMClassBreaksRenderer cimClassBreakRenderer = new CIMClassBreaksRenderer
                {
                    ClassBreakType = ClassBreakType.GraduatedColor,
                    ClassificationMethod = ClassificationMethod.Manual,
                    Field = SDKHelpers.GetNumericField(featureLayer),
                    //Important to add the Minimum break for your data to be classified correctly.
                    //This is vital especially if you have data with negative values.
                    //MinimumBreak =
                    Breaks = listClassBreaks.ToArray()
                };

                featureLayer?.SetRenderer(cimClassBreakRenderer);
            }));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Renders a feature layer using graduated colors to draw quantities. The outline width is varied based on attributes.
        /// ![graduatedColorOutline.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/graduatedColorOutline.png "Graduated colors with natural breaks renderer.")
        /// </summary>
        /// <returns></returns>
        internal static Task CBRendererGraduatedColorsOutlineAsync()
        {
            //Check feature layer name
            //Code works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data
            var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(f => f.Name == "USDemographics");

            if (featureLayer == null)
            {
                MessageBox.Show("This renderer works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data", "Data missing");
                return(Task.FromResult(0));
            }
            return(QueuedTask.Run(() =>
            {
                //Gets the first numeric field of the feature layer
                var firstNumericFieldOfFeatureLayer = SDKHelpers.GetNumericField(featureLayer);
                //Gets the min and max value of the field
                var minMax = SDKHelpers.GetFieldMinMax(featureLayer, firstNumericFieldOfFeatureLayer);
                GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition()
                {
                    ClassificationField = SDKHelpers.GetNumericField(featureLayer),
                    ClassificationMethod = ClassificationMethod.NaturalBreaks,
                    BreakCount = 5,
                    ColorRamp = SDKHelpers.GetColorRamp()
                };
                CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(gcDef);
                //Create array of CIMVisualVariables to hold the outline information.
                var visualVariables = new CIMVisualVariable[] {
                    new CIMSizeVisualVariable
                    {
                        ValueExpressionInfo = new CIMExpressionInfo
                        {
                            Title = "Custom",
                            Expression = "$feature.AREA",
                            ReturnType = ExpressionReturnType.Default
                        },
                        AuthoringInfo = new CIMVisualVariableAuthoringInfo
                        {
                            MinSliderValue = Convert.ToDouble(minMax.Item1),
                            MaxSliderValue = Convert.ToDouble(minMax.Item2),
                            ShowLegend = false,
                            Heading = firstNumericFieldOfFeatureLayer
                        },
                        VariableType = SizeVisualVariableType.Graduated,
                        Target = "outline",
                        MinSize = 1,
                        MaxSize = 13,
                        MinValue = Convert.ToDouble(minMax.Item1),
                        MaxValue = Convert.ToDouble(minMax.Item2)
                    },
                };
                renderer.VisualVariables = visualVariables;
                featureLayer?.SetRenderer(renderer);
            }));
        }
 /// <summary>
 /// Renders a feature layer using graduated colors to draw quantities.
 /// ![cb-colors.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/cb-colors.png "Graduated colors with natural breaks renderer.")
 /// </summary>
 /// <param name="featureLayer"></param>
 /// <returns>
 /// </returns>
 internal static async Task CBRendererGraduatedColors(FeatureLayer featureLayer)
 {
     await QueuedTask.Run(() =>
     {
         GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition()
         {
             ClassificationField  = SDKHelpers.GetNumericField(featureLayer),
             ClassificationMethod = ClassificationMethod.NaturalBreaks,
             BreakCount           = 5,
             ColorRamp            = SDKHelpers.GetColorRamp(),
         };
         CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(gcDef);
         featureLayer?.SetRenderer(renderer);
     });
 }
        /// <summary>
        /// Renders a feature layer using graduated colors and manual intervals to draw quantities.
        ///  ![cb-colors-manual-breaks.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/cb-colors-manual-breaks.png "Graduated colors with manual intervals renderer.")
        /// </summary>
        /// <param name="featureLayer"></param>
        /// <returns></returns>
        internal static Task CBGraduatedColorsManualBreaks(FeatureLayer featureLayer)
        {
            //Change these class breaks to be appropriate for your data. These class breaks defined below apply to the US States feature class
            List <CIMClassBreak> listClassBreaks = new List <CIMClassBreak>
            {
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB).MakeSymbolReference(),
                    UpperBound = 24228
                },
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreenRGB).MakeSymbolReference(),
                    UpperBound = 67290
                },
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlueRGB).MakeSymbolReference(),
                    UpperBound = 121757
                },
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreyRGB).MakeSymbolReference(),
                    UpperBound = 264435
                },
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.WhiteRGB).MakeSymbolReference(),
                    UpperBound = 576594
                }
            };

            return(QueuedTask.Run(() =>
            {
                CIMClassBreaksRenderer cimClassBreakRenderer = new CIMClassBreaksRenderer
                {
                    ClassBreakType = ClassBreakType.GraduatedColor,
                    ClassificationMethod = ClassificationMethod.Manual,
                    Field = SDKHelpers.GetNumericField(featureLayer),
                    //Important to add the Minimum break for your data to be classified correctly.
                    //This is vital especially if you have data with negative values.
                    //MinimumBreak =
                    Breaks = listClassBreaks.ToArray()
                };

                featureLayer?.SetRenderer(cimClassBreakRenderer);
            }));
        }
 /// <summary>
 /// Renders a feature layer using graduated symbols and natural breaks to draw quantities.
 /// ![cb-symbols.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/cb-symbols.png "Graduated symbols with natural breaks renderer.")
 /// </summary>
 /// <param name="featureLayer"></param>
 /// <returns>
 /// </returns>
 internal static async Task CBRendererGraduatedSymbols(FeatureLayer featureLayer)
 {
     await QueuedTask.Run(() =>
     {
         GraduatedSymbolsRendererDefinition gsDef = new GraduatedSymbolsRendererDefinition()
         {
             ClassificationField  = SDKHelpers.GetNumericField(featureLayer), //getting the first numeric field
             ClassificationMethod = ClassificationMethod.NaturalBreaks,
             MinimumSymbolSize    = 4,
             MaximumSymbolSize    = 50,
             BreakCount           = 5,
             ColorRamp            = SDKHelpers.GetColorRamp(), //getting a color ramp
         };
         CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(gsDef);
         featureLayer?.SetRenderer(renderer);
     });
 }
 /// <summary>
 /// Renders a feature layer using graduated colors to draw quantities. The outline width is varied based on attributes.
 /// ![graduatedColorOutline.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/graduatedColorOutline.png "Graduated colors with natural breaks renderer.")
 /// </summary>
 /// <param name="featureLayer"></param>
 /// <returns></returns>
 internal static Task CBRendererGraduatedColorsOutline(FeatureLayer featureLayer)
 {
     return(QueuedTask.Run(() =>
     {
         //Gets the first numeric field of the feature layer
         var firstNumericFieldOfFeatureLayer = SDKHelpers.GetNumericField(featureLayer);
         //Gets the min and max value of the field
         var minMax = SDKHelpers.GetFieldMinMax(featureLayer, firstNumericFieldOfFeatureLayer);
         GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition()
         {
             ClassificationField = SDKHelpers.GetNumericField(featureLayer),
             ClassificationMethod = ClassificationMethod.NaturalBreaks,
             BreakCount = 5,
             ColorRamp = SDKHelpers.GetColorRamp()
         };
         CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(gcDef);
         //Create array of CIMVisualVariables to hold the outline information.
         var visualVariables = new CIMVisualVariable[] {
             new CIMSizeVisualVariable
             {
                 ValueExpressionInfo = new CIMExpressionInfo
                 {
                     Title = "Custom",
                     Expression = "$feature.AREA",
                     ReturnType = ExpressionReturnType.Default
                 },
                 AuthoringInfo = new CIMVisualVariableAuthoringInfo
                 {
                     MinSliderValue = Convert.ToDouble(minMax.Item1),
                     MaxSliderValue = Convert.ToDouble(minMax.Item2),
                     ShowLegend = false,
                     Heading = firstNumericFieldOfFeatureLayer
                 },
                 VariableType = SizeVisualVariableType.Graduated,
                 Target = "outline",
                 MinSize = 1,
                 MaxSize = 13,
                 MinValue = Convert.ToDouble(minMax.Item1),
                 MaxValue = Convert.ToDouble(minMax.Item2)
             },
         };
         renderer.VisualVariables = visualVariables;
         featureLayer?.SetRenderer(renderer);
     }));
 }
        /// <summary>
        /// Renders a feature layer using graduated colors and manual intervals to draw quantities.
        ///  ![cb-colors-manual-breaks.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/cb-colors-manual-breaks.png "Graduated colors with manual intervals renderer.")
        /// </summary>
        /// <param name="featureLayer"></param>
        /// <returns></returns>
        internal static async Task CBGraduatedColorsManualBreaks(FeatureLayer featureLayer)
        {
            //Change these class breaks to be appropriate for your data. These class breaks defined below apply to the US States feature class
            List <CIMClassBreak> listClassBreaks = new List <CIMClassBreak>
            {
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB).MakeSymbolReference(),
                    UpperBound = 24228
                },
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreenRGB).MakeSymbolReference(),
                    UpperBound = 67290
                },
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlueRGB).MakeSymbolReference(),
                    UpperBound = 121757
                },
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreyRGB).MakeSymbolReference(),
                    UpperBound = 264435
                },
                new CIMClassBreak
                {
                    Symbol     = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.WhiteRGB).MakeSymbolReference(),
                    UpperBound = 576594
                }
            };
            await QueuedTask.Run(() =>
            {
                CIMClassBreaksRenderer cimClassBreakRenderer = new CIMClassBreaksRenderer
                {
                    ClassBreakType       = ClassBreakType.GraduatedColor,
                    ClassificationMethod = ClassificationMethod.Manual,
                    Field  = SDKHelpers.GetNumericField(featureLayer),
                    Breaks = listClassBreaks.ToArray()
                };

                featureLayer?.SetRenderer(cimClassBreakRenderer);
            });
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Renders a feature layer using an unclassed color gradient.
 /// ![cb-unclassed.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/cb-unclassed.png "Class breaks unclassed renderer.")
 /// </summary>
 /// <param name="featureLayer"></param>
 /// <returns>
 /// </returns>
 internal static Task UnclassedRenderer(FeatureLayer featureLayer)
 {
     return(QueuedTask.Run(() =>
     {
         //Gets the first numeric field of the feature layer
         var firstNumericFieldOfFeatureLayer = SDKHelpers.GetNumericField(featureLayer);
         //Gets the min and max value of the field
         var labels = SDKHelpers.GetFieldMinMax(featureLayer, firstNumericFieldOfFeatureLayer);
         UnclassedColorsRendererDefinition ucDef = new UnclassedColorsRendererDefinition()
         {
             Field = firstNumericFieldOfFeatureLayer,
             ColorRamp = SDKHelpers.GetColorRamp(),
             LowerColorStop = Convert.ToDouble(labels.Item1),
             UpperColorStop = Convert.ToDouble(labels.Item2),
             UpperLabel = labels.Item2,
             LowerLabel = labels.Item1,
         };
         CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(ucDef);
         featureLayer?.SetRenderer(renderer);
     }));
 }
        private void ExecuteRenderingClick()
        {
            // コンボ ボックスでレイヤー、フィールド、レンダリング手法が選択されているかをチェックする
            if (_selectedRenderingLayer is null)
            {
                MessageBox.Show("レイヤーを選択してください。");
            }
            else if (_selectedField is null)
            {
                MessageBox.Show("フィールドを選択してください。");
            }
            else if (_selectedRenderingMethod is null)
            {
                MessageBox.Show("レンダリング手法を選択してください。");
            }
            else
            {
                try
                {
                    // レンダラー作成の処理を実装
                    QueuedTask.Run(() =>
                    {
                        // レイヤー名で検索してマップ上のレイヤーを取得する
                        var lyr = MapView.Active.Map.FindLayers(_selectedRenderingLayer.Name).FirstOrDefault() as FeatureLayer;

                        // 「ArcGIS カラー」(ArcGIS Pro の表示言語が英語の場合は、「ArcGIS Colors」を指定)プロジェクト スタイル アイテムを取得
                        StyleProjectItem style = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS カラー");

                        // 名前で検索してカラーランプ アイテムを取得する(ArcGIS Pro の表示言語が英語の場合は、「Spectrum - Full Light」を指定)
                        IList <ColorRampStyleItem> colorRampList = style.SearchColorRamps("フル スペクトル (明るい)");

                        if (_selectedRenderingMethod == "個別値レンダリング")
                        {
                            // 個別値レンダラーの定義を作成する
                            UniqueValueRendererDefinition uvrDef = new
                                                                   UniqueValueRendererDefinition()
                            {
                                ValueFields = new String[] { _selectedField },   // 分類に使用するフィールド
                                ColorRamp   = colorRampList[0].ColorRamp,        // カラーランプ
                            };

                            // 個別値レンダラーを作成する
                            CIMUniqueValueRenderer cimRenderer = (CIMUniqueValueRenderer)lyr.CreateRenderer(uvrDef);
                            // レンダラーをレイヤーに設定する
                            lyr.SetRenderer(cimRenderer);
                        }
                        else // 等級色レンダリングの場合
                        {
                            if (GetNumericField(lyr, _selectedField)) // 数値型のフィールドを選択している場合のみ実行する
                            {
                                // 等級色レンダラーの定義を作成する
                                GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition()
                                {
                                    ClassificationField  = _selectedField,                     // 分類に使用するフィールド
                                    ColorRamp            = colorRampList[0].ColorRamp,         // カラーランプ
                                    ClassificationMethod = ClassificationMethod.NaturalBreaks, // 分類方法(自然分類)
                                    BreakCount           = 5,                                  // 分類数(5段階で分類)
                                };

                                // 等級色(クラス分類)レンダラーを作成する
                                CIMClassBreaksRenderer cimClassBreakRenderer = (CIMClassBreaksRenderer)lyr.CreateRenderer(gcDef);
                                // レンダラーをレイヤーに設定する
                                lyr.SetRenderer(cimClassBreakRenderer);
                            }
                        }
                    });
                }
                catch (Exception)
                {
                    MessageBox.Show("レンダリングに失敗しました。");
                }
            }
        }