《GIS二次开发》笔记
myetyet

GIS二次开发概述

  • GIS 开发模式

    • 独立开发模式
      • 不依赖于任何GIS工具软件,从空间数据的采集、编辑到数据的处理分析及结果输出,所有的算法都由开发者独立设计,然后选用某种程序设计语言,如Visual C++DelphiVisual Basic等,在一定的操作系统平台上编程实现。
      • 开发周期长;软件功能相对简单;对开发者要求高;用于购买软件的费用相对节省;独立开发难度大。
    • 宿主型开发模式
      • 基于GIS平台软件,进行应用系统开发。多数GIS平台软件都提供了可供用户进行二次开发的脚本语言,用户以原GIS软件为开发平台,利用这些脚本语言,开发出自己的针对不同应用领域的应用程序,如ArcView的Avenue语言,MapInfo Professional的MapBasic语言。
      • 开发较为容易;二次开发的脚本语言功能较弱;所开发的系统不能脱离GIS平台,且受平台所提供的脚本语言的限制;是解释执行的,运行效率低;用户界面受平台软件的限制。
    • GIS组件开发模式
      • 建立在组件技术基础上的GIS功能组件,实现了地理信息系统的各种功能,这些组件都具备GIS的基本功能。开发人员可以基于通用软件开发工具,尤其是可视化开发工具,如.NetDelphiVisual C++Visual BasicPower Builder等为开发平台,进行二次开发,实现GIS功能。
      • 大多数GIS软件产商都提供商业化的GIS组件。如ESRI公司的MapObjects、MapInfo公司的MapX等。
  • 面向对象程序设计模式

    • 对象:在一个面向对象的系统中,对象是运行期的基本实体,问题的分析一般以对象及对象间的自然联系为依据。对象在内存中占有一定空间,并且具有一个与之关联的地址。一个对象就是已定义的某个类型的变量。
    • 类:对象包含数据以及操作这些数据的代码。一个对象所包含的所有数据和代码可以通过类来构成一个用户定义的数据类型。事实上,对象就是类类型的变量。
    • 封装:把数据和函数包装在一个单独的单元(称为类)的行为称为封装。数据封装是类的最典型特点。数据不能被外界访问,只能被封装在同一个类中的函数访问。这些函数提供了对象数据和程序之间的接口。避免数据被程序直接访问的概念被称为“数据隐藏”。封装机制将数据和代码捆绑到一起,避免了外界的干扰和不确定性。
    • 继承:继承是可以让某个类型的对象获得另一个类型的对象的属性的方法。它支持按级分类的概念,这种分类的原则是,每一个子类都具有父类的公共特性。
    • 多态:事物具有不同形式的能力。例如,对于不同的实例,某个操作可能会有不同的行为,而这个行为依赖于所要操作数据的类型。
  • 组件式GIS

    • COM
      • COM是组件式对象模型(Component Object Model)的英文缩写,是组件之间相互接口的规范,是OLE(Object Linking & Embedding)和ActiveX共同的基础,其作用是使各种软件构件和应用软件能够用一种统一的标准方式进行交互。
      • COM不是一种面向对象的语言,而是一种与源代码无关的二进制标准。COM所建立的是一个软件模块与另一个软件模块之间的链接,当这种链接建立之后,模块之间就可以通过称之为“接口”的机制来进行通信。
      • COM本质上是客户/服务器模式。客户(通常是应用程序)请求创建COM对象并通过COM对象的接口操纵COM对象。服务器根据客户的请求创建并管理COM对象。客户和服务器这两种角色是相对的。
    • DCOM
      • 基于分布式环境下的COM被称作DCOM(Distribute COM,分布式组件对象模型)。
      • DCOM是ActiveX的基础,它实现了COM对象与远程计算机上的另一个对象之间直接进行交互。
    • ActiveX
      • ActiveX是Microsoft提出的一组基于COM(Component Object Model,组件对象模型)规范使得软件组件在网络环境中进行交互的技术集。它与具体的编程语言无关。
      • 作为针对Internet应用开发的技术,ActiveX被广泛应用于WEB服务器以及客户端的各个方面。同时,ActiveX技术也被 用于方便地创建普通的桌面应用程序。
      • 其内容包括控件、文档、脚本、服务器框架。
    • 组件式GIS
      • 基本思想是把GIS的各大功能模块划分为几个控件,每个控件完成不同的功能。各个GIS控件之间,以及GIS控件与其它非GIS控件之间,可以方便地通过可视化的软件开发工具集成起来,形成最终的GIS应用。
      • 控件如同一堆各式各样的积木,他们分别实现不同的功能(包括GIS和非GIS功能),根据需要把实现各种功能的 “积木”搭建起来,就构成应用系统。
      • 其开发平台通常可设计为三级结构:基础组件、高级通用组件、行业组件。
      • 其功能包括空间数据获取、坐标转换、图形编辑、数据存储、数据查询、数据分析、制图表示等。

ArcGIS Engine编程基础

  • ArcObjects

    • AO是ESRI公司ArcGIS™家族中应用程序(ArcMap、 ArcCatalog、 ArcScene)的开发平台,是基于Microsoft® COM技术所构建的一系列COM组件集。
    • AO是随ArcGIS产品一同发布的,要使用AO必须购买ArcGIS Desktop,才能利用AO提供的组件对象来进行应用开发。
    • 在ArcGIS 9中发布了一个新的产品:ArcGIS Engine,ArcGIS Engine基于AO,并且实现了更好的封装是一个独立的产品。
  • ArcGIS Engine

    • ArcGIS Engine是基于COM的集合,可以被任何支持COM的编程语言所调用。
    • 使用ArcGIS Engine编程真正实现GIS功能的灵活配置,不仅可以编写功能复杂的独立应用程序,而且可以将GIS的相关功能嵌入到现有的软件中。
    • 在产品架构上,ArcGIS Engine由两部分组成:构建GIS应用软件所用的开发工具包(ArcGIS Engine Developer Kit),以及可分发的、为应用程序提供运行基础的运行时(ArcGIS Engine Runtime)。
  • 上述两者联系与区别
    • 联系
      • ArcGIS Engine包括ArcObjects的核心功能,是对ArcObjects中大部分接口、类库进行封装所构成的。
      • ArcGIS Engine中组件的接口、方法、属性与ArcObjects是相同的。
    • 区别
      • 开发环境上:基于ArcObjects开发时,必须安装ArcGIS Desktop;基于ArcGIS Engine开发时,由于ArcGIS Engine是独立的COM组件,不需要安装ArcGIS Desktop,只需安装ArcGIS Engine Developer Kit即可。
      • 功能强弱上:ArcObjects包含了很多ArcGIS Desktop中的UI功能,而部分UI功能在ArcGIS Engine中是没有的,如在ArcCatalog中向地图文档中添加数据所用到的IGxDialog接口,用于打印设置的IPrintDialog接口等。
  • ArcGIS Engine类库

    • 不同的组件库分别封装不同的GIS功能。
    • .Net开发环境中,不同的GIS功能分别被定义在不同的命名空间内。
    • 提供的类库主要可以分为Version类库、界面和控件类库、可视化显示类库、数据访问类库、数据分析类库等几大部分。
  • ArcGIS Engine控件

    • ArcGIS Engine控件是一组可视化的开发组件。
    • 每个ArcGIS Engine控件都是一个COM组件。
  • 三种类型的类

    • AbstractClass
      • AbstractClass类是抽象类,不能被实例化。不能用new关键字去生成一个该类的对象。如Geometry类,可以用Polyline创建。
      • 抽象类的主要目的是为它的子类定义公共接口,一个抽象类将把它的部分或全部实现延迟到子类中,不同的类可以继承自同一个抽象类,但内部对同一个方法的实现可能是不一样的。
      • 抽象类不能直接创建类对象,只能通过派生子类的方法来实现自己。
    • CoClass
      • CoClass类是可创建类,可通过new关键字直接实例化对象。
      • 实例对象和生存周期都是独立的,其实例对象不依赖其他对象的存在而存在,其生存周期也不由其它的对象管理。
    • Class
      • Class类是一个可实例化类,不能直接使用new关键字创建对象,但是可以借助其它对象类来创建该类的实例,如Workspace类可以通过WorkspaceFactory类的OpenFromFile方法来创建。
  • 接口

    • 接口是指组件对象的接口,它是包含了一组函数的数据结构,通过这组数据结构,客户代码可以调用组件对象的功能,组件对象间的访问都是通过接口来进行的。
    • 接口设计必须满足以下两个条件:
      • 必须直接或间接地从IUnknown接口继承(该接口在AO中是省缺的)。
      • 接口必须有唯一的标识符号(接口不变性)。即,一旦分配和公布了ID,接口定义的任何因素都不能改变。
  • 对象模型图
    • 继承关系的类:空心三角箭头
    • 组合关系的类:实心菱形
    • 关联关系的类:实线
    • 依赖关系的类:虚线箭头
    • 入接口:空心圆
    • 出接口:实心圆
  • 空间数据库
    • 概念
      • 空间数据库指的是地理信息系统在计算机物理存储介质上存储的与应用相关的地理空间数据的总和,一般是以一系列特定结构的文件的形式组织在存储介质之上的。
    • 主要特点
      • 数据量庞大
      • 具有高可访问性
      • 空间数据模型复杂
    • 管理系统的实现方法
      • 寄生在关系数据库管理系统之上的空间数据引擎
      • 直接扩展通用数据库的空间数据库系统
  • 桌面GIS应用软件的开发方式

    • VBA开发
    • DLL开发
    • Add-in开发
    • ArcGIS Engine开发

