ArcGIS Engine 数据渲染

news/2024/11/24 15:12:10/

分级渲染

        /// <summary>/// 分级渲染/// </summary>/// <param name="pMapControl">数据视图</param>/// <param name="pFtLayer">图层</param>/// <param name="ClassCount">分为几类</param>/// <param name="pFieldName">字段名称</param>public ClassRender(AxMapControl pMapControl, IFeatureLayer pFtLayer, int ClassCount, string pFieldName){IGeoFeatureLayer pGeolayer = pFtLayer as IGeoFeatureLayer;IActiveView pActiveView = pMapControl.ActiveView;//以下是为了统计和分类所需要的对象ITable pTable = pGeolayer as ITable;IClassifyGEN pClassify = new EqualIntervalClass();//为一只分类IBasicHistogram pBasicHist = new BasicTableHistogramClass();ITableHistogram pTableHist = pBasicHist as ITableHistogram;//相当于一个统计表pTableHist.Table = pTable;//属性表信息pTableHist.Field = pFieldName;//字段名称IHsvColor pFromColor;IHsvColor pToColor;//用于构建另外一个颜色带对象。IMap pMap = pMapControl.Map;pMap.ReferenceScale = 0;object datavalus;object Frenquen;pBasicHist.GetHistogram(out datavalus, out  Frenquen);//获得数据和相应的频数。//datavalues与Frenquen对应,前者获取到数字,后者获取到该输出自出现的频率try{pClassify.Classify(datavalus, Frenquen, ref ClassCount);}catch (Exception e){MessageBox.Show(e.Message);}// 分类完成double[] ClassNum = (double[])pClassify.ClassBreaks;//得到分段值int  ClassCountResult = ClassNum.GetUpperBound(0);//返回分级个数,GetUpperBound获取最高下标//地图渲染IClassBreaksRenderer pClassBreak = new ClassBreaksRendererClass();pClassBreak.Field = pFieldName;//设置分级字段名称pClassBreak.BreakCount = ClassCountResult;//分级数pClassBreak.SortClassesAscending = true;IAlgorithmicColorRamp 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.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);}/// <summary>/// HSV颜色设置/// </summary>/// <param name="hue"></param>/// <param name="saturation"></param>/// <param name="val"></param>/// <returns></returns>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;}

有次可以看出分类主要使用 IClassifyGEN 接口,其接口描述如下:

Classify objects apply one of several methods to statistically subdivide a set of numeric values into classes.

The IClassifyGEN interface is implemented by all the data classification objects (DefinedInterval, EqualInterval, NaturalBreaks, Quantile,StandardDeviation); this is the interface used to pass in histogram data and then classify it into breaks. The ClassID and MethodName properties are used by user interface dialog boxes to identify the classification object and establish what the classification is called.

In general, to classify a dataset, use this interface together with IClassBreaksRenderer. Use the Classify method to add data to the classification; set the number of classes; and generate breaks (typically use the same number of classes specified here for IClassBreaksRenderer.BreakCount). Then apply the classification to the renderer by cycling through ClassBreaks and setting each IClassBreaksRenderer.Break.


遍历图层所有字段

  /// <summary>/// 添加字段/// </summary>private void AddField(){if (m_layer == null){ return; }IFeatureLayer feaLayer = m_layer as IFeatureLayer;IFields fields = feaLayer.FeatureClass.Fields;cmbFields.Items.Clear();if (fields != null){for (int i = 0; i < fields.FieldCount; ++i){string name = fields.get_Field(i).Name;if (name != "Shape" && name != "FID"){cmbFields.Items.Add(name);}}}}
