Arcgis Engine二次开发实验报告 下载本文

{

return\; }

elseif (featureRendererisIUniqueValueRenderer) {

return\; }

elseif (featureRendererisIDotDensityRenderer) {

return\; }

elseif (featureRendererisIChartRenderer) {

return\; }

elseif (featureRendererisIProportionalSymbolRenderer) {

return\; }

elseif (featureRendererisIRepresentationRenderer) {

return\; }

elseif (featureRendererisIClassBreaksRenderer) {

return\; }

elseif (featureRendererisIBivariateRenderer) {

return\; }

//如果匹配失败,返回提示

return\未知或渲染器获取失败\; }

//添加静态成员函数,获取指定图层的符号信息

publicstaticISymbolGetSymbolFromLayer(ILayer layer) {

//判断图层是否获取成功 if (layer == null) { returnnull; }

//访问图层,获取图层中的第一个要素,判断是否成功 IFeatureLayerfeatureLayer = layer asIFeatureLayer;

IFeatureCursorfeatureCursor = featureLayer.Search(null, false); IFeature feature = featureCursor.NextFeature(); if (feature == null) { returnnull; }

//访问指定图层,获取其渲染器,判断是否成功

IGeoFeatureLayergeoFeatureLayer = featureLayerasIGeoFeatureLayer; IFeatureRendererfeatureRenderer = geoFeatureLayer.Renderer; if (featureRenderer == null) { returnnull; }

//访问图层要素对应的符号信息,作为函数信息返回

ISymbol symbol = featureRenderer.get_SymbolByFeature(feature); return symbol; }

//添加静态成员函数,设置指定图层符号的颜色,并进行简单渲染 publicstaticboolRenderSimply(ILayer layer, IColor color) {

//判断图层和颜色是否获取成功

if (layer == null || color == null) { returnfalse; }

//调用成员函数,获取指定图层的符号,判断是否成功 ISymbol symbol = GetSymbolFromLayer(layer); if (symbol == null) { returnfalse; }

//获取指定图层的要素类,判断是否成功

IFeatureLayerfeatureLayer = layer asIFeatureLayer; IFeatureClassfeatureClass = featureLayer.FeatureClass; if (featureClass == null) { returnfalse; }

//获取指定图层要素类的几何形状信息,并匹配,设置不同类型符号的颜色 esriGeometryTypegeoType = featureClass.ShapeType; switch (geoType) {

caseesriGeometryType.esriGeometryPoint: {

IMarkerSymbolmarkerSymbol = symbol asIMarkerSymbol; markerSymbol.Color = color; break;

}

caseesriGeometryType.esriGeometryMultipoint: {

IMarkerSymbolmarkerSymbol = symbol asIMarkerSymbol; markerSymbol.Color = color; break;

}

caseesriGeometryType.esriGeometryPolyline: {

ISimpleLineSymbolsimplelinesymbol = symbol asISimpleLineSymbol; simplelinesymbol.Color = color; break;

}

caseesriGeometryType.esriGeometryPolygon: {

IFillSymbolfillSymbol = symbol asIFillSymbol; fillSymbol.Color = color; break;

} default: returnfalse; }

//新建简单渲染器对象,设置符号,通过接口访问,判断是否成功 ISimpleRenderersimpleRenderer = newSimpleRendererClass(); simpleRenderer.Symbol = symbol;

IFeatureRendererfeatureRenderer = simpleRendererasIFeatureRenderer; if (featureRenderer == null) { returnfalse; }

//通过接口访问指定图层,设置其渲染器

IGeoFeatureLayergeoFeatureLayer = featureLayerasIGeoFeatureLayer; geoFeatureLayer.Renderer = featureRenderer; returntrue; }

4.实现图层简单渲染

//实现图层简单渲染

privatevoidmiRenderSimply_Click(object sender, EventArgs e) {

//获取\图层

DataOperatordataOperator = newDataOperator(axMapControl1.Map); ILayer layer = dataOperator.GetLayerByName(\); //设置颜色为红色

IRgbColorrgbColor = newRgbColorClass(); rgbColor.Red = 255; rgbColor.Green = 0; rgbColor.Blue = 0;

//获取\图层的符号信息,并通过接口访问设置好的颜色对象 ISymbol symbol = MapComposer.GetSymbolFromLayer(layer); IColor color = rgbColorasIColor;

//实现该图层的简单渲染,判断是否成功,若成功,则刷新视图,显示渲染效果 boolbRes = MapComposer.RenderSimply(layer, color); if (bRes) {

axTOCControl1.ActiveView.ContentsChanged(); axMapControl1.ActiveView.Refresh(); miRenderSimply.Enabled = false; } else

{

MessageBox.Show(\简单渲染图层失败!\); } }

//生成获取图层渲染器类型信息的获取

privatevoidmiGetRendererInfo_Click(object sender, EventArgs e) {

//获取\图层

DataOperatordataOperator=newDataOperator(axMapControl1.Map); ILayer layer=dataOperator.GetLayerByName(\); //消息框显示该图层的渲染器类型信息

MessageBox.Show(MapComposer.GetRenderTypeByLayer(layer)); }

5. 运行结果