Arcgis 要素染色

       /// <summary>
        /// Defining a renderer for your layer
        /// </summary>
        /// <param name="pGeoFeatureLayer">图层</param>
        /// <param name="fieldName">sde数据库中字段名</param>
        /// <param name="pQueryFilter">过滤条件</param>
        private void DefineUniqueValueRenderer(IGeoFeatureLayer pGeoFeatureLayer, string fieldName, IQueryFilter pQueryFilter)
        {
            // IRandomColorRamp 对象
            IRandomColorRamp pRandomColorRamp = new RandomColorRampClass();
            //Make 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;

            //Make the renderer.
            IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();

            //填充样式
            ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();
            pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
            pSimpleFillSymbol.Outline.Width = 0.4;

            //These properties should be set prior to adding values.
            pUniqueValueRenderer.FieldCount = 1;
            pUniqueValueRenderer.set_Field(0, fieldName);
            pUniqueValueRenderer.DefaultSymbol = pSimpleFillSymbol as ISymbol;
            pUniqueValueRenderer.UseDefaultSymbol = true;

            //显示表
            IDisplayTable pDisplayTable = pGeoFeatureLayer as IDisplayTable;
            //IFeatureCursor 对象
            IFeatureCursor pFeatureCursor = pDisplayTable.SearchDisplayTable(pQueryFilter, false) as IFeatureCursor;
            //IFeature对象
            IFeature pFeature = pFeatureCursor.NextFeature();

            //bool对象,pUniqueValueRenderer中是否找到字段值
            bool ValFound;
            //字段索引号
            int fieldIndex;
            //IFields对象
            IFields pFields = pFeatureCursor.Fields;
            fieldIndex = pFields.FindField(fieldName);
            while (pFeature != null)//要素存在
            {
                //填充样式
                ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass();
                pClassSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                pClassSymbol.Outline.Width = 0.4;

                //字段值
                string classValue;
                classValue = pFeature.get_Value(fieldIndex) as string;

                //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 is new and it 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;
            //ok
            bool bOK;
            pRandomColorRamp.CreateRamp(out bOK);
            //IEnumColors 对象, 颜色集合
            IEnumColors pEnumColors = pRandomColorRamp.Colors;
            pEnumColors.Reset();
            for (int j = 0; j <= pUniqueValueRenderer.ValueCount - 1; j++)
            {
                //value值
                string xv;
                xv = pUniqueValueRenderer.get_Value(j);
                if (xv != "")
                {
                    //填充样式
                    ISimpleFillSymbol pSimpleFillColor = pUniqueValueRenderer.get_Symbol(xv) as ISimpleFillSymbol;
                    pSimpleFillColor.Color = pEnumColors.Next();
                    pUniqueValueRenderer.set_Symbol(xv, pSimpleFillColor as ISymbol);

                }
            }

            //'** If you didn't use a predefined color ramp
            //'** in a style, use "Custom" here. Otherwise,
            //'** use the name of the color ramp you selected.
            pUniqueValueRenderer.ColorScheme = "Custom";
            //ITable对象
            ITable pTable = pDisplayTable as ITable;
            //是否string
            bool isString = pTable.Fields.get_Field(fieldIndex).Type == esriFieldType.esriFieldTypeString;
            pUniqueValueRenderer.set_FieldType(0, isString);
            pGeoFeatureLayer.Renderer = pUniqueValueRenderer as IFeatureRenderer;

        }

### 配置和使用 ArcGIS 要素服务器 #### 创建并配置地理数据库 为了成功配置ArcGIS要素服务,需先建立一个合适的地理数据库环境。这通常涉及安装ArcGIS Map(或ArcGIS SDE)以及相应版本的直联数据库,例如PostgreSQL 9.3与ArcGIS Map 10.3组合,并确保这些组件部署在同一操作系统环境中,如Windows Server 2012[^2]。 #### 数据库注册至ArcGIS Server 完成上述准备工作之后,下一步是将构建好的SDE地理数据库注册到ArcGIS Server中去。此过程允许Server识别并管理来自该数据库的数据资源,在此基础上才能进一步执行服务发布的操作[^4]。 #### 连接ArcGIS Server 通过添加一个新的ArcGIS Server连接来实现这一点;此时所使用的URL应指向目标ArcGIS Server实例的具体位置——即其公网可达的IP地址(比如`http://192.168.1.100/arcgis/admin`),同时提供具有适当权限级别的用户名及密码用于身份验证[^3]。 #### 发布要素服务 一旦完成了前提到的各项设定工作,则可以着手准备实际的服务发布了。这一环节主要是在ArcGIS Desktop内完成,具体来说是从已加载入项目中的图层里挑选出希望共享给其他用户的那些部分,随后按照向导指示一步步推进直至最终确认发布为要素服务[^1]。 ```python # Python脚本示例:自动化发布要素服务流程的一部分 import arcpy arcpy.env.workspace = r"C:\path\to\sde_connection_file.sde" service_definition_draft = "C:\\temp\\MyServiceDefinitionDraft.sd" # 准备地图文档对象 mxd = arcpy.mapping.MapDocument(r"C:\path\to\your_map_document.mxd") # 执行分析以获取可能存在的错误警告信息 analysis = arcpy.mapping.CreateMapSDDraft(mxd, service_definition_draft) if analysis['errors'] == {}: print("无误") else: print(analysis['errors']) del mxd ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值