江西理工大学 – developing gis applications with arcobjects using c#.net gis 应用开发...

89
江江江江 西 Developing GIS Applications with ArcObjects using C# GIS 江江江江 Developing GIS Applications with ArcObjects using C#.NET 江江江江江江江江 西 江江江江江 GIS 江江 江江 Email : [email protected] QQ 305333315 江江

Upload: margaretmargaret-holmes

Post on 30-Dec-2015

284 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

GIS 应用开发Developing GIS Applications with ArcObjects using

C#.NET

江西省研究生优质课程

主讲:兰小机 GIS 博士、教授 Email : [email protected] QQ : 305333315

课件: ftp://218.87.136.94/

Page 2: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

兰小机简历主要经历

1988 年 7 月毕业于南方冶金学院工程测量专业,获学士学位,并留校任教

1994 年 6 月毕业于武汉测绘科技大学工程测量专业,获硕士学位,回校任教

2005 年 6 月毕业于南京师范大学地图学与地理信息系统专业,获理学博士学位,回校任教

主要研究方向GML 空间数据挖掘GML 空间数据库理论与 GMLGIS空间数据集成与共享GIS 应用开发

Page 3: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

科研项目 国家自然科学基金项目 -- 面向 GML 的时空关联规则及序列模式

挖掘研究 ( 编号: 40971234) , 35 万元,主持 国家自然科学基金项目 -- 本原 GML 空间数据库理论及 GMLGIS

与传统 GIS 集成研究(编号: 40761017 ) , 16 万元,主持 国家自然科学基金项目 -- GML 空间数据存储索引机制研究(编

号: 40401045 ) , 26 万元,排名第二 地理信息科学江苏省重点实验室开发基金项目 -- 面向对象的

GML 空间数据库及其应用研究(编号: JK20050302 ) , 5万元主持

江西省教育厅科技项目— GML 空间数据库理论及 GMLGIS 研究,1 万元,主持

萍乡市基础地理信息系统研究与开发, 22 万元,主持 城市公众地理信息服务系统研究与开发, 10 万元,主持

Page 4: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

教学目标

《 GIS 应用开发》课程是 GIS 研究生重要的专业课程,通过课程的学习,了解ArcGIS 软件体系结构及 ArcObjects

(ArcGIS Engine) 组件构成,并能熟练使用 ArcObjects (ArcGIS Engine) 进行应用型 GIS 开发 ; 掌握应用型 GIS

开发的基本思路、技术方法 .

Page 5: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

教学内容及时间安排序号 教学内容 学时

1 开发基础 4

2 ArcGIS Application framework 4

3 使用 ArcObjects控件编程 4

4 几何形体对象 --GEOMETRY 3

5 地图的组成 5

6 空间数据的符号化 5

7 空间数据管理 6

8 空间分析 6

9 空间数据编辑 6

Page 6: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

教材及参考材料 教材:

1. 《 ArcObjects GIS 应用开发 -- 基于 C#.NET 》,兰小机、刘德儿编著, 2006 年 9 月

2. 最新课件 参考材料:

1.Extending ArcGIS Desktop with .NET2.Building solutions with ArcGIS Engine

using .NET

3.Creating ArcGIS Server solutions 4. ArcGIS 开发工具包中的文档,包括 ArcGIS 开发帮助、组件

帮助、对象模型图和示例5. ESRI Developer Network: http://edn.esri.com/ 提供

有关 ArcGIS 开发方面的最新信息, ESRI 在线论坛等。

Page 7: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Chap.4 几何对象与空间参考 ( 3学时)

1. 几何对象概述2. 使用几何对象3. 空间参考

Page 8: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

4.1 几何对象概述 Geometry 对象用于表达要素 (Feature) 或

图形元素 (Graphic Element) 的几何形状。 ArcGIS 的几何对象被分为两个层次

高级几何对象:用于定义要素的几何形状; 构件几何对象:用于构建高级几何对象。

Page 9: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

高级几何对象包括以下类型: Point :具有 X 、 Y 坐标值,以及可选的属性,如高程

(Z 值 ) ,测量值 (M) 和 ID 号。 Multipoint :是无序点的群集,它用于表示具有相同属

性设置的同一组点。 Polyline :是一个有序路径 (Path) 的集合,这些路径既

可以是连续的,也可以是离散的。 Polygon :是环 (Ring) 的集合,环是一种封闭的路

径。 Polygon 可以由一个或者多个环组成,甚至环内套环,形成岛环的情况,但是内外环之间不能重叠。

MultiPatch :用于描述三维几何形体。

Page 10: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

几何构件: Paths, Rings, Segments, TriangleStrips, TriangleFans, and

Triangles serve as building blocks for polylines, polygons, and MultiPatches.

Polylines contain paths, polygons contain rings and MultiPatches contain TriangleStrips, TriangleFans, triangles, and rings.

Paths and rings are sequences of vertices connected by segments.

A segment is a parametric function that defines the shape of the curve connecting its vertices. Segment types include CircularArc, Line, EllipticArc, and BezierCurve.

Envelope : Envelopes describe the spatial extent of other

geometries ,是一个矩形,它用于表示要素的空间范围。它覆盖了几何对象的最小坐标和最大坐标、 Z 值和M 值的变化范围。

GeometryBags provide operations on collections of geometries.

Page 11: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

一个几何对象的每个顶点,除了有 XY 坐标值外,还可以有其它可选属性,如 Z 值、 M 值和 ID 。 IZAware

