Delphi ArcEngine 创建独立值专题

type UniqueValueType = (uvtFillSymbol, uvtMarkerSymbol);

function UniqueValueRenderer(pLayer: ILayer; sField: string; estyle: UniqueValueType; iDotSize: Integer = 25): Boolean;

var
  pGeoLayer: IGeoFeatureLayer;
  pTable: ITable;
  iFieldIndex: Integer;
  pRenderer: IUniqueValueRenderer;
  pColorRamp: IRandomColorRamp;
  pEnumColors: IEnumColors;

  pQueryFilter: IQueryFilter;
  pCursor: ICursor;
  pRow: IRow;
  pColor: IColor;

  pFillSymbol: ISimpleFillSymbol;
  pMarkerSymbol: ISimpleMarkerSymbol;
  pSymbol: ISymbol;
  sValue: string;
  ok: WordBool;
begin
  pGeoLayer := pLayer as IGeoFeatureLayer;
  pTable := pLayer as ITable;
  pRenderer := CoUniqueValueRenderer.Create as IUniqueValueRenderer;

  pRenderer.FieldCount := 1;
  pRenderer.Field[0] := sField;

  //创建随机色带
  pColorRamp := CoRandomColorRamp.Create as IRandomColorRamp;
  pColorRamp.StartHue := 0;
  pColorRamp.EndHue := 300;
  pColorRamp.MinSaturation := 0;
  pColorRamp.MaxSaturation := 100;
  pColorRamp.MinValue := 0;
  pColorRamp.MaxValue := 100;
  pColorRamp.Size := 255;
  pColorRamp.CreateRamp(ok);

  if ok then
  begin
    pEnumColors := pColorRamp.Colors;
    pQueryFilter := CoQueryFilter.Create as IQueryFilter;
    pQueryFilter.AddField(sField);

    pCursor := pTable.Search(pQueryFilter, True);
    pRow := pCursor.NextRow;
    iFieldIndex := pTable.FindField(sField); //获得指定指端的索引号
    while pRow <> nil do
    begin
      sValue := pRow.Value[iFieldIndex];
      pColor := pEnumColors.Next;
      if pColor = nil then
      begin
        pEnumColors.Reset;
        pColor := pEnumColors.Next;
      end;
      case estyle of
        uvtFillSymbol:
          begin
            pFillSymbol := CoSimpleFillSymbol.Create as ISimpleFillSymbol;
            pFillSymbol.Color := pColor;
            pSymbol := pFillSymbol as ISymbol;
          end;

        uvtMarkerSymbol:
          begin
            pMarkerSymbol := CoSimpleMarkerSymbol.Create as ISimpleMarkerSymbol;
            pMarkerSymbol.Color := pColor;
            pMarkerSymbol.Style := esriSMSCircle;
            pMarkerSymbol.Size := StrToIntDef(sValue, 1) * iDotSize;
            pSymbol := pMarkerSymbol as ISymbol;
          end;
      end;
      pRenderer.AddValue(sValue, '', pSymbol);
      pRow := pCursor.NextRow;
    end;
    pGeoLayer.Renderer := pRenderer as IFeatureRenderer;
    Result := True;
  end
  else
  begin
    Result := False;
  end;
end;
原文地址:https://www.cnblogs.com/chinacodegear/p/1423291.html