Add-in开发

  • 在Visual Studio 2012中新建项目,选择“类库”。
  • 更改[Properties]->[生成]->[目标平台]为x86,勾选[为 COM 互操作注册]。
  • 更改[Properties]->[AssemblyInfo.cs]的第20行为[assembly: ComVisible(true)]
  • 添加引用ESRI.ArcGIS.ArcMapUIESRI.ArcGIS.CartoESRI.ArcGIS.FrameworkESRI.ArcGIS.SystemUISystem.Windows.Forms
  • 下面例子实现功能:在ArcMap中点击一个工具栏上的按钮,弹出对话框,显示当前所有图层名。
  • 将一个类实现ICommand接口,关键代码如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    public class GetLayerNameClass : ICommand {
    IApplication m_App;
    public string Caption { get { return "Get Layer Names"; } }
    public string Category { get { return "myetyet Tools"; } }
    public string Message { get { return "My first add-in."; } }
    public string Name { get { return "Get Layer Names"; } }
    public void OnClick() {
    IMxDocument pMxDoc = m_App.Document as IMxDocument;
    IMap pMap = pMxDoc.FocusMap;
    int n = pMap.LayerCount;
    string[] names = new string[n];
    for (int i = 0; i < n; ++i)
    names[i] = pMap.Layer[i].Name;
    MessageBox.Show(string.Join("\n", names));
    }
    public void OnCreate(object Hook) {
    m_App = Hook as IApplication;
    }
    }
  • F6生成解决方案。
  • 在ArcMap中,打开[Customize]->[Customize Mode],在弹出的对话框中切换至[Commands]选项卡,点击[Add From File],选择解决方案中的*.tlb文件,点击[打开],找到[myetyet Tools]下的[Get Layer Names],将其拖至任一工具条上即可单击该图标使用。