IMAware

IPointIDAware

IPoint pnt = new PointClass() as IPoint;

pnt.PutCoords(1, 1);

IZAware zAware = pnt as IZAware;

zAware.ZAware = true;

pnt.Z = 11.1;

Page 12: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Multipoint, polyline, polygon, and MultiPatch geometries have constraints on their shapes.

For example, a polygon must have its interior clearly defined and separated from its exterior.

When all constraints are satisfied, a geometry is said to be simple. When a constraint is violated, or it is not known if the constraint is met, then the geometry is said to be non-simple.

The ITopologicalOperator, IPolygonN, and IPolylineN interfaces provide operations for testing and enforcing simplicity.

Page 13: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Geometries, especially the segment types, have a rich set of methods for defining their location. For example, the IConstructCircularArc

interface shows the different ways you can define a circular arc segment. Typically, interfaces or methods that include the word "construct" in their name use a set of input parameters (including other geometries) to completely define the target geometry.  

Page 14: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Top level geometries support the classical set-theoretic operations for generating new geometries including union, intersection, difference, and symmetric difference. These operations are exposed on the ITopologicalOperator interface and usually operate on a pair of geometries at a time. ITopologicalOperator.ConstructUnion can operate on

more than two. New geometries are created to represent the results.

Top level geometries also support the IRelationalOperator interface, which can perform a variety of tests on a pair of geometries such as disjoint, contains, and touches.

Page 15: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Polyline( 多义线 ) 对象Polyline(多义线 ) 对象是相连或不相连的路径对象的有

序集合,它可以分别是单个路径、多个不相连的路径和多个相连路径的集合。

Page 16: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

路径 (Path) 是连续 Segment 对象的集合,除了路径的第一个和最后一个 Segment外,每一个 Segment 的起始点都是前一个 Segment 的终止点,即路径对象中的 Segment不能出现分离的情况。路径可以是任意数目的Line 、 CircularArc 、 EllipticArc 和BezierCurve 的组合。一个或多个路径对象组成一个 Polyline 对象。

Page 17: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NETGeometry

Curve

Paths

PolyCurve

BezierCurveCircularArc EllipticArcLine

Polyline

Is composed of Paths

Are composed of Segments

Segments can be of 4 different TypesSegments

图 4-32 Polyline及相关对象结构图

Points are used to build Segments or Polyline

Points

Page 18: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Polygon 对象 Polygon(多边形 ) 对象是一个有序环对象的集

合,这些环可以是一个或者多个。多边形对象通常可以用于描述具有面积的多边形离散矢量对象。

Page 19: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NETGeometry

Curve

Rings

PolyCurve

BezierCurveCircularArc EllipticArcLine

Polygon

Is composed of Rings

Are composed of Segments

Segments can be of 4 different TypesSegments

图 4-34 Polygon 及相关对象结构图

Points are used to build Segments or Polygon

Points

Page 20: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

MultiPatch

MultiPatches describe 3D geometries that can have multiple, textured surfaces. They can also store vertex normals (顶点法线) , vertex ids, vertex measures and several part-level attributes.

You can create MultiPatches by importing data from a variety of different file formats (3D Studio Max .3ds files, OpenFlight .flt files, Sketchup .skp files, VRML .wrl files).

Page 21: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

You can also create them programmatically in several different ways. MultiPatches without textures, normals, or part

attributes can be defined in a manner similar to building a polygon: create the parts, create a MultiPatch, then use the latter’s IGeometryCollection interface to add the parts.

Creating a MultiPatch with textures, normals or part attributes requires the use of the GeneralMultiPatchCreator helper object (requires a 3D Analyst license). You can obtain information on normals and materials from an existing MultiPatch by using its IGeneralMultiPatchInfo interface.

Page 22: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

MultiPatches support the IRelationalOperator3D interface (New in 9.3), which contains the Disjoint3D method, and the IProximityOperator3D interface, which has methods for reporting the nearest distance from a query geometry to the MultiPatch and the nearest point on the MultiPatch from a query geometry.

These interfaces treat MultiPatches as a collection of surfaces with no interior, so if you have a MultiPatch in the shape of a cube, and a point apparently inside that cube, the point will be classified as disjoint because it is not intersecting any of the cube's sides.  

Page 23: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

MultiPatches contain multiple parts: TriangleStrips, TriangleFans, Triangles, and rings. Each part in a MultiPatch has several additional properties: 

Type (TriangleStrip, TriangleFan, Triangle, Outer Ring, etc)

Priority — used to control the drawing order of overlapping parts

An index into the array of materials

MultiPatches can contain materials (specifying color, texture, and transparency information) and texture coordinates that specify the placement of textures on each part.

ArcScene provides style galleries containing MultiPatch models for 3D buildings (industrial and residential), trees, vehicles, street ‘furniture’ and other thematic categories.

Page 24: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Triangle Strips (条、带)Triangle Fans (扇)

Page 25: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Rings as used in MultiPatches

Page 26: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

4.2 使用几何对象1. Working with the geometry environment2. Create a multipoint3. Create a polyline4. Create a polygon5. Creating a union of several polygons6. Modify a specific vertex of a polyline7. Modify a specific segment of a polyline8. Create a multipatch9. IGeometryBag vs. IGeometryCollection10.Simplifying a geometry

Page 27: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

4.2.1 Working with the geometry environmentThe GeometryEnvironment object is a singleton

