cxi一意値レンダリングインスタンスコード
追加するクラスライブラリが必要です。
using System.Collections;
using System.Windows.Forms;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
具体的なコード(本例はシングルレンダリング)
private ISymbol GetSymbol(IColor pColor)
{
ISymbol pSymbol;
ISimpleFillSymbol pSymbolFillSymbol = new SimpleFillSymbolClass();
pSymbolFillSymbol.Color = pColor;
pSymbolFillSymbol.Outline.Width = 0.4;
pSymbol = pSymbolFillSymbol as ISymbol;
return pSymbol;
}
private void uniqueValueRendererToolStripMenuItem_Click(object sender, EventArgs e)
{
IMap pMap = this.axMapControl1.ActiveView.FocusMap;
if (pMap.LayerCount== 0)
{
MessageBox.Show(" , !", " ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
IGeoFeatureLayer pGeoLayer = this.axMapControl1.get_Layer(0) as IGeoFeatureLayer ;
ITable pTable = pGeoLayer.FeatureClass as ITable;
ICursor pCursor;
IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.AddField("PERIMETER");
pCursor = pTable.Search(pQueryFilter, true);//
IEnumerator pEnumreator;
//
IDataStatistics pDataStatistics = new DataStatisticsClass();
pDataStatistics.Field = "PERIMETER";//
pDataStatistics.Cursor = pCursor;
pEnumreator = pDataStatistics.UniqueValues;
int fieldcount = pDataStatistics.UniqueValueCount;// ,
IUniqueValueRenderer pUniqueValueR = new UniqueValueRendererClass();
pUniqueValueR.FieldCount = 1;//
pUniqueValueR.set_Field(0, "PERIMETER");//
IEnumColors pEnumColor = GetColorRamp(fieldcount).Colors;
pEnumColor.Reset();
while (pEnumreator.MoveNext())
{
string value = pEnumreator.Current.ToString();
if (value != null)
{
IColor pColor = pEnumColor.Next();
ISymbol pSymbol = GetSymbol(pColor);
pUniqueValueR.AddValue(value, "PERIMETER", pSymbol);
//pUniqueValueR.set_Symbol(value, pSymbol);
}
}
pGeoLayer.Renderer = pUniqueValueR as IFeatureRenderer;
this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
this.axTOCControl1.Update();
}
private IRandomColorRamp GetColorRamp(int size)
{
IRandomColorRamp pRandomColorRamp = new RandomColorRampClass();
pRandomColorRamp.StartHue = 10;
pRandomColorRamp.EndHue = 300;
pRandomColorRamp.MaxSaturation =100;
pRandomColorRamp.MinSaturation = 0;
pRandomColorRamp.MaxValue = 100;
pRandomColorRamp.MinValue = 0;
pRandomColorRamp.Size = size;
bool ok = true;
pRandomColorRamp.CreateRamp(out ok);
return pRandomColorRamp;
}
その中でdatastatisticとuniqueValueRendererのfieldは明確にしなければならなくて、しかも同じ値です。