ArcEngine栅格和矢量渲染(含可视化颜色带)

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

开发环境:ArcEngine9.3,VS2008。

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

开发界面如图所示。

图1 主界面

图2 栅格渲染界面

图3 矢量渲染界面

部分源码:

按 Ctrl+C 复制代码

public void SimpleRenderer(IFeatureLayer featLayer, string fieldName, IColorRamp colorRamp)
{
IGeoFeatureLayer pGeoFeatureLayer = featLayer as IGeoFeatureLayer;
IFeatureClass pFeatureClass = featLayer.FeatureClass; //获取图层上的featureClass
IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); //唯一值渲染器
//设置渲染字段对象
pUniqueValueRenderer.FieldCount = 1;
pUniqueValueRenderer.set_Field(0, fieldName);
ISimpleFillSymbol pSimFillSymbol = new SimpleFillSymbolClass(); //创建填充符号
pUniqueValueRenderer.DefaultSymbol = (ISymbol)pSimFillSymbol;
pUniqueValueRenderer.UseDefaultSymbol = false;
int n = pFeatureClass.FeatureCount(null);
for (int i = 0; i < n; i++)
{
IFeature pFeature = pFeatureCursor.NextFeature();
IClone pSourceClone = pSimFillSymbol as IClone;
ISimpleFillSymbol pSimpleFillSymbol = pSourceClone.Clone() as ISimpleFillSymbol;
string pFeatureValue = pFeature.get_Value(pFeature.Fields.FindField(fieldName)).ToString();
pUniqueValueRenderer.AddValue(pFeatureValue, "", (ISymbol)pSimpleFillSymbol);

}

//为每个符号设置颜色

for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++)
{
string xv = pUniqueValueRenderer.get_Value(i);

if (xv != "")
{
ISimpleFillSymbol pNextSymbol = (ISimpleFillSymbol)pUniqueValueRenderer.get_Symbol(xv);
pNextSymbol.Color = colorRamp.get_Color(127);
pUniqueValueRenderer.set_Symbol(xv, (ISymbol)pNextSymbol);
}
}

pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
}

public void UniqueRenderer(IFeatureLayer featLayer, string fieldName, IColorRamp colorRamp)
{
IGeoFeatureLayer pGeoFeatureLayer = featLayer as IGeoFeatureLayer;
IFeatureClass pFeatureClass = featLayer.FeatureClass; //获取图层上的featureClass
IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); //唯一值渲染器
//设置渲染字段对象
pUniqueValueRenderer.FieldCount = 1;
pUniqueValueRenderer.set_Field(0, fieldName);
ISimpleFillSymbol pSimFillSymbol = new SimpleFillSymbolClass(); //创建填充符号
pUniqueValueRenderer.DefaultSymbol = (ISymbol)pSimFillSymbol;
pUniqueValueRenderer.UseDefaultSymbol = false;
int n = pFeatureClass.FeatureCount(null);
for (int i = 0; i < n; i++)
{
IFeature pFeature = pFeatureCursor.NextFeature();
IClone pSourceClone = pSimFillSymbol as IClone;
ISimpleFillSymbol pSimpleFillSymbol = pSourceClone.Clone() as ISimpleFillSymbol;
string pFeatureValue = pFeature.get_Value(pFeature.Fields.FindField(fieldName)).ToString();
pUniqueValueRenderer.AddValue(pFeatureValue, "", (ISymbol)pSimpleFillSymbol);

}

//为每个符号设置颜色

for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++)
{
string xv = pUniqueValueRenderer.get_Value(i);

if (xv != "")
{
ISimpleFillSymbol pNextSymbol = (ISimpleFillSymbol)pUniqueValueRenderer.get_Symbol(xv);
//pColor = ramp.get_Color(j * (ramp.Size - 1) / (count - 1));
pNextSymbol.Color = colorRamp.get_Color(i * (colorRamp.Size-1) / (pUniqueValueRenderer.ValueCount-1));
pUniqueValueRenderer.set_Symbol(xv, (ISymbol)pNextSymbol);
}
}

pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
}

