public static void UniqueValueRenderer(ILayer layer)
{
IFeatureLayer pFLayer = layer as IFeatureLayer;
IGeoFeatureLayer geoLayer = layer 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,"乡名");
IFeature pFeat = fCursor.NextFeature();
int index = pFeat.Fields.FindField("乡名");
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;
}