Esempio n. 1
0
        private void GenerateRangeValueClick(object sender, System.Windows.RoutedEventArgs e)
        {
            ClassBreaksDefinition classBreaksDefinition = new ClassBreaksDefinition()
            {
                ClassificationField       = "SQMI",
                ClassificationMethod      = ClassificationMethod.StandardDeviation,
                BreakCount                = 5,
                StandardDeviationInterval = ESRI.ArcGIS.Client.Tasks.StandardDeviationInterval.OneQuarter
            };

            classBreaksDefinition.ColorRamps.Add(new ColorRamp()
            {
                From      = Colors.Blue,
                To        = Colors.Red,
                Algorithm = Algorithm.HSVAlgorithm
            });

            GenerateRendererParameters rendererParams = new GenerateRendererParameters()
            {
                ClassificationDefinition = classBreaksDefinition,
                Where = "STATE_NAME NOT IN ('Alaska', 'Hawaii')"
            };

            generateRendererTask.ExecuteAsync(rendererParams, rendererParams.Where);
        }
        private void RenderButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            ObservableCollection <ColorRamp> colorRamps = new ObservableCollection <ColorRamp>();

            colorRamp = new ColorRamp()
            {
                From      = ((StartColorListBox.SelectedItem as ListBoxItem).Background as SolidColorBrush).Color,
                To        = ((EndColorListBox.SelectedItem as ListBoxItem).Background as SolidColorBrush).Color,
                Algorithm = (Algorithm)AlgorithmListBox.SelectedItem,
            };
            colorRamps.Add(colorRamp);

            generateClassesParameters.ClassificationDefinition = new ClassBreaksDefinition()
            {
                BaseSymbol = new ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol()
                {
                    Fill = (ColorRampListBox.SelectedItem as ListBoxItem).Background
                },
                ClassificationField  = ((ClassificationFieldListBox.SelectedItem) as Field).Name,
                ClassificationMethod = (ClassificationMethod)ClassificationMethodListBox.SelectedItem,

                BreakCount = int.Parse(BreakCountTB.Text.Trim()),
                ColorRamps = colorRamps,
            };

            ClassBreaksDefinition classBreakDef =
                generateClassesParameters.ClassificationDefinition as ClassBreaksDefinition;

            if (classBreakDef.ClassificationMethod == ClassificationMethod.StandardDeviation)
            {
                classBreakDef.StandardDeviationInterval = (StandardDeviationInterval)IntervalListBox.SelectedItem;
            }

            if (NormalizationTypeListBox.SelectedItem != null)
            {
                classBreakDef.NormalizationType = (NormalizationType)NormalizationTypeListBox.SelectedItem;

                if (classBreakDef.NormalizationType == NormalizationType.Field)
                {
                    if (NormalizationFieldListBox.SelectedItem != null)
                    {
                        classBreakDef.NormalizationField = ((NormalizationFieldListBox.SelectedItem) as Field).Name;
                    }
                    else
                    {
                        MessageBox.Show("Normalization Field must be selected");
                        return;
                    }
                }
            }
            if (generateRendererTask.IsBusy)
            {
                generateRendererTask.CancelAsync();
            }
            generateRendererTask.ExecuteAsync(generateClassesParameters);

            ThematicPropertiesPage.IsOpen = false;
        }