object (单例对象) , so calling new several times does not create a new object each time. Instead, it returns a reference to the existing GeometryEnvironment.

GeometryEnvironment provides a way of creating geometries from different inputs and setting or getting global variables for controlling the behavior of geometry methods. It also provides Java and .NET friendly versions of methods originally defined on other geometry objects (see the IGeometryBridge and IGeometryBridge2 interfaces).  

Page 28: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

IGeometryBridge and IGeometryBridge2 act as a connection to allow methods to be accessed in all supported languages. Both are implemented by GeometryEnvironmentClass. This implementation circumvents (回避, 绕过) limitations placed on Component Object Model (COM) objects in the Java and .NET environments.

In Java and .NET, it is not possible to directly call certain methods on the original interfaces, since the original interfaces were implemented using C-style arrays. Java and the .NET Framework languages do not support C-style arrays. Only safe arrays are permissible in these languages.

Page 29: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NETInterfaces and methods IGeometryBridge  or IGeometryBridge2

IPointCollection.AddPoints AddPoints

IPointCollection.QueryPoints QueryPoints

IPointCollection.InsertPoints InsertPoints

IPointCollection2.GetPoints GetPoints

IPointCollection.ReplacePoints ReplacePoints

IPointCollection.SetPoints SetPoints

IPointCollection4.QueryWKSPointZs QueryWKSPointZs

IPointCollection4.InsertWKSPointZs InsertWKSPointZs

IPointCollection4.AddWKSPointZs AddWKSPointZs

IPointCollection4.AddWKSPoints* AddWKSPoints

IPointCollection4.InsertWKSPoints* InsertWKSPoints

IPointCollection4.QueryWKSPoints* QueryWKSPoints

IPointCollection4.SetWKSPoints* SetWKSPoints

IPolycurve2.SplitAtDistances SplitAtDistances

Interfaces and methods IGeometryBridge  or IGeometryBridge2

ISegmentCollection.AddSegments AddSegments

ISegmentCollection.InsertSegments InsertSegments

ISegmentCollection.QuerySegments QuerySegments

ISegmentCollection.ReplaceSegments ReplaceSegments

ISegmentCollection.SetSegments SetSegments

ITopologicalOperator2.ConstructBuffers ConstructBuffers

IMultipatch.QueryBeginningRings QueryBeginningRings

IMultipatch.QueryFollowingRings QueryFollowingRings

IGeometryCollection.AddGeometries AddGeometries

IGeometryCollection.InsertGeometries InsertGeometries

IGeometryCollection.QueryGeometries QueryGeometries

IGeometryCollection.SetGeometries SetGeometries

ISegment.Densify Densify

ISegment.SplitDivideLength SplitDivideLength

Page 30: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

IGeometryBridge2 pGeomBridge = new GeometryEnvironmentClass();

IPointCollection4 pPointCollection = new MultipointClass();

IPoint[] pPoints = new IPoint[3];

for (int i = 0; i < 3; i++)

{

pPoints[i] = new PointClass();

pPoints[i].PutCoords(i, 2 * i);

}

pGeomBridge.AddPoints(pPointCollection, ref pPoints);

Page 31: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

4.2.2 Create a multipoint

Building a multipoint using points

Creating a multipoint using existing geometries

Page 32: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Building a multipoint using pointspublic void SetWKSPoints()

{ int length = 10; WKSPoint[] pointArray = new WKSPoint[length];

for (int i = 0; i < length; i++)

{ pointArray[i] = new WKSPoint();

pointArray[i].X = i * 10; pointArray[i].Y = i * 10; }

IPointCollection4 pointCollection = new MultipointClass();

//add points to pointCollection

IGeometryBridge2 geometryBridge = new GeometryEnvironmentClass();

geometryBridge.AddWKSPoints(pointCollection, ref pointArray);

}

Page 33: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Creating a multipoint using existing geometries public void

CreateMultipointFromExistingGeometry(IPolyline pPoly) { ITopologicalOperator2 pTopoOp2 = pPoly as

ITopologicalOperator2;

pTopoOp2.IsKnownSimple_2 = false;

pTopoOp2.Simplify();

IPolygon pBufferedPoly = pTopoOp2.Buffer(5) as IPolygon;

IPointCollection pPointCollPoly = pBufferedPoly as IPointCollection;

IGeometry pMultipoint = new MultipointClass();

pMultipoint.SpatialReference = pPoly.SpatialReference;

IPointCollection pPointCollMultipoint = pMultipoint as IPointCollection;

pPointCollMultipoint.AddPointCollection(pPointCollPoly);

}

Page 34: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

4.2.3 Create a polyline

1. Building a polyline using points

2. Building a polyline using segments

3. Creating a polyline using existing geometries

4. Creating a multipart polyline

Page 35: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Building a polyline using points

public void CreatePolylineByPoints() { int length = 10;

WKSPoint[] pointArray = new WKSPoint[length];

for (int i = 0; i < length; i++)

{ pointArray[i] = new WKSPoint();

pointArray[i].X = i * 10; pointArray[i].Y = i * 10;

}

IPointCollection4 pointCollection = new PolylineClass();

IGeometryBridge2 geometryBridge = new GeometryEnvironmentClass();

geometryBridge.SetWKSPoints(pointCollection, ref pointArray);

}

Page 36: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Building a polyline using segments public void CreatePolylineBySegments()

