ArcEngine Geometry库定义了基本几何图形的矢量表达形式,顶级的几何图形有Points、Multipoints、Polylines、Polygons、 Multipatches,Geodatabase和绘图系统使用这些几何图形来定义其他各种形状的特征和图形,提供了编辑图形的操作方法和地图符号系统符号化特征数据的途径。
Geometry库中几个核心类和接口构成了Geometry对象的基本框架。
GeometryEnvironment
GeometryEnvironment提供了从不同的输入、设置或获取全局变量来创建几何图形的方法,以便控制geometry方法的行为。GeometryEnvironment对象是一个单例对象。
new GeometryEnvironmentClass仅仅是创建了一个指向已存在的GeometryEnvironmentClass的引用。注意 IGeometryBridge2接口的使用,addWKSPoints方法将WKSPoint二维点添加到PointCollection中,用于构建 path、ring、polyline、polygon,或增加新点到Multipoint、TriangleFan、TriangleStrip。在 Geometry库中,除了IGeometryBridge2还有IGeometryBridge接口,后者继承了前者,增加了一些编辑功能(添加点、插入点、重置点、分段等)。
GeometryBag
GeometryBag是支持IGeometry接口的几何对象引用的集合,任何几何对象都可以通过IGeometryCollection接口添加到 GeometryBag中,但是在使用拓扑操作的时候,需要注意不同类型的几何类型可能会有相互不兼容的情况。在向GeometryBag中添加几何对象的时候,GeometryBag对象需要指定空间参考,添加到其中的几何对象均拥有和GeometryBag对象一样的空间参考。
Points
一个点包括X、Y坐标,同时可以增加M、Z值及ID属性来扩展点的功能。
Multipoints
点的集合,多点组成Multipoint几何类型,使用multipoint对象实现了的IPointCollection接口可以访问所有的点元素,这些点同样可以拥有M、Z值及ID属性来获得更多的地理空间内涵。
下面列举一个例子,通过一个已知的polyline来定义一个新的multipart polyline。
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
public IPolyline ConstructMultiPartPolyline(IPolyline inputPolyline)
![](http://img.e-com-net.com/image/product/d55068b7eba0455eba2e81fccabd26f6.png)
{
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
IGeometry outGeometry = new PolylineClass();
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//Always associate new, top-level geometries with an appropriate spatial reference.
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
outGeometry.SpatialReference = inputPolyline.SpatialReference;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
IGeometryCollection geometryCollection = outGeometry as IGeometryCollection;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
ISegmentCollection segmentCollection = inputPolyline as ISegmentCollection;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//Iterate over existing polyline segments using a segment enumerator.
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
IEnumSegment segments = segmentCollection.EnumSegments;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
ISegment currentSegment;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
int partIndex = 0;;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
int segmentIndex = 0;;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
segments.Next(out currentSegment,ref partIndex, ref segmentIndex);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
while(currentSegment != null)
![](http://img.e-com-net.com/image/product/d55068b7eba0455eba2e81fccabd26f6.png)
{
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
ILine normal = new LineClass();
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//Geometry methods with _Query_ in their name expect to modify existing geometries.
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//In this case, the QueryNormal method modifies an existing line
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//segment (normal) to be the normal vector to
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//currentSegment at the specified location along currentSegment.
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
currentSegment.QueryNormal(esriSegmentExtension.esriNoExtension, 0.5, true, currentSegment.Length / 3, normal);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//Since each normal vector is not connected to others, create a new path for each one.
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
ISegmentCollection newPath = new PathClass();
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
object missing = Type.Missing;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
newPath.AddSegment(normal as ISegment, ref missing, ref missing);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//The spatial reference associated with geometryCollection will be assigned to all incoming paths and segments.
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
geometryCollection.AddGeometry(newPath as IGeometry, ref missing, ref missing);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
segments.Next(out currentSegment,ref partIndex, ref segmentIndex);
![](http://img.e-com-net.com/image/product/fd30ab844bef43f6b8a6ceb02f8ad366.gif)
}
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//The geometryCollection now contains the new, multipart polyline.
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
return geometryCollection as IPolyline;
![](http://img.e-com-net.com/image/product/cc612d05a8624bada20221f76e20a5bc.gif)
}
ISegment接口的QueryNormal方法用来在弧段上的某一点生成该弧段的法线,指定其长度,这样就生成了新的segment,并且多个path添加到geometryCollection中,以IPolyline的形式返回。
Polylines
Polylines是有序path组成的集合,可以拥有M、Z和ID属性值。Polyline对象的IPointCollection接口包含了所有节点的复制,IGeometryCollection接口可以获取polyline的paths,ISegmentCollection接口可以获取 polyline的segments。
Polyline结构图
![Geometry 对象浅析 ( 作者:Flyingis)](http://img.e-com-net.com/image/product/d012d9dea35a43aba5a2ceb18e5e0d37.png)
Polygons
Polygon是一系列rings组成的集合,可以拥有M、Z和ID属性值。每一个ring由一个或多个segment组成,Polygon或ring对象的IPointCollection接口包含了所有节点的复制,IGeometryCollection接口可以获取polygon的rings, ISegmentCollection接口可以获取polygon的segments。
Polygon结构图
![Geometry 对象浅析 ( 作者:Flyingis)](http://img.e-com-net.com/image/product/ea851b1c65d0496b8bf97afb4c6f132b.png)
Multipatch
Multipatch用于描述3D面状几何类型,由一系列的矢量三角形构成,如果其中的part是一个ring,那么它必须是封闭的,第一个节点和最后一个节点相同,另外每个part所包含节点的顺序非常重要,Inner Rings在Outer Rings之后,代表单个表面patch的一系列rings必须由第一个ring开始。
![Geometry 对象浅析 ( 作者:Flyingis)](http://img.e-com-net.com/image/product/713ecf0c39a64126b5adb2e90dbb2882.png)
在9.0以后的开发包中,使用IGeneralMultiPatchCreator创建新的Multipatch,IGeometryMaterial进行材质贴图。
![](http://img.e-com-net.com/image/product/46339e8aae704cb1a8b93e7cd90036c0.gif)
public IMultiPatch CreateMultipatch()
![](http://img.e-com-net.com/image/product/d55068b7eba0455eba2e81fccabd26f6.png)
{
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//Prepare the geometry material list.
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
IGeometryMaterial texture = new GeometryMaterialClass();
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
texture.TextureImage = "C:\\Temp\\MyImage.bmp";
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
IGeometryMaterialList materialList = new GeometryMaterialListClass();
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
materialList.AddMaterial(texture);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//Create the multipatch.
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
IGeneralMultiPatchCreator multiPatchCreator = new GeneralMultiPatchCreatorClass();
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
multiPatchCreator.Init(4, 1, false, false, false, 4, materialList);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//Set up part.
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//Could also use a Ring or a TriangleFan.
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
multiPatchCreator.SetPatchType(0, esriPatchType.esriPatchTypeTriangleStrip);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
multiPatchCreator.SetMaterialIndex(0, 0);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
multiPatchCreator.SetPatchPointIndex(0, 0);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
multiPatchCreator.SetPatchTexturePointIndex(0, 0);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//Set real-world points.
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
WKSPointZ upperLeft = new WKSPointZ();
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
WKSPointZ lowerLeft = new WKSPointZ();
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
WKSPointZ upperRight = new WKSPointZ();
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
WKSPointZ lowerRight = new WKSPointZ();
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
upperLeft.X = 0;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
upperLeft.Y = 0;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
upperLeft.Z = 0;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
upperRight.X = 300;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
upperRight.Y = 0;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
upperRight.Z = 0;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
lowerLeft.X = 0;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
lowerLeft.Y = 0;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
lowerLeft.Z = -100;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
lowerRight.X = 300;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
lowerRight.Y = 1;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
lowerRight.Z = -100;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
multiPatchCreator.SetWKSPointZ(0, ref upperRight);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
multiPatchCreator.SetWKSPointZ(1, ref lowerRight);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
multiPatchCreator.SetWKSPointZ(2, ref upperLeft);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
multiPatchCreator.SetWKSPointZ(3, ref lowerLeft);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//Set texture points.
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
//Set the texture coordinates for a panel.
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
WKSPoint textureUpperLeft = new WKSPoint();
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
WKSPoint textureLowerLeft = new WKSPoint();
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
WKSPoint textureUpperRight = new WKSPoint();
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
WKSPoint textureLowerRight = new WKSPoint();
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
textureUpperLeft.X = 0;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
textureUpperLeft.Y = 0;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
textureUpperRight.X = 1;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
textureUpperRight.Y = 0;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
textureLowerLeft.X = 0;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
textureLowerLeft.Y = 1;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
textureLowerRight.X = 1;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
textureLowerRight.Y = 1;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
multiPatchCreator.SetTextureWKSPoint(0, ref textureUpperRight);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
multiPatchCreator.SetTextureWKSPoint(1, ref textureLowerRight);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
multiPatchCreator.SetTextureWKSPoint(2, ref textureUpperLeft);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
multiPatchCreator.SetTextureWKSPoint(3, ref textureLowerLeft);
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
IMultiPatch multiPatch = multiPatchCreator.CreateMultiPatch() as IMultiPatch;
![](http://img.e-com-net.com/image/product/b5ccfbfdc70d443ba19cbdc6a5005b86.gif)
return multiPatch;
![](http://img.e-com-net.com/image/product/cc612d05a8624bada20221f76e20a5bc.gif)
}