Esempio n. 3
0
        public StatisticsRenderOnMap()
        {
            InitializeComponent();

            subRegionGraphicsLayer = MyMap.Layers["SumGraphicsLayer"] as GraphicsLayer;

            // Generate a unique value renderer on the server
            GenerateRendererTask generateRendererTask = new GenerateRendererTask();

            generateRendererTask.Url = _layerUrl;

            generateRendererTask.ExecuteCompleted += (o, e) =>
            {
                subRegionGraphicsLayer.Renderer = e.GenerateRendererResult.Renderer;
            };

            UniqueValueDefinition uniqueValueDefinition = new UniqueValueDefinition()
            {
                Fields = new List <string>()
                {
                    "SUB_REGION"
                }
            };

            uniqueValueDefinition.ColorRamps.Add(new ColorRamp()
            {
                From      = Colors.Purple,
                To        = Colors.Yellow,
                Algorithm = Algorithm.LabLChAlgorithm
            });

            GenerateRendererParameters rendererParams = new GenerateRendererParameters()
            {
                ClassificationDefinition = uniqueValueDefinition,
            };

            generateRendererTask.ExecuteAsync(rendererParams);

            // When layers initialized, return all states, generate statistics for a group,
            // union graphics based on grouped statistics
            MyMap.Layers.LayersInitialized += (a, b) =>
            {
                QueryTask queryTask1     = new QueryTask(_layerUrl);
                Query     queryAllStates = new Query()
                {
                    ReturnGeometry      = true,
                    OutSpatialReference = MyMap.SpatialReference,
                    Where = "1=1"
                };
                queryAllStates.OutFields.Add("SUB_REGION");

                queryTask1.ExecuteCompleted += (c, d) =>
                {
                    // Return statistics for states layer. Population and total count of states grouped by sub-region.
                    QueryTask queryTask2 = new QueryTask(_layerUrl);
                    Query     query      = new Query()
                    {
                        GroupByFieldsForStatistics = new List <string> {
                            "SUB_REGION"
                        },

                        OutStatistics = new List <OutStatistic> {
                            new OutStatistic()
                            {
                                OnStatisticField      = "POP2000",
                                OutStatisticFieldName = "SubRegionPopulation",
                                StatisticType         = StatisticType.Sum
                            },
                            new OutStatistic()
                            {
                                OnStatisticField      = "SUB_REGION",
                                OutStatisticFieldName = "NumberOfStates",
                                StatisticType         = StatisticType.Count
                            }
                        }
                    };
                    queryTask2.ExecuteCompleted += (e, f) =>
                    {
                        // foreach group (sub-region) returned from statistic results
                        foreach (Graphic regionGraphic in f.FeatureSet.Features)
                        {
                            // Collection of graphics based on sub-region
                            IEnumerable <Graphic> toUnion =
                                (f.UserState as FeatureSet).Features.Where(stateGraphic =>
                                                                           (string)stateGraphic.Attributes["SUB_REGION"] ==
                                                                           (string)regionGraphic.Attributes["SUB_REGION"]);

                            // Union graphics based on sub-region, add to graphics layer
                            GeometryService geometryService =
                                new GeometryService("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer");
                            geometryService.UnionCompleted += (g, h) =>
                            {
                                Graphic unionedGraphic = h.UserState as Graphic;
                                unionedGraphic.Geometry = h.Result;
                                subRegionGraphicsLayer.Graphics.Add(unionedGraphic);
                            };
                            geometryService.UnionAsync(toUnion.ToList(), regionGraphic);
                        }

                        // populate the ListBox
                        FeatureSet featureSet = f.FeatureSet;
                        if (featureSet != null && featureSet.Features.Count > 0)
                        {
                            OutStatisticsListBox.ItemsSource = featureSet.Features;
                        }
                    };

                    queryTask2.ExecuteAsync(query, d.FeatureSet);
                };

                queryTask1.ExecuteAsync(queryAllStates);
            };
        }
        public StatisticsRenderOnMap()
        {
            InitializeComponent();

            subRegionGraphicsLayer = MyMap.Layers["SumGraphicsLayer"] as GraphicsLayer;

            // Generate a unique value renderer on the server
            GenerateRendererTask generateRendererTask = new GenerateRendererTask();
            generateRendererTask.Url = _layerUrl;

            generateRendererTask.ExecuteCompleted += (o, e) =>
            {
                subRegionGraphicsLayer.Renderer = e.GenerateRendererResult.Renderer;
            };

            UniqueValueDefinition uniqueValueDefinition = new UniqueValueDefinition()
            {
                Fields = new List<string>() { "SUB_REGION" }
            };

            uniqueValueDefinition.ColorRamps.Add(new ColorRamp()
            {
                From = Colors.Purple,
                To = Colors.Yellow,
                Algorithm = Algorithm.LabLChAlgorithm
            });

            GenerateRendererParameters rendererParams = new GenerateRendererParameters()
            {
                ClassificationDefinition = uniqueValueDefinition,
            };

            generateRendererTask.ExecuteAsync(rendererParams);

            // When layers initialized, return all states, generate statistics for a group,
            // union graphics based on grouped statistics
            MyMap.Layers.LayersInitialized += (a, b) =>
              {
                  QueryTask queryTask1 = new QueryTask(_layerUrl);
                  Query queryAllStates = new Query()
                  {
                      ReturnGeometry = true,
                      OutSpatialReference = MyMap.SpatialReference,
                      Where = "1=1"
                  };
                  queryAllStates.OutFields.Add("SUB_REGION");

                  queryTask1.ExecuteCompleted += (c, d) =>
                      {
                          // Return statistics for states layer. Population and total count of states grouped by sub-region.
                          QueryTask queryTask2 = new QueryTask(_layerUrl);
                          Query query = new Query()
                          {
                              GroupByFieldsForStatistics = new List<string> { "SUB_REGION" },

                              OutStatistics = new List<OutStatistic> {
                                new OutStatistic(){
                                    OnStatisticField = "POP2000",
                                    OutStatisticFieldName = "SubRegionPopulation",
                                    StatisticType = StatisticType.Sum
                                },
                                new OutStatistic(){
                                    OnStatisticField = "SUB_REGION",
                                    OutStatisticFieldName = "NumberOfStates",
                                    StatisticType = StatisticType.Count
                                }
                             }
                          };
                          queryTask2.ExecuteCompleted += (e, f) =>
                          {
                              // foreach group (sub-region) returned from statistic results
                              foreach (Graphic regionGraphic in f.FeatureSet.Features)
                              {
                                  // Collection of graphics based on sub-region
                                  IEnumerable<Graphic> toUnion =
                                      (f.UserState as FeatureSet).Features.Where(stateGraphic =>
                                          (string)stateGraphic.Attributes["SUB_REGION"] ==
                                          (string)regionGraphic.Attributes["SUB_REGION"]);

                                  // Union graphics based on sub-region, add to graphics layer
                                  GeometryService geometryService =
                                      new GeometryService("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer");
                                  geometryService.UnionCompleted += (g, h) =>
                                  {
                                      Graphic unionedGraphic = h.UserState as Graphic;
                                      unionedGraphic.Geometry = h.Result;
                                      subRegionGraphicsLayer.Graphics.Add(unionedGraphic);
                                  };
                                  geometryService.UnionAsync(toUnion.ToList(), regionGraphic);
                              }

                              // populate the ListBox
                              FeatureSet featureSet = f.FeatureSet;
                              if (featureSet != null && featureSet.Features.Count > 0)
                              {
                                  OutStatisticsListBox.ItemsSource = featureSet.Features;
                              }
                          };

                          queryTask2.ExecuteAsync(query, d.FeatureSet);
                      };

                  queryTask1.ExecuteAsync(queryAllStates);
              };
        }