{ IPolyline pSegPoly = new PolylineClass(); ICircularArc cArc = new CircularArcClass(); IBezierCurve bCur = new BezierCurveClass(); ILine line = new LineClass(); ISegmentCollection path1 = new PathClass(); ISegmentCollection path2 = new PathClass(); object obj=Type.Missing; path1.AddSegment(cArc as ISegment,ref obj,ref obj); path2.AddSegment(bCur as ISegment, ref obj, ref obj); path2.AddSegment(line as ISegment, ref obj, ref obj); IGeometryCollection pGeoColl = pSegPoly as

IGeometryCollection; pGeoColl.AddGeometry(path1 as IGeometry ,ref obj,ref

obj); pGeoColl.AddGeometry(path2 as IGeometry, ref obj, ref

obj);

Page 37: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

IPoint pPnt = new PointClass();

pPnt.X = -10;

pPnt.Y = 0;

cArc.PutCoordsByAngle(pPnt, 0, 3.14159265358979, 10.0);

IPoint[] pntArray = new IPoint[4];

for (int i = 0; i <= 4; i++) pntArray[i] = new PointClass();

pntArray[0].X = 10; pntArray[0].Y = 0;

pntArray[1].X = 10; pntArray[1].Y = 10;

pntArray[2].X = 20; pntArray[2].Y = 10;

pntArray[3].X = 20; pntArray[3].Y = 0;

bCur.PutCoords(4,ref pntArray[0]);

line.FromPoint.PutCoords(20, 0);

line.ToPoint.PutCoords(30, 0);

pGeoColl.GeometriesChanged();

}

Page 38: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Creating a polyline using existing geometriespublic void CreatePolylineFromExistingGeometries

( IPolygon pPolygon1, IPolygon pPolygon2)

{ //Build a new polyline by intersecting two existing polygons.

ITopologicalOperator2 pTopoOp2 = pPolygon1 as ITopologicalOperator2;

pTopoOp2.IsKnownSimple_2 = false;

pTopoOp2.Simplify();

IPolyline pPoly = pTopoOp2.Intersect(pPolygon2, esriGeometryDimension.esriGeometry1Dimension) as IPolyline;

}

Page 39: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Creating a multipart polyline

使用已有的线对象创建一个多部分线对象 .

要求:创建的多部分线对象的每一线段与已有线对象垂直,且位于已有线段的中点处,长度为已有线段的1/3.

Page 40: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

public IPolyline ConstructMultiPartPolyline( IPolyline inputPolyline)

{ IGeometry outGeometry = new PolylineClass();

outGeometry.SpatialReference = inputPolyline.SpatialReference; IGeometryCollection geometryCollection = outGeometry as IGeometryCollection;

ISegmentCollection segmentCollection = inputPolyline as ISegmentCollection;

IEnumSegment segments = segmentCollection.EnumSegments;

ISegment currentSegment;

int partIndex = 0; int segmentIndex = 0;

segments.Next(out currentSegment, ref partIndex, ref segmentIndex);

Page 41: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

while (currentSegment != null)

{ ILine normal = new LineClass();

currentSegment.QueryNormal(esriSegmentExtension.esriNoExtension, 0.5, true, currentSegment.Length / 3, normal);

ISegmentCollection newPath = new PathClass();

object missing = Type.Missing;

newPath.AddSegment(normal as ISegment, ref missing, ref missing);

geometryCollection.AddGeometry(newPath as IGeometry, ref missing, ref missing);

segments.Next(out currentSegment, ref partIndex, ref segmentIndex);

}

return geometryCollection as IPolyline;

}

public void QueryNormal (     esriSegmentExtension extension,  double DistanceAlongCurve,  bool asRatio,     Double Length,     ILine normal );

Page 42: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

4.2.4 Create a polygon

1. Building a polygon using points

2. Building a polygon using segments

3. Creating a polygon using existing geometries

4. Creating a union of several polygons

Page 43: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Building a polygon using points

public void CreatePolygonByPoints() { int length = 10;

WKSPoint[] pointArray = new WKSPoint[length];

for (int i = 0; i < length; i++)

{ pointArray[i] = new WKSPoint();

pointArray[i].X = i * 10; pointArray[i].Y = i * 10;

}

IGeometryBridge2 pGeoBrg = new GeometryEnvironmentClass();

IPointCollection4 pPointColl = new PolygonClass();

//add points to pointCollection

pGeoBrg.SetWKSPoints(pPointColl, ref pointArray);

}

Page 44: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Building a polygon using segments public void CreatePolygonBySegments()

{ IPolygon pSegPoly = new PolygonClass(); ICircularArc cArc = new CircularArcClass(); IBezierCurve bCur = new BezierCurveClass(); ISegmentCollection ring1 = new RingClass(); ISegmentCollection ring2 = new RingClass(); object obj = Type.Missing; ring1.AddSegment(cArc as ISegment, ref obj, ref obj); ring2.AddSegment(bCur as ISegment, ref obj, ref obj); IGeometryCollection pGeoColl = pSegPoly as

IGeometryCollection; pGeoColl.AddGeometry(ring1 as IGeometry, ref obj, ref

obj); pGeoColl.AddGeometry(ring2 as IGeometry, ref obj, ref

obj);

Page 45: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

IPoint pPnt = new PointClass();

pPnt.X = -10; pPnt.Y = 0;

cArc.PutCoordsByAngle(pPnt, 0, 2 * 3.14159265358979, 10.0);

IPoint[] pntArray = new IPoint[4];

for (int i = 0; i <= 4; i++) pntArray[i] = new PointClass();

pntArray[0].X = 10; pntArray[0].Y = 0;

pntArray[1].X = 10; pntArray[1].Y = 10;

pntArray[2].X = 20; pntArray[2].Y = 10;

pntArray[3].X = 20; pntArray[3].Y = 0;

bCur.PutCoords(4, ref pntArray[0]);

pGeoColl.GeometriesChanged();

}

