private void 添加点型图层ToolStripMenuItem_Click(object sender, EventArgs e) { //创建要素类 #region 创建新的内存工作空间 IWorkspaceFactory pWSF = new InMemoryWorkspaceFactoryClass(); IWorkspaceName pWSName = pWSF.Create("", "Temp", null, 0); IName pName = (IName)pWSName; IWorkspace pMemoryWS = (IWorkspace)pName.Open(); #endregion IField oField = new FieldClass(); IFields oFields = new FieldsClass(); IFieldsEdit oFieldsEdit = null; IFieldEdit oFieldEdit = null; IFeatureClass oFeatureClass = null; IFeatureLayer oFeatureLayer = null; oFieldsEdit = oFields as IFieldsEdit; oFieldEdit = oField as IFieldEdit; oFieldEdit.Name_2 = "OBJECTID"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; oFieldEdit.IsNullable_2 = false; oFieldEdit.Required_2 = false; oFieldsEdit.AddField(oField); oField = new FieldClass(); oFieldEdit = oField as IFieldEdit; IGeometryDef pGeoDef = new GeometryDefClass(); IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef; pGeoDefEdit.AvgNumPoints_2 = 5; pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint; pGeoDefEdit.GridCount_2 = 1; pGeoDefEdit.HasM_2 = false; pGeoDefEdit.HasZ_2 = false; pGeoDefEdit.SpatialReference_2 = axMapControl1.SpatialReference; oFieldEdit.Name_2 = "SHAPE"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; oFieldEdit.GeometryDef_2 = pGeoDef; oFieldEdit.IsNullable_2 = true; oFieldEdit.Required_2 = true; oFieldsEdit.AddField(oField); oField = new FieldClass(); oFieldEdit = oField as IFieldEdit; oFieldEdit.Name_2 = "Code"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger; //oFieldEdit.Length = 10; oFieldEdit.IsNullable_2 = true; oFieldsEdit.AddField(oField); //创建要素类 oFeatureClass = (pMemoryWS as IFeatureWorkspace).CreateFeatureClass("Temp", oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", ""); oFeatureLayer = new FeatureLayerClass(); oFeatureLayer.Name = "PointLayer"; oFeatureLayer.FeatureClass = oFeatureClass; //创建唯一值符号化对象 IUniqueValueRenderer pURender = new UniqueValueRendererClass(); pURender.FieldCount = 1; pURender.set_Field(0, "Code"); pURender.UseDefaultSymbol = false; //创建SimpleMarkerSymbolClass对象 ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); //创建RgbColorClass对象为pSimpleMarkerSymbol设置颜色 IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 255; pSimpleMarkerSymbol.Color = pRgbColor as IColor; //设置pSimpleMarkerSymbol对象的符号类型,选择钻石 pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond; //设置pSimpleMarkerSymbol对象大小,设置为5 pSimpleMarkerSymbol.Size = 5; //显示外框线 pSimpleMarkerSymbol.Outline = true; //为外框线设置颜色 IRgbColor pLineRgbColor = new RgbColorClass(); pLineRgbColor.Green = 255; pSimpleMarkerSymbol.OutlineColor = pLineRgbColor as IColor; //设置外框线的宽度 pSimpleMarkerSymbol.OutlineSize = 1; //半透明颜色 pURender.AddValue("1", "", pSimpleMarkerSymbol as ISymbol); //唯一值符号化内存图层 (oFeatureLayer as IGeoFeatureLayer).Renderer = pURender as IFeatureRenderer; ILayerEffects pLyrEffect = oFeatureLayer as ILayerEffects; //透明度 pLyrEffect.Transparency = 0; oFeatureLayer.Visible = true; this.axMapControl1.AddLayer(oFeatureLayer,axMapControl1.LayerCount); insertpoint = true; }
/// <summary> /// Render City and Village /// </summary> /// <param name="currentLayer"></param> /// <author>Shen Yongyuan</author> /// <date>20091114</date> public static void RenderCityVillage(ILayer currentLayer) { IUniqueValueRenderer pUniqueValueR = new UniqueValueRendererClass(); pUniqueValueR.FieldCount = 1; string fieldName = Town.Constant.Constant.TmpTableDevide + "." + Town.Constant.Constant.TmpFieldName; pUniqueValueR.set_Field(0, fieldName); ISimpleFillSymbol pFillSymbolDef = new SimpleFillSymbolClass(); pFillSymbolDef.Color = Town.ArcGIS.Color.ToEsriColor(System.Drawing.Color.Gray); pUniqueValueR.DefaultSymbol = pFillSymbolDef as ISymbol; pUniqueValueR.UseDefaultSymbol = true; ISimpleFillSymbol citySymbol = new SimpleFillSymbolClass(); citySymbol.Color = Town.ArcGIS.Color.ToEsriColor(System.Drawing.Color.Yellow); pUniqueValueR.AddValue("城镇", "城镇", citySymbol as ISymbol); ISimpleFillSymbol vilageSymbol = new SimpleFillSymbolClass(); vilageSymbol.Color = Town.ArcGIS.Color.ToEsriColor(System.Drawing.Color.Tomato); pUniqueValueR.AddValue("乡村", "乡村", vilageSymbol as ISymbol); IGeoFeatureLayer geoFeaLayer = currentLayer as IGeoFeatureLayer; geoFeaLayer.Renderer = pUniqueValueR as IFeatureRenderer; }
private void button4_Click(object sender, EventArgs e) { int selectedFieldIndex = m_pTarFeatureLayer.FeatureClass.Fields.FindField(comboBox1.SelectedItem.ToString()); IField selectedField = m_pTarFeatureLayer.FeatureClass.Fields.get_Field(selectedFieldIndex); IUniqueValueRenderer unqValueRenderr = new UniqueValueRendererClass(); #region UniqueValueRenderer需要定义字段数,字段名,并最后添加字段中每一种值对应的渲染方式(AddValue) unqValueRenderr.FieldCount = 1; unqValueRenderr.set_Field(0, selectedField.Name);//0是干什么的? #endregion IAlgorithmicColorRamp acr = new AlgorithmicColorRampClass(); acr.FromColor = m_pFillColor; acr.ToColor = m_pOutlineColor; acr.Size = m_pTarFeatureLayer.FeatureClass.FeatureCount(null); bool isOK; acr.CreateRamp(out isOK); #region 很迷,不知道为什么直接acr.colors.next遍历不了colorramp IEnumColors enumColor = acr.Colors; IColor curColor = enumColor.Next(); #endregion #region 开始遍历图层获取所有feature for (int i = 0; i < m_pTarFeatureLayer.FeatureClass.FeatureCount(null); i++) { IFeature curFeature = m_pTarFeatureLayer.FeatureClass.GetFeature(i); switch (m_pTarFeatureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPolygon: { ISimpleFillSymbol sfs = new SimpleFillSymbolClass(); sfs.Color = curColor; unqValueRenderr.AddValue(curFeature.get_Value(selectedFieldIndex).ToString(), "", sfs as ISymbol); break; } case esriGeometryType.esriGeometryPoint: { ISimpleMarkerSymbol sms = new SimpleMarkerSymbolClass { Color = curColor }; unqValueRenderr.AddValue(curFeature.get_Value(selectedFieldIndex).ToString(), "", sms as ISymbol); break; } case esriGeometryType.esriGeometryPolyline: { ISimpleLineSymbol sls = new SimpleLineSymbolClass(); sls.Color = curColor; unqValueRenderr.AddValue(curFeature.get_Value(selectedFieldIndex).ToString(), "", sls as ISymbol); break; } } curColor = enumColor.Next(); } m_pTarGeoFeatureLayer.Renderer = unqValueRenderr as IFeatureRenderer; frmMainOper(OperationType.RefreshMapCtrl); frmMainOper(OperationType.UpdateTOCCtrl); #endregion }
public static void ApplyUniqueValueRenderer(IGeoFeatureLayer fl) { //COD (101,103...) IUniqueValueRenderer uvr = new UniqueValueRendererClass(); uvr.FieldCount = 1; uvr.set_Field(0, "COD"); uvr.DefaultSymbol = (ISymbol)CreateSimpleFillSymbol(0,0,255); uvr.UseDefaultSymbol = true; //add values uvr.AddValue("101", "101", (ISymbol)CreateSimpleFillSymbol(255,0,0)); uvr.AddValue("103", "103", (ISymbol)CreateSimpleFillSymbol(0, 255, 0)); //render fl.Renderer = (IFeatureRenderer)uvr; }
private void styleGipodLyr(IGeoFeatureLayer geolayer) { IUniqueValueRenderer renderer = new UniqueValueRendererClass(); renderer.FieldCount = 1; renderer.set_Field(0, "hinder"); renderer.set_FieldType(0, false); //renderer.UseDefaultSymbol = true; renderer.DefaultLabel = "other"; ISimpleMarkerSymbol trueMarkerSymbol = new SimpleMarkerSymbolClass(); trueMarkerSymbol.Color = new RgbColorClass() { Red = 255, Blue = 0, Green = 255 }; trueMarkerSymbol.Outline = true; trueMarkerSymbol.OutlineColor = new RgbColorClass() { Red = 0, Blue = 0, Green = 0 };; trueMarkerSymbol.Size = 5; trueMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; ISimpleMarkerSymbol falseMarkerSymbol = new SimpleMarkerSymbolClass(); falseMarkerSymbol.Color = new RgbColorClass() { Red = 255, Blue = 0, Green = 0 }; falseMarkerSymbol.Outline = true; falseMarkerSymbol.OutlineColor = new RgbColorClass() { Red = 0, Blue = 0, Green = 0 };; falseMarkerSymbol.Size = 5; falseMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; renderer.AddValue("0", "", falseMarkerSymbol as ISymbol); renderer.set_Label("0", "Geen hinder"); renderer.AddValue("1", "", trueMarkerSymbol as ISymbol); renderer.set_Label("1", "Veel hinder"); geolayer.Renderer = renderer as IFeatureRenderer; IMxDocument mxDoc = ArcMap.Document; mxDoc.CurrentContentsView.Refresh(null); }
public static void ApplyUniqueValueRenderer(IGeoFeatureLayer fl) { //COD (101,103...) IUniqueValueRenderer uvr = new UniqueValueRendererClass(); uvr.FieldCount = 1; uvr.set_Field(0, "COD"); uvr.DefaultSymbol = (ISymbol)CreateSimpleFillSymbol(0, 0, 255); uvr.UseDefaultSymbol = true; //add values uvr.AddValue("101", "101", (ISymbol)CreateSimpleFillSymbol(255, 0, 0)); uvr.AddValue("103", "103", (ISymbol)CreateSimpleFillSymbol(0, 255, 0)); //render fl.Renderer = (IFeatureRenderer)uvr; }
private void BreakClassRender() { IGeoFeatureLayer geoFeatureLayer; geoFeatureLayer = getGeoLayer("Continents"); IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass(); uniqueValueRenderer.FieldCount = 1; uniqueValueRenderer.set_Field(0, "SQMI"); ISimpleFillSymbol simpleFillSymbol = SymbolWorker.CreateSimpleFillSymbol() as ISimpleFillSymbol; IFeatureCursor featureCursor = geoFeatureLayer.FeatureClass.Search(null, false); IFeature feature; if (featureCursor != null) { IEnumColors enumColors = SymbolWorker.CreateAlgorithmicColorRamp(7).Colors; int fiedIndex = geoFeatureLayer.FeatureClass.Fields.FindField("SQMI"); for (int i = 0; i < 7; i++) { feature = featureCursor.NextFeature(); string nameValue = feature.get_Value(fiedIndex).ToString(); simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = enumColors.Next(); uniqueValueRenderer.AddValue(nameValue, "SQMI", simpleFillSymbol as ISymbol); } } geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer; }
///<summary> ///设置要素图层唯一值符号化 ///</summary> ///<param name="pFeatureLayer"></param> private void UniqueValueRenderFlyr(IFeatureLayer pFeatureLayer) { //创建SimpleMarkerSymbolClass对象 SimpleLineSymbolClass pSimpleMarkerSymbol = new SimpleLineSymbolClass(); //创建RgbColorClass对象为pSimpleMarkerSymbol设置颜色 IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 255; pSimpleMarkerSymbol.Color = pRgbColor as IColor; pSimpleMarkerSymbol.Style = esriSimpleLineStyle.esriSLSDash; //设置pSimpleMarkerSymbol对象大小,设置为5 pSimpleMarkerSymbol.Width = 1; //显示外框线 //pSimpleMarkerSymbol.Outline = true; //为外框线设置颜色 IRgbColor pLineRgbColor = new RgbColorClass(); pLineRgbColor.Green = 255; //pSimpleMarkerSymbol.OutlineColor = pLineRgbColor as IColor; //设置外框线的宽度 //pSimpleMarkerSymbol.OutlineSize = 1; IUniqueValueRenderer pUVRender = new UniqueValueRendererClass(); pUVRender.AddValue("", "", pSimpleMarkerSymbol as ISymbol); pUVRender.DefaultLabel = "Name"; pUVRender.DefaultSymbol = pSimpleMarkerSymbol as ISymbol; //设置IGeofeatureLayer的Renderer属性 (pFeatureLayer as IGeoFeatureLayer).Renderer = pUVRender as IFeatureRenderer; }
//单一值专题图 private void button3_Click(object sender, EventArgs e) { IGeoFeatureLayer geoFeatureLayer; geoFeatureLayer = getGeoLayer("Continents"); IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass(); uniqueValueRenderer.FieldCount = 1; uniqueValueRenderer.set_Field(0, "continent"); //简单填充符号 ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; IFeatureCursor featureCursor = geoFeatureLayer.FeatureClass.Search(null, false); IFeature feature; if (featureCursor != null) { IEnumColors enumColors = CreateAlgorithmicColorRamp(8).Colors; int fieldIndex = geoFeatureLayer.FeatureClass.Fields.FindField("continent"); for (int i = 0; i < 8; i++) { feature = featureCursor.NextFeature(); string nameValue = feature.get_Value(fieldIndex).ToString(); simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = enumColors.Next(); uniqueValueRenderer.AddValue(nameValue, "continent", simpleFillSymbol as ISymbol); } } geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer; this.axMapControl1.Refresh(); }
///<summary> ///设置要素图层唯一值符号化 ///</summary> ///<param name="pFeatureLayer"></param> private void UniqueValueRenderFlyr(AxMapControl axMapControl1, IFeatureLayer pFeatureLayer) { try { //创建UniqueValueRendererClass对象 IUniqueValueRenderer pUVRender = new UniqueValueRendererClass(); List <string> pFieldValues = new List <string>(); pFieldValues.Add("Hospital 2"); pFieldValues.Add("School 1"); pFieldValues.Add("Airport"); for (int i = 0; i < pFieldValues.Count; i++) { ISymbol pSymbol = new SimpleMarkerSymbolClass(); pSymbol = GetSymbol(@"D:\Program Files\ArcGIS\Styles\ESRI.ServerStyle", "Marker Symbols", pFieldValues[i]); //添加唯一值符号化字段值和相对应的符号 pUVRender.AddValue(pFieldValues[i], pFieldValues[i], pSymbol); } //设置唯一值符号化的字段个数和字段名 pUVRender.FieldCount = 1; pUVRender.set_Field(0, "类别"); IGeoFeatureLayer pGFeatureLyr = pFeatureLayer as IGeoFeatureLayer; //设置IGeofeatureLayer的Renderer属性 pGFeatureLyr.Renderer = pUVRender as IFeatureRenderer; } catch (Exception Err) { MessageBox.Show(Err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private static void DirectRender(ILayer pLayer) { IGeoFeatureLayer MyGeoFeatureLayer = pLayer as IGeoFeatureLayer; IFeatureCursor MyFeatureCursor = MyGeoFeatureLayer.Search(null, false); IFeature MyFeature = MyFeatureCursor.NextFeature(); Render renderer = new Render(); IUniqueValueRenderer pUniqueValueR = new UniqueValueRendererClass(); pUniqueValueR.FieldCount = 1;//单值渲染 string FieldName = MyFeature.Fields.get_Field(0).Name; pUniqueValueR.set_Field(0, FieldName);//渲染字段 while (null != MyFeature) { //MyFeature.Fields.FindField("OBJECTID"); string value = Convert.ToString((int)MyFeature.get_Value(0)); pUniqueValueR.AddValue(value, FieldName, renderer.GetSymbol(MyFeature)); MyFeature = MyFeatureCursor.NextFeature(); } //pUniqueValueR.AddValue((Convert.ToString(tem)), "FID", pSymbol); MyGeoFeatureLayer.Renderer = pUniqueValueR as IFeatureRenderer; }
/// <summary> /// 根据图层唯一值渲染图层,地震烈度 /// </summary> /// <param name="R_pFeatureLayer"></param> /// <param name="sFieldName"></param> public static void UniqueValueRendererEarthquake(IFeatureLayer R_pFeatureLayer, string sFieldName) { IGeoFeatureLayer geoLayer = R_pFeatureLayer as IGeoFeatureLayer; ITable pTable = geoLayer.FeatureClass as ITable; ICursor pCursor; IQueryFilter pQueryFilter = new QueryFilter(); pQueryFilter.AddField(sFieldName); //以唯一值作为条件 pCursor = pTable.Search(pQueryFilter, true); IUniqueValueRenderer pUniqueValueR = new UniqueValueRendererClass(); pUniqueValueR.FieldCount = 1; //单值渲染 pUniqueValueR.set_Field(0, sFieldName); //渲染字段 IFeatureCursor pFeatureCursor = R_pFeatureLayer.Search(pQueryFilter, false); IFeature pFeature = pFeatureCursor.NextFeature(); int index = R_pFeatureLayer.FeatureClass.FindField(sFieldName); List <Color> colors = new List <Color>(); //存储地震烈度连续颜色带,以要素数量为上限 colors = createEarthquakecolor(colors, R_pFeatureLayer.FeatureClass.FeatureCount(pQueryFilter)); int i = 5; while (pFeature != null) { string value = pFeature.get_Value(index).ToString(); pFeature = pFeatureCursor.NextFeature(); ISimpleFillSymbol symd = new SimpleFillSymbolClass(); symd.Style = esriSimpleFillStyle.esriSFSSolid; symd.Outline.Width = 1; if (value.Equals("Ⅸ度")) //此处用于渲染原始图层 { symd.Color = ConvertColorToIColor(colors[4]); } else if (value.Equals("Ⅷ度")) { symd.Color = ConvertColorToIColor(colors[3]); } else if (value.Equals("Ⅶ度")) { symd.Color = ConvertColorToIColor(colors[2]); } else if (value.Equals("Ⅵ度")) { symd.Color = ConvertColorToIColor(colors[1]); } else if (value.Equals("V度")) { symd.Color = ConvertColorToIColor(colors[0]); } else { symd.Color = ConvertColorToIColor(colors[i]); //i后移一位,以便于对应name字段 i++; } pUniqueValueR.AddValue(value, "", symd as ISymbol); } geoLayer.Renderer = pUniqueValueR as IFeatureRenderer; MainFrom.m_mapControl.Refresh(); }
private static IUniqueValueRenderer GenerateUniqueValueRenderer(IFeatureLayer featureLayer) { IFeatureWorkspace featureWorkspace = ((IDataset)featureLayer.FeatureClass).Workspace as IFeatureWorkspace; ITable table = featureWorkspace.OpenTable(TableName); string relClassName = string.Format("{0}_{1}", ((IDataset)featureLayer.FeatureClass).Name, ((IDataset)table).Name); IRelationshipClass relClass = featureWorkspace.OpenRelationshipClass(relClassName); IDisplayRelationshipClass displayRelClass = featureLayer as IDisplayRelationshipClass; if (displayRelClass == null) { return(null); } displayRelClass.DisplayRelationshipClass(relClass, esriJoinType.esriLeftOuterJoin); IUniqueValueRenderer uvRenderer = new UniqueValueRendererClass { FieldCount = 1 }; uvRenderer.Field[0] = string.Format("{0}.{1}", ((IDataset)table).Name, JoinField); IFeatureCursor cursor = ((IGeoFeatureLayer)featureLayer).SearchDisplayFeatures(null, true); DataStatisticsClass dataStatistics = new DataStatisticsClass { Field = uvRenderer.Field[0], Cursor = cursor as ICursor }; IEnumerator pEnumerator = dataStatistics.UniqueValues; pEnumerator.Reset(); Random random = new Random(); while (pEnumerator.MoveNext()) { string value = Convert.ToString(pEnumerator.Current); RgbColorClass fillColor = new RgbColorClass { Red = random.Next(0, 255), Green = random.Next(0, 255), Blue = random.Next(0, 255) }; SimpleFillSymbolClass fillSymbol = new SimpleFillSymbolClass { Color = fillColor }; uvRenderer.AddValue(value, "ZONE", fillSymbol); } Marshal.ReleaseComObject(cursor); return(uvRenderer); }
public void LayerRender() { try { //IFeatureLayer pFeatureLayer = featLayer; 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(i * (colorRamp.Size / pUniqueValueRenderer.ValueCount)); pUniqueValueRenderer.set_Symbol(xv, (ISymbol)pNextSymbol); if (xv.Contains(".")) { pUniqueValueRenderer.set_Label(xv, xv.Substring(0, xv.IndexOf(".") + 4)); } else { pUniqueValueRenderer.set_Label(xv, xv); } } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); axtoccontrol.Update(); } catch (Exception e) { MessageBox.Show(e.Message); } }
public IUniqueValueRenderer MakeUniqueValueRenderer() { IFeatureLayer data = (this.cboLayers.SelectedItem as LayerObject).Layer as IFeatureLayer; IUniqueValueRenderer renderer = new UniqueValueRendererClass(); ISymbol symbol = this.method_3(data.FeatureClass.ShapeType); if (symbol != null) { renderer.FieldCount = 1; renderer.set_Field(0, this.cboFields.Text); renderer.DefaultLabel = "默认符号"; renderer.DefaultSymbol = symbol; renderer.UseDefaultSymbol = true; try { bool flag; string str = this.method_4(data.FeatureClass.ShapeType); this.icolorRamp_0.Size = this.listView1.Items.Count; this.icolorRamp_0.CreateRamp(out flag); IEnumColors colors = this.icolorRamp_0.Colors; colors.Reset(); for (int i = 0; i < this.listView1.Items.Count; i++) { ISymbol symbol2; ListViewItem item = this.listView1.Items[i]; IStyleGalleryItem item2 = SymbolFind.FindStyleGalleryItem(item.SubItems[0].Text, this.m_pSG, this.cboStyleGrally.Text, str, ""); if (item2 == null) { IColor color = colors.Next(); symbol2 = (symbol as IClone).Clone() as ISymbol; this.method_2(symbol2, color); } else { symbol2 = (item2.Item as IClone).Clone() as ISymbol; } renderer.AddValue(item.SubItems[0].Text, null, symbol2); } (data as IGeoFeatureLayer).Renderer = renderer as IFeatureRenderer; (this.imap_0 as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, data, null); return(renderer); } catch (Exception exception) { Logger.Current.Error("", exception, ""); } } return(renderer); }
private void btn_OK_Click(object sender, EventArgs e) { string FieldName = cbx_Field.SelectedItem.ToString(); IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)m_FeatureLayer; pGeoFeatureLayer.ScaleSymbols = false; ITable pTable = (ITable)pGeoFeatureLayer; if (pTable.FindField(FieldName) == -1) { return; } else { IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, FieldName); IColorRamp pColorRamp = (IColorRamp)m_StyleGallertItem.Item; pColorRamp.Size = pTable.RowCount(null); bool ok = true; pColorRamp.CreateRamp(out ok); IEnumColors pEnumRamp = pColorRamp.Colors; IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(FieldName); //依据某个字段在表中找出指向所有行的游标对象 ICursor pCursor = pTable.Search(pQueryFilter, true); IRow pNextRow = pCursor.NextRow(); //遍历所有的要素 IColor pNextUniqueColor; string codeValue; while (pNextRow != null) { codeValue = pNextRow.get_Value(pTable.FindField(FieldName)).ToString(); //获得随机颜色带中的任意一种颜色 pNextUniqueColor = pEnumRamp.Next(); IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pNextUniqueColor; //将每次得到的要素字段值和修饰它的符号放入着色对象中 pUniqueValueRenderer.AddValue(codeValue, FieldName, (ISymbol)pFillSymbol); pNextRow = pCursor.NextRow(); } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; m_MapControl.ActiveView.ContentsChanged(); m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } }
/// <summary> /// 唯一值法渲染器(UniqueValueRender)——根据特征的某不同属性值来绘制该特征的符号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 唯一值法渲染ToolStripMenuItem_Click(object sender, EventArgs e) { //定义IGeoFeatureLayer变量, 提供一个要素图层对成员控制地理特征的入口 IGeoFeatureLayer geoFeatureLayer = getGeoLayer("北部湾"); //使用查询的方式, 获得参与渲染的记录条数 int get_Count = geoFeatureLayer.FeatureClass.FeatureCount(null); //提供操作唯一值的相关成员 IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass(); //设置渲染的字段个数范围:0~3个 //这里仅设置1个字段 uniqueValueRenderer.FieldCount = 1; //设置渲染字段, 并制定到索引处 //索引从0开始; 设定渲染字段为"地市名" uniqueValueRenderer.set_Field(0, "地市名"); //简单填充符号 ISimpleFillSymbol simpleFillSymbol; //获得指向渲染要素的游标 IFeatureCursor pFtCursor = geoFeatureLayer.FeatureClass.Search(null, false); IFeature pFeature; if (pFtCursor != null) { //定义枚举颜色带, 调用函数, 生成随机颜色带 IEnumColors enumColors = CreateRandomColorRamp(get_Count).Colors; //查找到"地市名"字段的索引(index) int fieldIndex = geoFeatureLayer.FeatureClass.Fields.FindField("地市名"); while ((pFeature = pFtCursor.NextFeature()) != null) { //获取要素值 string nameValue = pFeature.get_Value(fieldIndex).ToString(); //实例化填充符号 //使用填充符号来赋值地图的背景值 simpleFillSymbol = new SimpleFillSymbolClass(); //给要素附上样式 simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; //给要素附上颜色 simpleFillSymbol.Color = enumColors.Next() as IColor; //值和符号对应 uniqueValueRenderer.AddValue(nameValue, "地市", simpleFillSymbol as ISymbol); } } //赋值目标图层的渲染器属性 geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer; axMapControl1.Refresh(); //刷新axMapControl1 axTOCControl1.Update(); //更新axTOCControl1 }
/// <summary> /// 设置图层根据某字段的值进行显示 /// </summary> /// <param name="layer"></param> /// <param name="filedName"></param> /// <param name="symbolDic"></param> public static void SetLayerGraderSymbol(ILayer layer, string filedName, IDictionary <string, ISymbol> symbolDic) { IFeatureLayer featureLayer = layer as IFeatureLayer; IUniqueValueRenderer pRender = new UniqueValueRendererClass(); pRender.FieldCount = 1; pRender.set_Field(0, filedName); foreach (var dicValue in symbolDic) { // pRender.AddValue(dicValue.Key, dicValue.Key, dicValue.Value); pRender.AddValue(dicValue.Key, "", dicValue.Value); } IGeoFeatureLayer geoLayer = layer as IGeoFeatureLayer; geoLayer.Renderer = pRender as IFeatureRenderer; }
public static void uniqueRender(IFeatureLayer featLayer, string fieldName) { 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(); string pFeatureValue = pFeature.get_Value(pFeature.Fields.FindField(fieldName)).ToString(); pUniqueValueRenderer.AddValue(pFeatureValue, "", null); } IRandomColorRamp colorRamp = new RandomColorRampClass(); colorRamp.Size = pUniqueValueRenderer.ValueCount; bool b = true; colorRamp.CreateRamp(out b); //为每个符号设置颜色 for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++) { string xv = pUniqueValueRenderer.get_Value(i); if (xv != "") { pUniqueValueRenderer.set_Symbol(xv, getISymbolByGeomType(featLayer, colorRamp.get_Color(i * (colorRamp.Size - 1) / (pUniqueValueRenderer.ValueCount - 1)))); } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; }
/// <summary> /// UniqueValueRenderer唯一值渲染:统计字段不重复值进行分组渲染图层 /// </summary> /// <param name="geoFeatureLayer"></param> /// <param name="fieldName">唯一值字段</param> public static void SetUniqueValueRenderer(this IGeoFeatureLayer geoFeatureLayer, string fieldName) { ITable table = (ITable)geoFeatureLayer.FeatureClass; IQueryFilter queryFilter = new QueryFilter(); queryFilter.AddField(fieldName); var cursor = table.Search(queryFilter, true); //获取字段中各要素属性唯一值 IDataStatistics dataStatistics = new DataStatisticsClass { Field = fieldName, Cursor = cursor }; var enumreator = dataStatistics.UniqueValues; var fieldCount = dataStatistics.UniqueValueCount; IUniqueValueRenderer uvRenderer = new UniqueValueRendererClass(); uvRenderer.FieldCount = 1; //单值渲染 uvRenderer.set_Field(0, fieldName); //渲染字段 IEnumColors enumColor = GetColorRamp(fieldCount).Colors; enumColor.Reset(); while (enumreator.MoveNext()) { var value = enumreator.Current?.ToString(); if (value == null) { continue; } IColor color = enumColor.Next(); ISymbol symbol = GetDefaultSymbol(geoFeatureLayer.FeatureClass.ShapeType, color); uvRenderer.AddValue(value, fieldName, symbol); } geoFeatureLayer.Renderer = (IFeatureRenderer)uvRenderer; }
public void UniqueValueRender(AxMapControl pMapcontrol, IFeatureLayer pFtLayer, int pCount, string pFieldName) { IGeoFeatureLayer pGeoFeaturelayer = pFtLayer as IGeoFeatureLayer; IUniqueValueRenderer pUnique = new UniqueValueRendererClass(); pUnique.FieldCount = 1; pUnique.set_Field(0, pFieldName); ISimpleFillSymbol pSimFill = new SimpleFillSymbolClass(); //给颜色 IFeatureCursor pFtCursor = pFtLayer.FeatureClass.Search(null, false); IFeature pFt = pFtCursor.NextFeature(); IFillSymbol pFillSymbol1; ////添加第一个符号 //pFillSymbol1 = new SimpleFillSymbolClass(); //pFillSymbol1.Color = GetRGBColor(103, 252, 179) as IColor; ////添加第二个符号 //IFillSymbol pFillSymbol2 = new SimpleFillSymbolClass(); //pFillSymbol2.Color = GetRGBColor(125, 155, 251) as IColor; //创建并设置随机色谱从上面的的图可以看出我们要给每一个值定义一种颜色,我 们可以创建色谱,但是色谱的这些参数 IRandomColorRamp pColorRamp = new RandomColorRampClass(); pColorRamp.StartHue = 0; pColorRamp.MinValue = 20; pColorRamp.MinSaturation = 15; pColorRamp.EndHue = 360; pColorRamp.MaxValue = 100; pColorRamp.MaxSaturation = 30; pColorRamp.Size = pCount; //pColorRamp.Size = pUniqueValueRenderer.ValueCount; bool ok = true; pColorRamp.CreateRamp(out ok); IEnumColors pEnumRamp = pColorRamp.Colors; //IColor pColor = pEnumRamp.Next(); int pIndex = pFt.Fields.FindField(pFieldName); //因为我只有24条记录,所以改变这些,这些都不会超过255或者为负数.求余 int i = 0; while (pFt != null) { IColor pColor = pEnumRamp.Next(); if (pColor == null) { pEnumRamp.Reset(); pColor = pEnumRamp.Next(); } //以下注释代码为自定义的两种颜色 ,如果不使用随机的颜色,可以采用这样的 //if (i % 2 == 0) //{ // pUnique.AddValue(Convert.ToString(pFt.get\_Value(pIndex)) , pFieldName, pFillSymbol1 as ISymbol); //} //else //{ // pUnique.AddValue(Convert.ToString(pFt.get\_Value(pIndex)) , pFieldName, pFillSymbol2 as ISymbol); //} //i++; pFillSymbol1 = new SimpleFillSymbolClass(); pFillSymbol1.Color = pColor; pUnique.AddValue(Convert.ToString(pFt.get_Value(pIndex)), pFieldName, pFillSymbol1 as ISymbol); pFt = pFtCursor.NextFeature(); // pColor = pEnumRamp.Next(); } pGeoFeaturelayer.Renderer = pUnique as IFeatureRenderer; pMapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
private void UniqueValueRender_Click(object sender, EventArgs e) { // ITable pTable= (ITable)this.mainMapControl.get_Layer(0); int fieldIndex = pTable.FindField("NAME");//取得"NAME"字段的index,关键 IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.WhereClause = ""; pQueryFilter.AddField("NAME"); //IFeatureCursor pFeatureCursor = pTable.Search(pQueryFilter, false); int rowCount = pTable.RowCount(pQueryFilter);//取得"NAME"字段有值得行的数目,关键!!!!! //以下代码创建并设置随机颜色带对象,并生成颜色 IRandomColorRamp pColorRamp = new RandomColorRampClass(); pColorRamp.StartHue = 0; pColorRamp.MinValue = 99; pColorRamp.MinSaturation = 15; pColorRamp.EndHue = 360; pColorRamp.MaxValue = 100; pColorRamp.MaxSaturation = 30; pColorRamp.Size = rowCount; bool ok = true; pColorRamp.CreateRamp(out ok);//产生颜色 if (ok) { IEnumColors pEnumColors = pColorRamp.Colors; ISimpleFillSymbol pSimpleFillSymbol; IRowBuffer pRowBuffer; IColor pColor; string value; IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();//创建着色对象 pUniqueValueRenderer.FieldCount = 1;//设置只对一个字段进行着色 pUniqueValueRenderer.set_Field(0, "NAME"); for (int i = 0; i < rowCount; i++) { pRowBuffer = (IRowBuffer)pTable.GetRow(i);//关键,用于取得字段值 value = pRowBuffer.get_Value(fieldIndex).ToString(); pColor = pEnumColors.Next(); pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Color = pColor; pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pUniqueValueRenderer.AddValue(value, "", (ISymbol)pSimpleFillSymbol);//为每个唯一值设置Symbol,关键!!!!!! } //ITransparencyRenderer pTransparencyRenderer = pUniqueValueRenderer as ITransparencyRenderer; //pTransparencyRenderer.TransparencyField = ""; ((IGeoFeatureLayer)pTable).Renderer = pUniqueValueRenderer as IFeatureRenderer; this.mainMapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null); //this.axTOCControl.SetBuddyControl(this.mainMapControl.Object); this.axTOCControl.Update(); } }
private static void doSymbolizeLayer(IActiveView activeView, int i, string fieldName, bool doRemove, string filenamePrefix, string filenameSuffix, string filename) { if (filename == "") filename = fieldName; try { if (ArcMap.Document.SelectedLayer == null) { System.Windows.Forms.MessageBox.Show("Select a layer before continuing."); return; } IFeatureLayer ifl = (IFeatureLayer)ArcMap.Document.SelectedLayer; if (fieldName == "Chemistry1" && ifl.FeatureClass.FindField(fieldName) < 0) { //try Chem if Chemistry1 not found fieldName = "Chem"; } if (ifl.FeatureClass.FindField(fieldName) < 0) { System.Windows.Forms.MessageBox.Show("Selected layer does not contain the " + fieldName + " field and can't be symbolized " + "with this tool. Select another layer to continue."); return; } string geomTypeName = "Polygon"; if (ifl.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) geomTypeName = "Polyline"; var asmPath = GetAssemblyPath(); ILayerFile layerFile = new LayerFileClass(); if (filenamePrefix == "NWIPlus") { layerFile.Open(asmPath + "/Symbology/" + filenamePrefix + filename + ".lyr"); } else { if (fieldName == "Chem") { layerFile.Open(asmPath + "/Symbology/" + filenamePrefix + "Chemistry1" + filenameSuffix + ".lyr"); } else { layerFile.Open(asmPath + "/Symbology/" + filenamePrefix + filename +filenameSuffix + ".lyr"); } } IGeoFeatureLayer igfl = (IGeoFeatureLayer)layerFile.Layer; IUniqueValueRenderer iuvr = (IUniqueValueRenderer)igfl.Renderer; IUniqueValueRenderer iuvr_new = iuvr; #if false if( filenameSuffix == "Rated") { iuvr_new = new UniqueValueRendererClass(); iuvr_new.FieldCount = 1; iuvr_new.Field[0] = fieldName; iuvr_new.DefaultSymbol = iuvr.DefaultSymbol; iuvr_new.UseDefaultSymbol = false; // iuvr.UseDefaultSymbol = false; // iuvr.Field[0] = symbType; for (int l = 0; l < iuvr.ValueCount; l++) { //iuvr.Heading[iuvr.Value[l]] = symbType; iuvr_new.AddValue(iuvr.Value[l], fieldName, iuvr.Symbol[iuvr.Value[l]]); } } #endif /*ILegendInfo li = (ILegendInfo)iuvr; ILegendGroup gp = (ILegendGroup)li.LegendGroup[0]; gp.Heading = symbType;*/ IFeatureWorkspace iw = (IFeatureWorkspace)((IDataset)ifl.FeatureClass).Workspace; ISQLSyntax sql = (ISQLSyntax)iw; string prefix = sql.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); string suffix = sql.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); IQueryFilter f = new QueryFilterClass(); int vCount = iuvr_new.ValueCount; List<string> values = new List<string>(); #if false for (int k0 = 0; k0 < iuvr_new.ValueCount; k0++) { try { IFillSymbol ifs = (IFillSymbol) iuvr_new.Symbol[iuvr.Value[k0]]; ifs.Outline = null; //ifs.Outline.Width = 0; } catch(Exception abcd) { } } #endif if (doRemove) { char[] delimiter = { iuvr_new.FieldDelimiter[0] }; for (int j = 0; j < vCount; j++) { f.WhereClause = ""; string[] currValues = iuvr_new.Value[j].Split(delimiter); for (int k = 0; k < currValues.Length; k++) { if (k > 0) f.WhereClause += " AND "; f.WhereClause += prefix + iuvr_new.Field[k] + suffix + " = '" + currValues[k].Trim() + "'"; } ICursor fc = null; bool bFound = false; try { fc = ((ITable)ifl).Search(f, true); bFound = (fc.NextRow() == null) ? false : true; } catch (Exception v) { //fc = null; } if (!bFound) values.Add(iuvr_new.Value[j]); } } foreach (string v in values) { iuvr_new.RemoveValue(v); } if (iuvr_new.ValueCount > 0) { IGeoFeatureLayer igd_dest = (IGeoFeatureLayer)ifl; igd_dest.Renderer = (IFeatureRenderer)iuvr_new; ArcMap.Document.ActiveView.ContentsChanged(); ArcMap.Document.UpdateContents(); ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } else { System.Windows.Forms.MessageBox.Show("No values found. No changes will be made to the symbology"); return; } //ArcMap.Document.CurrentContentsView.Deactivate(); //ArcMap.Document.ContentsView[0].Activate(ArcMap.Application.hWnd, ArcMap.Document); } catch (Exception e) { } finally { } }
public static void DefineUniqueValueRenderer(IGeoFeatureLayer geoFealyr,string fieldName) { // Create color ramp for the symbol in rendere IRandomColorRamp randomColorRamp = new RandomColorRampClass(); randomColorRamp.MinSaturation = 20; randomColorRamp.MaxSaturation = 40; randomColorRamp.MinValue = 85; randomColorRamp.MaxValue = 100; randomColorRamp.StartHue = 76; randomColorRamp.EndHue = 188; randomColorRamp.UseSeed = true; randomColorRamp.Seed = 43; // Create a symbol ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; simpleFillSymbol.Outline.Width = 0.4; // Create the renderer IUniqueValueRenderer uniqueValueRender = new UniqueValueRendererClass(); uniqueValueRender.FieldCount = 1; uniqueValueRender.set_Field(0, fieldName); uniqueValueRender.DefaultSymbol = simpleFillSymbol as ISymbol; uniqueValueRender.UseDefaultSymbol = true; IDisplayTable displayTable = geoFealyr as IDisplayTable; IFeatureCursor feacursor = displayTable.SearchDisplayTable(null, false) as IFeatureCursor; IFeature fea = feacursor.NextFeature(); bool valfound; int fieldIndex; IFields fields = feacursor.Fields; fieldIndex = fields.FindField(fieldName); while(fea!=null) { ISimpleFillSymbol classSymbol = new SimpleFillSymbolClass(); classSymbol.Style = esriSimpleFillStyle.esriSFSSolid; classSymbol.Outline.Width = 0.4; string classValue; classValue = fea.get_Value(fieldIndex) as string; valfound = false; for(int i=0;i<=uniqueValueRender.ValueCount-1;i++) { if(uniqueValueRender.get_Value(i)==classValue) { valfound = true; break; } } if(valfound==false) { uniqueValueRender.AddValue(classValue, fieldName, classSymbol as ISymbol); uniqueValueRender.set_Label(classValue, classValue); uniqueValueRender.set_Symbol(classValue, classSymbol as ISymbol); } fea = feacursor.NextFeature(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(feacursor); randomColorRamp.Size = uniqueValueRender.ValueCount; bool bOK; randomColorRamp.CreateRamp(out bOK); IEnumColors enumColors = randomColorRamp.Colors; enumColors.Reset(); for(int j=0;j<=uniqueValueRender.ValueCount-1;j++) { string xv; xv = uniqueValueRender.get_Value(j); if(xv!="") { ISimpleFillSymbol simplefs = uniqueValueRender.get_Symbol(xv) as ISimpleFillSymbol; simplefs.Color = enumColors.Next(); uniqueValueRender.set_Symbol(xv, simplefs as ISymbol); } } uniqueValueRender.ColorScheme = "Custome"; ITable tbl = displayTable as ITable; bool isString = tbl.Fields.get_Field(fieldIndex).Type == esriFieldType.esriFieldTypeString; uniqueValueRender.set_FieldType(0, isString); geoFealyr.Renderer = uniqueValueRender as IFeatureRenderer; IUID uid = new UIDClass(); uid.Value = "{25AE5C2F-0B57-41C6-A492-31352BAD3A37}"; geoFealyr.RendererPropertyPageClassID = uid as UIDClass; }
public IFeatureRenderer UniqueValueRenderer(IFeatureWorkspace workspace, IFeatureClass fc) { try { string tablename = ((IDataset)fc).BrowseName; ITable ipTable = workspace.OpenTable(tablename); IFeatureCursor featureCursor = fc.Search(null, false); IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.Cursor = featureCursor as ICursor; dataStatistics.Field = "gridcode"; System.Collections.IEnumerator enumerator = dataStatistics.UniqueValues; enumerator.Reset(); while (enumerator.MoveNext()) { object myObject = enumerator.Current; } int uniqueValues = dataStatistics.UniqueValueCount; //Create colors for each unique value. IRandomColorRamp colorRamp = new RandomColorRampClass(); colorRamp.Size = uniqueValues; colorRamp.Seed = 100; bool createColorRamp; colorRamp.CreateRamp(out createColorRamp); if (createColorRamp == false) { return(null); } IUniqueValueRenderer uvRenderer = new UniqueValueRendererClass(); IFeatureRenderer featRenderer = (IFeatureRenderer)uvRenderer; uvRenderer.FieldCount = 1; ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); ISimpleFillSymbol fillSymbol2 = new SimpleFillSymbolClass(); ISimpleLineSymbol outlineSymbol = new SimpleLineSymbolClass(); outlineSymbol.Color = new RgbColorClass() { NullColor = true } as IColor; outlineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; if (ShowNonVisibleData == true) { fillSymbol.Color = new RgbColorClass() { Red = 255 } as IColor; fillSymbol.Outline = outlineSymbol; uvRenderer.AddValue("0", "", fillSymbol as ISymbol); uvRenderer.set_Label("0", "Non-Visible"); } fillSymbol2.Color = new RgbColorClass() { Green = 255 } as IColor; fillSymbol2.Outline = outlineSymbol; uvRenderer.AddValue("1", "", fillSymbol2 as ISymbol); uvRenderer.set_Label("1", "Visible by 1 Observer"); int field = ipTable.FindField("gridcode"); uvRenderer.set_Field(0, "gridcode"); for (int i = 2; i < uniqueValues; i++) { ISimpleFillSymbol newFillSymbol = new SimpleFillSymbolClass(); newFillSymbol.Color = colorRamp.get_Color(i); newFillSymbol.Outline = outlineSymbol; uvRenderer.AddValue(i.ToString(), "", newFillSymbol as ISymbol); string label = "Visible by " + i.ToString() + " Observers"; uvRenderer.set_Label(i.ToString(), label); } return(featRenderer); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return(null); } }
public static void UpdateMapUnitPolysRenderer(IWorkspace theWorkspace) { // Get the MapUnitPolys Layer from the ToC IFeatureLayer theLayer = commonFunctions.FindFeatureLayer(theWorkspace, "MapUnitPolys"); // If the layer was not found, don't try and update the renderer! if (theLayer == null) { return; } // Setup the renderer IUniqueValueRenderer theRenderer = new UniqueValueRendererClass(); theRenderer.FieldCount = 1; theRenderer.Field[0] = "MapUnit"; // Setup a couple variables IColor nullColor = new RgbColorClass(); nullColor.NullColor = true; // Setup a blank line ILineSymbol nullLine = new SimpleLineSymbolClass(); nullLine.Color = nullColor; // Setup the "All Other Values" symbol ISimpleFillSymbol defaultSymbol = new SimpleFillSymbolClass(); IColor defaultColor = new RgbColorClass(); defaultColor.RGB = 255; defaultSymbol.Color = defaultColor; defaultSymbol.Outline = nullLine; // Apply the "All other values" symbol to the renderer theRenderer.DefaultSymbol = defaultSymbol as ISymbol; theRenderer.UseDefaultSymbol = true; string theHeading = "Geologic Map Units"; // Get the Legend Items var sortedDmu = GetDmuSortedByHierarchy(theWorkspace); // Loop through the legend items foreach (KeyValuePair <string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> legendEntry in sortedDmu) { DescriptionOfMapUnitsAccess.DescriptionOfMapUnit thisDmuEntry = legendEntry.Value; // If this is a heading, make it so if (thisDmuEntry.ParagraphStyle.Contains("Heading") == true) { theHeading = thisDmuEntry.Name; continue; } // Make a Simple Fill RuleID ISimpleFillSymbol theSymbol = new SimpleFillSymbolClass(); //theRuleID.Style = esriSimpleFillStyle.esriSFSSolid; // Get the right color IColor symbolColor = new RgbColorClass(); string rgbString = thisDmuEntry.AreaFillRGB; string[] rgbValues = rgbString.Split(';'); // Long integer representations of RGB values are dumb: G*65536 + B*256 + R if (rgbValues.Length < 3) { symbolColor.RGB = 16777215; } else { symbolColor.RGB = int.Parse(rgbValues[0]) + int.Parse(rgbValues[1]) * 256 + int.Parse(rgbValues[2]) * 65536; } theSymbol.Color = symbolColor; theSymbol.Outline = nullLine; // Add it to the renderer theRenderer.AddValue(thisDmuEntry.MapUnit, theHeading, theSymbol as ISymbol); // Give it the right label theRenderer.Label[thisDmuEntry.MapUnit] = thisDmuEntry.MapUnit + " - " + thisDmuEntry.Name; } // Apply the renderer IGeoFeatureLayer geoFLayer = (IGeoFeatureLayer)theLayer; geoFLayer.Renderer = (IFeatureRenderer)theRenderer; // Minimizing the legend info in the Table of Contents is not trivial ILegendInfo layerLegendInfo = (ILegendInfo)theLayer; for (int i = 0; i < layerLegendInfo.LegendGroupCount; i++) { ILegendGroup layerLegendGroup = layerLegendInfo.get_LegendGroup(i); layerLegendGroup.Visible = false; } // Update the views ArcMap.Document.UpdateContents(); ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, theLayer, null); }
///<summary> ///�ڳ�������ʱ���ڴ��д���ʸ��Ҫ�ز㣬���ӵ���ͼ�ؼ���� ///</summary> ///<param name="pMapCtrl">��ͼ�ؼ�</param> ///<returns>IFeatureLayer �¼ӵ�Ҫ�ز�</returns> public IFeatureLayer AddFeatureLayerByMemoryWS(AxMapControl pMapCtrl, ISpatialReference pSReference) { try { if (pMapCtrl == null) return null; #region �����µ��ڴ湤���ռ� IWorkspaceFactory pWSF = new InMemoryWorkspaceFactoryClass(); IWorkspaceName pWSName = pWSF.Create("", "Temp", null, 0); IName pName = (IName)pWSName; IWorkspace pMemoryWS = (IWorkspace)pName.Open(); #endregion IField oField = new FieldClass(); IFields oFields = new FieldsClass(); IFieldsEdit oFieldsEdit = null; IFieldEdit oFieldEdit = null; IFeatureClass oFeatureClass = null; IFeatureLayer oFeatureLayer = null; try { oFieldsEdit = oFields as IFieldsEdit; oFieldEdit = oField as IFieldEdit; oFieldEdit.Name_2 = "OBJECTID"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; oFieldEdit.IsNullable_2 = false; oFieldEdit.Required_2 = false; oFieldsEdit.AddField(oField); oField = new FieldClass(); oFieldEdit = oField as IFieldEdit; IGeometryDef pGeoDef = new GeometryDefClass(); IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef; pGeoDefEdit.AvgNumPoints_2 = 5; pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon; pGeoDefEdit.GridCount_2 = 1; pGeoDefEdit.HasM_2 = false; pGeoDefEdit.HasZ_2 = false; pGeoDefEdit.SpatialReference_2 = pSReference; oFieldEdit.Name_2 = "SHAPE"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; oFieldEdit.GeometryDef_2 = pGeoDef; oFieldEdit.IsNullable_2 = true; oFieldEdit.Required_2 = true; oFieldsEdit.AddField(oField); oField = new FieldClass(); oFieldEdit = oField as IFieldEdit; oFieldEdit.Name_2 = "Code"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger; oFieldEdit.IsNullable_2 = true; oFieldsEdit.AddField(oField); //����Ҫ���� oFeatureClass = (pMemoryWS as IFeatureWorkspace).CreateFeatureClass("Temp", oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", ""); oFeatureLayer = new FeatureLayerClass(); oFeatureLayer.Name = "TransTemp"; oFeatureLayer.FeatureClass = oFeatureClass; //����Ψһֵ���Ż����� IUniqueValueRenderer pURender = new UniqueValueRendererClass(); pURender.FieldCount = 1; pURender.set_Field(0, "Code"); pURender.UseDefaultSymbol = false; ISimpleFillSymbol pFillSym = new SimpleFillSymbolClass(); pFillSym.Style = esriSimpleFillStyle.esriSFSSolid; //������ɫ IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 255; pFillSym.Color = pColor; pURender.AddValue("1", "", pFillSym as ISymbol); pFillSym = new SimpleFillSymbolClass(); pFillSym.Style = esriSimpleFillStyle.esriSFSSolid; //Ψһֵ���Ż��ڴ�ͼ�� (oFeatureLayer as IGeoFeatureLayer).Renderer = pURender as IFeatureRenderer; ILayerEffects pLyrEffect = oFeatureLayer as ILayerEffects; //���� pLyrEffect.Transparency = 80; } catch (Exception Err) { MessageBox.Show(Err.Message); } finally { try { System.Runtime.InteropServices.Marshal.ReleaseComObject(oField); System.Runtime.InteropServices.Marshal.ReleaseComObject(oFields); System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldsEdit); System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldEdit); System.Runtime.InteropServices.Marshal.ReleaseComObject(pName); System.Runtime.InteropServices.Marshal.ReleaseComObject(pWSF); System.Runtime.InteropServices.Marshal.ReleaseComObject(pWSName); System.Runtime.InteropServices.Marshal.ReleaseComObject(pMemoryWS); System.Runtime.InteropServices.Marshal.ReleaseComObject(oFeatureClass); } catch { } GC.Collect(); } return oFeatureLayer; } catch (Exception Err) { MessageBox.Show(Err.Message, "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information); return null; } }
private IUniqueValueRenderer CreateTrackUniqueValueRenderer(IFeatureClass featureClass, string fieldName) { IRgbColor color = new RgbColorClass(); color.Red = 0; color.Blue = 0; color.Green = 255; ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = (IColor)color; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = 1.0; IUniqueValueRenderer uniqueRenderer = new UniqueValueRendererClass(); uniqueRenderer.FieldCount = 1; uniqueRenderer.set_Field(0, fieldName); uniqueRenderer.DefaultSymbol = (ISymbol)simpleLineSymbol; uniqueRenderer.UseDefaultSymbol = true; Random rand = new Random(); bool bValFound = false; IFeatureCursor featureCursor = featureClass.Search(null, true); IFeature feature = null; string val = string.Empty; int fieldID = featureClass.FindField(fieldName); if (-1 == fieldID) return uniqueRenderer; while ((feature = featureCursor.NextFeature()) != null) { bValFound = false; val = Convert.ToString(feature.get_Value(fieldID)); for (int i = 0; i < uniqueRenderer.ValueCount - 1; i++) { if (uniqueRenderer.get_Value(i) == val) bValFound = true; } if (!bValFound)//need to add the value to the renderer { color.Red = rand.Next(255); color.Blue = rand.Next(255); color.Green = rand.Next(255); simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = (IColor)color; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = 1.0; //add the value to the renderer uniqueRenderer.AddValue(val, "name", (ISymbol)simpleLineSymbol); } } //release the featurecursor ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor); return uniqueRenderer; }
private void 添加面形地物ToolStripMenuItem_Click(object sender, EventArgs e) { //创建要素类 #region 创建新的内存工作空间 IWorkspaceFactory pWSF = new InMemoryWorkspaceFactoryClass(); IWorkspaceName pWSName = pWSF.Create("", "Temp", null, 0); IName pName = (IName)pWSName; IWorkspace pMemoryWS = (IWorkspace)pName.Open(); #endregion IField oField = new FieldClass(); IFields oFields = new FieldsClass(); IFieldsEdit oFieldsEdit = null; IFieldEdit oFieldEdit = null; IFeatureClass oFeatureClass = null; IFeatureLayer oFeatureLayer = null; oFieldsEdit = oFields as IFieldsEdit; oFieldEdit = oField as IFieldEdit; oFieldEdit.Name_2 = "OBJECTID"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; oFieldEdit.IsNullable_2 = false; oFieldEdit.Required_2 = false; oFieldsEdit.AddField(oField); oField = new FieldClass(); oFieldEdit = oField as IFieldEdit; IGeometryDef pGeoDef = new GeometryDefClass(); IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef; pGeoDefEdit.AvgNumPoints_2 = 5; pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon; pGeoDefEdit.GridCount_2 = 1; pGeoDefEdit.HasM_2 = false; pGeoDefEdit.HasZ_2 = false; pGeoDefEdit.SpatialReference_2 = axMapControl1.SpatialReference; oFieldEdit.Name_2 = "SHAPE"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; oFieldEdit.GeometryDef_2 = pGeoDef; oFieldEdit.IsNullable_2 = true; oFieldEdit.Required_2 = true; oFieldsEdit.AddField(oField); oField = new FieldClass(); oFieldEdit = oField as IFieldEdit; oFieldEdit.Name_2 = "Code"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger; oFieldEdit.IsNullable_2 = true; oFieldsEdit.AddField(oField); //创建要素类 oFeatureClass = (pMemoryWS as IFeatureWorkspace).CreateFeatureClass("Temp", oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", ""); oFeatureLayer = new FeatureLayerClass(); oFeatureLayer.Name = "PolygonLayer"; oFeatureLayer.FeatureClass = oFeatureClass; //创建唯一值符号化对象 IUniqueValueRenderer pURender = new UniqueValueRendererClass(); pURender.FieldCount = 1; pURender.set_Field(0, "Code"); pURender.UseDefaultSymbol = false; ISimpleFillSymbol pFillSym = new SimpleFillSymbolClass(); pFillSym.Style = esriSimpleFillStyle.esriSFSSolid; //半透明颜色 IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 255; pFillSym.Color = pColor; pURender.AddValue("1", "", pFillSym as ISymbol); pFillSym = new SimpleFillSymbolClass(); pFillSym.Style = esriSimpleFillStyle.esriSFSSolid; //唯一值符号化内存图层 (oFeatureLayer as IGeoFeatureLayer).Renderer = pURender as IFeatureRenderer; ILayerEffects pLyrEffect = oFeatureLayer as ILayerEffects; //透明度 pLyrEffect.Transparency = 0; this.axMapControl1.AddLayer(oFeatureLayer, axMapControl1.LayerCount); insertPolygon = true; }
public static void UpdateMapUnitPolysRenderer(IWorkspace theWorkspace) { // Get the MapUnitPolys Layer from the ToC IFeatureLayer theLayer = commonFunctions.FindFeatureLayer(theWorkspace, "MapUnitPolys"); // If the layer was not found, don't try and update the renderer! if (theLayer == null) { return; } // Setup the renderer IUniqueValueRenderer theRenderer = new UniqueValueRendererClass(); theRenderer.FieldCount = 1; theRenderer.Field[0] = "MapUnit"; // Setup a couple variables IColor nullColor = new RgbColorClass(); nullColor.NullColor = true; // Setup a blank line ILineSymbol nullLine = new SimpleLineSymbolClass(); nullLine.Color = nullColor; // Setup the "All Other Values" symbol ISimpleFillSymbol defaultSymbol = new SimpleFillSymbolClass(); IColor defaultColor = new RgbColorClass(); defaultColor.RGB = 255; defaultSymbol.Color = defaultColor; defaultSymbol.Outline = nullLine; // Apply the "All other values" symbol to the renderer theRenderer.DefaultSymbol = defaultSymbol as ISymbol; theRenderer.UseDefaultSymbol = true; string theHeading = "Geologic Map Units"; // Get the Legend Items var sortedDmu = GetDmuSortedByHierarchy(theWorkspace); // Loop through the legend items foreach (KeyValuePair<string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> legendEntry in sortedDmu) { DescriptionOfMapUnitsAccess.DescriptionOfMapUnit thisDmuEntry = legendEntry.Value; // If this is a heading, make it so if (thisDmuEntry.ParagraphStyle.Contains("Heading") == true) { theHeading = thisDmuEntry.Name; continue; } // Make a Simple Fill RuleID ISimpleFillSymbol theSymbol = new SimpleFillSymbolClass(); //theRuleID.Style = esriSimpleFillStyle.esriSFSSolid; // Get the right color IColor symbolColor = new RgbColorClass(); string rgbString = thisDmuEntry.AreaFillRGB; string[] rgbValues = rgbString.Split(';'); // Long integer representations of RGB values are dumb: G*65536 + B*256 + R if (rgbValues.Length < 3) { symbolColor.RGB = 16777215; } else { symbolColor.RGB = int.Parse(rgbValues[0]) + int.Parse(rgbValues[1]) * 256 + int.Parse(rgbValues[2]) * 65536; } theSymbol.Color = symbolColor; theSymbol.Outline = nullLine; // Add it to the renderer theRenderer.AddValue(thisDmuEntry.MapUnit, theHeading, theSymbol as ISymbol); // Give it the right label theRenderer.Label[thisDmuEntry.MapUnit] = thisDmuEntry.MapUnit + " - " + thisDmuEntry.Name; } // Apply the renderer IGeoFeatureLayer geoFLayer = (IGeoFeatureLayer)theLayer; geoFLayer.Renderer = (IFeatureRenderer)theRenderer; // Minimizing the legend info in the Table of Contents is not trivial ILegendInfo layerLegendInfo = (ILegendInfo)theLayer; for (int i = 0; i < layerLegendInfo.LegendGroupCount; i++) { ILegendGroup layerLegendGroup = layerLegendInfo.get_LegendGroup(i); layerLegendGroup.Visible = false; } // Update the views ArcMap.Document.UpdateContents(); ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, theLayer, null); }
private void resultSymbologyTab() { IGeoFeatureLayer pGeoFeatureLayer = this.pLayer as IGeoFeatureLayer; TreeNode currentNode = this.trvSymbologyShows.SelectedNode; if (currentNode.Text == "单一符号") { if (this.singleSymbol == null) { return; } ISimpleRenderer pSimpleRender = new SimpleRendererClass(); pSimpleRender.Symbol = this.singleSymbol; pSimpleRender.Label = this.txtSingleSymbolLabel.Text; pSimpleRender.Description = this.txtSingleSymbolDescription.Text; pGeoFeatureLayer.Renderer = pSimpleRender as IFeatureRenderer; } else if (currentNode.Text == "唯一值") { if (this.lsvUniqueValue.Items.Count == 0 || this.pUniValueColorRamp == null) { return; } this.pUniValueColorRamp.Size = this.lsvUniqueValue.Items.Count - 1; bool IsColorRampCreatedOK = false; this.pUniValueColorRamp.CreateRamp(out IsColorRampCreatedOK); if (IsColorRampCreatedOK) { IEnumColors pEnumColors = pUniValueColorRamp.Colors; pEnumColors.Reset(); IUniqueValueRenderer pUniqueValueRender = new UniqueValueRendererClass(); pUniqueValueRender.FieldCount = 1; pUniqueValueRender.set_Field(0, this.cbbUniValueField.Text); IColor pColor; if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPolygon) { ISimpleFillSymbol pSimpleFillSymbol; for (int i = 0; i < pUniValueColorRamp.Size; i++) { pColor = pEnumColors.Next(); pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Color = pColor; pUniqueValueRender.AddValue(this.lsvUniqueValue.Items[i + 1].Text, "", (ISymbol)pSimpleFillSymbol); } } else if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPolyline) { ISimpleLineSymbol pSimpleLineSymbol; for (int i = 0; i < pUniValueColorRamp.Size; i++) { pColor = pEnumColors.Next(); pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Color = pColor; pUniqueValueRender.AddValue(this.lsvUniqueValue.Items[i + 1].Text, "", (ISymbol)pSimpleLineSymbol); } } else if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPoint) { ISimpleMarkerSymbol pSimpleMarkerSymbol; for (int i = 0; i < pUniValueColorRamp.Size; i++) { pColor = pEnumColors.Next(); pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Color = pColor; pUniqueValueRender.AddValue(this.lsvUniqueValue.Items[i + 1].Text, "", (ISymbol)pSimpleMarkerSymbol); } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRender; } } else if (currentNode.Text == "分级颜色") { if (this.lsvClassBreaksSymbol.Items.Count == 0 || this.pClassBreaksColorRamp == null) { return; } int classCount = int.Parse(this.cbbClassBreaksCount.Text); IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass(); pClassBreaksRenderer.BreakCount = classCount; pClassBreaksRenderer.Field = this.cbbClassBreakField.Text; pClassBreaksRenderer.SortClassesAscending = true; IColorRamp pColorRamp = this.pClassBreaksColorRamp; pColorRamp.Size = classCount; bool ok; pColorRamp.CreateRamp(out ok); if (!ok) { return; } IEnumColors pEnumColors = pColorRamp.Colors; pEnumColors.Reset(); IColor pColor; if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPolygon) { for (int i = 0; i < classCount; i++)//为每个值范围设置符号(此处为SimpleFillSymbol) { pColor = pEnumColors.Next(); ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Color = pColor; pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pClassBreaksRenderer.set_Break(i, this.classBreaks[i + 1]);//设置临界值,注意下标,关键!!! pClassBreaksRenderer.set_Symbol(i, (ISymbol)pSimpleFillSymbol);//设置Symbol,关键!!! pClassBreaksRenderer.set_Label(i, this.lsvClassBreaksSymbol.Items[i].Text); pClassBreaksRenderer.set_Description(i, this.lsvClassBreaksSymbol.Items[i].Text); } } else if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPolyline) { for (int i = 0; i < classCount; i++)//为每个值范围设置符号 { pColor = pEnumColors.Next(); ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Color = pColor; pClassBreaksRenderer.set_Symbol(i, (ISymbol)pSimpleLineSymbol);//设置Symbol,关键!!! pClassBreaksRenderer.set_Label(i, this.lsvClassBreaksSymbol.Items[i].Text); pClassBreaksRenderer.set_Break(i, this.classBreaks[i + 1]);//设置临界值,注意下标,关键!!! } } else if (((IFeatureLayer2)this.pLayer).ShapeType == esriGeometryType.esriGeometryPoint) { for (int i = 0; i < classCount; i++)//为每个值范围设置符号 { pColor = pEnumColors.Next(); ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Color = pColor; pClassBreaksRenderer.set_Symbol(i, (ISymbol)pSimpleMarkerSymbol);//设置Symbol,关键!!! pClassBreaksRenderer.set_Label(i, this.lsvClassBreaksSymbol.Items[i].Text); pClassBreaksRenderer.set_Break(i, this.classBreaks[i + 1]);//设置临界值,注意下标,关键!!! } } pGeoFeatureLayer.Renderer = pClassBreaksRenderer as IFeatureRenderer; } }
private IUniqueValueRenderer CreateTrackUniqueValueRenderer(IFeatureClass featureClass, string fieldName) { IRgbColor color = new RgbColorClass(); color.Red = 0; color.Blue = 0; color.Green = 255; ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = (IColor)color; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = 1.0; IUniqueValueRenderer uniqueRenderer = new UniqueValueRendererClass(); uniqueRenderer.FieldCount = 1; uniqueRenderer.set_Field(0, fieldName); uniqueRenderer.DefaultSymbol = (ISymbol)simpleLineSymbol; uniqueRenderer.UseDefaultSymbol = true; Random rand = new Random(); bool bValFound = false; IFeatureCursor featureCursor = featureClass.Search(null, true); IFeature feature = null; string val = string.Empty; int fieldID = featureClass.FindField(fieldName); if (-1 == fieldID) { return(uniqueRenderer); } while ((feature = featureCursor.NextFeature()) != null) { bValFound = false; val = Convert.ToString(feature.get_Value(fieldID)); for (int i = 0; i < uniqueRenderer.ValueCount - 1; i++) { if (uniqueRenderer.get_Value(i) == val) { bValFound = true; } } if (!bValFound)//need to add the value to the renderer { color.Red = rand.Next(255); color.Blue = rand.Next(255); color.Green = rand.Next(255); simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = (IColor)color; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = 1.0; //add the value to the renderer uniqueRenderer.AddValue(val, "name", (ISymbol)simpleLineSymbol); } } //release the featurecursor ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor); return(uniqueRenderer); }
public UniqueValueRender(AxMapControl pMapcontrol, IFeatureLayer pFtLayer,int pCount, string pFieldName) { IGeoFeatureLayer pGeoFeaturelayer = pFtLayer as IGeoFeatureLayer; IUniqueValueRenderer pUnique = new UniqueValueRendererClass(); pUnique.FieldCount = 1; pUnique.set_Field(0, pFieldName); ISimpleFillSymbol pSimFill = new SimpleFillSymbolClass(); //给颜色 IFeatureCursor pFtCursor = pFtLayer.FeatureClass.Search(null, false); IFeature pFt = pFtCursor.NextFeature(); IFillSymbol pFillSymbol1; ////添加第一个符号 //pFillSymbol1 = new SimpleFillSymbolClass(); //pFillSymbol1.Color = GetRGBColor(103, 252, 179) as IColor; ////添加第二个符号 //IFillSymbol pFillSymbol2 = new SimpleFillSymbolClass(); //pFillSymbol2.Color = GetRGBColor(125, 155, 251) as IColor; //创建并设置随机色谱从上面的的图可以看出我们要给每一个值定义一种颜色,我们可以创建色谱,但是色谱的这些参数 //我调不好这个没,因此掠过则个步骤,我重新定义了两个符号。 IRandomColorRamp pColorRamp = new RandomColorRampClass(); pColorRamp.StartHue = 0; pColorRamp.MinValue = 20; pColorRamp.MinSaturation = 15; pColorRamp.EndHue = 360; pColorRamp.MaxValue = 100; pColorRamp.MaxSaturation = 30; pColorRamp.Size = pCount ; //pColorRamp.Size = pUniqueValueRenderer.ValueCount; bool ok = true; pColorRamp.CreateRamp(out ok); IEnumColors pEnumRamp = pColorRamp.Colors; //IColor pColor = pEnumRamp.Next(); int pIndex =pFt.Fields.FindField(pFieldName); //因为我只有24条记录,所以改变这些,这些都不会超过255或者为负数.求余 int i = 0; while (pFt != null) { IColor pColor = pEnumRamp.Next(); if(pColor ==null) { pEnumRamp.Reset(); pColor = pEnumRamp.Next(); } //if (i % 2 == 0) //{ // pUnique.AddValue(Convert.ToString(pFt.get_Value(pIndex)), pFieldName, pFillSymbol1 as ISymbol); //} //else //{ // pUnique.AddValue(Convert.ToString(pFt.get_Value(pIndex)), pFieldName, pFillSymbol2 as ISymbol); //} //i++; pFillSymbol1 = new SimpleFillSymbolClass(); pFillSymbol1.Color = pColor; pUnique.AddValue(Convert.ToString(pFt.get_Value(pIndex)), pFieldName, pFillSymbol1 as ISymbol); pFt = pFtCursor.NextFeature(); // pColor = pEnumRamp.Next(); } pGeoFeaturelayer.Renderer = pUnique as IFeatureRenderer; pMapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
private IUniqueValueRenderer CreateRenderer(IFeatureClass featureClass) { int uniqueValuesCount = GetUniqueValuesCount(featureClass, strRendererField); System.Collections.IEnumerator enumerator = GetUniqueValues(featureClass, strRendererField); if (uniqueValuesCount == 0) return null; IEnumColors pEnumRamp = GetEnumColorsByRandomColorRamp(uniqueValuesCount); //IEnumColors pEnumRamp = GetEnumColorsBySelectColorRamp(uniqueValuesCount); pEnumRamp.Reset(); IUniqueValueRenderer pUniqueValueR = new UniqueValueRendererClass(); //只用一个字段进行单值着色 pUniqueValueR.FieldCount = 1; //用于区分着色的字段 pUniqueValueR.set_Field(0, strRendererField); IColor pColor = null; ISymbol symbol = null; enumerator.Reset(); while (enumerator.MoveNext()) { object codeValue = enumerator.Current; pColor = pEnumRamp.Next(); switch (featureClass.ShapeType) { case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint: ISimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbolClass() as ISimpleMarkerSymbol; markerSymbol.Color = pColor; symbol = markerSymbol as ISymbol; break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline: ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass() as ISimpleLineSymbol; lineSymbol.Color = pColor; symbol = lineSymbol as ISymbol; break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon: ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass() as ISimpleFillSymbol; fillSymbol.Color = pColor; symbol = fillSymbol as ISymbol; break; default: break; } //将每次得到的要素字段值和修饰它的符号放入着色对象中 pUniqueValueR.AddValue(codeValue.ToString(), strRendererField, symbol); } return pUniqueValueR; }
//单一或多字段符号化 private void UniqueValueRenderer(IFeatureLayer pFeatLyr, string[] sFieldName) { IFeatureLayer pFLayer = pLayer as IFeatureLayer; IGeoFeatureLayer geoLayer = pLayer as IGeoFeatureLayer; IFeatureClass fcls = pFLayer.FeatureClass; IQueryFilter pQueryFilter = new QueryFilterClass(); IFeatureCursor fCursor = fcls.Search(pQueryFilter, false); IRandomColorRamp rx = new RandomColorRampClass(); rx.MinSaturation = 15; rx.MaxSaturation = 30; rx.MinValue = 85; rx.MaxValue = 100; rx.StartHue = 0; rx.EndHue = 360; rx.Size = 100; bool ok;; rx.CreateRamp(out ok); IEnumColors RColors = rx.Colors; RColors.Reset(); IUniqueValueRenderer pRender = new UniqueValueRendererClass(); pRender.FieldCount = 1; pRender.set_Field(0, sFieldName[0]); IFeature pFeat = fCursor.NextFeature(); int index = pFeat.Fields.FindField(sFieldName[0]); while (pFeat != null) { ISimpleFillSymbol symd = new SimpleFillSymbolClass(); symd.Style = esriSimpleFillStyle.esriSFSSolid; symd.Outline.Width = 1; symd.Color = RColors.Next(); string valuestr = pFeat.get_Value(index).ToString(); pRender.AddValue(valuestr, valuestr, symd as ISymbol); pFeat = fCursor.NextFeature(); } geoLayer.Renderer = pRender as IFeatureRenderer; //刷新地图和TOOCotrol IActiveView pActiveView = _MapControl.Map as IActiveView; pActiveView.Refresh(); axTOCControl1.Update(); }
/// <summary> /// 按聚类号对凸包进行渲染 /// </summary> /// <param name="pGeoFeatureLayer"></param> /// <param name="fieldName"></param> public void DefinePointUniqueValueRenderer(IGeoFeatureLayer pGeoFeatureLayer, string fieldName) { IRandomColorRamp pRandomColorRamp = new RandomColorRampClass(); //Create the color ramp for the symbols in the renderer. pRandomColorRamp.MinSaturation = 20; pRandomColorRamp.MaxSaturation = 40; pRandomColorRamp.MinValue = 85; pRandomColorRamp.MaxValue = 100; pRandomColorRamp.StartHue = 76; pRandomColorRamp.EndHue = 188; pRandomColorRamp.UseSeed = true; pRandomColorRamp.Seed = 43; //Create the renderer. IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); /* ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSimpleFillSymbol.Outline.Width = 0.4; */ ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pSimpleMarkerSymbol.Size = 5; pSimpleMarkerSymbol.Outline = true; IRgbColor pLineRgbColor = new RgbColorClass(); pLineRgbColor.Red = 0; pLineRgbColor.Green = 0; pLineRgbColor.Blue = 0; pSimpleMarkerSymbol.OutlineColor = pLineRgbColor as IColor; //These properties should be set prior to adding values. pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, fieldName); pUniqueValueRenderer.DefaultSymbol = pSimpleMarkerSymbol as ISymbol; pUniqueValueRenderer.UseDefaultSymbol = true; IDisplayTable pDisplayTable = pGeoFeatureLayer as IDisplayTable; IFeatureCursor pFeatureCursor = pDisplayTable.SearchDisplayTable(null, false) as IFeatureCursor; IFeature pFeature = pFeatureCursor.NextFeature(); bool ValFound; int fieldIndex; IFields pFields = pFeatureCursor.Fields; fieldIndex = pFields.FindField(fieldName); while (pFeature != null) { /* ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass(); pClassSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pClassSymbol.Outline.Width = 0.4; */ ISimpleMarkerSymbol pClassSymbol = new SimpleMarkerSymbolClass(); pClassSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pClassSymbol.Size = 5; pClassSymbol.Outline = true; pClassSymbol.OutlineColor = pLineRgbColor as IColor; string classValue; classValue = pFeature.get_Value(fieldIndex).ToString(); //Test to see if this value was added to the renderer. If not, add it. ValFound = false; for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++) { if (pUniqueValueRenderer.get_Value(i) == classValue) { ValFound = true; break; //Exit the loop if the value was found. } } //If the value was not found, it's new and will be added. if (ValFound == false) { pUniqueValueRenderer.AddValue(classValue, fieldName, pClassSymbol as ISymbol); pUniqueValueRenderer.set_Label(classValue, classValue); pUniqueValueRenderer.set_Symbol(classValue, pClassSymbol as ISymbol); } pFeature = pFeatureCursor.NextFeature(); } //Since the number of unique values is known, the color ramp can be sized and the colors assigned. pRandomColorRamp.Size = pUniqueValueRenderer.ValueCount; bool bOK; pRandomColorRamp.CreateRamp(out bOK); IEnumColors pEnumColors = pRandomColorRamp.Colors; pEnumColors.Reset(); for (int j = 0; j <= pUniqueValueRenderer.ValueCount - 1; j++) { string xv; xv = pUniqueValueRenderer.get_Value(j); if (xv != "") { ISimpleMarkerSymbol pSimpleMarkerColor = pUniqueValueRenderer.get_Symbol(xv) as ISimpleMarkerSymbol; pSimpleMarkerColor.Color = pEnumColors.Next(); pUniqueValueRenderer.set_Symbol(xv, pSimpleMarkerColor as ISymbol); } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; pGeoFeatureLayer.DisplayField = fieldName; }
private void btnRun_Click(object sender, EventArgs e) { if (cboFldnm1.Text == "" || cboFldnm2.Text == "") { MessageBox.Show("Please select target field"); return; } frmProgress pfrmProgress = new frmProgress(); pfrmProgress.lblStatus.Text = "Processing:"; pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee; pfrmProgress.Show(); REngine pEngine = m_pForm.pEngine; // Creates the input and output matrices from the shapefile// string strLayerName = cboTargetLayer.Text; int intLIndex = m_pSnippet.GetIndexNumberFromLayerName(m_pActiveView, strLayerName); ILayer pLayer = m_pForm.axMapControl1.get_Layer(intLIndex); IFeatureLayer pFLayer = pLayer as IFeatureLayer; IFeatureClass pFClass = pFLayer.FeatureClass; int nFeature = pFClass.FeatureCount(null); IFeatureCursor pFCursor = pFLayer.Search(null, true); IFeature pFeature = pFCursor.NextFeature(); //Get index for independent and dependent variables //Get variable index string strVarNM1 = (string)cboFldnm1.SelectedItem; string strVarNM2 = (string)cboFldnm2.SelectedItem; int intVarIdx1 = pFClass.FindField(strVarNM1); int intVarIdx2 = pFClass.FindField(strVarNM2); //Store Variable at Array double[] arrVar1 = new double[nFeature]; double[] arrVar2 = new double[nFeature]; int i = 0; while (pFeature != null) { arrVar1[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx1)); arrVar2[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx2)); i++; pFeature = pFCursor.NextFeature(); } pFCursor.Flush(); //Plot command for R StringBuilder plotCommmand = new StringBuilder(); string strStartPath = m_pForm.strPath; string pathr = strStartPath.Replace(@"\", @"/"); pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_LARRY.R')"); pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_neighbor.R')"); pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_SASbi.R')"); //Get the file path and name to create spatial weight matrix string strNameR = m_pSnippet.FilePathinRfromLayer(pFLayer); if (strNameR == null) { return; } //Create spatial weight matrix in R pEngine.Evaluate("library(spdep); library(maptools)"); pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')"); pEngine.Evaluate("sample.nb <- poly2nb(sample.shp)"); NumericVector vecVar1 = pEngine.CreateNumericVector(arrVar1); pEngine.SetSymbol("sample.v1", vecVar1); NumericVector vecVar2 = pEngine.CreateNumericVector(arrVar2); pEngine.SetSymbol("sample.v2", vecVar2); string strRSigLv = nudRsigLv.Value.ToString(); string strLSigLv = nudLsigLv.Value.ToString(); string strLSig = cboLocalL.Text; string strRsig = cboLocalPearson.Text; string strRowStd = cboRowStandardization.Text; string strNonZero = null; if (chkDiagZero.Checked) { strNonZero = "FALSE"; } else { strNonZero = "TRUE"; } pEngine.Evaluate("sample.result <- LARRY.bivariate.spatial.outlier(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, pearson.sig = " + strRSigLv + ", lee.sig = " + strLSigLv + ", method.pearson = '" + strRsig + "', method.lee = '" + strLSig + "', type.row.stand = '" + strRowStd + "', alternative = 'two', diag.zero = " + strNonZero + ")"); string[] strSPOutliers = pEngine.Evaluate("as.character(sample.result$sp.outlier)").AsCharacter().ToArray(); //Save Output on SHP //Add Target fields to store results in the shapefile // Keep loop for (int j = 0; j < 1; j++) { string strfldName = lvFields.Items[j].SubItems[1].Text; if (pFClass.FindField(strfldName) == -1) { IField newField = new FieldClass(); IFieldEdit fieldEdit = (IFieldEdit)newField; fieldEdit.Name_2 = strfldName; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; pFClass.AddField(newField); } } //Update Field pFCursor = pFClass.Update(null, false); pFeature = pFCursor.NextFeature(); string strSpOutlierFldName = lvFields.Items[0].SubItems[1].Text; int intSpOutlierFldIdx = pFClass.FindField(strSpOutlierFldName); int featureIdx = 0; while (pFeature != null) { pFeature.set_Value(intSpOutlierFldIdx, strSPOutliers[featureIdx]); pFCursor.UpdateFeature(pFeature); pFeature = pFCursor.NextFeature(); featureIdx++; } pFCursor.Flush(); if (chkMap.Checked) { ITable pTable = (ITable)pFClass; IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, strSpOutlierFldName); if (cboMaptype.Text == "choropleth map") { ISimpleFillSymbol pSymbol; IQueryFilter pQFilter = new QueryFilterClass(); int intTotalCount = 0; string strLabel = null; for (int j = 0; j < 4; j++) { pSymbol = new SimpleFillSymbolClass(); pSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSymbol.Color = m_pSnippet.getRGB(m_pOutlierSymbols[j].R, m_pOutlierSymbols[j].G, m_pOutlierSymbols[j].B); pQFilter.WhereClause = strSpOutlierFldName + " = '" + m_pOutlierSymbols[j].Value + "'"; intTotalCount = pTable.RowCount(pQFilter); strLabel = m_pOutlierSymbols[j].Label + " (" + intTotalCount.ToString() + ")"; pUniqueValueRenderer.AddValue(m_pOutlierSymbols[j].Value, null, (ISymbol)pSymbol); pUniqueValueRenderer.set_Label(m_pOutlierSymbols[j].Value, strLabel); } pUniqueValueRenderer.UseDefaultSymbol = false; } else if (cboMaptype.Text == "point map") { ICharacterMarkerSymbol pSymbol; stdole.IFontDisp stdFontCls = ((stdole.IFontDisp)(new stdole.StdFont())); stdFontCls.Name = "ESRI NIMA VMAP1&2 PT"; stdFontCls.Size = 10; IQueryFilter pQFilter = new QueryFilterClass(); int intTotalCount = 0; string strLabel = null; for (int j = 0; j < 4; j++) { pSymbol = new CharacterMarkerSymbolClass(); pSymbol.CharacterIndex = 248; //pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B); pSymbol.Size = 10; pSymbol.Font = stdFontCls; pSymbol.Angle = m_pOutlierSymbols[j].Angle; pQFilter.WhereClause = strSpOutlierFldName + " = '" + m_pOutlierSymbols[j].Value + "'"; intTotalCount = pTable.RowCount(pQFilter); strLabel = m_pOutlierSymbols[j].Label + " (" + intTotalCount.ToString() + ")"; pUniqueValueRenderer.AddValue(m_pOutlierSymbols[j].Value, null, (ISymbol)pSymbol); pUniqueValueRenderer.set_Label(m_pOutlierSymbols[j].Value, strLabel); } pUniqueValueRenderer.UseDefaultSymbol = false; } IFeatureLayer pNewFLayer = new FeatureLayerClass(); pNewFLayer.FeatureClass = pFClass; pNewFLayer.Name = "Bivariate Spatial Quadrants"; IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer; pGFLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; m_pActiveView.FocusMap.AddLayer(pGFLayer); m_pActiveView.Refresh(); m_pForm.axTOCControl1.Update(); pfrmProgress.Close(); } else { MessageBox.Show("Complete. The results are stored in the shape file"); } }
private void styleGipodLyr( IGeoFeatureLayer geolayer ) { IUniqueValueRenderer renderer = new UniqueValueRendererClass(); renderer.FieldCount = 1; renderer.set_Field(0, "hinder"); renderer.set_FieldType(0, false); //renderer.UseDefaultSymbol = true; renderer.DefaultLabel = "other"; ISimpleMarkerSymbol trueMarkerSymbol = new SimpleMarkerSymbolClass(); trueMarkerSymbol.Color = new RgbColorClass(){Red= 255, Blue= 0, Green= 255 }; trueMarkerSymbol.Outline = true; trueMarkerSymbol.OutlineColor = new RgbColorClass() { Red = 0, Blue = 0, Green = 0 }; ; trueMarkerSymbol.Size = 5; trueMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; ISimpleMarkerSymbol falseMarkerSymbol = new SimpleMarkerSymbolClass(); falseMarkerSymbol.Color = new RgbColorClass() { Red = 255, Blue = 0, Green = 0 }; falseMarkerSymbol.Outline = true; falseMarkerSymbol.OutlineColor = new RgbColorClass() { Red = 0, Blue = 0, Green = 0 }; ; falseMarkerSymbol.Size = 5; falseMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; renderer.AddValue("0","", falseMarkerSymbol as ISymbol); renderer.set_Label("0", "Geen hinder"); renderer.AddValue("1", "", trueMarkerSymbol as ISymbol); renderer.set_Label("1", "Veel hinder"); geolayer.Renderer = renderer as IFeatureRenderer; IMxDocument mxDoc = ArcMap.Document; mxDoc.CurrentContentsView.Refresh(null); }
private IUniqueValueRenderer CreateRenderer(IFeatureClass featureClass) { int uniqueValuesCount = GetUniqueValuesCount(featureClass, strRendererField); System.Collections.IEnumerator enumerator = GetUniqueValues(featureClass, strRendererField); if (uniqueValuesCount == 0) { return(null); } IEnumColors pEnumRamp = GetEnumColorsByRandomColorRamp(uniqueValuesCount); //IEnumColors pEnumRamp = GetEnumColorsBySelectColorRamp(uniqueValuesCount); pEnumRamp.Reset(); IUniqueValueRenderer pUniqueValueR = new UniqueValueRendererClass(); //只用一个字段进行单值着色 pUniqueValueR.FieldCount = 1; //用于区分着色的字段 pUniqueValueR.set_Field(0, strRendererField); IColor pColor = null; ISymbol symbol = null; enumerator.Reset(); while (enumerator.MoveNext()) { object codeValue = enumerator.Current; pColor = pEnumRamp.Next(); switch (featureClass.ShapeType) { case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint: ISimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbolClass() as ISimpleMarkerSymbol; markerSymbol.Color = pColor; symbol = markerSymbol as ISymbol; break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline: ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass() as ISimpleLineSymbol; lineSymbol.Color = pColor; symbol = lineSymbol as ISymbol; break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon: ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass() as ISimpleFillSymbol; fillSymbol.Color = pColor; symbol = fillSymbol as ISymbol; break; default: break; } //将每次得到的要素字段值和修饰它的符号放入着色对象中 pUniqueValueR.AddValue(codeValue.ToString(), strRendererField, symbol); } return(pUniqueValueR); }
//单一值专题图 private void button3_Click(object sender, EventArgs e) { IGeoFeatureLayer geoFeatureLayer; geoFeatureLayer = getGeoLayer("东丰县行政区域"); IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass(); uniqueValueRenderer.FieldCount = 1; uniqueValueRenderer.set_Field(0, "CC"); //简单填充符号 ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; IFeatureCursor featureCursor = geoFeatureLayer.FeatureClass.Search(null, false); IFeature feature; if (featureCursor != null) { IEnumColors enumColors = CreateAlgorithmicColorRamp(8).Colors; int fieldIndex = geoFeatureLayer.FeatureClass.Fields.FindField("CC"); for (int i = 0; i < 8; i++) { feature = featureCursor.NextFeature(); string nameValue = feature.get_Value(fieldIndex).ToString(); simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = enumColors.Next(); uniqueValueRenderer.AddValue(nameValue, "CC", simpleFillSymbol as ISymbol); } } geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer; this.axMapControl1.Refresh(); }
private IUniqueValueRenderer CreateUniqueValueRenderer(IFeatureClass featureClass, string fieldName) { IRgbColor color = new RgbColorClass(); color.Red = 255; color.Blue = 0; color.Green = 0; ICharacterMarkerSymbol charMarkersymbol = new CharacterMarkerSymbolClass(); charMarkersymbol.Font = Converter.ToStdFont(new Font(new FontFamily("ESRI Default Marker"), 12.0f, FontStyle.Regular)); charMarkersymbol.CharacterIndex = 96; charMarkersymbol.Size = 12.0; charMarkersymbol.Color = (IColor)color; IRandomColorRamp randomColorRamp = new RandomColorRampClass(); randomColorRamp.MinSaturation = 20; randomColorRamp.MaxSaturation = 40; randomColorRamp.MaxValue = 85; randomColorRamp.MaxValue = 100; randomColorRamp.StartHue = 75; randomColorRamp.EndHue = 190; randomColorRamp.UseSeed = true; randomColorRamp.Seed = 45; IUniqueValueRenderer uniqueRenderer = new UniqueValueRendererClass(); uniqueRenderer.FieldCount = 1; uniqueRenderer.set_Field(0, fieldName); uniqueRenderer.DefaultSymbol = (ISymbol)charMarkersymbol; uniqueRenderer.UseDefaultSymbol = true; Random rand = new Random(); bool bValFound = false; IFeatureCursor featureCursor = featureClass.Search(null, true); IFeature feature = null; string val = string.Empty; int fieldID = featureClass.FindField(fieldName); if (-1 == fieldID) return uniqueRenderer; while ((feature = featureCursor.NextFeature()) != null) { bValFound = false; val = Convert.ToString(feature.get_Value(fieldID)); for (int i = 0; i < uniqueRenderer.ValueCount - 1; i++) { if (uniqueRenderer.get_Value(i) == val) bValFound = true; } if (!bValFound)//need to add the value to the renderer { color.Red = rand.Next(255); color.Blue = rand.Next(255); color.Green = rand.Next(255); charMarkersymbol = new CharacterMarkerSymbolClass(); charMarkersymbol.Font = Converter.ToStdFont(new Font(new FontFamily("ESRI Default Marker"), 10.0f, FontStyle.Regular)); charMarkersymbol.CharacterIndex = rand.Next(40, 118); charMarkersymbol.Size = 20.0; charMarkersymbol.Color = (IColor)color; //add the value to the renderer uniqueRenderer.AddValue(val, "name", (ISymbol)charMarkersymbol); } } //release the featurecursor ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor); return uniqueRenderer; }
protected override void handleClick( ) { startHourGlass("Add Edit Layers"); try { /* Value Map Renderer? */ IMap mp = this.ext.FocusMap; IGroupLayer grp = null; // look up layer for fc try { // to avoid first chance exceptions -- look for a group layer manually first // this is a work-around for an ESRI bug ... bool bGroup = false; for (int i = 0; i < mp.LayerCount; i++) { if (mp.get_Layer(i) is IGroupLayer) { bGroup = true; break; } } if (bGroup) { UID uid = new UIDClass(); // IGroupLayer uid.Value = "{EDAD6644-1810-11D1-86AE-0000F8751720}"; // may throw a 'A first chance exception of type // 'System.Runtime.InteropServices.COMException' occurred in ISDUTLib.dll' // seems to occur when there are not any group layers IEnumLayer layers = mp.get_Layers(uid, true); for (ILayer lyr = layers.Next(); lyr != null; lyr = layers.Next()) { if (lyr is IGroupLayer && lyr.Name == EDITS_LAYER_GRP_NAME) { Logger.Write("Found layer Edits"); mp.DeleteLayer(lyr); break; } } } } catch(Exception e) { Logger.Write(e); } // create it grp = new GroupLayerClass(); grp.Name = "Edits"; grp.Visible = true; grp.Expanded = false; mp.AddLayer(grp); IEnumDatasetName names = this.ext.TransactionManager.Current().PGDBConnection.get_DatasetNames(esriDatasetType.esriDTAny); for(IDatasetName curName = names.Next();curName!=null;curName = names.Next()) { string key = curName.Name; if (key != null && !key.Equals("ISDUT_SPATIAL_EDIT_EXTENTS_SP") && !key.Equals("DATA_ERRORS") && !key.Equals("METADATA") && !key.StartsWith("P_") && !key.StartsWith("C_") && !key.StartsWith("E_")) { // we have a working layer string editname = "E_" + key; // this.ext.TransactionManager.transactionConfig().get_EditIndicator(key); IFeatureClass edit_fc = null; try { edit_fc = ((IFeatureWorkspace)this.ext.TransactionManager.Current().PGDBConnection).OpenFeatureClass(editname); } catch(Exception e) { MessageBox.Show("PGDB Feature Class "+editname+" Not Found", "EXCEPTION", MessageBoxButtons.OK, MessageBoxIcon.Error); throw new HandledException(e); } if(edit_fc!=null) { try { // add layer Logger.Write("Create Layer "+editname); IFeatureLayer pFeatureLayer = new FeatureLayer(); pFeatureLayer.Name = editname; pFeatureLayer.FeatureClass = edit_fc; pFeatureLayer.SpatialReference = ((IGeoDataset)edit_fc).SpatialReference; // setup renderer // http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)pFeatureLayer; IUniqueValueRenderer pRender = new UniqueValueRendererClass(); pRender.FieldCount = 1; pRender.set_Field(0,EditsDAO.EDIT_STATE); pRender.DefaultSymbol = ((ISimpleRenderer)geoFeatureLayer.Renderer).Symbol; pRender.UseDefaultSymbol = true; IRgbColor red = new RgbColorClass(); red.Red = 255; IRgbColor orange = new RgbColorClass(); orange.Red = 255; orange.Green = 165; IRgbColor green = new RgbColorClass(); green.Green = 255; ISymbol delSym = null; ISymbol updSym = null; ISymbol insSym = null; switch (edit_fc.ShapeType) { case esriGeometryType.esriGeometryPoint: case esriGeometryType.esriGeometryMultipoint: { ISimpleMarkerSymbol s = new SimpleMarkerSymbolClass(); s.Style = esriSimpleMarkerStyle.esriSMSCircle; s.Size = 0.4; s.Color = red; delSym = (ISymbol)s; s = new SimpleMarkerSymbolClass(); s.Style = esriSimpleMarkerStyle.esriSMSCircle; s.Size = 0.4; s.Color = orange; updSym = (ISymbol)s; s = new SimpleMarkerSymbolClass(); s.Style = esriSimpleMarkerStyle.esriSMSCircle; s.Size = 0.4; s.Color = green; insSym = (ISymbol)s; } break; case esriGeometryType.esriGeometryLine: case esriGeometryType.esriGeometryPath: case esriGeometryType.esriGeometryPolyline: { ISimpleLineSymbol s = new SimpleLineSymbolClass(); s.Style = esriSimpleLineStyle.esriSLSSolid; s.Width = 0.4; s.Color = red; delSym = (ISymbol)s; s = new SimpleLineSymbolClass(); s.Style = esriSimpleLineStyle.esriSLSSolid; s.Width = 0.4; s.Color = orange; updSym = (ISymbol)s; s = new SimpleLineSymbolClass(); s.Style = esriSimpleLineStyle.esriSLSSolid; s.Width = 0.4; s.Color = green; insSym = (ISymbol)s; } break; case esriGeometryType.esriGeometryPolygon: case esriGeometryType.esriGeometryRing: case esriGeometryType.esriGeometryMultiPatch: default: { ISimpleFillSymbol s = new SimpleFillSymbolClass(); s.Style = esriSimpleFillStyle.esriSFSSolid; s.Outline.Width = 0.4; s.Color = red; delSym = (ISymbol)s; s = new SimpleFillSymbolClass(); s.Style = esriSimpleFillStyle.esriSFSSolid; s.Outline.Width = 0.4; s.Color = orange; updSym = (ISymbol)s; s = new SimpleFillSymbolClass(); s.Style = esriSimpleFillStyle.esriSFSSolid; s.Outline.Width = 0.4; s.Color = green; insSym = (ISymbol)s; } break; } Logger.Write("Setup Value Map Renderer"); // add values pRender.AddValue(EditsDAO.DEL,EditsDAO.EDIT_STATE,delSym); pRender.AddValue(EditsDAO.UPD,EditsDAO.EDIT_STATE,updSym); pRender.AddValue(EditsDAO.INS,EditsDAO.EDIT_STATE,insSym); geoFeatureLayer.Renderer = (IFeatureRenderer)pRender; pFeatureLayer.Visible = true; pFeatureLayer.Selectable = false; Logger.Write("Adding layer "+editname); grp.Add(pFeatureLayer); } catch(Exception e) { MessageBox.Show("Error Creating new Edit Layer "+editname+": "+e.Message, "EXCEPTION", MessageBoxButtons.OK, MessageBoxIcon.Error); throw new HandledException(e); } } } } } finally { endHourGlass(); } this.ext.MxDocument.UpdateContents(); this.app.RefreshWindow(); }
private void polygonUniqueDye(ILayer pLayer) { IGeoFeatureLayer m_pGeoFeatureL; IUniqueValueRenderer pUniqueValueR; IFillSymbol pFillSymbol; IColor pNextUniqueColor; IEnumColors pEnumRamp; ITable pTable; int iFieldNumber; IRow pNextRow; IRowBuffer pNextRowBuffer; ICursor pCursor; IQueryFilter pQueryFilter; string codeValue; IRandomColorRamp pColorRamp; string strNameField = cbField1.Text; IMap pMap = axMapControl1.Map; pMap.ReferenceScale = 0; m_pGeoFeatureL = pLayer as IGeoFeatureLayer; pUniqueValueR = new UniqueValueRendererClass(); pTable = (ITable)m_pGeoFeatureL; iFieldNumber = pTable.FindField(strNameField); if (iFieldNumber == -1) { MessageBox.Show("未能找到字段" + strNameField); return; } //只用一个字段进行单值着色 pUniqueValueR.FieldCount = 1; //用于区分着色的字段 pUniqueValueR.set_Field(0, strNameField); //产生一个随机的颜色条,用的是HSV颜色模式 pColorRamp = new RandomColorRampClass(); pColorRamp.StartHue = 0; pColorRamp.MinValue = 99; pColorRamp.MinSaturation = 15; pColorRamp.EndHue = 360; pColorRamp.MaxValue = 100; pColorRamp.MaxSaturation = 30; //任意产生100歌颜色,如果知道要素的数据可以产生精确的颜色数目 pColorRamp.Size = 100; bool ok = true; pColorRamp.CreateRamp(out ok); pEnumRamp = pColorRamp.Colors; pNextUniqueColor = null; //产生查询过滤器的对象 pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(strNameField); //根据某个字段在表中找出指向所有行的游标对象 pCursor = pTable.Search(pQueryFilter, true); pNextRow = pCursor.NextRow(); //遍历所有的要素 while (pNextRow != null) { pNextRowBuffer = pNextRow; //找出row为某个定值的值 codeValue = pNextRowBuffer.get_Value(iFieldNumber).ToString(); //获取随机颜色带中的任意一个颜色 pNextUniqueColor = pEnumRamp.Next(); if (pNextUniqueColor == null) { pEnumRamp.Reset(); pNextUniqueColor = pEnumRamp.Next(); } pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pNextUniqueColor; //将每次得到的要素字段值和修饰它的符号值放入着色对象中 pUniqueValueR.AddValue(codeValue, strNameField, (ISymbol)pFillSymbol); pNextRow = pCursor.NextRow(); } m_pGeoFeatureL.Renderer = (IFeatureRenderer)pUniqueValueR; axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
//进行唯一值渲染 private void UniqueValueRenderer(IFeatureLayer featureLayer, string FieldName) { int FieldIndex = featureLayer.FeatureClass.Fields.FindField(FieldName); IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass(); uniqueValueRenderer.FieldCount = 1; uniqueValueRenderer.set_Field(0, FieldName); IRandomColorRamp randomColorRamp = new RandomColorRampClass(); randomColorRamp.StartHue = 0; randomColorRamp.MinValue = 0; randomColorRamp.MinSaturation = 15; randomColorRamp.EndHue = 360; randomColorRamp.MaxValue = 100; randomColorRamp.MaxSaturation = 30; IQueryFilter queryFilter = new QueryFilterClass(); randomColorRamp.Size = featureLayer.FeatureClass.FeatureCount(queryFilter); bool flag = false; randomColorRamp.CreateRamp(out flag); IEnumColors enumColors = randomColorRamp.Colors; IColor color = null; object codeValue = null; queryFilter = new QueryFilterClass(); queryFilter.AddField(FieldName); IFeatureCursor featureCursor= featureLayer.FeatureClass.Search(queryFilter, true); IFeature feature = featureCursor.NextFeature(); while (feature != null) { codeValue = feature.get_Value(FieldIndex); color = enumColors.Next(); if (color == null) { enumColors.Reset(); color = enumColors.Next(); } ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = color; uniqueValueRenderer.AddValue(codeValue.ToString(), "", simpleLineSymbol as ISymbol); feature = featureCursor.NextFeature(); } IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer; geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer; System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor); axMapControl1.Refresh(); axMapControl1.Update(); }
///<summary> ///在程序运行时的内存中创建矢量要素层,并加到地图控件最顶端 ///</summary> ///<param name="pMapCtrl">地图控件</param> ///<returns>IFeatureLayer 新加的要素层</returns> public IFeatureLayer AddFeatureLayerByMemoryWS(AxMapControl pMapCtrl, ISpatialReference pSReference) { try { if (pMapCtrl == null) { return(null); } #region 创建新的内存工作空间 IWorkspaceFactory pWSF = new InMemoryWorkspaceFactoryClass(); IWorkspaceName pWSName = pWSF.Create("", "Temp", null, 0); IName pName = (IName)pWSName; IWorkspace pMemoryWS = (IWorkspace)pName.Open(); #endregion IField oField = new FieldClass(); IFields oFields = new FieldsClass(); IFieldsEdit oFieldsEdit = null; IFieldEdit oFieldEdit = null; IFeatureClass oFeatureClass = null; IFeatureLayer oFeatureLayer = null; try { oFieldsEdit = oFields as IFieldsEdit; oFieldEdit = oField as IFieldEdit; oFieldEdit.Name_2 = "OBJECTID"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; oFieldEdit.IsNullable_2 = false; oFieldEdit.Required_2 = false; oFieldsEdit.AddField(oField); oField = new FieldClass(); oFieldEdit = oField as IFieldEdit; IGeometryDef pGeoDef = new GeometryDefClass(); IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef; pGeoDefEdit.AvgNumPoints_2 = 5; pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon; pGeoDefEdit.GridCount_2 = 1; pGeoDefEdit.HasM_2 = false; pGeoDefEdit.HasZ_2 = false; pGeoDefEdit.SpatialReference_2 = pSReference; oFieldEdit.Name_2 = "SHAPE"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; oFieldEdit.GeometryDef_2 = pGeoDef; oFieldEdit.IsNullable_2 = true; oFieldEdit.Required_2 = true; oFieldsEdit.AddField(oField); oField = new FieldClass(); oFieldEdit = oField as IFieldEdit; oFieldEdit.Name_2 = "Code"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger; oFieldEdit.IsNullable_2 = true; oFieldsEdit.AddField(oField); //创建要素类 oFeatureClass = (pMemoryWS as IFeatureWorkspace).CreateFeatureClass("Temp", oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", ""); oFeatureLayer = new FeatureLayerClass(); oFeatureLayer.Name = "TransTemp"; oFeatureLayer.FeatureClass = oFeatureClass; //创建唯一值符号化对象 IUniqueValueRenderer pURender = new UniqueValueRendererClass(); pURender.FieldCount = 1; pURender.set_Field(0, "Code"); pURender.UseDefaultSymbol = false; ISimpleFillSymbol pFillSym = new SimpleFillSymbolClass(); pFillSym.Style = esriSimpleFillStyle.esriSFSSolid; //半透明颜色 IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 255; pFillSym.Color = pColor; pURender.AddValue("1", "", pFillSym as ISymbol); pFillSym = new SimpleFillSymbolClass(); pFillSym.Style = esriSimpleFillStyle.esriSFSSolid; //唯一值符号化内存图层 (oFeatureLayer as IGeoFeatureLayer).Renderer = pURender as IFeatureRenderer; ILayerEffects pLyrEffect = oFeatureLayer as ILayerEffects; //透明度 pLyrEffect.Transparency = 80; } catch (Exception Err) { MessageBox.Show(Err.Message); } finally { try { System.Runtime.InteropServices.Marshal.ReleaseComObject(oField); System.Runtime.InteropServices.Marshal.ReleaseComObject(oFields); System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldsEdit); System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldEdit); System.Runtime.InteropServices.Marshal.ReleaseComObject(pName); System.Runtime.InteropServices.Marshal.ReleaseComObject(pWSF); System.Runtime.InteropServices.Marshal.ReleaseComObject(pWSName); System.Runtime.InteropServices.Marshal.ReleaseComObject(pMemoryWS); System.Runtime.InteropServices.Marshal.ReleaseComObject(oFeatureClass); } catch { } GC.Collect(); } return(oFeatureLayer); } catch (Exception Err) { MessageBox.Show(Err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return(null); } }
public static void UniqueRender(ILayer currentLayer, string fieldName) { IGeoFeatureLayer m_pGeoFeatureL; IUniqueValueRenderer pUniqueValueR; IFillSymbol pFillSymbol; IColor pNextUniqueColor; IEnumColors pEnumRamp; ITable pTable; int lfieldNumber; IRow pNextRow; IRowBuffer pNextRowBuffer; ICursor pCursor; IQueryFilter pQueryFilter; string codeValue; IRandomColorRamp pColorRamp; m_pGeoFeatureL = (IGeoFeatureLayer)currentLayer; pUniqueValueR = new UniqueValueRendererClass(); pTable = (ITable)m_pGeoFeatureL; lfieldNumber = 0; for (int i = 0; i < pTable.Fields.FieldCount; i++) { if (pTable.Fields.get_Field(i).Name.ToUpper().Contains(fieldName.ToUpper())) { fieldName = pTable.Fields.get_Field(i).Name; lfieldNumber = i; break; } } pUniqueValueR.FieldCount = 1; pUniqueValueR.set_Field(0, fieldName); pColorRamp = new RandomColorRampClass(); pColorRamp.StartHue = 0; pColorRamp.MinValue = 99; pColorRamp.MinSaturation = 15; pColorRamp.EndHue = 360; pColorRamp.MaxValue = 100; pColorRamp.MaxSaturation = 30; pColorRamp.Size = 100; bool ok = true; pColorRamp.CreateRamp(out ok); pEnumRamp = pColorRamp.Colors; pNextUniqueColor = null; pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(fieldName); pCursor = pTable.Search(pQueryFilter, true); pNextRow = pCursor.NextRow(); while (pNextRow != null) { pNextRowBuffer = pNextRow; codeValue = (string)pNextRowBuffer.get_Value(lfieldNumber); pNextUniqueColor = pEnumRamp.Next(); if (pNextUniqueColor == null) { pEnumRamp.Reset(); pNextUniqueColor = pEnumRamp.Next(); } pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pNextUniqueColor; pUniqueValueR.AddValue(codeValue, fieldName, (ISymbol) pFillSymbol); pNextRow = pCursor.NextRow(); } m_pGeoFeatureL.Renderer = (IFeatureRenderer)pUniqueValueR; }
private IUniqueValueRenderer CreateUniqueValueRenderer(IFeatureClass featureClass, string fieldName) { IRgbColor color = new RgbColorClass(); color.Red = 255; color.Blue = 0; color.Green = 0; ICharacterMarkerSymbol charMarkersymbol = new CharacterMarkerSymbolClass(); charMarkersymbol.Font = Converter.ToStdFont(new Font(new FontFamily("ESRI Default Marker"), 12.0f, FontStyle.Regular)); charMarkersymbol.CharacterIndex = 96; charMarkersymbol.Size = 12.0; charMarkersymbol.Color = (IColor)color; IRandomColorRamp randomColorRamp = new RandomColorRampClass(); randomColorRamp.MinSaturation = 20; randomColorRamp.MaxSaturation = 40; randomColorRamp.MaxValue = 85; randomColorRamp.MaxValue = 100; randomColorRamp.StartHue = 75; randomColorRamp.EndHue = 190; randomColorRamp.UseSeed = true; randomColorRamp.Seed = 45; IUniqueValueRenderer uniqueRenderer = new UniqueValueRendererClass(); uniqueRenderer.FieldCount = 1; uniqueRenderer.set_Field(0, fieldName); uniqueRenderer.DefaultSymbol = (ISymbol)charMarkersymbol; uniqueRenderer.UseDefaultSymbol = true; Random rand = new Random(); bool bValFound = false; IFeatureCursor featureCursor = featureClass.Search(null, true); IFeature feature = null; string val = string.Empty; int fieldID = featureClass.FindField(fieldName); if (-1 == fieldID) { return(uniqueRenderer); } while ((feature = featureCursor.NextFeature()) != null) { bValFound = false; val = Convert.ToString(feature.get_Value(fieldID)); for (int i = 0; i < uniqueRenderer.ValueCount - 1; i++) { if (uniqueRenderer.get_Value(i) == val) { bValFound = true; } } if (!bValFound)//need to add the value to the renderer { color.Red = rand.Next(255); color.Blue = rand.Next(255); color.Green = rand.Next(255); charMarkersymbol = new CharacterMarkerSymbolClass(); charMarkersymbol.Font = Converter.ToStdFont(new Font(new FontFamily("ESRI Default Marker"), 10.0f, FontStyle.Regular)); charMarkersymbol.CharacterIndex = rand.Next(40, 118); charMarkersymbol.Size = 20.0; charMarkersymbol.Color = (IColor)color; //add the value to the renderer uniqueRenderer.AddValue(val, "name", (ISymbol)charMarkersymbol); } } //release the featurecursor ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor); return(uniqueRenderer); }
///<summary> ///����Ҫ��ͼ��Ψһֵ���Ż� ///</summary> ///<param name="pFeatureLayer"></param> private void UniqueValueRenderFlyr(AxMapControl axMapControl1, IFeatureLayer pFeatureLayer) { try { //����UniqueValueRendererClass���� IUniqueValueRenderer pUVRender = new UniqueValueRendererClass(); List<string> pFieldValues = new List<string>(); pFieldValues.Add("Hospital 2"); pFieldValues.Add("School 1"); pFieldValues.Add("Airport"); for (int i = 0; i < pFieldValues.Count; i++) { ISymbol pSymbol = new SimpleMarkerSymbolClass(); pSymbol = GetSymbol(@"D:\Program Files\ArcGIS\Styles\ESRI.ServerStyle", "Marker Symbols", pFieldValues[i]); //���Ψһֵ���Ż��ֶ�ֵ�����Ӧ�ķ��� pUVRender.AddValue(pFieldValues[i], pFieldValues[i], pSymbol); } //����Ψһֵ���Ż����ֶθ������ֶ��� pUVRender.FieldCount = 1; pUVRender.set_Field(0, "���"); IGeoFeatureLayer pGFeatureLyr = pFeatureLayer as IGeoFeatureLayer; //����IGeofeatureLayer��Renderer���� pGFeatureLyr.Renderer = pUVRender as IFeatureRenderer; } catch (Exception Err) { MessageBox.Show(Err.Message, "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
// 唯一值符号化 public static void UniqueValueRenderer(IFeatureLayer featureLayer, string fieldName, IMapControl2 mapControl, AxTOCControl tocControl) { ITable pTable = featureLayer as ITable; IUniqueValueRenderer pRenderer = new UniqueValueRendererClass(); pRenderer.FieldCount = 1; // 设置唯一值符号化的关键字段为一个 pRenderer.set_Field(0, fieldName); // 设置唯一值符号化的第一个关键字段 IRandomColorRamp pColorRamp = new RandomColorRampClass() { StartHue = 0, MinValue = 0, MinSaturation = 0, EndHue = 100, MaxValue = 100, MaxSaturation = 100 }; // 根据渲染字段的值的个数,设置一组随机颜色 pColorRamp.Size = featureLayer.FeatureClass.FeatureCount(new QueryFilterClass()); bool bSuccess = false; pColorRamp.CreateRamp(out bSuccess); IEnumColors pEnumColors = pColorRamp.Colors; IColor pNextUniqueColor = null; // 查询字段的值 IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(fieldName); int fieldNumber = pTable.FindField(fieldName); // 获取渲染字段索引 ICursor pCursor = pTable.Search(pQueryFilter, true); IRow pNextRow = pCursor.NextRow(); object codeValue = null; IRowBuffer pNextRowBuffer = null; while (pNextRow != null) { pNextRowBuffer = pNextRow as IRowBuffer; // 获取渲染字段的每一个值 codeValue = pNextRowBuffer.get_Value(fieldNumber); pNextUniqueColor = pEnumColors.Next(); if (pNextUniqueColor == null) { pEnumColors.Reset(); pNextUniqueColor = pEnumColors.Next(); } ISymbol pSymbol = null; switch (featureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPolygon: pSymbol = new SimpleFillSymbolClass() { Color = pNextUniqueColor }; break; case esriGeometryType.esriGeometryPolyline: pSymbol = new SimpleLineSymbolClass() { Color = pNextUniqueColor }; break; case esriGeometryType.esriGeometryPoint: pSymbol = new SimpleMarkerSymbolClass() { Color = pNextUniqueColor }; break; } pRenderer.AddValue(codeValue.ToString(), "", pSymbol); pNextRow = pCursor.NextRow(); } (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer; mapControl.Refresh(); tocControl.Update(); }
public IFeatureRenderer UnqueValueRenderer(IFeatureWorkspace workspace, IFeatureClass fc) { try { string tablename = ((IDataset)fc).BrowseName; ITable ipTable = workspace.OpenTable(tablename); IFeatureCursor featureCursor = fc.Search(null, false); IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.Cursor = featureCursor as ICursor; dataStatistics.Field = "gridcode"; System.Collections.IEnumerator enumerator = dataStatistics.UniqueValues; enumerator.Reset(); while (enumerator.MoveNext()) { object myObject = enumerator.Current; } int uniqueValues = dataStatistics.UniqueValueCount; //Create colors for each unique value. IRandomColorRamp colorRamp = new RandomColorRampClass(); colorRamp.Size = uniqueValues; colorRamp.Seed = 100; bool createColorRamp; colorRamp.CreateRamp(out createColorRamp); if (createColorRamp == false) { return null; } IUniqueValueRenderer uvRenderer = new UniqueValueRendererClass(); IFeatureRenderer featRenderer = (IFeatureRenderer)uvRenderer; uvRenderer.FieldCount = 1; ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); ISimpleFillSymbol fillSymbol2 = new SimpleFillSymbolClass(); if (ShowNonVisibleData == true) { fillSymbol.Color = new RgbColorClass() { Red = 255 } as IColor; uvRenderer.AddValue("0", "", fillSymbol as ISymbol); uvRenderer.set_Label("0", "Non-Visible"); } fillSymbol2.Color = new RgbColorClass() { Green = 255 } as IColor; uvRenderer.AddValue("1", "", fillSymbol2 as ISymbol); uvRenderer.set_Label("1", "Visible by 1 Observer"); int field = ipTable.FindField("gridcode"); uvRenderer.set_Field(0, "gridcode"); for (int i = 2; i < uniqueValues; i++) { ISimpleFillSymbol newFillSymbol = new SimpleFillSymbolClass(); newFillSymbol.Color = colorRamp.get_Color(i); uvRenderer.AddValue(i.ToString(), "", newFillSymbol as ISymbol); string label = "Visible by " + i.ToString() + " Observers"; uvRenderer.set_Label(i.ToString(), label); } return featRenderer; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return null; } }