ArcGIS Engine 10 开发手册(7-8)ArcGIS Engine分类图调用示例

本文目录
  • 正文

本文介绍使用ArcGIS Engine调用接口生成分类图的方法。

示例:分类渲染代码

代码如下:

public class ClassRender

{

  public ClassRender (AxMapControl pMapControl, IFeatureLayer pFtLayer, int ClassCount, string pFieldName)

  {

    IGeoFeatureLayer pGeolayer;

    IActiveView pActiveView;

    pGeolayer = pFtLayer as IGeoFeatureLayer;
    pActiveView = pMapControl.ActiveView;

    //以下是为了统计和分类所需要的对象 ITable pTable;

    IClassifyGEN pClassify; //C\#要作为分类对象。 
    ITableHistogram pTableHist; //相当于一个统计表 
    IBasicHistogram pBasicHist; //这个对象有一个很重要的方法 
    double[] ClassNum;

    int ClassCountResult; //返回分类个数。 IHsvColor pFromColor;

    IHsvColor pToColor; //用于构建另外一个颜色带对象。 IAlgorithmicColorRamp pAlgo;

    pTable = pGeolayer as ITable;
    IMap pMap;

    pMap = pMapControl.Map;

    pMap.ReferenceScale = 0;

    pBasicHist = new BasicTableHistogramClass (); //也可以实例化pTableHist 
    pTableHist = pBasicHist as ITableHistogram;

    pTableHist.Table = pTable;
    pTableHist.Field = pFieldName;
    object datavalus;

    object Frenquen;

    pBasicHist.GetHistogram (out datavalus, out Frenquen); //获得数据和相应的频数。
    pClassify = new EqualIntervalClass ();
    try

    {
      pClassify.Classify (datavalus, Frenquen, ref ClassCount);

    } catch (Exception e)

    {

      MessageBox.Show (e.Message);

    }

    // 分类完成

    ClassNum = (double\[\]) pClassify.ClassBreaks;

    ClassCountResult = ClassNum.GetUpperBound (0); //返回分级个数。 
    IClassBreaksRenderer pClassBreak;

    pClassBreak = new ClassBreaksRendererClass ();
    pClassBreak.Field = pFieldName;
    pClassBreak.BreakCount = ClassCountResult;
    pClassBreak.SortClassesAscending = true;

    pAlgo = new AlgorithmicColorRampClass ();

    pAlgo.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
    pFromColor = Hsv (60, 100, 96);

    pToColor = Hsv (0, 100, 96);
    pAlgo.FromColor = pFromColor;
    pAlgo.ToColor = pToColor;
    pAlgo.Size = ClassCountResult;
    bool ok;

    pAlgo.CreateRamp (out ok);
    IEnumColors pEnumColor;
    pEnumColor = pAlgo.Colors;
    pEnumColor.Reset ();

    IColor pColor;
    ISimpleFillSymbol pSimFill;

    for (int indexColor = 0; indexColor <= ClassCountResult - 1; indexColor++)

    {

      pColor = pEnumColor.Next ();

      pSimFill = new SimpleFillSymbolClass ();
      pSimFill.Color = pColor;

      // pSimFill.Color = pRgbColor[indexColor ]; 
      pSimFill.Style = esriSimpleFillStyle.esriSFSSolid;

      //染色

      pClassBreak.set_Symbol (indexColor, pSimFill as ISymbol);
      pClassBreak.set_Break (indexColor, ClassNum[indexColor + 1]);

    }

    pGeolayer.Renderer = pClassBreak as IFeatureRenderer;

    pActiveView.PartialRefresh (esriViewDrawPhase.esriViewGeography, null,null);

  }

  public IHsvColor Hsv (int hue, int saturation, int val)

  {

    IHsvColor pHsvC;

    pHsvC = new HsvColorClass ();
    pHsvC.Hue = hue;
    pHsvC.Saturation = saturation;
    pHsvC.Value = val;

    return pHsvC;

  }

  public IRgbColor ColorRgb (int r, int g, int b)

  {

    IRgbColor pRGB;

    pRGB = new RgbColorClass ();
    pRGB.Red = r;

    pRGB.Green = g;

    pRGB.Blue = b;
    return pRGB;

  }

}

运行结果

ArcGIS Engine 10 开发手册全集

ArcGIS Engine 10 开发手册全集: ArcGIS Engine 10 开发手册

如果本文对你有所帮助,欢迎对我们团队进行打赏捐助,让我们在传播3S的路上可以走得更远。
赞赏支持
微信捐助麻辣GIS 支付宝捐助麻辣GIS

麻辣GIS-Sailor
作者:
GIS爱好者,学GIS,更爱玩GIS。

如您有疑问,可在文末留言,或到QQ群中提问。

本站QQ群(一):291616564 麻辣GIS

本站QQ群(二):166408035 麻辣GIS(二)

本站QQ群(三):627853279 麻辣GIS(三)

微信公众号:malagis,扫描右边二维码直接关注。

发表评论