ESRI.ArcGIS下常用接口及其常用成员

  • Carto

    • IAnnotateLayerPropertiesCollection

      1
      2
      3
      4
      5
      6
      7
      8
      9
      void Add(IAnnotateLayerProperties Item);
      void Clear();
      int Count { get; }
      void QueryItem(
      int Index, ref IAnnotateLayerProperties Item,
      ref IElementCollection placedElements, ref IElementCollection unplacedElements
      );
      void Remove(IAnnotateLayerProperties Layerprops);
      void Sort();
    • IBasicGeoprocessor

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      IFeatureClass Clip(
      ITable inputTable, bool useSelectedInput, ITable clipTable,
      bool useSelectedClip, double Tolerance, IFeatureClassName outputName
      );
      ITable Dissolve(
      ITable inputTable, bool useSelected, string dissolveField,
      string summaryFields, IDatasetName outputName
      );
      IFeatureClass Intersect(
      ITable inputTable, bool useSelectedInput, ITable overlayTable,
      bool useSelectedOverlay, double Tolerance, IFeatureClassName outputName
      );
      IFeatureClass Merge(IArray tables, ITable fieldsTable, IFeatureClassName outputName);
      IFeatureClass Union(
      ITable inputTable, bool useSelectedInput, ITable overlayTable,
      bool useSelectedOverlay, double Tolerance, IFeatureClassName outputName
      );
    • IBasicHistogram

      1
      bool GetHistogram(ref object doubleArrayValues, ref objectlongArrayFrequencies);
    • IClassBreaksRenderer

      1
      2
      3
      4
      5
      6
      7
      8
      9
      int BreakCount { get; set; }
      string Field { get; set; }
      double MinimumBreak { get; set; }
      double get_Break(int Index);
      void set_Break(int Index, double Value);
      string get_Label(int Index);
      void set_Label(int Index, string Label);
      ISymbol get_Symbol(int Index);
      void set_Symbol(int Index, ISymbol sym);
    • IElement

      1
      2
      IGeometry Geometry { get; set; }
      bool HitTest(double x, double y, double Tolerance);
    • IFeatureLayer : ILayer

      1
      2
      3
      string DisplayField { get; set; }
      IFeatureClass FeatureClass { get; set; }
      string Name { get; set; }
    • IFillShapeElement

      1
      IFillSymbol Symbol { get; set; }
    • IGeoFeatureLayer : IFeatureLayer, ILayer

      1
      2
      3
      IAnnotateLayerPropertiesCollection AnnotationProperties { get; set; }
      bool DisplayAnnotation { get; set; }
      IFeatureRenderer Renderer { get; set; }
    • ILabelEngineLayerProperties

      1
      2
      string Expression { get; set; }
      ITextSymbol Symbol { get; set; }
    • ILineElement

      1
      ILineSymbol Symbol { get; set; }
    • IMarkerElement

      1
      IMarkerSymbol Symbol { get; set; }
    • IPictureElement

      1
      2
      void ImportPictureFromFile(string Name);
      bool SavePictureInDocument { get; set; }
    • IRasterClassifyColorRampRenderer

      1
      2
      3
      4
      5
      6
      7
      8
      int ClassCount { get; set; }
      string ClassField { get; set; }
      double get_Break(int Index);
      void set_Break(int Index, double Value);
      string get_Label(int Index);
      void set_Label(int Index, string Label);
      ISymbol get_Symbol(int Index);
      void set_Symbol(int Index, ISymbol Symbol);
    • IRasterRGBRenderer

      1
      2
      3
      4
      5
      6
      7
      8
      int BlueBandIndex { get; set; }
      int GreenBandIndex { get; set; }
      void QueryBandIndices(ref int redIndex, ref int greenIndex, ref int blueIndex);
      int RedBandIndex { get; set; }
      SetBandIndices(int redIndex, int greenIndex, int blueIndex);
      bool UseBlueBand { get; set; }
      bool UseGreenBand { get; set; }
      bool UseRedBand { get; set; }
    • IRasterRenderer

      1
      2
      IRaster Raster { get; set; }
      void Update();
    • IRasterStretchColorRampRenderer

      1
      2
      3
      4
      5
      6
      7
      int BandIndex { get; set; }
      IColorRamp ColorRamp { get; set; }
      string ColorScheme { get; set; }
      string LabelHigh { get; set; }
      string LabelLow { get; set; }
      string LabelMedium { get; set; }
      void ResetLabels();
    • IRasterUniqueValueRenderer

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      void AddValue(int iHeading, int iClass, object Value);
      string DefaultLabel { get; set; }
      ISymbol DefaultSymbol { get; set; }
      int HeadingCount { get; set; }
      string Field { get; set; }
      void RemoveValues(int iHeading, int iClass);
      bool UseDefaultSymbol { get; set; }
      int get_ClassCount(int iHeading);
      void set_ClassCount(int iHeading, int pCount);
      string get_Heading(int iHeading);
      void set_Heading(int iHeading, string pHeading);
      string get_Label(int iHeading);
      void set_Label(int iHeading, int iClass, string pLabel);
      ISymbol get_Symbol(int iHeading, int iClass);
      void set_Symbol(int iHeading, int iClass, ISymbol pSymbol);
    • ISimpleRenderer

      1
      ISymbol Symbol { get; set; }
    • ITableHistogram

      1
      2
      string Field { get; set; }
      ITable Table { get; set; }
    • ITextElement

      1
      2
      3
      bool ScaleText { get; set; }
      ITextSymbol Symbol { get; set; }
      string Text { get; set; }
    • IUniqueValueRenderer

      1
      2
      3
      4
      5
      ISymbol DefaultSymbol { get; set; }
      int FieldCount { get; set; }
      bool UseDefaultSymbol { get; set; }
      string get_Field(int Index);
      void set_Field(int Index, string Field);
  • Controls

    • IMapControl2

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      IActiveView ActiveView { get; }
      void AddLayer(ILayer Layer, int toIndex = 0);
      void CenterAt(IPoint centerPoint);
      bool CheckMxFile(string fileName);
      void ClearLayers();
      ITool CurrentTool { get; set; }
      void DeleteLayer(int index);
      void FlashShape(
      IGeometry pShape, int nFlashes = 3, int flashInterval = 300,
      object symbol = Type.Missing
      );
      int LayerCount { get; }
      void LoadMxFile(
      string mxPath,
      object mapNameOrIndex = Type.Missing, object password = Type.Missing
      );
      IMap Map { get; set; }
      void MoveLayerTo(int fromIndex, int toIndex);
      void Refresh(
      esriViewDrawPhase phase = 65535,
      object layerOrElement = Type.Missing, object envelope = Type.Missing
      );
      IPoint ToMapPoint(int X, int Y);
      IGeometry TrackCircle();
      IGeometry TrackLine();
      IGeometry TrackPolygon();
      IEnvelope TrackRectangle();
      ILayer get_Layer(int index);
  • DataSourcesRaster

    • IRaster2

      1
      2
      3
      4
      5
      6
      7
      8
      9
      ITable AttributeTable { get; set; }
      object GetPixelValue(int iBand, int iColumn, int iRow);
      void MapToPixel(double x, double y, ref int pColumn, ref int pRow);
      void PixelToMap(int iColumn, int iRow, ref double pX, ref double pY);
      IRasterDataset RasterDataset { get; }
      double ToMapX(int iColumn);
      double ToMapY(int iRow);
      int ToPixelColumn(double x);
      int ToPixelRow(double y);
    • IRasterBand

      1
      2
      3
      4
      5
      6
      7
      8
      ITable AttributeTable { get; }
      string Bandname { get; }
      void ComputeStatsAndHist();
      void HasStatistics(ref bool b);
      void HasTable(ref bool b);
      IRasterHistogram Histogram { get; }
      IRasterDataset RasterDataset { get; }
      IRasterStatistics Statistics { get; }
    • IRasterBandCollection

      1
      2
      3
      4
      5
      6
      7
      8
      9
      void Add(IRasterBand Element, int index);
      void AppendBand(IRasterBand Element);
      IEnumRasterBand Bands { get; }
      void Clear();
      int Count { get; }
      IRasterBand Item(int BandIndex);
      void Remove(int index);
      IRasterBand get_BandByName(string Name);
      int get_BandIndex(string Name);
    • IRasterProps

      1
      2
      3
      4
      5
      int Height { get; set; }
      bool IsInteger { get; }
      object NoDataValue { get; set; }
      rstPixelType PixelType { get; set; }
      int Width { get; set; }
    • IRasterStatistics

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      object IgnoredValues { get; set; }
      bool IsValid { get; set; }
      double Maximum { get; set; }
      double Median { get; }
      double Minimum { get; set; }
      double Mode { get; }
      void Recalculate();
      int SkipFactorX { get; set; }
      int SkipFactorY { get; set; }
      double StandardDeviation { get; set; }
  • Display

    • IAlgorithmicColorRamp : IColorRamp

      1
      2
      3
      esriColorRampAlgorithm Algorithm { get; set; }
      IColor FromColor { get; set; }
      IColor ToColor { get; set; }
    • IColor

      1
      2
      3
      int CMYK { get; set; }
      int RGB { get; set; }
      byte Transparency { get; set; }
    • IColorRamp

      1
      2
      3
      4
      5
      IEnumColors Colors { get; }
      void CreateRamp(ref bool ok);
      string Name { get; set; }
      int Size { get; set; }
      IColor get_Color(int index);
    • IEnumColors

      1
      2
      IColor Next();
      void Reset();
    • IFillSymbol

      1
      2
      IColor Color { get; set; }
      ILineSymbol Outline { get; set; }
    • ILineSymbol

      1
      2
      IColor Color { get; set; }
      double Width { get; set; }
    • IMarkerSymbol

      1
      2
      3
      4
      5
      double Angle { get; set; }
      IColor Color { get; set; }
      double Size { get; set; }
      double XOffset { get; set; }
      double YOffset { get; set; }
    • ITextSymbol

      1
      2
      3
      4
      5
      6
      7
      8
      double Angle { get; set; }
      IColor Color { get; set; }
      stdole.IFontDisp Font { get; set; }
      esriTextHorizontalAlignment HorizontalAlignment { get; set; }
      bool RightToLeft { get; set; }
      double Size { get; set; }
      string Text { get; set; }
      esriTextVerticalAlignment VerticalAlignment { get; set; }
    • IRandomColorRamp : IColorRamp

      1
      2
      3
      4
      5
      6
      7
      8
      int EndHue { get; set; }
      int MaxSaturation { get; set; }
      int MaxValue { get; set; }
      int MinSaturation { get; set; }
      int MinValue { get; set; }
      int Seed { get; set; }
      int StartHue { get; set; }
      bool UseSeed { get; set; }
    • IRgbColor : IColor

      1
      2
      3
      int Blue { get; set; }
      int Green { get; set; }
      int Red { get; set; }
    • ISimpleFillSymbol : IFillSymbol

      1
      esriSimpleFillStyle Style { get; set; }
    • ISimpleLineSymbol : ILineSymbol

      1
      esriSimpleLineStyle Style { get; set; }
    • ISimpleMarkerSymbol : IMarkerSymbol

      1
      2
      3
      4
      bool Outline { get; set; }
      IColor OutlineColor { get; set; }
      double OutlineSize { get; set; }
      esriSimpleMarkerStyle Style { get; set; }
  • Geodatabase

    • IDatasetName

      1
      2
      3
      string Category { get; set; }
      string Name { get; set; }
      esriDatasetType Type { get; }
    • IFeature : IObject, IRow, IRowBuffer

      1
      2
      3
      IEnvelope Extent { get; }
      esriFeatureType FeatureType { get; }
      IGeometry Shape { get; set; }
    • IFeatureBuffer : IRowBuffer

      1
      IGeometry Shape { get; set; }
    • IFeatureClass : IClass, IObjectClass

      1
      2
      3
      4
      5
      6
      7
      void AddField(IField Field);
      string AliasName { get; }
      IFeature CreateFeature();
      void DeleteField(IField Field);
      IFields Fields { get; }
      IFeatureCursor Search(IQueryFilter filter, bool Recycling);
      esriGeometryType ShapeType { get; }
    • IFeatureClassName

      1
      2
      3
      4
      IDatasetName FeatureDatasetName { get; set; }
      esriFeatureType FeatureType { get; set; }
      string ShapeFieldName { get; set; }
      esriGeometryType ShapeType { get; set; }
    • IFeatureCursor

      1
      2
      3
      4
      5
      6
      7
      void DeleteFeature();
      IFields Fields { get; }
      int FindField(string Name);
      void Flush();
      object InsertFeature(IFeatureBuffer buffer);
      IFeature NextFeature();
      void UpdateFeature(IFeature Object);
    • IFeatureWorkspace

      1
      2
      3
      IFeatureClass OpenFeatureClass(string Name);
      IFeatureDataset OpenFeatureDataset(string Name);
      ITable OpenTable(string Name);
    • IField

      1
      2
      3
      string AliasName { get; }
      string Name { get; }
      esriFieldType Type { get; }
    • IFields

      1
      2
      3
      int FieldCount { get; }
      int FindField(string Name);
      IField get_Field(int Index);
    • IPixelBlock

      1
      2
      3
      4
      5
      6
      7
      int BytesPerPixel { get; }
      object GetVal(int plane, int X, int Y);
      int Height { get; set; }
      int Planes { get; }
      int Width { get; }
      object get_SafeArray(int plane);
      void set_SafeArray(int plane, object val);
    • IPnt

      1
      2
      3
      4
      5
      void Convert2Point(IPoint env);
      void Set2Point(IPoint env);
      void SetCoords(double X, double Y);
      double X { get; set; }
      double Y { get; set; }
    • IQueryFilter

      1
      2
      3
      void AddField(string subField);
      string SubFields { get; set; }
      string WhereClause { get; set; }
    • IRaster

      1
      2
      3
      4
      IRasterCursor CreateCursor();
      IPixelBlock CreatePixelBlock(IPnt Size);
      void Read(IPnt tlc, IPixelBlock block);
      rstResamplingTypes ResampleMethod { get; set; }
    • IRow : IRowBuffer

      1
      2
      void Delete();
      void Store();
    • IRowBuffer

      1
      2
      3
      IFields Fields { get; }
      object get_Value(int Index);
      object set_Value(int Index, object Value);
    • ISaveAs

      1
      2
      bool CanSaveAs(string Format);
      IDataset SaveAs(string Name, IWorkspace Workspace, string Format);
    • ISpatialFilter : IQueryFilter

      1
      2
      3
      IGeometry Geometry { get; set; }
      string GeometryField { get; set; }
      esriSpatialRelEnum SpatialRel { get; set; }
    • ITable : IClass

      1
      2
      3
      4
      5
      IRow CreateRow();
      IRowBuffer CreateRowBuffer();
      void DeleteSearchedRows(IQueryFilter QueryFilter);
      IRow GetRow(int OID);
      int RowCount(IQueryFilter QueryFilter);
    • IWorkspace

      1
      2
      3
      4
      5
      bool Exists();
      string PathName { get; }
      esriWorkspaceType Type { get; }
      IWorkspaceFactory WorkspaceFactory { get; }
      IEnumDataset get_Datasets(esriDatasetType DatasetType);
    • IWorkspaceEdit

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      void AbortEditOperation();
      void DisableUndoRedo();
      void EnableUndoRedo();
      void HasEdits(ref bool pHasEdits);
      void HasRedos(ref bool pHasRedos);
      void HasUndos(ref bool pHasUndos);
      bool IsBeingEdited();
      void RedoEditOperation();
      void StartEditing(bool withUndoRedo);
      void StartEditOperation();
      void StopEditing(bool saveEdits);
      void StopEditOperation();
      void UndoEditOperation();
    • IWorkspaceFactory

      1
      2
      IWorkspace OpenFromFile(string fileName, int hWnd);
      esriWorkspaceType WorkspaceType { get; }
  • GeoAnalyst

    • IGeoAnalysisEnvironment

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      IWorkspace OutWorkspace { get; set; }
      // object Missing = Type.Missing;
      void SetCellSize(
      esriRasterEnvSettingEnumenv Type,
      ref object cellSizeProvider = ref Missing
      );
      void SetExtent(
      esriRasterEnvSettingEnumenv Type,
      ref object extentProvider = ref Missing, ref object snapRasterData = ref Missing
      );
    • IGeoAnalysisSemiVariogram

      1
      2
      3
      4
      5
      6
      7
      8
      9
      void DefineVariogram(
      esriGeoAnalysisSemiVariogramEnum Type,
      double aRange, double sill, double aNugget
      );
      double Lag { get; set; }
      double Nugget { get; }
      double PartialSill { get; }
      double Range { get; }
      esriGeoAnalysisSemiVariogramEnum VariogramType { get; set; }
    • IInterpolationOp2

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      // object Missing = Type.Missing;
      IGeoDataset IDW(
      IGeoDataset geoData, double power, IRasterRadius radius,
      ref object barrier = ref Missing
      );
      IGeoDataset Krige(
      IGeoDataset geoData, esriGeoAnalysisSemiVariogramEnum semiVariogramType,
      IRasterRadius radius, bool outSemiVariance,
      ref object barrier = ref Missing
      );
      IGeoDataset NaturalNeighbor(IGeoDataset GeoDataset);
      IGeoDataset Spline(
      IGeoDataset geoData, esriGeoAnalysisSplineEnum splineType,
      ref object weight = ref Missing, ref object numPoints = ref Missing
      );
      IGeoDataset TopoToRasterByFile(
      string paramFile,
      ref IFeatureClass outStream, ref IFeatureClass outSink
      );
      IGeoDataset Trend(IGeoDataset geoData, esriGeoAnalysisTrendEnum trendType, int order);
      IGeoDataset Variogram(
      IGeoDataset geoData, IGeoAnalysisSemiVariogram semiVariogram,
      IRasterRadius radius, bool outSemiVariance,
      ref object barrier = Missing
      );
    • IRasterAnalysisEnvironment

      1
      2
      IGeoDataset Mask { get; set; }
      void Reset();
    • IRasterNeighborhood

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      void SetAnnulus(
      double innerRadius, double outerRadius,
      esriGeoAnalysisUnitsEnum unitsType
      );
      void SetCircle(double radius, esriGeoAnalysisUnitsEnum unitsType);
      void SetDefault();
      void SetIrregular(int height, int width, ref object entryValues);
      void SetRectangle(double width, double height, esriGeoAnalysisUnitsEnum unitsType);
      void SetWedge(
      double radius, double startAngle, double endAngle,
      esriGeoAnalysisUnitsEnum unitsType
      );
      void SetWeight(int height, int width, ref object entryValues);
    • IRasterRadius

      1
      2
      3
      // object Missing = Type.Missing;
      void SetFixed(double distance, ref object minCount = ref Missing);
      void SetVariable(int count, ref object maxDistance = ref Missing);
    • IReclassOp

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      IGeoDataset Lookup(IGeoDataset GeoDataset, string FieldName);
      IGeoDataset Reclass(
      IGeoDataset GeoDataset, ITable remapTable, string fromField,
      string toField, string OutField, bool retainMissingValues
      );
      IGeoDataset ReclassByASCIIFile(
      IGeoDataset inRaster, string sRemapFile,
      bool retainMissingValues
      );
      IGeoDataset ReclassByRemap(IGeoDataset GeoDataset, IRemap Remap, bool retainMissingValues);
      // object Missing = Type.Missing;
      IGeoDataset Slice(
      IGeoDataset GeoDataset, esriGeoAnalysisSliceEnum sliceType, int zoneCount,
      ref object baseZone = ref Missing
      );
    • ISurfaceOp2

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      IGeoDataset Aspect(IGeoDataset GeoDataset);
      // object Missing = Type.Missing;
      IGeoDataset Contour(
      IGeoDataset GeoDataset, double interval,
      ref object base = ref Missing, ref object zFactor = ref Missing
      );
      IGeoDataset ContourList(IGeoDataset GeoDataset, ref object contoursArray);
      IGeoDataset Curvature(
      IGeoDataset GeoDataset, bool profile, bool plan,
      ref objectzFactor = ref Missing
      );
      IGeoDataset CutFill(
      IGeoDataset beforeGeoDataset, IGeoDataset afterGeoDataset,
      ref objectzFactor = ref Missing
      );
      IGeoDataset HillShade(
      IGeoDataset GeoDataset, double azimuth, double altitude,
      bool inModelShadows,
      ref objectzFactor = ref Missing
      );
      IGeoDataset Slope(
      IGeoDataset GeoDataset, esriGeoAnalysisSlopeEnum slopeType,
      ref objectzFactor = ref Missing
      );
      IGeoDataset Visibility(
      IGeoDataset GeoDataset, IGeoDataset observers,
      esriGeoAnalysisVisibilityEnum visType,
      ref objectzFactor = ref Missing, ref object pRefractivityCoefficient = ref Missing
      );
  • Geometry

    • IArea

      1
      2
      3
      double Area { get; }
      IPoint Centroid { get; }
      IPoint LabelPoint { get; }
    • IGeometry

      1
      2
      3
      esriGeometryDimension Dimension { get; }
      IEnvelope Envelope { get; }
      esriGeometryType GeometryType { get; }
    • IPoint : IGeometry

      1
      2
      3
      void PutCoords(double X, double Y);
      double X { get; set; }
      double Y { get; set; }
    • IPointCollection

      1
      2
      3
      4
      5
      6
      7
      8
      9
      // object Missing = Type.Missing;
      void AddPoint(
      IPoint inPoint,
      ref object before = ref Missing, ref objectafter = ref Missing
      );
      void AddPointCollection(IPointCollection newPoints);
      int PointCount { get; }
      void RemovePoints(int Index, int Count);
      IPoint get_Point(int i);
    • IRelationalOperator

      1
      2
      3
      4
      5
      6
      7
      bool Contains(IGeometry other);
      bool Crosses(IGeometry other);
      bool Disjoint(IGeometry other);
      bool Equals(IGeometry other);
      bool Overlaps(IGeometry other);
      bool Touches(IGeometry other);
      bool Within(IGeometry other);
    • ITopologicalOperator

      1
      2
      3
      4
      5
      6
      IGeometry Boundary { get; }
      IGeometry Buffer(double distance);
      IGeometry Difference(IGeometry other);
      IGeometry Intersect(IGeometry other, esriGeometryDimension resultDimension);
      void Simplify();
      IGeometry SymmetricDifference(IGeometry other);
  • SpatialAnalyst

    • IDensityOp

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      // object Missing = Type.Missing;
      IGeoDataset KernelDensity(
      IGeoDataset sourceFeatures,
      ref object radiusDistance = ref Missing, ref object scaleFactor = ref Missing
      );
      IGeoDataset LineDensity(
      IGeoDataset lineFeatures,
      ref object radiusDistance = ref Missing, ref object scaleFactor = ref Missing
      );
      IGeoDataset PointDensity(
      IGeoDataset pointFeatures, IRasterNeighborhood nbrhood,
      ref object scaleFactor = ref Missing
      );
    • IDistanceOp

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      IGeoDataset Corridor(IGeoDataset distance1, IGeoDataset distance2);
      // object Missing = Type.Missing;
      IGeoDataset CostAllocation(
      IGeoDataset sourceData, IGeoDataset costRaster,
      ref object maxDistance = ref Missing, ref object valueRaster = ref Missing
      );
      IGeoDataset CostBackLink(
      IGeoDataset sourceData, IGeoDataset costRaster,
      ref object maxDistance = ref Missing, ref object valueRaster = ref Missing
      );
      IGeoDataset CostDistance(
      IGeoDataset sourceData, IGeoDataset costRaster,
      ref object maxDistance = ref Missing, ref object valueRaster = ref Missing
      );
      IGeoDataset CostPath(
      IGeoDataset fromData, IGeoDataset distance, IGeoDataset backlink,
      esriGeoAnalysisPathEnum pathType
      );
      IGeoDataset EucAllocation(
      IGeoDataset sourceData,
      ref object maxDistance = ref Missing, ref object valueRaster = ref Missing
      );
      IGeoDataset EucDirection(
      IGeoDataset sourceData,
      ref object maxDistance = ref Missing, ref object valueRaster = ref Missing
      );
      IGeoDataset EucDistance(
      IGeoDataset sourceData,
      ref object maxDistance = ref Missing, ref object valueRaster = ref Missing
      );
    • IMapAlgebraOp

      1
      2
      3
      void BindRaster(IGeoDataset geoDataset, string symbol);
      IGeoDataset Execute(string expression);
      void UnbindRaster(string symbolName);
  • SystemUI

    • ICommand

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      int Bitmap { get; }
      string Caption { get; }
      string Category { get; }
      bool Checked { get; }
      bool Enabled { get; }
      string Message { get; }
      string Name { get; }
      void OnClick();
      void OnCreate(object Hook);
      string Tooltip { get; }
    • ITool

      1
      2
      3
      int Cursor { get; }
      bool Deactivate();
      void OnMouseDown();
  • esriSystem

    • IClassifyGEN

      1
      2
      object ClassBreaks { get; }
      void Classify(object doubleArrayValues, object longArrayFrequencies, ref int numClasses);
    • IObjectCopy

      1
      2
      object Copy(object pInObject);
      void Overwrite(object pInObject, ref object pOverwriteObject);