Page 46: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Creating a polygon using existing geometries

public void CreatePolygonFromExistingGeometries( IPolygon pPolygon1, IPolygon pPolygon2)

{

ITopologicalOperator2 pTopoOp2 = pPolygon1 as ITopologicalOperator2;

pTopoOp2.IsKnownSimple_2 = false;

pTopoOp2.Simplify();

IPolygon pPoly = pTopoOp2.Union(pPolygon2) as IPolygon;

}

Page 47: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

4.2.5 Creating a union of several polygons private IPolygon

GeometryBag_Example(IFeatureClass featureClass) {

if (featureClass == null) return null;

IGeoDataset geoDataset = featureClass as IGeoDataset;

IGeometry geometryBag = new GeometryBagClass();

geometryBag.SpatialReference = geoDataset.SpatialReference;

IFeatureCursor featureCursor = featureClass.Search(null, false);

IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;

IFeature currentFeature = featureCursor.NextFeature();

Page 48: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

while (currentFeature != null) { object missing = Type.Missing;

geometryCollection.AddGeometry(currentFeature.Shape, ref missing, ref missing);

currentFeature = featureCursor.NextFeature();

} ITopologicalOperator unionedPolygon =

new PolygonClass();

unionedPolygon.ConstructUnion(geometryBag as IEnumGeometry);

return unionedPolygon as IPolygon; }

Page 49: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

4.2.6 Modify a specific vertex of a polyline

The following are the steps to modify a vertex of a polyline:1. Cast the IGeometryCollection for IPolyline.

2. Cast the polyline for IHitTest and use the HitTest method (esriGeometryPartVertex option).

3. Use the geometry property with the part index returned by the HitTest to get the path containing the point to modify.

4. Cast the path for IPointCollection.

5. Use the point property with the vertex (segment) index returned by the HitTest (get a copy of the point).

6. Modify the point using any methods.

7. Update the point using UpdatePoint with the vertex index from HitTest.

Page 50: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

public bool IHitTest .HitTest (      IPoint QueryPoint,     

double searchRadius,     

esriGeometryHitPartType geometryPart,     

IPoint hitPoint,     

ref double hitDistance,     

ref int hitPartIndex,     

ref int hitSegmentIndex,     

ref bool bRightSide );

Page 51: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

The segment index returned has different meanings depending on the esriGeometryHitPartType used .EsriGeometryPartVertex: returns a vertex index

EsriGeometryPartBoundary, esriGeometryPartMidpoint and esriGeometryPartEndpoint: return a segment index

EsriGeometryPartCentroid: Always returns 0 for the part index and the segment index.

brightside: Indicates if the input point is on the right side of the input geometry

Page 52: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

public IPointCollection4 modify1VertexOfAPolyline( IGeometryCollection mPolyline, Double searchRadius, Double offsetX, Double offsetY)

{ IPolyline polyline = (IPolyline)mPolyline;

IPoint queryPoint = polyline.FromPoint;

IPoint hitPoint = new PointClass();

Double hitDistance = 0; Int32 hitPartIndex = 0;

Int32 hitSegmentIndex = 0;

Boolean rightSide = false;

IHitTest hitTest = (IHitTest)mPolyline;

Boolean foundGeometry = hitTest.HitTest (queryPoint, searchRadius, esriGeometryHitPartType.esriGeometryPartVertex, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref rightSide);

Page 53: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

if (foundGeometry == true)

{ IGeometry geometry = mPolyline.get_Geometry(hitPartIndex);

IPointCollection4 pointCollection = (IPointCollection4)geometry;

IPoint transformPoint = pointCollection.get_Point(hitSegmentIndex);

ITransform2D transform2D = (ITransform2D)transformPoint;

transform2D.Move(offsetX, offsetY);

IPoint afterMovePoint = (IPoint)transform2D;

pointCollection.UpdatePoint(hitSegmentIndex, (IPoint)transform2D);

return pointCollection;

} return null;

}

Page 54: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

4.2.7 Modify a specific segment of a polylineThe following are the steps to modify a polyline

segment:

1. Cast the IGeometryCollection for the polyline.

2. Cast the polyline for IHitTest and use the HitTest method (esriGeometryPartBoundary option).

3. Use the geometry property with the part index returned by the HitTest to get the path containing the point to modify.

4. Cast the path for ISegmentCollection.

5. Use the segment property with the segment index returned by the HitTest (get a reference to the segment).

6. Modify the segment.

Page 55: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

public ISegmentCollection ModifyFirstSegmentOfAPolyline (IGeometryCollection mPolyline, Double searchRadius, Double offsetX, Double offsetY)