将symbol转换成图片

        //Preview an image of the symbol/// <summary>/// 将符号转换为图片/// </summary>/// <param name="pSymbol">符号</param>/// <param name="iwidth">宽度</param>/// <param name="iheight">高度</param>/// <param name="lGap">边距</param>/// <returns></returns>private System.Drawing.Bitmap SymbolToBitmp(ESRI.ArcGIS.Display.ISymbol pSymbol, int iwidth, int iheight, int lGap){///根据高宽创建图象Bitmap bmp = new Bitmap(iwidth, iheight);Graphics gImage = Graphics.FromImage(bmp);//转化成GraphicsgImage.Clear(Color.White);                //清除底色,设置为白色double dpi = gImage.DpiX;                 //IEnvelope pEnvelope = new EnvelopeClass();//创建矩形范围pEnvelope.PutCoords(0, 0, (double)bmp.Width, (double)bmp.Height);//设置边界值tagRECT deviceRect;deviceRect.left = lGap;deviceRect.right = bmp.Width - lGap;deviceRect.top = lGap;deviceRect.bottom = bmp.Height - lGap;IDisplayTransformation pDisplayTransformation = new DisplayTransformationClass();pDisplayTransformation.VisibleBounds = pEnvelope;pDisplayTransformation.Bounds = pEnvelope;pDisplayTransformation.set_DeviceFrame(ref deviceRect);pDisplayTransformation.Resolution = dpi;          IGeometry pGeo = CreateGeometryFromSymbol(pSymbol, pEnvelope);//符号转为图片System.IntPtr hdc = new IntPtr();hdc = gImage.GetHdc();pSymbol.SetupDC((int)hdc, pDisplayTransformation);pSymbol.Draw(pGeo);pSymbol.ResetDC();gImage.ReleaseHdc(hdc);gImage.Dispose();return bmp;}/// <summary>/// 通过符号转换为几何图形/// </summary>/// <param name="sym">符号</param>/// <param name="env">几何边界</param>/// <returns></returns>private ESRI.ArcGIS.Geometry.IGeometry CreateGeometryFromSymbol(ISymbol sym, IEnvelope env){if (sym is IMarkerSymbol){IArea area = env as IArea;return area.Centroid as IGeometry;}else if (sym is ILineSymbol || sym is ITextSymbol){IPolyline line = new PolylineClass();IPoint pt = new PointClass();pt.PutCoords(env.LowerLeft.X, (env.LowerLeft.Y + env.UpperRight.Y) / 2);line.FromPoint = pt;pt = new PointClass();pt.PutCoords(env.UpperRight.X, (env.LowerLeft.Y + env.UpperRight.Y) / 2);line.ToPoint = pt;return line as IGeometry;}else if (sym is IFillSymbol){IPolygon polygon = new PolygonClass();IPointCollection ptCol = (IPointCollection)polygon;IPoint pt = new PointClass();pt.PutCoords(env.LowerLeft.X, env.LowerLeft.Y);ptCol.AddPoints(1, ref pt);pt.PutCoords(env.UpperLeft.X, env.UpperLeft.Y);ptCol.AddPoints(1, ref pt);pt.PutCoords(env.UpperRight.X, env.UpperRight.Y);ptCol.AddPoints(1, ref pt);pt.PutCoords(env.LowerRight.X, env.LowerRight.Y);ptCol.AddPoints(1, ref pt);pt.PutCoords(env.LowerLeft.X, env.LowerLeft.Y);ptCol.AddPoints(1, ref pt);return polygon as IGeometry;}else{System.Windows.Forms.MessageBox.Show("找到一种特殊的符号!");return null;}}/// <summary>/// 设置栅格数据渲染/// </summary>/// <param name="mRasterLayer">栅格图层</param>private void SetRasterSymbol(IRasterLayer mRasterLayer){try{int symbol_index = cmb_symbol.SelectedIndex;//获取选择的序号ISymbologyStyleClass symbologyStyleClass = axSymbologyControl1.GetStyleClass(esriSymbologyStyleClass.esriStyleClassColorRamps);IStyleGalleryItem mStyleGalleryItem = symbologyStyleClass.GetItem(symbol_index);IColorRamp colorramp_select = (IColorRamp)mStyleGalleryItem.Item;//获取选择的符号//IColorRampSymbol mColorRampSymbol = new ColorRampSymbolClass();//mColorRampSymbol = (IColorRampSymbol)symbol_select;IRasterStretchColorRampRenderer pStretchRen = (IRasterStretchColorRampRenderer)mRasterLayer.Renderer;pStretchRen.ColorRamp = colorramp_select;}catch (Exception ex){System.Diagnostics.Trace.WriteLine(ex.Message);}}


      重写ComboBox控件,用于显示颜色