public void ClassRenderer(IFeatureLayer featLayer, string fieldName, IColorRamp colorRamp, int count)
{
//值分级
IBasicHistogram pBasicHis = new BasicTableHistogramClass();
ITableHistogram pTabHis = (ITableHistogram)pBasicHis;
//贫困发生率
IClassifyGEN pClassify = new EqualIntervalClass();
pTabHis.Field = fieldName;
//IGeoFeatureLayer geolayer = (IGeoFeatureLayer)Layer;
ILayer Layer = (ILayer)featLayer;
ITable pTab = (ITable)Layer;
pTabHis.Table = pTab;
object doubleArrVal, longArrFreq;
pBasicHis.GetHistogram(out doubleArrVal, out longArrFreq);

int nDes = count;
pClassify.Classify(doubleArrVal, longArrFreq, ref nDes);
object classes = pClassify.ClassBreaks;
double[] ClassNum;
ClassNum = (double[])pClassify.ClassBreaks;
int ClassCountResult = ClassNum.GetUpperBound(0);
IClassBreaksRenderer pRender = new ClassBreaksRendererClass();
pRender.BreakCount = ClassCountResult;
pRender.Field = fieldName;
ISimpleFillSymbol pSym;
IColor pColor;
for (int j = 0; j < ClassCountResult; j++)
{
pColor = colorRamp.get_Color(j * (colorRamp.Size-1) / (ClassCountResult-1));
pSym = new SimpleFillSymbolClass();
pSym.Color = pColor;
pRender.set_Symbol(j, (ISymbol)pSym);
pRender.set_Break(j, ClassNum[j + 1]);
pRender.set_Label(j, ClassNum[j].ToString("0.00") + " - " + ClassNum[j + 1].ToString("0.00"));
}

IGeoFeatureLayer pGeoLyr = (IGeoFeatureLayer)Layer;
pGeoLyr.Renderer = (IFeatureRenderer)pRender;
}