{ IPolyline polyline = (IPolyline)mPolyline;

IPoint queryPoint = polyline.FromPoint;

IPoint hitPoint = new PointClass();

Double hitDistance = 0; Int32 hitPartIndex = 0;

Int32 hitSegmentIndex = 0; Boolean rightSide = false;

IHitTest hitTest = (IHitTest)mPolyline;

Boolean foundGeometry = hitTest.HitTest (queryPoint, searchRadius, esriGeometryHitPartType.esriGeometryPartVertex, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref rightSide);

Page 56: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

if (foundGeometry == true)

{ IGeometry geometry = mPolyline.get_Geometry(hitPartIndex);

ISegmentCollection segmentCollection =

(ISegmentCollection)geometry;

ISegment segment = segmentCollection.get_Segment(hitSegmentIndex);

ITransform2D transform2D = (ITransform2D)segment;

transform2D.Move(offsetX, offsetY);

segmentCollection.SegmentsChanged();

return segmentCollection;

} return null;

}

Page 57: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

4.2.8 Create a multipatch

Creating a multipatch using a series of triangles

Sample: 3D multipatch examples

Page 58: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

4.2.9 IGeometryBag vs. IGeometryCollection

A GeometryBag is a heterogeneous collection of references to objects that support the IGeometry interface.  Operations on GeometryBags that depend upon a specific

interface require that all geometries within the Bag support that interface.  Otherwise, an error will be returned.  (ex. To Buffer the elements of a GeometryBag using the ITopologicalOperator, only geometries that support ITopologicalOperator can be collected in the Bag.)   

When adding elements to a GeometryBag, keep in mind that the elements acquire the spatial reference of the bag. If the spatial reference of the bag is nil, for example, and the element references a well-defined spatial reference, then the element will lose that reference when it is added to the bag.

Page 59: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

IGeometryCollection provides access to members that can be used for accessing, adding and removing individual geometries of a multi-part geometry (Multipoint, Polyline, Polygon, MultiPatch, and GeometryBag).

A Collection of Geometry parts. 

• For Multipoints, Triangles, TriangleFans, and TriangleStrips, the Geometry parts are Points. 

• For Polylines, the Geometry parts are Paths. 

• For Polygons, the Geometry parts are Rings. 

• For MultiPatches, the Geometry parts are Triangles, TriangleFans, TriangleStrips, or Rings. 

• For GeometryBags, the Geometry parts are any IGeometry object.

Page 60: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

The GeometryCollection can be used to access, manipulate, add, insert, remove, and set specific parts of a composite geometry.

If you are using a development language that does not support C style arrays, use IGeometryBridge instead.

Page 61: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NETIGeometryBag IGeometryCollection

Page 62: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

4.2.10 Simplifying a geometry

Simplify permanently alters the input geometry, making its definition topologically legal with respect to its geometry type.

Simplify and points Simplify does nothing for points. A point

has no constraints on the values of its coordinates.  

Page 63: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Simplify and multipoints For multipoints, simplify snaps all x-, y-, z-,

and m-coordinates to the grid of the associated spatial reference, and removes identical points.

A point is identical to another point when the two have identical x,y coordinates (after snapping) and when attributes for which it is aware are identical to the attributes for which the other point is aware. For example, if both points are z-aware, the z-coordinate values must be identical.

Page 64: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Simplify and polylines

Simplify has two variations for polylines: planar and nonplanar.

•By default, polylines that are not m-aware are simplified in a planar manner — all overlapping segments are reduced to a single segment and segments are split at intersection points. Output paths are created for connected sequences of segments. Input segment orientation is preserved where possible, but segments in the interior of a path are reoriented if necessary.

Page 65: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

•Polylines that are m-aware use the following nonplanar simplification:

– Overlaps and self-intersections are preserved, but zero-length segments are removed.

– Segment orientations are adjusted so that the to point of segment I is identical to (considering vertex attributes) the from point of segment I+1.

– New paths are created where segments are not connected.

– Existing paths are merged where only two of them meet at a segment endpoint.

Page 66: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Simplify and polygons Simplify identifies an interior and exterior for polygons

and modifies the polygon structure to be consistent with that determination. The default methodology for identifying interior and exterior is as follows:

•Remove all dangling sequences of segments.

•Identify the largest legal rings, add them to the output version of the polygon, then delete them from the working version.

•Repeat. If this approach ends up removing too many segments for your application, consider using IPolygon4.SimplifyEx with the XOR parameter set to true. At the end of Simplify, no rings overlap, no self-intersection occurs (except in certain circumstances), and in general, an arbitrary point can always be classified unambiguously as outside, on the boundary of, or inside the polygon.

Page 67: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

What Simplify considersSimplify looks at the

ITopologicalOperator.IsKnownSimple flag before starting processing. If the flag is set to true, operation is interrupted and the geometry is considered simple. If the flag is set to false, the geometry consistency is checked and the geometry is updated as needed.

ITopologicalOperator methods must be applied on high-level geometries only. High-level geometries are point, multipoint, polyline, and polygon. To use this method with low-level geometries, such as segments (line, circular arc, elliptic arc, Bézier curve), paths, or rings, they must be wrapped into high-level geometry types.

Page 68: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

4.3 空间参考空间参考( Spatial Reference )是 GIS 数据的骨骼框架,能够将空间数据定位到相应的位置,为地图中的每一点提供准确的坐标。

Geodatabase 中新建一个要素数据集或一个单独的要素类都必须设置它们的空间参考。

空间参考包括以下属性:坐标系分辨率与空间域容差

地理坐标系、投影坐标系、垂直坐标系

Page 69: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

GEOGCS

["GCS_Xian_1980",

DATUM["D_Xian_1980",SPHEROID["Xian_1980",6378140.0,298.257] ],

PRIMEM["Greenwich",0.0],

UNIT["Degree",0.0174532925199433]]

Page 70: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

PROJCS

