zoukankan      html  css  js  c++  java
  • ArcEngine栅格和矢量渲染(含可视化颜色带)

    使用ArcEngine9.3开发的栅格和矢量的渲染。

    开发环境:ArcEngine9.3,VS2008。

    功能:栅格(拉伸和分级)和矢量(简单、唯一值、分级、比例)渲染。

    开发界面如图所示。

    图1 主界面

    图2 栅格渲染界面

    图3 矢量渲染界面

    部分源码:

      1 public void SimpleRenderer(IFeatureLayer featLayer, string fieldName, IColorRamp colorRamp)
      2         {
      3             IGeoFeatureLayer pGeoFeatureLayer = featLayer as IGeoFeatureLayer;
      4             IFeatureClass pFeatureClass = featLayer.FeatureClass;      //获取图层上的featureClass            
      5             IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
      6             IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();   //唯一值渲染器
      7             //设置渲染字段对象
      8             pUniqueValueRenderer.FieldCount = 1;
      9             pUniqueValueRenderer.set_Field(0, fieldName);
     10             ISimpleFillSymbol pSimFillSymbol = new SimpleFillSymbolClass();   //创建填充符号
     11             pUniqueValueRenderer.DefaultSymbol = (ISymbol)pSimFillSymbol;
     12             pUniqueValueRenderer.UseDefaultSymbol = false;
     13             int n = pFeatureClass.FeatureCount(null);
     14             for (int i = 0; i < n; i++)
     15             {
     16                 IFeature pFeature = pFeatureCursor.NextFeature();
     17                 IClone pSourceClone = pSimFillSymbol as IClone;
     18                 ISimpleFillSymbol pSimpleFillSymbol = pSourceClone.Clone() as ISimpleFillSymbol;
     19                 string pFeatureValue = pFeature.get_Value(pFeature.Fields.FindField(fieldName)).ToString();
     20                 pUniqueValueRenderer.AddValue(pFeatureValue, "", (ISymbol)pSimpleFillSymbol);
     21 
     22             }
     23 
     24             //为每个符号设置颜色
     25 
     26             for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++)
     27             {
     28                 string xv = pUniqueValueRenderer.get_Value(i);
     29 
     30                 if (xv != "")
     31                 {
     32                     ISimpleFillSymbol pNextSymbol = (ISimpleFillSymbol)pUniqueValueRenderer.get_Symbol(xv);
     33                     pNextSymbol.Color = colorRamp.get_Color(127);
     34                     pUniqueValueRenderer.set_Symbol(xv, (ISymbol)pNextSymbol);
     35                 }
     36             }
     37 
     38             pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
     39         }
     40 
     41         public void UniqueRenderer(IFeatureLayer featLayer, string fieldName, IColorRamp colorRamp)
     42         {
     43             IGeoFeatureLayer pGeoFeatureLayer = featLayer as IGeoFeatureLayer;
     44             IFeatureClass pFeatureClass = featLayer.FeatureClass;      //获取图层上的featureClass            
     45             IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
     46             IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();   //唯一值渲染器
     47             //设置渲染字段对象
     48             pUniqueValueRenderer.FieldCount = 1;
     49             pUniqueValueRenderer.set_Field(0, fieldName);
     50             ISimpleFillSymbol pSimFillSymbol = new SimpleFillSymbolClass();   //创建填充符号
     51             pUniqueValueRenderer.DefaultSymbol = (ISymbol)pSimFillSymbol;
     52             pUniqueValueRenderer.UseDefaultSymbol = false;
     53             int n = pFeatureClass.FeatureCount(null);
     54             for (int i = 0; i < n; i++)
     55             {
     56                 IFeature pFeature = pFeatureCursor.NextFeature();
     57                 IClone pSourceClone = pSimFillSymbol as IClone;
     58                 ISimpleFillSymbol pSimpleFillSymbol = pSourceClone.Clone() as ISimpleFillSymbol;
     59                 string pFeatureValue = pFeature.get_Value(pFeature.Fields.FindField(fieldName)).ToString();
     60                 pUniqueValueRenderer.AddValue(pFeatureValue, "", (ISymbol)pSimpleFillSymbol);
     61 
     62             }
     63 
     64             //为每个符号设置颜色
     65 
     66             for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++)
     67             {
     68                 string xv = pUniqueValueRenderer.get_Value(i);
     69 
     70                 if (xv != "")
     71                 {
     72                     ISimpleFillSymbol pNextSymbol = (ISimpleFillSymbol)pUniqueValueRenderer.get_Symbol(xv);
     73                     //pColor = ramp.get_Color(j * (ramp.Size - 1) / (count - 1));
     74                     pNextSymbol.Color = colorRamp.get_Color(i * (colorRamp.Size-1) / (pUniqueValueRenderer.ValueCount-1));
     75                     pUniqueValueRenderer.set_Symbol(xv, (ISymbol)pNextSymbol);
     76                 }
     77             }
     78 
     79             pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
     80         }
     81 
     82         public void ClassRenderer(IFeatureLayer featLayer, string fieldName, IColorRamp colorRamp, int count)
     83         {
     84             //值分级
     85             IBasicHistogram pBasicHis = new BasicTableHistogramClass();
     86             ITableHistogram pTabHis = (ITableHistogram)pBasicHis;
     87             //贫困发生率
     88             IClassifyGEN pClassify = new EqualIntervalClass();
     89             pTabHis.Field = fieldName;
     90             //IGeoFeatureLayer geolayer = (IGeoFeatureLayer)Layer;
     91             ILayer Layer = (ILayer)featLayer;
     92             ITable pTab = (ITable)Layer;
     93             pTabHis.Table = pTab;
     94             object doubleArrVal, longArrFreq;
     95             pBasicHis.GetHistogram(out doubleArrVal, out longArrFreq);
     96 
     97             int nDes = count;
     98             pClassify.Classify(doubleArrVal, longArrFreq, ref nDes);
     99             object classes = pClassify.ClassBreaks;
    100             double[] ClassNum;
    101             ClassNum = (double[])pClassify.ClassBreaks;
    102             int ClassCountResult = ClassNum.GetUpperBound(0);
    103             IClassBreaksRenderer pRender = new ClassBreaksRendererClass();
    104             pRender.BreakCount = ClassCountResult;
    105             pRender.Field = fieldName;
    106             ISimpleFillSymbol pSym;
    107             IColor pColor;
    108             for (int j = 0; j < ClassCountResult; j++)
    109             {
    110                 pColor = colorRamp.get_Color(j * (colorRamp.Size-1) / (ClassCountResult-1));
    111                 pSym = new SimpleFillSymbolClass();
    112                 pSym.Color = pColor;
    113                 pRender.set_Symbol(j, (ISymbol)pSym);
    114                 pRender.set_Break(j, ClassNum[j + 1]);
    115                 pRender.set_Label(j, ClassNum[j].ToString("0.00") + " - " + ClassNum[j + 1].ToString("0.00"));
    116             }
    117 
    118             IGeoFeatureLayer pGeoLyr = (IGeoFeatureLayer)Layer;
    119             pGeoLyr.Renderer = (IFeatureRenderer)pRender;
    120         }
    121 
    122         public void ProportionalRenderer(IFeatureLayer featLayer, string fieldName, IColorRamp colorRamp, double count)
    123         {
    124             IProportionalSymbolRenderer psrender = new ProportionalSymbolRendererClass();
    125             psrender.Field = fieldName;
    126             psrender.ValueUnit = esriUnits.esriUnknownUnits;
    127             psrender.ValueRepresentation = esriValueRepresentations.esriValueRepUnknown;
    128             //选择渲染的样式,与颜色 minsymbol为比填内容,否则没有效果
    129             ISimpleMarkerSymbol markersym = new SimpleMarkerSymbol();
    130             markersym.Size = count;
    131             markersym.Style = esriSimpleMarkerStyle.esriSMSCircle;
    132             markersym.Color = colorRamp.get_Color(127);
    133             psrender.MinSymbol = markersym as ISymbol;
    134             //IFeatureLayer featLayer = featLayer;
    135             IGeoFeatureLayer geofeat = featLayer as IGeoFeatureLayer;
    136             ICursor cursor = ((ITable)featLayer).Search(null, true);
    137             IDataStatistics datastat = new DataStatisticsClass();
    138             datastat.Cursor = cursor;
    139             datastat.Field = fieldName;//千万不能忽视
    140             IStatisticsResults statisticsResult;
    141             try
    142             {
    143                 statisticsResult = datastat.Statistics;
    144                 psrender.MinDataValue = statisticsResult.Minimum + 0.1;
    145                 psrender.MaxDataValue = statisticsResult.Maximum;
    146             }
    147             catch
    148             {
    149                 MessageBox.Show("错误,选择的属性不是数值型!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
    150             }
    151             ////设置background的样式
    152             IFillSymbol fillsym = new SimpleFillSymbolClass();
    153             fillsym.Color = getcolor(201, 201, 251);
    154             ILineSymbol linesym = new SimpleLineSymbolClass();
    155             linesym.Width = 1;
    156             fillsym.Outline = linesym;
    157             psrender.BackgroundSymbol = fillsym;
    158             psrender.LegendSymbolCount = 6;//legend的数量
    159             psrender.CreateLegendSymbols();//创建TOC的legend
    160             geofeat.Renderer = (IFeatureRenderer)psrender;
    161         }

    完整源码下载:FeatureAndRasterRenderer.rar

  • 相关阅读:
    用Chrome和android SDK远程调试移动端页面
    如何配置能让fiddler抓去https的请求?
    开源免费的简易中文分词系统SCWS – PHP版
    Node.js 开发环境搭建及设置
    linux 安装 git server
    linux下 删除乱码文件名
    PowerDesigner 使用问题
    linux 设置开机大全
    mysql 实现 row_number() over(pattition by a order by b )
    WebApi Filter 中断返回字符串信息
  • 原文地址:https://www.cnblogs.com/zhzhx/p/3594312.html
Copyright © 2011-2022 走看看