/// <summary>/// 重写ComboBox控件/// </summary>public partial class ComboboxSymbol : ComboBox{public ComboboxSymbol(){//以下两句是关键的;DrawMode = DrawMode.OwnerDrawFixed;DropDownStyle = ComboBoxStyle.DropDownList;}//重写函数protected override void OnDrawItem(DrawItemEventArgs e){e.DrawBackground();e.DrawFocusRectangle();try{                    //显示图片Image image = (Image)Items[e.Index];System.Drawing.Rectangle rect = e.Bounds;e.Graphics.DrawImage(image, rect);}catch{}finally{base.OnDrawItem(e);}}}




http://www.ppmy.cn/news/323172.html

相关文章

[CVPR2017] Weakly Supervised Cascaded Convolutional Networks论文笔记

https://www.csee.umbc.edu/~hpirsiav/papers/cascade_cvpr17.pdf Weakly Supervised Cascaded Convolutional Networks, Ali Diba, Vivek Sharma, Ali Pazandeh, Hamed Pirsiavash and Luc Van Gool 亮点 通过多任务叠加&#xff08;分类&#xff0c;分割&#xff09;提高了多…

蛇行矩阵-C语言

题目 蛇形矩阵是由1开始的自然数依次排列成的一个矩阵上三角形。 输入格式&#xff1a; 本题有多组数据&#xff0c;每组数据由一个正整数N组成。&#xff08;N不大于100&#xff09; 输出格式&#xff1a; 对于每一组数据&#xff0c;输出一个N行的蛇形矩阵。 两组输出之…

模拟数字电路->绪论

模拟数字电路 绪论信号相关放大电路模型抽象放大器 放大电路模型分析电压放大电路电流放大模型 主要性能指标增益Av,输入电阻Ri,输出电阻Ro频率响应和非线性失真非线性失真 问题总结题型输出电压,输出电阻放大倍数 课程无关 绪论 信号相关 信号:信息的载体 电信号源的电路表达…

leetcode链表(简单难度)

leetcode链表简单题 21.合并两个有序链表83.删除排序链表中的重复元素141.环形链表160.相交链表暴力法长度差法通过“增加”消除长度差 203.移除链表元素206.反转链表234.回文链表237.删除链表中的节点876.链表的中间节点1290.二进制链表转整数get flag 21.合并两个有序链表 /…

机械制造作业考研题目答案分享——金属切削规律2

金属减削规律的四道题目以及答案解释(english version)。 版权声明 本内容由狂小虎原创整合&#xff0c;请不要售卖&#xff0c;为了防止爬虫以及保持免费性&#xff0c;设置为仅粉丝可见。另外&#xff0c;题目以及解释可能不完全正确&#xff0c;仅供参考&#xff0c;同时也…

小白C语言Leetcode————160.相交链表

本题我按Leetcode上所要求的函数运行出错&#xff0c;但我大概想明白在何处出错&#xff1a;创造两个链表时时分别创造的&#xff0c;所以在创造这两个链表时他们占用了不同的地址空间&#xff0c;即使他们的值相同&#xff0c;但他们并不相交&#xff0c;因此出错。 因此在这…

java翻译smali_求大佬帮我把这个smali文件翻译成java或者C#好吗

[Asm] 纯文本查看 复制代码.class public Lcom/mob/commons/a; .super Ljava/lang/Object; # static fields .field private static a:Ljava/util/HashMap; .annotation system Ldalvik/annotation/Signature; value { "Ljava/util/HashMap", " "Ljava/la…

AE+VS+c#开发颜色符号系统之点值符号化(七)

首先总结一下之前写的几篇符号化文章&#xff0c;列表如下&#xff1a; AEVS开发颜色符号系统之单一值符号&#xff08;一&#xff09; AEVS开发颜色符号系统之唯一值符号&#xff08;二&#xff09; AEVS开发颜色符号系统之分类符号&#xff08;三&#xff09; AEVS开发颜…