示例

  • 绑定运行时:修改Program.cs文件中相关代码。
    1
    2
    3
    4
    5
    6
    static void Main() {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
    Application.Run(new Form1());
    }
  • 切换Map和Layout选项卡时互相传递数据。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) {
    IObjectCopy pOC = new ObjectCopyClass();
    if (tabControl1.SelectedIndex == 0) {
    object pSourceMap = axPageLayoutControl1.ActiveView.FocusMap;
    object pDestMap = axMapControl1.ActiveView.FocusMap;
    pOC.Overwrite(pSourceMap, ref pDestMap);
    axTOCControl1.SetBuddyControl(axMapControl1);
    axMapControl1.Refresh();
    } else if (tabControl1.SelectedIndex == 1) {
    object pSourceMap = axMapControl1.ActiveView.FocusMap;
    object pDestMap = axPageLayoutControl1.ActiveView.FocusMap;
    pOC.Overwrite(pSourceMap, ref pDestMap);
    axTOCControl1.SetBuddyControl(axPageLayoutControl1);
    axPageLayoutControl1.Refresh();
    }
    }
  • listBox1中列出了当前所有图层,选择其中一个,在listBox2中列出该图层属性表中的所有属性名。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    IMap pMap = App.ActiveView.FocusMap;
    ILayer pLayer = pMap.Layer[listBox1.SelectedIndex];
    IFields pFields = null;
    if (pLayer is IFeatureLayer) {
    IFeatureLayer pFL = pLayer as IFeatureLayer;
    IFeatureClass pFC = pFL.FeatureClass;
    pFields = pFC.Fields;
    } else if (pLayer is IRasterLayer) {
    IRasterLayer pRL = pLayer as IRasterLayer;
    IRasterBandCollection pRBC = pRL.Raster as IRasterBandCollection;
    IRasterBand pRB = pRBC.Item(0);
    ITable pTable = pRB.AttributeTable;
    if (pTable != null) pFields = pTable.Fields;
    }
    listBox2.Items.Clear();
    if (pFields != null)
    for (int i = 0; i < pFields.FieldCount; ++i)
    listBox2.Items.Add(pFields.Field[i].Name);
  • listBox1中列出了当前所有图层,创建两个按钮,分别控制将选中图层向上、下移动一层。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    private void btnLayerUp_Click(object sender, EventArgs e) {
    int index = listBox1.SelectedIndex;
    IMap pMap = App.ActiveView.FocusMap;
    ILayer pLayer = pMap.Layer[index];
    if (index > 0) {
    pMap.MoveLayer(pLayer, index - 1);
    listBox1.Items.Insert(index - 1, pLayer.Name);
    listBox1.Items.RemoveAt(index + 1);
    listBox1.SelectedIndex = index - 1;
    }
    }
    private void btnLayerDown_Click(object sender, EventArgs e) {
    int index = listBox1.SelectedIndex;
    IMap pMap = App.ActiveView.FocusMap;
    ILayer pLayer = pMap.Layer[index];
    if (index > -1 && index < pMap.LayerCount - 1) {
    pMap.MoveLayer(pLayer, index + 1);
    listBox1.Items.Insert(index + 2, pLayer.Name);
    listBox1.Items.RemoveAt(index);
    listBox1.SelectedIndex = index + 1;
    }
    }
  • 在点击处添加标记元素。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    IMarkerElement pME = new MarkerElementClass();
    ISimpleMarkerSymbol pSMS = new SimpleMarkerSymbolClass();
    pSMS.Style = (esriSimpleMarkerStyle)4;
    pSMS.Size = 8.0; pSMS.Angle = 359.9;
    IRgbColor pColor = new RgbColorClass(); pColor.Red = 255;
    pSMS.Color = pColor as IColor;
    pME.Symbol = pSMS as IMarkerSymbol; // Optional
    IElement pE = pME as IElement;
    pE.Geometry = m_App.ToMapPoint(x, y);
    m_App.ActiveView.GraphicsContainer.AddElement(pE, 0);
    m_App.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pE, null);
  • 跟踪绘制线条元素。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    ILineElement pLE = new LineElementClass();
    ISimpleLineSymbol pSLS = new SimpleLineSymbolClass();
    pSLS.Style = (esriSimpleLineStyle)6;
    pSLS.Width = 2.0;
    IRgbColor pColor = new RgbColorClass(); pColor.Green = 255;
    pSLS.Color = pColor as IColor;
    pLE.Symbol = pSLS as ILineSymbol; // Optional
    IElement pE = pLE as IElement;
    pE.Geometry = m_App.TrackLine();
    m_App.ActiveView.GraphicsContainer.AddElement(pE, 0);
    m_App.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pE, null);
  • 跟踪绘制面元素。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    IFillShapeElement pPE = new PolygonElementClass();
    ISimpleFillSymbol pSFS = new SimpleFillSymbolClass();
    pSFS.Style = (esriSimpleFillStyle)7;
    IRgbColor pColor = new RgbColorClass(); pColor.Blue = 255;
    pSFS.Color = pColor as IColor;
    pPE.Symbol = pSFS as IFillSymbol; // Optional
    IElement pE = pPE as IElement;
    pE.Geometry = m_App.TrackPolygon();
    m_App.ActiveView.GraphicsContainer.AddElement(pE, 0);
    m_App.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pE, null);
  • 在点击处添加文字元素。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    ITextElement pTE = new TextElementClass();
    pTE.Text = "myetyet";
    ITextSymbol pSTS = new TextSymbolClass();
    pSTS.Size = 16.0; pSTS.Angle = 45.0;
    IRgbColor pColor = new RgbColorClass();
    pColor.RGB = 0x808080;
    pSTS.Color = pColor as IColor;
    stdole.StdFontClass pFD = new stdole.StdFontClass();
    pFD.Name = "Consolas";
    pSTS.Font = pFD as stdole.IFontDisp;
    pTE.Symbol = pSTS; // Optional
    IElement pE = pTE as IElement;
    pE.Geometry = m_App.ToMapPoint(x, y);
    m_App.ActiveView.GraphicsContainer.AddElement(pE, 0);
    m_App.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pE, null);
  • 在矩形框选区内充填BMP图片,作为元素绘制在地图上。
    1
    2
    3
    4
    5
    6
    IPictureElement pPE = new BmpPictureElementClass();
    pPE.ImportPictureFromFile(@"C:\myetyet.bmp");
    IElement pE = pPE as IElement;
    pE.Geometry = m_App.TrackRectangle();
    m_App.ActiveView.GraphicsContainer.AddElement(pE, 0);
    m_App.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pE, null);
  • country图层中所有国家的货币代码不重复地加入comboBox1
    1
    2
    3
    4
    5
    6
    IFeatureLayer pFL = App.ActiveView.FocusMap.Layer[0] as IFeatureLayer;
    IFeatureCursor pFC = pFL.Search(null, false);
    for (IFeature pF = pFC.NextFeature(); pF != null; pF = pFC.NextFeature()) {
    string s = pF.Value[pFC.FindField("CURR_CODE")].ToString();
    if (comboBox1.FindStringExact(s) == -1) comboBox1.Items.Add(s);
    }
  • 将所有使用comboBox1中选中的货币代码的国家图形选中,并将这些国家的全名列于listBox1
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    IFeatureLayer pFL = App.ActiveView.FocusMap.Layer[0] as IFeatureLayer;
    IQueryFilter pQF = new QueryFilterClass();
    pQF.WhereClause = String.Format("CURR_CODE = '{0}'", comboBox1.SelectedItem.ToString());
    IFeatureCursor pFC = pFL.Search(pQF, false);
    listBox1.Items.Clear();
    App.ActiveView.FocusMap.ClearSelection();
    for (IFeature pF = pFC.NextFeature(); pF != null; pF = pFC.NextFeature()) {
    listBox1.Items.Add(pF.Value[pFC.FindField("LONG_NAME")].ToString());
    App.ActiveView.FocusMap.SelectFeature(pFL, pF);
    }
    App.Refresh(esriViewDrawPhase.esriViewGeoSelection);
  • 选中所有与绘制出的矩形包围框相交的图形。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    IFeatureLayer pFL = m_App.ActiveView.FocusMap.Layer[0] as IFeatureLayer;
    ISpatialFilter pSF = new SpatialFilterClass();
    pSF.Geometry = m_App.TrackRectangle();
    pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
    IFeatureCursor pFC = pFL.Search(pSF, false);
    m_App.ActiveView.FocusMap.ClearSelection();
    for (IFeature pF = pFC.NextFeature(); pF != null; pF = pFC.NextFeature())
    m_App.ActiveView.FocusMap.SelectFeature(pFL, pF);
    m_App.Refresh(esriViewDrawPhase.esriViewGeoSelection);
  • 在世界地图上绘制一条“铁路”(线条)并建立距离为的缓冲区,并显示该缓冲区在与之相交的国家内的面积。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    IGeometry pRailway = m_App.TrackLine();
    IElement pElement = new LineElementClass() as IElement;
    pElement.Geometry = pRailway;
    m_App.ActiveView.GraphicsContainer.AddElement(pElement, 0);
    m_App.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, null);
    ITopologicalOperator pTO1 = pRailway as ITopologicalOperator; pTO1.Simplify();
    IGeometry pRailwayBuffer = pTO1.Buffer(1.0);
    IFeatureLayer pFL = m_App.ActiveView.FocusMap.Layer[0] as IFeatureLayer;
    ISpatialFilter pSF = new SpatialFilterClass();
    pSF.Geometry = pRailway;
    pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
    IFeatureCursor pFC = pFL.Search(pSF, false);
    ITopologicalOperator pTO2 = pRailwayBuffer as ITopologicalOperator; pTO2.Simplify();
    List<string> res = new List<string>();
    for (IFeature pF = pFC.NextFeature(); pF != null; pF = pFC.NextFeature()) {
    IGeometry pInGeo = pTO2.Intersect(pF.Shape, esriGeometryDimension.esriGeometry2Dimension);
    double area = (pInGeo as IArea).Area;
    res.Add(String.Format("{0}: {1}", pF.Value[pF.Fields.FindField("CNTRY_NAME")], area));
    }
    MessageBox.Show(string.Join("\n", res));
  • 两相交面图层的裁剪分析。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    IFeatureLayer pFLclip = axMapControl1.get_Layer(0) as  IFeatureLayer;
    IFeatureLayer pFLin = axMapControl1.get_Layer(1) as IFeatureLayer;
    IFeatureClass pFCclip = pFLclip.FeatureClass,pFCin = pFLin.FeatureClass;
    // Get shapefile workspace
    IWorkspaceName pWN = new WorkspaceNameClass(); pWN.PathName = @"C:\myetyet";
    pWN.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
    // Set paraments of the result FeatureClass
    IFeatureClassName pFCN = new FeatureClassNameClass();
    pFCN.ShapeType = pFCin.ShapeType;
    pFCN.ShapeFieldName = pFCin.ShapeFieldName;
    pFCN.FeatureType = esriFeatureType.esriFTSimple;
    IDatasetName pDN = pFCN as IDatasetName;
    pDN.Name = "ClippedDatasetFileName"; pDN.WorkspaceName = pWN;
    // Initialize the BasicGeoprocessor
    IBasicGeoprocessor pGB = new BasicGeoprocessorClass();
    pGB.SpatialReference = axMapControl1.SpatialReference; // Optional
    ITable pTin = pFCin as ITable, pTclip = pFCclip as ITable;
    IFeatureClass pFCout = pGB.Clip(pTin, false, pTclip, false, 0.01, pFCN);
    // Add to the map
    IFeatureLayer pFLout = new FeatureLayerClass();
    pFLout.FeatureClass = pFCout;
    axMapControl1.AddLayer(pFLout);
  • 用打开文件对话框添加多个.shp文件至地图中。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    IWorkspaceFactory pWF = new ShapefileWorkspaceFactoryClass();
    OpenFileDialog pOFD = new OpenFileDialog();
    pOFD.Filter = "Shape File(*.shp)|*.shp"; pOFD.Multiselect = true;
    if (pOFD.ShowDialog() == DialogResult.OK) {
    string pDN = System.IO.Path.GetDirectoryName(pOFD.FileNames[0]);
    IFeatureWorkspace pFW = pWF.OpenFromFile(pDN, 0) as IFeatureWorkspace;
    for (int i = 0, len = pOFD.FileNames.Length; i < len; ++i) {
    IFeatureLayer pFL = new FeatureLayerClass();
    pFL.FeatureClass = pFW.OpenFeatureClass(pOFD.SafeFileNames[i]);
    pFL.Name = pFL.FeatureClass.AliasName;
    m_App.ActiveView.FocusMap.AddLayer(pFL);
    }
    }
  • 添加World数据库中所有矢量要素至地图中。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    string pPath = @"C:\myetyet\World", pExt = ".mdb";
    IWorkspaceFactory pWF = null;
    if (pExt == ".gdb") pWF = new FileGDBWorkspaceFactoryClass();
    else pWF = new AccessWorkspaceFactoryClass();
    IWorkspace pWs = pWF.OpenFromFile(pPath + pExt, 0);
    IFeatureWorkspace pFW = pWs as IFeatureWorkspace;
    IEnumDataset pED = pWs.Datasets[esriDatasetType.esriDTFeatureClass];
    for (IDataset pD = pED.Next(); pD != null; pD = pED.Next()) {
    IFeatureLayer pFL = new FeatureLayerClass();
    pFL.FeatureClass = pFW.OpenFeatureClass(pD.Name);
    pFL.Name = pFL.FeatureClass.AliasName;
    m_App.ActiveView.FocusMap.AddLayer(pFL);
    }
  • 显示C:\myetyet目录下所有数据集的名称。
    1
    2
    3
    4
    5
    6
    IWorkspaceFactory pWF = new ShapefileWorkspaceFactoryClass();
    IWorkspace pWs = pWF.OpenFromFile(@"C:\myetyet", 0);
    IEnumDataset pED = pWs.Datasets[esriDatasetType.esriDTAny];
    List<string> res = new List<string>(); IDataset pD;
    while ((pD = pED.Next()) != null) res.Add(pD.Name);
    MessageBox.Show(string.Join("\n", res));
  • 单一符号化渲染。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    ISimpleFillSymbol pSFS = new SimpleFillSymbolClass();
    IRgbColor pColor1 = new RgbColorClass(); pColor1.Red = 0xff;
    pSFS.Color = pColor1 as IColor;
    ILineSymbol pLS = new SimpleLineSymbolClass();
    IRgbColor pColor2 = new RgbColorClass(); pColor2.Blue = 0xff;
    pLS.Color = pColor2 as IColor; pLS.Width = 2;
    pSFS.Outline = pLS;
    ISimpleRenderer pSR = new SimpleRendererClass();
    pSR.Symbol = pSFS as ISymbol;
    IFeatureLayer pFL = Layer as IFeatureLayer;
    IGeoFeatureLayer pGFL = pFL as IGeoFeatureLayer;
    pGFL.Renderer = pSR as IFeatureRenderer;
    m_App.ActiveView.Refresh(); m_TOC.Update();
  • 唯一值符号化、随机色带、按值渲染国家名字段。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    // Define default symbol
    ISimpleFillSymbol pSFS = new SimpleFillSymbolClass();
    pSFS.Style = esriSimpleFillStyle.esriSFSHollow;
    pSFS.Outline.Width = 0.4;
    // Set the UniqueValueRenderer
    IUniqueValueRenderer pUVR = new UniqueValueRendererClass();
    pUVR.FieldCount = 1; pUVR.Field[0] = "CNTRY_NAME";
    pUVR.DefaultSymbol = pSFS as ISymbol; pUVR.UseDefaultSymbol = true;
    // Build a RandomColorRamp and get the cursor
    IRandomColorRamp pRCR = new RandomColorRampClass();
    pRCR.MinSaturation = 20; pRCR.MaxSaturation = 40;
    pRCR.MinValue = 85; pRCR.MaxValue = 100;
    pRCR.StartHue = 76; pRCR.EndHue = 188;
    pRCR.UseSeed = true; pRCR.Seed = pUVR.ValueCount + 5;
    pRCR.Size = pUVR.ValueCount;
    bool pCheck; pRCR.CreateRamp(out pCheck);
    IEnumColors pEC = pRCR.Colors; pEC.Reset();
    // Set the symbol of each Feature(country)
    List<string> pValues = new List<string>();
    IFeatureLayer pFL = Layer as IFeatureLayer;
    IFeatureCursor pFC = pFL.Search(null, false);
    IFields pFields = pFC.Fields; int pIndex = pFields.FindField("CNTRY_NAME");
    for (IFeature pF = pFC.NextFeature(); pF != null; pF = pFC.NextFeature()) {
    if (pValues.Contains(pF.Value[pIndex].ToString())) continue;
    pValues.Add(pCN);
    ISimpleFillSymbol ppSFS = new SimpleFillSymbolClass();
    ppSFS.Style = esriSimpleFillStyle.esriSFSSolid;
    ppSFS.Outline.Width = 0.4; ppSFS.Color = pEC.Next();
    pUVR.AddValue(pCN, "CNTRY_NAME", ppSFS as ISymbol);
    pUVR.set_Label(pCN, pCN); pUVR.set_Symbol(pCN, ppSFS as ISymbol);
    }
    // Render and refresh
    IGeoFeatureLayer pGFL = pFL as IGeoFeatureLayer;
    pGFL.Renderer = pUVR as IFeatureRenderer;
    m_App.ActiveView.Refresh(); m_TOC.Update();
  • 分级符号化、渐变色带、渲染国家人口字段。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    // Prepare the histogram of the field "POP_CNTRY"
    IFeatureLayer pFL = m_App.get_Layer(0) as IFeatureLayer;
    ITable pTable = pFL.FeatureClass as ITable;
    ITableHistogram pTH = new BasicTableHistogramClass();
    pTH.Field = "POP_CNTRY"; pTH.Table = pTable;
    object pValues, pFrequencies;
    (pTH as IBasicHistogram).GetHistogram(out pValues, out pFrequencies);
    // Get the result of quantile classification with 5 classes
    IClassifyGEN pCGEN = new QuantileClass();
    pCGEN.Classify(pValues, pFrequencies, 5);
    double[] pClasses = pCGEN.ClassBreaks as double[]; // double[6]
    // Set the UniqueValueRenderer
    IClassBreaksRenderer pCBR = new ClassBreaksRenderer();
    pCBR.Field = "POP_CNTRY"; pCBR.BreakCount = 5; pCBR.MinimumBreak = pClasses[0];
    // Build an AlgorithmicColorRamp and get the cursor
    IRgbColor pRC1 = new RgbColorClass();
    pRC1.RGB = ColorTranslator.ToOle(ColorTranslator.FromHtml("#D6D6FF"));
    IRgbColor pRC2 = new RgbColorClass();
    pRC2.RGB = ColorTranslator.ToOle(ColorTranslator.FromHtml("#003994"));
    IAlgorithmicColorRamp pACR = new AlgorithmicColorRampClass();
    pACR.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
    pACR.FromColor = pRC1; pACR.ToColor = pRC2; pACR.Size = 5;
    bool pCheck; pACR.CreateRamp(out pCheck);
    IEnumColors pEnumColors = pACR.Colors; pEnumColors.Reset();
    // Set the symbol of each class
    for (int i = 0; i <= 4; ++i) {
    pCBR.set_Break(i, pClasses[i + 1]);
    pCBR.set_Label(i, String.Format("{0} - {1}", pClasses[i], pClasses[i + 1]));
    ISimpleFillSymbol pSFS = new SimpleFillSymbolClass();
    pSFS.Color = pEnumColors.Next();
    pCBR.set_Symbol(i, pSFS as ISymbol);
    }
    // Render and refresh
    (pFL as IGeoFeatureLayer).Renderer = pCBR as IFeatureRenderer;
    m_App.ActiveView.Refresh(); m_TOC.Update();
  • 在世界地图上文字标注每个国家的全名和面积。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    IGeoFeatureLayer pGFL = pFL as IGeoFeatureLayer;
    IAnnotateLayerPropertiesCollection pALPC = pGFL.AnnotationProperties;
    // Set the font
    ITextSymbol pTS = new TextSymbolClass(); pTS.Size = 8;
    pTS.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
    pTS.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
    stdole.IFontDisp pFD = new stdole.StdFontClass() as stdole.IFontDisp;
    pFD.Name = "Consolas"; pTS.Font = pFD;
    // Modify the first (already existed) AnnotateLayerProperties
    IAnnotateLayerProperties pALP; IElementCollection pECpe, pECue;
    pALPC.QueryItem(0, out pALP, out pECpe, out pECue);
    ILabelEngineLayerProperties pLELP = pALP as ILabelEngineLayerProperties;
    pLELP.Expression = String.Format("[{0}]", ed.SelectedField);
    pLELP.Symbol = pTS;
    // Construct a new AnnotateLayerProperties and add it
    pLELP = new LabelEngineLayerPropertiesClass();
    pLELP.Expression = "[Area]"; pLELP.Symbol = pTS;
    pALPC.Add(pLELP as IAnnotateLayerProperties);
    // Display the annotation and refresh
    pGFL.DisplayAnnotation = true;
    m_App.ActiveView.Refresh();
  • 创建一个点矢量图层,拥有OIDShapeName字段。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    // Prepare a FeatureWorkspace and a FeatureLayer
    IWorkspaceFactory pWF = new ShapefileWorkspaceFactoryClass();
    IFeatureWorkspace pFW = pWF.OpenFromFile(@"C:\myetyet", 0) as IFeatureWorkspace;
    IFeatureLayer pFL = new FeatureLayerClass(); pFL.Name = "New Point Layer";
    // Create a fields collection for the feature class
    IFields pFs = new FieldsClass(); IFieldsEdit pFsE = pFs as IFieldsEdit;
    // Add an ObjectID field to the fields collection
    IField pOIDF = new FieldClass(); IFieldEdit pOIDFE = pOIDF as IFieldEdit;
    pOIDFE.Name_2 = "OID"; pOIDFE.Type_2 = esriFieldType.esriFieldTypeOID;
    pFsE.AddField(pOIDF);
    // (Optional) Set the spatial reference
    ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass();
    int pPCS = (int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_20N;
    ISpatialReference pSR = pSRF.CreateProjectedCoordinateSystem(pPCS);
    ISpatialReferenceResolution pSRR = pSR as ISpatialReferenceResolution;
    pSRR.ConstructFromHorizon(); pSRR.SetDefaultXYResolution();
    ISpatialReferenceTolerance pSRT = pSR as ISpatialReferenceTolerance;
    pSRT.SetDefaultXYTolerance();
    // Define the GeometryDef
    IGeometryDefEdit pGDE = new GeometryDefClass();
    pGDE.GeometryType_2 = esriGeometryType.esriGeometryPoint;
    pGDE.SpatialReference_2 = pSR;
    // Add the field "Shape"
    IField pGDF = new FieldClass(); IFieldEdit pGDFE = pGDF as IFieldEdit;
    pGDFE.Name_2 = "Shape"; pGDFE.Type_2 = esriFieldType.esriFieldTypeGeometry;
    pGDFE.GeometryDef_2 = pGDE as IGeometryDef;
    pFsE.AddField(pGDF);
    // Add the field "Name"
    IField pNF = new FieldClass(); IFieldEdit pNFE = pNF as IFieldEdit;
    pNFE.Name_2 = "Name"; pNFE.Type_2 = esriFieldType.esriFieldTypeString;
    pNFE.Length_2 = 20;
    pFsE.AddField(pNF);
    // (Optional) Use a FieldChecker to create a validated fields collection
    IFieldChecker pFC = new FieldCheckerClass();
    IEnumFieldError pEFE = null; IFields pVFs = null;
    pFC.ValidateWorkspace = pFW as IWorkspace;
    pFC.Validate(pFs, out pEFE, out pVFs);
    // Create the feature class
    esriFeatureType pFT = esriFeatureType.esriFTSimple;
    pFL.FeatureClass = pFW.CreateFeatureClass(pFCN, pVFs, null, null, pFT, "Shape", "");
    // Write as follows if did not use a FieldChecker
    // pFL.FeatureClass = pFW.CreateFeatureClass(pFCN, pFs, null, null, pFT, "Shape", "");
    m_App.AddLayer(pFL);
  • 编辑新建的点矢量图层,添加两个坐标不同的点。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    IWorkspaceEdit pWE = pFW as IWorkspaceEdit;
    pWE.StartEditing(true); pWE.StartEditOperation();
    IFeature pFeature1 = pFL.FeatureClass.CreateFeature();
    IPoint pPoint1 = new PointClass(); pPoint1.PutCoords(0, 0);
    pFeature1.Shape = pPoint1 as IGeometry;
    int index = pFeature1.Fields.FindField("Name");
    pFeature1.Value[index] = "Point 1"; pFeature1.Store();
    IFeature pFeature2 = pFL.FeatureClass.CreateFeature();
    IPoint pPoint2 = new PointClass(); pPoint2.PutCoords(2, 3);
    pFeature2.Shape = pPoint2 as IGeometry;
    pFeature2.Value[index] = "Point 2"; pFeature2.Store();
    pWE.StopEditOperation(); pWE.StopEditing(true);
  • 对人口排行字段进行IDW插值,然后将生成的栅格保存为.tiff格式的文件并进行栅格数据统计分析。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    // IDW interpolation
    IFeatureLayer pFL = m_App.get_Layer(1) as IFeatureLayer; // cities
    IFeatureClassDescriptor pFCD = new FeatureClassDescriptorClass();
    pFCD.Create(pFL.FeatureClass, null, "POP_RANK");
    IRasterRadius pRR = new RasterRadiusClass(); pRR.SetVariable(12);
    IInterpolationOp pIO = new RasterInterpolationOpClass();
    IRasterAnalysisEnvironment pRAE = pIO as IRasterAnalysisEnvironment;
    pRAE.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, 0.5);
    IGeoDataset pGDin = pFCD as IGeoDataset;
    IGeoDataset pGDout = pIO.IDW(pGDin, 2, pRR);
    IRasterLayer pRL = new RasterLayerClass();
    pRL.CreateFromRaster(pGDout as IRaster);
    m_App.AddLayer(pRL);
    // Save file
    IWorkspaceFactory pWF = new RasterWorkspaceFactoryClass();
    IRasterWorkspace pRW = pWF.OpenFromFile(@"C:\myetyet", 0) as IRasterWorkspace;
    (pGDout as ISaveAs).SaveAs("IDW.tiff", pRW as IWorkspace, "TIFF");
    // Raster statistics
    IRasterBandCollection pRBC = pGDout as IRasterBandCollection;
    IRasterBand pRB = pRBC.Item(0);
    bool pCheck; pRB.HasStatistics(out pCheck);
    if (!pCheck) pRB.ComputeStatsAndHist();
    IRasterStatistics pRS = pRB.Statistics;
    List<string> res = new List<string>();
    res.Add(String.Format("Max = {0}", pRS.Maximum));
    res.Add(String.Format("Min = {0}", pRS.Minimum));
    res.Add(String.Format("Ave = {0}", pRS.Mean));
    res.Add(String.Format("Mode = {0}", pRS.Mode));
    res.Add(String.Format("StdEv = {0}", pRS.StandardDeviation));
    MessageBox.Show(string.Join("\n", res));
  • 由栅格数据生成五级等高线。
    1
    2
    3
    4
    ISurfaceOp pSO = new RasterSurfaceOpClass(); double[] pSep = { 0, 1, 2, 3, 4 };
    IFeatureClass pFC = pSO.ContourList(pRD as IGeoDataset, pSep) as IFeatureClass;
    IFeatureLayer pFL = new FeatureLayer(); pFL.FeatureClass = pFC;
    m_App.AddLayer(pFL);
  • 用矩形包围框对矢量数据进行裁切并添加图层至地图。
    1
    2
    3
    4
    5
    6
    7
    8
    IRasterLayer pRL = m_App.Layer[0] as IRasterLayer;
    IEnvelope pEnvelope = m_App.TrackRectangle();
    IExtractionOp pEO = new RasterExtractionOpClass();
    IRasterAnalysisEnvironment pRAE = pEO as IRasterAnalysisEnvironment;
    pRAE.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, pEnvelope);
    IGeoDataset pGD = pEO.Rectangle(pRL.Raster as IGeoDataset, pEnvelope, true);
    pRL = new RasterLayerClass(); pRL.CreateFromRaster(pGD as IRaster);
    m_App.AddLayer(pRL);
  • 修改现有矢量数据的对角线上(横纵索引号一致)的数据为原先的倍。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    IRasterProps pRP = pRaster as IRasterProps;
    int pWidth = pRP.Width, pHeight = pRP.Height;
    IPnt pPnt = new PntClass(); pPnt.SetCoords(pWidth, pHeight);
    IPixelBlock pPB = pRaster.CreatePixelBlock(pPnt);
    pPnt.SetCoords(0, 0); pRaster.Read(pPnt, pPB);
    float[,] pArray = pPB.SafeArray[0] as float[,];
    for (int i = 0; i < pWidth; ++i)
    for (int j = 0; j < pHeight; ++j)
    if (i == j) pArray[i, j] *= 10;
    pPB.SafeArray[0] = pArray;
    IRasterEdit pRE = pRaster as IRasterEdit;
    pPnt.SetCoords(0, 0); pRE.Write(pPnt, pPB);
    pRE.Refresh();
  • 将矢量数据所有单元格的数据乘以并作为新的图层添加至地图。
    1
    2
    3
    4
    5
    6
    IMapAlgebraOp pMAO = new RasterMapAlgebraOpClass();
    pMAO.BindRaster(pRaster as IGeoDataset, "Rmyetyet");
    IGeoDataset pGDout = pMAO.Execute("[Rmyetyet] * 2");
    IRasterLayer pRL = new RasterLayerClass();
    pRL.CreateFromRaster(pGDout as IRaster);
    m_App.AddLayer(pRL);
  • 添加包含多波段的*.tif文件中的特定波段至地图。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    // Open raster dataset
    IWorkspaceFactory pWF = new RasterWorkspaceFactoryClass();
    IRasterWorkspace pRW = pWF.OpenFromFile(@"C:\myetyet", 0) as IRasterWorkspace;
    IRasterDataset pRD = pRW.OpenRasterDataset("Layers.tif");
    IRasterBandCollection pRBC = pRD as IRasterBandCollection;
    // Add a RasterLayer to the map with the speicific band (e.g. third)
    IRasterBand pRB3 = pRBC.Item(3);
    IRaster pRaster3 = new RasterClass();
    (pRaster3 as IRasterBandCollection).AppendBand(pRB3);
    IRasterLayer pRL = new RasterLayerClass();
    pRL.CreateFromRaster(pRaster3); pRL.Name = pRB3.Bandname;
    m_App.AddLayer(pRL);
  • 矢量数据的拉伸渲染。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    // Build an AlgorithmicColorRamp
    IRgbColor pColor1 = new RgbColorClass(); pColor1.Red = 0xff;
    IRgbColor pColor2 = new RgbColorClass(); pColor2.Blue = 0xff;
    IAlgorithmicColorRamp pACR = new AlgorithmicColorRampClass();
    pACR.Size = 255; pACR.FromColor = pColor1; pACR.ToColor = pColor2;
    bool pCheck; pACR.CreateRamp(out pCheck);
    // Set the RasterStretchColorRampRenderer
    IRasterStretchColorRampRenderer pRSCRR = new RasterStretchColorRampRendererClass();
    pRSCRR.BandIndex = 0; pRSCRR.ColorRamp = pACR;
    IRasterRenderer pRR = pRSCRR as IRasterRenderer;
    IRasterLayer pRL = m_App.Layer[0] as IRasterLayer;
    pRR.Raster = pRL.Raster;
    IRasterStretch pRS = pRR as IRasterStretch;
    pRS.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
    pRS.StandardDeviationsParam = 2.0;
    pRR.Update();
    // Render and refresh
    pRL.Renderer = pRR;
    m_App.ActiveView.Refresh(); m_TOC.Update();
  • 矢量数据的分级渲染。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    // Build an AlgorithmicColorRamp simply
    IAlgorithmicColorRamp pACR = new AlgorithmicColorRamp(); pACR.Size = 5;
    bool pCheck; pACR.CreateRamp(out pCheck);
    // Set the RasterClassifyColorRampRenderer
    IRasterClassifyColorRampRenderer pRCCRR = new RasterClassifyColorRampRendererClass();
    pRCCRR.ClassCount = 5;
    IRasterRenderer pRR = pRCCRR as IRasterRenderer;
    IRasterLayer pRL = m_App.Layer[0] as IRasterLayer;
    pRR.Raster = pRL.Raster;
    for (int i = 0; i < 5; i++) {
    ISimpleFillSymbol pSFS = new SimpleFillSymbol();
    pSFS.Color = pACR.Color[i];
    pRCCRR.set_Symbol(i, pSFS as ISymbol);
    pRCCRR.set_Label(i, "Class " + i.ToString());
    }
    pRR.Update();
    // Render and refresh
    pRL.Renderer = pRR;
    m_App.ActiveView.Refresh(); m_TOC.Update();
  • 本文标题:《GIS二次开发》笔记
  • 本文作者:myetyet
  • 创建时间:2020-12-12 11:02:18
  • 本文链接:https://myetyet.github.io/posts/23459c4c/
  • 版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
 评论