Esempio n. 5
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            layer = (map.Layers[0] as ArcGISDynamicMapServiceLayer);
            DynamicLayerInfoCollection myDynamicLayerInfos = layer.DynamicLayerInfos;

            if (myDynamicLayerInfos == null)
            {
                myDynamicLayerInfos = layer.CreateDynamicLayerInfosFromLayerInfos();
            }

            #region TableDataSource
            DynamicLayerInfo info = new DynamicLayerInfo()
            {
                ID     = 1,
                Source = new LayerDataSource()
                {
                    DataSource = new QueryDataSource()
                    {
                        GeometryType = ESRI.ArcGIS.Client.Tasks.GeometryType.Polyline,
                        OIDFields    = new string[] { "OBJECTID" },
                        Query        = "SELECT * FROM  SDE.china_road where FNODE_ > 1000",
                        WorkspaceID  = "MyDatabaseWorkspaceID"
                    }
                }
            };
            #endregion

            #region QueryDataSource
            DynamicLayerInfo info = new DynamicLayerInfo()
            {
                ID     = 1,
                Source = new LayerDataSource()
                {
                    DataSource = new QueryDataSource()
                    {
                        GeometryType = ESRI.ArcGIS.Client.Tasks.GeometryType.Polyline,
                        OIDFields    = new string[] { "OBJECTID" },
                        Query        = "SELECT * FROM  SDE.china_road where FNODE_ > 1000",
                        WorkspaceID  = "MyDatabaseWorkspaceID"
                    }
                }
            };
            #endregion

            #region UserDefine Simple Render Line
            //LayerDrawingOptions layerDrawOptions = new LayerDrawingOptions();
            //layerDrawOptions.LayerID = 1;
            //layerDrawOptions.Renderer = new SimpleRenderer()
            //{
            //	Symbol = new SimpleLineSymbol()
            //	{
            //		Color = new SolidColorBrush(Color.FromArgb((int)255, (int)0, (int)0, (int)255)),
            //		Width = 2
            //	}
            //};

            //layer.LayerDrawingOptions = new LayerDrawingOptionsCollection() { layerDrawOptions };
            #endregion

            #region UserDefine Simple Render Poly
            LayerDrawingOptions layerDrawOptions = new LayerDrawingOptions();
            layerDrawOptions.LayerID  = 1;
            layerDrawOptions.Renderer = new SimpleRenderer()
            {
                Symbol = new SimpleFillSymbol()
                {
                    Fill = new SolidColorBrush(Color.FromArgb((int)255, (int)0, (int)0, (int)255)),
                }
            };

            layer.LayerDrawingOptions =
                new LayerDrawingOptionsCollection()
            {
                layerDrawOptions
            };
            #endregion

            #region JoinDataSource
            DynamicLayerInfo info = new DynamicLayerInfo()
            {
                ID     = 1,
                Source = new LayerDataSource()
                {
                    DataSource = new JoinDataSource()
                    {
                        JoinType        = JoinType.LeftInnerJoin,
                        LeftTableSource = new LayerDataSource()
                        {
                            DataSource = new TableDataSource()
                            {
                                DataSourceName = "SDE.china_county",
                                WorkspaceID    = "MyDatabaseWorkspaceID"
                            }
                        },
                        LeftTableKey     = "OBJECTID",
                        RightTableSource = new LayerDataSource()
                        {
                            DataSource = new TableDataSource()
                            {
                                DataSourceName = "SDE.china_road",
                                WorkspaceID    = "MyDatabaseWorkspaceID"
                            }
                        },
                        RightTableKey = "OBJECTID"
                    }
                }
            };
            #endregion

            #region RasterDataSource
            //DynamicLayerInfo info = new DynamicLayerInfo()
            //{
            //	ID = 1,
            //	Source = new LayerDataSource()
            //	{
            //		DataSource = new RasterDataSource()
            //		{
            //			DataSourceName = "rr1",
            //			WorkspaceID = "MyRasterWorkspaceID"
            //		}
            //	}
            //};
            #endregion

            myDynamicLayerInfos.Add(info);
            layer.DynamicLayerInfos = myDynamicLayerInfos;


            layer.VisibleLayers = new int[] { 1 };
            //layer.Refresh();
            //map.ZoomTo(new Envelope(11.8435360079, 49.4443060783, 11.8568721432, 49.4528247773));
            //map.ZoomTo(layer.Layers[1].e)

            #region Generate Render Class Break
            ClassBreaksDefinition classBreaksDefinition = new ClassBreaksDefinition()
            {
                ClassificationField       = "FNODE_",
                ClassificationMethod      = ClassificationMethod.StandardDeviation,
                BreakCount                = 10,
                StandardDeviationInterval = ESRI.ArcGIS.Client.Tasks.StandardDeviationInterval.OneQuarter
            };
            classBreaksDefinition.ColorRamps.Add(new ColorRamp()
            {
                From      = Colors.Blue,
                To        = Colors.Red,
                Algorithm = Algorithm.HSVAlgorithm
            });

            GenerateRendererParameters rendererParams = new GenerateRendererParameters()
            {
                ClassificationDefinition = classBreaksDefinition,
                Source = info.Source
            };

            generateRendererTask.ExecuteAsync(rendererParams, rendererParams.Where);
            #endregion

            #region Generate Render Unique Value
            UniqueValueDefinition uniqueValueDefinition = new UniqueValueDefinition()
            {
                Fields = new List <string>()
                {
                    "FNODE_"
                }
            };
            uniqueValueDefinition.ColorRamps.Add(new ColorRamp()
            {
                From      = Colors.Blue,
                To        = Colors.Red,
                Algorithm = Algorithm.CIELabAlgorithm
            });

            GenerateRendererParameters rendererParams = new GenerateRendererParameters()
            {
                ClassificationDefinition = uniqueValueDefinition,
                Source = info.Source
            };

            generateRendererTask.ExecuteAsync(rendererParams, rendererParams.Where);
            #endregion
        }