Ejemplo n.º 1
0
        internal static void Render()
        {
            if (CboLayers.GetSelectedLayer() == null ||
                CboFields.GetSelectedField() == null ||
                s_selectedRenderer == null ||
                CboColors.GetSelectedColor() == null ||
                CboClasses.GetSelectedClass() == null)
            {
                return;
            }

            switch (s_selectedRenderer)
            {
            case "Simple Marker Renderer":
                MapUsingSimpleMarkerRenderer();
                break;

            case "Proportional Symbol Renderer":
                MapUsingProportionalSymbolRenderer();
                break;

            case "Simple Fill Renderer":
                MapUsingSimpleFillRenderer();
                break;

            case "Classbreaks Renderer":
                MapUsingClassbreaksRenderer();
                break;
            }
        }
Ejemplo n.º 2
0
        private static void MapUsingProportionalSymbolRenderer()
        {
            ISimpleMarkerSymbol marker = new SimpleMarkerSymbol();

            marker.Style = esriSimpleMarkerStyle.esriSMSCircle;

            ICmykColor markerColor = ColorbrewerExtension.GetSingleCMYKColor();

            marker.Size  = 10;
            marker.Color = markerColor;

            IMxDocument mxDoc = ArcMap.Application.Document as IMxDocument;
            IMap        map   = mxDoc.FocusMap;

            string          layerName = CboLayers.GetSelectedLayer();
            ILayer          layer     = GetLayerByName(layerName);
            IFeatureLayer   fLayer    = layer as IFeatureLayer;
            IFeatureClass   fClass    = fLayer.FeatureClass as IFeatureClass;
            IFeatureCursor  cursor    = fClass.Search(null, true);
            IDataStatistics dataStats = new DataStatisticsClass();

            dataStats.Cursor = cursor as ICursor;

            string fieldName = CboFields.GetSelectedField();

            dataStats.Field = fieldName;
            IStatisticsResults statResult = dataStats.Statistics;

            IProportionalSymbolRenderer propSymRenderer = new ProportionalSymbolRendererClass();

            propSymRenderer.Field                = fieldName;
            propSymRenderer.MinDataValue         = statResult.Minimum == 0.0 ? 1 : statResult.Minimum;
            propSymRenderer.MaxDataValue         = statResult.Maximum;
            propSymRenderer.FlanneryCompensation = true;
            propSymRenderer.ValueUnit            = esriUnits.esriUnknownUnits;
            propSymRenderer.MinSymbol            = marker as ISymbol;
            propSymRenderer.LegendSymbolCount    = 3;
            propSymRenderer.CreateLegendSymbols();

            IGeoFeatureLayer gFLayer = layer as IGeoFeatureLayer;

            gFLayer.Renderer = propSymRenderer as IFeatureRenderer;
            mxDoc.ActiveView.Refresh();
            mxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, gFLayer
                                            , mxDoc.ActiveView.Extent);
            mxDoc.UpdateContents();
        }
Ejemplo n.º 3
0
 protected override void OnUpdate()
 {
     Enabled = CboFields.GetSelectedField() != null;
 }
Ejemplo n.º 4
0
        private static void MapUsingClassbreaksRenderer()
        {
            string layerName = CboLayers.GetSelectedLayer();
            ILayer layer     = GetLayerByName(layerName);

            IFeatureLayer2 fLayer    = layer as IFeatureLayer2;
            string         fieldName = CboFields.GetSelectedField();

            // Get the number of classes
            string selectedClass   = CboClasses.GetSelectedClass();
            int    numberOfClasses = Convert.ToInt32(selectedClass);

            ITableHistogram tableHistogram = new TableHistogramClass();

            tableHistogram.Table = fLayer.FeatureClass as ITable;
            tableHistogram.Field = fieldName;
            IHistogram histo = tableHistogram as IHistogram;
            object     datavalues, datafrequencies;

            histo.GetHistogram(out datavalues, out datafrequencies);

            IClassify classify = new QuantileClass();

            classify.SetHistogramData(datavalues, datafrequencies);
            classify.Classify(ref numberOfClasses);

            if (numberOfClasses <= 1)
            {
                return;
            }

            double[] classBreaks = (double[])classify.ClassBreaks;

            IClassBreaksRenderer render = new ClassBreaksRenderer();

            render.Field        = fieldName;
            render.BreakCount   = numberOfClasses;
            render.MinimumBreak = classBreaks[0];

            // Get the colors
            ICmykColor[] colors = ColorbrewerExtension.GetCmykColors();
            IFillSymbol  fill   = null;

            // Iterate through the colors
            for (int i = 0; i < numberOfClasses; i++)
            {
                fill               = new SimpleFillSymbol();
                fill.Color         = colors[i];
                fill.Outline.Width = 0.5;
                render.Symbol[i]   = fill as ISymbol;
                render.Break[i]    = classBreaks[i + 1];
                render.Label[i]    = string.Format("{0} to {1}", classBreaks[i]
                                                   , classBreaks[i + 1]);
            }

            IGeoFeatureLayer gFLayer = layer as IGeoFeatureLayer;

            gFLayer.Renderer = render as IFeatureRenderer;
            IMxDocument mxDoc = ArcMap.Application.Document as IMxDocument;

            mxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, gFLayer
                                            , mxDoc.ActiveView.Extent);
            mxDoc.UpdateContents();
        }