["Xian_1980_3_Degree_GK_Zone_38",

GEOGCS["GCS_Xian_1980",DATUM["D_Xian_1980",SPHEROID["Xian_1980",6378140.0,298.257]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],

PROJECTION["Gauss_Kruger"],

PARAMETER["False_Easting",38500000.0],

PARAMETER["False_Northing",0.0],

PARAMETER["Central_Meridian",114.0],

PARAMETER["Scale_Factor",1.0],

PARAMETER["Latitude_Of_Origin",0.0],

UNIT["Meter",1.0]]

Page 71: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Page 72: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Use the SpatialReferenceEnvironment ArcObjects includes a vast array of

predefined spatial reference systems and building blocks for spatial reference systems.

Each predefined object is identified by a factory code. Factory codes are defined enumeration sets that begin with esriSR. Use the enumeration macro rather than the integer value it represents.

esriSRGeoCS_Beijing1954 4214 Beijing 1954.

esriSRGeoCS_Xian1980 4610 Xian 1980.

esriSRProjCS_Beijing1954GK_23

21423 Beijing 1954 GK Zone 23.

esriSRProjCS_Beijing1954GK_13N

21473 Beijing 1954 GK Zone 13N.

esriSRProjCS_Beijing1954_3_Degree_GK_Zone_38

2414 Beijing 1954 3 Degree GK Zone 38.

esriSRProjCS_Xian1980_3_Degree_GK_Zone_38

2362 Xian 1980 3 Degree GK Zone 38.

Page 73: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

The ISpatialReferenceFactory interface provides methods that use the FactoryCode to generate predefined factory spatial reference objects. There are three types of functions on this interface: Those that return single object

Those that return a set of objects of the same type

Those that are used to import and export SpatialReference objects to and from a PRJ file or a PRJ string representation

Page 74: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

private void PrintPreDefinedProjections()

{ ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

ISet projectionSet = spatialReferenceFactory.CreatePredefinedProjections(); MessageBox.Show("Number of predefined Projections = " + projectionSet.Count);

projectionSet.Reset();

for(int i = 0; i < projectionSet.Count; i++)

{ IProjection projection = projectionSet.Next() as IProjection; MessageBox.Show(projection.Name); }

}

Page 75: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

private IProjectedCoordinateSystem LoadProjectedCoordinateSystem()

{ ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

IProjectedCoordinateSystem projectedCoordinateSystem = spatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile("C:\\Program Files\\ArcGIS\\Coordinate Systems\\Projected Coordinate Systems\\World\\Mollweide (world).prj") as IProjectedCoordinateSystem;

return projectedCoordinateSystem;

}

Page 76: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Creating a predefined vertical coordinate systemprivate static void GetVCSList()

{ISpatialReferenceFactory3 srFact3 = new SpatialReferenceEnvironmentClass() as ISpatialReferenceFactory3;

ISet vcsSet = srFact3.CreatePredefinedVerticalCoordinateSystems();

vcsSet.Reset();

IVerticalCoordinateSystem vcs;

for (int i = 0; i < vcsSet.Count; i++)

{ vcs = vcsSet.Next() as IVerticalCoordinateSystem;

Console.WriteLine("VCS Name: {0} (Code: {1})", vcs.Name, vcs.FactoryCode);

}

}

Page 77: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

private void CreateVerticalReferenceSystem()

{

ISpatialReferenceFactory3 spatialReferenceFactory3 = new SpatialReferenceEnvironmentClass();

IVerticalCoordinateSystem verticalCoordinateSystem = spatialReferenceFactory3.CreateVerticalCoordinateSystem((int) esriSRVerticalCSType.esriSRVertCS_Alicante);

}

Page 78: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Creating a custom geographic coordinate system

A geographic coordinate system includes a name, angular unit of measure, datum (which includes a spheroid), and a prime meridian. You can access the majority of the properties and methods through the IGeographicCoordinateSystem interface with a few more properties that are available in IGeographicCoordinateSystem2.

Although most developers will not need to create a custom geographic coordinate system, the IGeographicCoordinateSystemEdit contains the Define and DefineEx methods.  

Page 79: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

private IGeographicCoordinateSystem CreateGeographicCoordinateSystem()

{ ISpatialReferenceFactory3 spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

IDatum datum = spatialReferenceFactory.CreateDatum((int)esriSRDatumType.esriSRDatum_OSGB1936);

IPrimeMeridian primeMeridian = spatialReferenceFactory.CreatePrimeMeridian((int)esriSRPrimeMType.esriSRPrimeM_Greenwich);

IUnit unit = spatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Degree);

IGeographicCoordinateSystemEdit geographicCoordinateSystemEdit = new GeographicCoordinateSystemClass();

object name = "UserDefined Geographic Coordinate System";

object alias = "UserDefined GCS";

Page 80: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

object abbreviation = "UserDefined";

object remarks = "User Defined Geographic Coordinate System based on OSGB1936";

object usage = "Suitable for the UK";

object datumObject = datum as object;

object primeMeridianObject = primeMeridian as object;

object unitObject = unit as object;

geographicCoordinateSystemEdit.Define (ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref datumObject, ref primeMeridianObject, ref unitObject);

IGeographicCoordinateSystem userDefinedGeographicCoordinateSystem = geographicCoordinateSystemEdit as IGeographicCoordinateSystem;

return userDefinedGeographicCoordinateSystem;

}

