麻辣GIS微信平台

更多 GIS 干货

微信关注不错过

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 开发手册

相关阅读

麻辣GIS-Sailor

作者:

GIS爱好者,学GIS,更爱玩GIS。

声明

1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。

2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。

手机阅读
公众号关注
知识星球
手机阅读
麻辣GIS微信公众号关注
最新GIS干货
关注麻辣GIS知识星球
私享圈子

留言板(小编看到第一时间回复)