技术开发 频道

Geometry 对象浅析

IT168  技术文档】 ArcEngine Geometry库定义了基本几何图形的矢量表达形式,优异的几何图形有Points、Multipoints、Polylines、Polygons、 Multipatches,Geodatabase和绘图系统使用这些几何图形来定义其他各种形状的特征和图形,提供了编辑图形的操作方法和地图符号系统符号化特征数据的途径。

    Geometry库中几个核心类和接口构成了Geometry对象的基本框架。

    GeometryEnvironment

    GeometryEnvironment提供了从不同的输入、设置或获取全局变量来创建几何图形的方法,以便控制geometry方法的行为。GeometryEnvironment对象是一个单例对象。
public IPolyline TestGeometryEnvironment() { ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); //Create a projected coordinate system and define its domain, resolution, and x,y tolerance. ISpatialReferenceResolution spatialReferenceResolution = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_11N) as ISpatialReferenceResolution; spatialReferenceResolution.ConstructFromHorizon(); ISpatialReferenceTolerance spatialReferenceTolerance = spatialReferenceResolution as ISpatialReferenceTolerance; spatialReferenceTolerance.SetDefaultXYTolerance(); ISpatialReference spatialReference = spatialReferenceResolution as ISpatialReference; //Create an array of WKSPoint structures starting in the middle of the x,y domain of the //projected coordinate system. double xMin; double xMax; double yMin; double yMax; spatialReference.GetDomain(out xMin, out xMax, out yMin, out yMax); double xFactor = (xMin + xMax) * 0.5; double yFactor = (yMin + yMax) * 0.5; WKSPoint[] wksPoints = new WKSPoint[10]; for (int i = 0; i < wksPoints.Length; i++) { wksPoints[i].X = xFactor + i; wksPoints[i].Y = yFactor + i; } IPointCollection4 pointCollection = new PolylineClass(); IGeometryBridge2 geometryBridge = new GeometryEnvironmentClass(); geometryBridge.AddWKSPoints(pointCollection, ref wksPoints); IPolyline polyline = pointCollection as IPolyline; polyline.SpatialReference = spatialReference; return polyline; }
new GeometryEnvironmentClass仅仅是创建了一个指向已存在的GeometryEnvironmentClass的引用。注意 IGeometryBridge2接口的使用,addWKSPoints方法将WKSPoint二维点添加到PointCollection中,用于构建 path、ring、polyline、polygon,或增加新点到Multipoint、TriangleFan、TriangleStrip。在 Geometry库中,除了IGeometryBridge2还有IGeometryBridge接口,后者继承了前者,增加了一些编辑功能(添加点、插入点、重置点、分段等)。
0