Page 81: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Creating a custom projected coordinate systemThe parts of a PCS, such as the projection, linear unit,

and geographic coordinate system, are objects. All support ISpatialReference2 and ISpatialReferenceFactory. When defining a custom projected coordinate system, make use of the predefined objects available in the various esriSR* enumerations.  

You can access the majority of the properties and methods through the IProjectedCoordinateSystem2 interface, although a few more properties are available in IProjectedCoordinateSystem3 and IProjectedCoordinateSystem4.

Page 82: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

 The IProjectedCoordinateSystemEdit contains the Define method, which allows you to define a custom projected coordinate system. To access the hundreds of predefined projected coordinate systems, ISpatialReferenceFactory has the CreateProjectedCoordinateSystem method. The predefined projected coordinate systems are listed in the esriSRProjCSType, esriSRProjCS2Type, esriSRProjCS3Type, and esriSRProjCS4Type enumerations.  

The IProjectedCoordinateSystemEdit interface provides you with the Define method to create your own PCS object based on parameters such as Name, GeographicCoordinateSystem, projectedUnit, Projection, and if necessary, projection Parameters.

Page 83: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

private IProjectedCoordinateSystem CreateProjectedCoordinateSystem()

{ ISpatialReferenceFactory2 spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

IProjectionGEN projection = spatialReferenceFactory.CreateProjection( (int) esriSRProjectionType.esriSRProjection_Sinusoidal) as IProjectionGEN;

IGeographicCoordinateSystem geographicCoordinateSystem = spatialReferenceFactory.CreateGeographicCoordinateSystem((int) esriSRGeoCSType.esriSRGeoCS_WGS1984);

ILinearUnit unit = spatialReferenceFactory.CreateUnit((int) esriSRUnitType.esriSRUnit_Meter)as ILinearUnit;

IParameter[] parameters = projection.GetDefaultParameters();

IProjectedCoordinateSystemEdit projectedCoordinateSystemEdit = new ProjectedCoordinateSystemClass();

Page 84: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

object name = "Newfoundland"; object alias = "NF_LAB";

object abbreviation = "NF";

object remarks = "Most Eastern Province in Canada";

object usage = "When making maps of Newfoundland";

object geographicCoordinateSystemObject = geographicCoordinateSystem as object;

object unitObject = unit as object;

object projectionObject = projection as object;

object parametersObject = parameters as object; projectedCoordinateSystemEdit.Define( ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref geographicCoordinateSystemObject, ref unitObject, ref projectionObject, ref parametersObject);

return projectedCoordinateSystemEdit as IProjectedCoordinateSystem;

}

Page 85: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

Creating a custom vertical coordinate system

The ISpatialReferenceFactory3 interface allows you to create the Datum, VerticalDatum, and LinearUnit component parts. These components can also be created using a similar Define method available on their classes.

Page 86: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

private IVerticalCoordinateSystem CreateVerticalCoordinateSystem()

{ ISpatialReferenceFactory3 spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

IVerticalDatum verticalDatum = spatialReferenceFactory.CreateVerticalDatum((int)esriSRVerticalDatumType.esriSRVertDatum_Taranaki);

IHVDatum hvDatum = verticalDatum as IHVDatum;

ILinearUnit linearUnit = spatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter) as ILinearUnit;

IVerticalCoordinateSystemEdit verticalCoordinateSystemEdit = new VerticalCoordinateSystemClass();

object name = "New VCoordinateSystem";

object alias = "VCoordinateSystem alias";

object abbreviation = "abbr";

Page 87: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

object remarks = "Test for options";

object usage = "New Zealand";

object hvDatumObject = hvDatum as object;

object unitObject = linearUnit as object;

object verticalShift = 40 as object;

object positiveDirection = -1 as object;

verticalCoordinateSystemEdit.Define (ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref hvDatumObject, ref unitObject, ref verticalShift, ref positiveDirection);

IVerticalCoordinateSystem verticalCoordinateSystem = verticalCoordinateSystemEdit as IVerticalCoordinateSystem;

return verticalCoordinateSystem;

}

Page 88: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

private IVerticalCoordinateSystem CreateEllipsoidBasedVerticalCoordinateSystem()

{ ISpatialReferenceFactory3 spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

IDatum datum = spatialReferenceFactory.CreateDatum((int)esriSRDatumType.esriSRDatum_WGS1984);

IHVDatum hvDatum = datum as IHVDatum;

ILinearUnit linearUnit = spatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Foot) as ILinearUnit;

IVerticalCoordinateSystemEdit verticalCoordinateSystemEdit = new VerticalCoordinateSystemClass();

object name = "WGS84 vcs";

object alias = "WGS84 ellipsoid";

Page 89: 江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET GIS 应用开发 Developing GIS Applications with ArcObjects using C#.NET 江西省研究生优质课程

江西理工大学 – Developing GIS Applications with ArcObjects using C#.NET

object abbreviation = "w84 3d";

object remarks = "WGS84 ell-based vcs";

object usage = "everywhere!";

object hvDatumObject = hvDatum as object;

object unitObject = linearUnit as object;

object verticalShift = 0.4839 as object;

object positiveDirection = -1 as object;

verticalCoordinateSystemEdit.Define (ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref hvDatumObject, ref unitObject, ref verticalShift, ref positiveDirection);

IVerticalCoordinateSystem verticalCoordinateSystem = verticalCoordinateSystemEdit as IVerticalCoordinateSystem;

return verticalCoordinateSystem;

}