public void ProportionalRenderer(IFeatureLayer featLayer, string fieldName, IColorRamp colorRamp, double count)
{
IProportionalSymbolRenderer psrender = new ProportionalSymbolRendererClass();
psrender.Field = fieldName;
psrender.ValueUnit = esriUnits.esriUnknownUnits;
psrender.ValueRepresentation = esriValueRepresentations.esriValueRepUnknown;
//选择渲染的样式,与颜色 minsymbol为比填内容,否则没有效果
ISimpleMarkerSymbol markersym = new SimpleMarkerSymbol();
markersym.Size = count;
markersym.Style = esriSimpleMarkerStyle.esriSMSCircle;
markersym.Color = colorRamp.get_Color(127);
psrender.MinSymbol = markersym as ISymbol;
//IFeatureLayer featLayer = featLayer;
IGeoFeatureLayer geofeat = featLayer as IGeoFeatureLayer;
ICursor cursor = ((ITable)featLayer).Search(null, true);
IDataStatistics datastat = new DataStatisticsClass();
datastat.Cursor = cursor;
datastat.Field = fieldName;//千万不能忽视
IStatisticsResults statisticsResult;
try
{
statisticsResult = datastat.Statistics;
psrender.MinDataValue = statisticsResult.Minimum + 0.1;
psrender.MaxDataValue = statisticsResult.Maximum;
}
catch
{
MessageBox.Show("错误,选择的属性不是数值型!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
////设置background的样式
IFillSymbol fillsym = new SimpleFillSymbolClass();
fillsym.Color = getcolor(201, 201, 251);
ILineSymbol linesym = new SimpleLineSymbolClass();
linesym.Width = 1;
fillsym.Outline = linesym;
psrender.BackgroundSymbol = fillsym;
psrender.LegendSymbolCount = 6;//legend的数量
psrender.CreateLegendSymbols();//创建TOC的legend
geofeat.Renderer = (IFeatureRenderer)psrender;
}

按 Ctrl+C 复制代码

完整源码下载:FeatureAndRasterRenderer.rar

时间: 2024-10-20 15:41:48

ArcEngine栅格和矢量渲染(含可视化颜色带)的相关文章

AE 栅格图分级渲染

AE 栅格图分级渲染 ArcEngine对矢量数据进行风格化实在是得心应手,同样的对于栅格图像也能进行风格化!以前没接触过,今天正好需要,做出了栅格图像的渲染!下面实现的思路: 1.定义渲染的一系列接口 2.判断图像是否建立了直方图,如果没有则进行创建. 3.定义颜色序列,为渲染提供渲染的方案. 4.调用Render方法进行渲染. 下面是代码:有两个方法,一个是加载栅格数据,一个是进行渲染,接着在事件里面调用方法,实现图像渲染! /// /// 栅格分类专题图 /// /// 栅格图层 publ

ArcGIS教程:栅格河网矢量化的工作原理

栅格河网矢量化工具使用的算法主要用于矢量化河流网络或任何其他表示方向已知的栅格线性网络的栅格. 该工具已优化为使用方向栅格来帮助矢量化相交像元和相邻像元.可将两个值相同的相邻栅格河网矢量化为两条平行线.这与栅格转折线 (Polyline) 工具相反,后者通常更倾向于将线折叠在一起. 为使这一区别可视化,下面显示了输入河流网络,将栅格河网矢量化的模拟输出与栅格转折线 (Polyline) 的模拟输出进行比较. 版权声明:本文为博主原创文章,未经博主允许不得转载.

Android 颜色渲染(三) Shader颜色渲染

版权声明:本文为博主原创文章,未经博主允许不得转载. 相信看过在上一篇中提到的三篇文章后,大家已经对颜色处理方面有更深的体会. 之前讲到颜色渐变的效果, 具体怎么做呢,这就需要应用颜色渲染. 首先要介绍Android Api中关于颜色渲染的几个重要的类:    Shader,BitmapShader,ComposeShader,LinearGradient,RadialGradient,SweepGradient 看一下它们之间的关系:  public class Shader extends 

栅格转矢量

#!/usr/bin/env python # -*- coding: utf-8 -*- from osgeo import ogr from osgeo import gdal # get raster datasource open_image = gdal.Open( "../geodata/cadaster_borders-2tone-black-white.png" ) input_band = open_image.GetRasterBand(3) # create ou

BZOJ2120数颜色(带修改莫队)

2120: 数颜色 Time Limit: 6 Sec  Memory Limit: 259 MBSubmit: 7384  Solved: 2998[Submit][Status][Discuss] Description 墨 墨购买了一套N支彩色画笔(其中有些颜色可能相同),摆成一排,你需要回答墨墨的提问.墨墨会像你发布如下指令: 1. Q L R代表询问你从第L支画笔到第R支画笔中共有几种不同颜色的画笔. 2. R P Col 把第P支画笔替换为颜色Col.为了满足墨墨的要求,你知道你需要

[国家集训队][bzoj2120] 数颜色 [带修改莫队]

题面: 传送门 思路: 这道题和SDOI2009的HH的项链很像,只是多了一个修改 模板套上去呀 莫队学习请戳这里:莫队 Code: 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 using namespace std; 7 inline int read(){ 8 int re=0,fla

BZOJ 2120: 数颜色 带修改的莫队算法 树状数组套主席树

https://www.lydsy.com/JudgeOnline/problem.php?id=2120 标题里是两种不同的解法. 带修改的莫队和普通莫队比多了个修改操作,影响不大,但是注意一下细节不要出现zz错误. 这道题修改的数量比较少可以写莫队,但是如果修改数量多或者是特别极限的数据大概是不行的吧. 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cstrin

基于三维GIS技术的矢量地图动态LOD渲染方法研究现状

“地图是人类文化的杰作,它融科学.艺术于一体,作为描述.研究人类生存环境的一种信息载体是人类生产与生活中不可缺少的一种工具.”这是陈述彭院士为<中国地图学年鉴>作序的开场语.Taylor也曾指出“当涉及应用人脑来识别空间联系中的模式与相互关系时,地图学的认知方法是唯一的过程”.地图存在于我们生活的方方面面,应用广泛且己经产生了巨大的社会效应和经济效益,其重要性不言而喻.地图是地图可视化的结果,地图可视化作为现代地图学的核心一直是三维GIS的研究热点.地图可视化将电子设备的视觉传输能力和人类的视

AE栅格分类渲染问题解决

当按照下面方式写代码时,真正的分类break并没有设置成功.注意黑体部分: public static void ClassifyRenderRaster(IRasterLayer pRasterLayer, int ClassifyNum) { IRasterClassifyColorRampRenderer pRClassRend = new RasterClassifyColorRampRenderer() as IRasterClassifyColorRampRenderer; IRas