




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
ArcEngine 中Geometry对象浅析本帖最后由 shisanshao 于 2011-4-13 00:12 编辑 ArcEngine Geometry库定义了基本几何图形的矢量表达形式,顶级的几何图形有Points、Multipoints、Polylines、Polygons、 Multipatches,Geodatabase和绘图系统使用这些几何图形来定义其他各种形状的特征和图形,提供了编辑图形的操作方法和地图符号系统符号化特征数据的途径。 Geometry库中几个核心类和接口构成了Geometry对象的基本框架。 GeometryEnvironment提供了从不同的输入、设置或获取全局变量来创建几何图形的方法,以便控制geometry方法的行为。GeometryEnvironment对象是一个单例对象。以下为引用的内容: 1. public IPolyline TestGeometryEnvironment()2. 3. ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();4. /Create a projected coordinate system and define its domain, resolution, and x,y tolerance.5. IspatialReferenceResolution spatialReferenceResolution = spatialReferenceFactory.CreateProjectedCoordinateSystem(int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_11N) as ISpatialReferenceResolution;6. spatialReferenceResolution.ConstructFromHorizon();7. ISpatialReferenceTolerance spatialReferenceTolerance = spatialReferenceResolution as ISpatialReferenceTolerance;8. spatialReferenceTolerance.SetDefaultXYTolerance();9. ISpatialReference spatialReference = spatialReferenceResolution as ISpatialReference;10. C11. /Create an array of WKSPoint structures starting in the middle of the x,y domain of the 12. /projected coordinate system.13. double xMin;14. double xMax; 15. double yMin;16. double yMax;17. spatialReference.GetDomain(out xMin, out xMax, out yMin, out yMax);18. double xFactor = (xMin xMax) * 0.5;19. double yFactor = (yMin yMax) * 0.5;20. WKSPoint wksPoints = new WKSPoint10;21. for (int i = 0; i wksPoints.Length; i) 22. 23. wksPoints.X = xFactor i;24. wksPoints.Y = yFactor i;25. 26. IPointCollection4 pointCollection = new PolylineClass(); 27. IGeometryBridge2 geometryBridge = new GeometryEnvironmentClass();28. geometryBridge.AddWKSPoints(pointCollection, ref wksPoints);29. IPolyline polyline = pointCollection as IPolyline;30. polyline.SpatialReference = spatialReference;31. return polyline;32. 复制代码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对象一样的空间参考。以下为引用的内容:1.2. private IPolygon GeometryBag_Example(IFeatureClass featureClass)3. 4. /Check input objects.5. if (featureClass = null)6. 7. return null;8. 9. IGeoDataset geoDataset = featureClass as IGeoDataset;10. ISpatialFilter queryFilter = new SpatialFilterClass(); 11. /Set the properties of the spatial filter here.12. IGeometry geometryBag = new GeometryBagClass();13. /Define the spatial reference of the bag before adding geometries to it. 14. geometryBag.SpatialReference = geoDataset.SpatialReference;15. /Use a nonrecycling cursor so each returned geometry is a separate object. 16. IFeatureCursor featureCursor = featureClass.Search(queryFilter, false); 17. IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;18. IFeature currentFeature = featureCursor.NextFeature();19. while (currentFeature != null) 20. 21. /Add a reference to this features geometry into the bag.22. /You dont specify the before or after geometry (missing),23. /so the currentFeature.Shape IGeometry is added to the end of the geometryCollection.24. object missing = Type.Missing; 25. geometryCollection.AddGeometry(currentFeature.Shape, ref missing, ref missing);26. currentFeature = featureCursor.NextFeature();27. 28. / Create the polygon that will be the union of the features returned from the search cursor. 29. / The spatial reference of this feature does not need to be set ahead of time. The 30. / ConstructUnion method defines the constructed polygons spatial reference to be the same as 31. / the input geometry bag.32. ITopologicalOperator unionedPolygon = new PolygonClass(); 33. unionedPolygon.ConstructUnion(geometryBag as IEnumGeometry);34. return unionedPolygon as IPolygon;35. 复制代码Points一个点包括X、Y坐标,同时可以增加M、Z值及ID属性来扩展点的功能。Multipoints 点的集合,多点组成Multipoint几何类型,使用multipoint对象实现了的IPointCollection接口可以访问所有的点元素,这些点同样可以拥有M、Z值及ID属性来获得更多的地理空间内涵。下面列举一个例子,通过一个已知的polyline来定义一个新的multipart polyline。以下为引用的内容:1.2. public IPolyline ConstructMultiPartPolyline(IPolyline inputPolyline)3. 4. IGeometry outGeometry = new PolylineClass();5. /Always associate new, toplevel geometries with an appropriate spatial reference.6. outGeometry.SpatialReference = inputPolyline.SpatialReference; 7. IGeometryCollection geometryCollection = outGeometry as IGeometryCollection;8. ISegmentCollection segmentCollection = inputPolyline as ISegmentCollection;9. /Iterate over existing polyline segments using a segment enumerator. Chinazcom 10. IEnumSegment segments = segmentCollection.EnumSegments;11. ISegment currentSegment;12. int partIndex = 0;13. int segmentIndex = 0;14. segments.Next(out currentSegment,ref partIndex, ref segmentIndex);15. while(currentSegment != null)16. 17. ILine normal = new LineClass();18. /Geometry methods with _Query_ in their name expect to modify existing geometries. 19. /In this case, the QueryNormal method modifies an existing line20. /segment (normal) to be the normal vector to 21. /currentSegment at the specified location along currentSegment.22. currentSegment.QueryNormal(esriSegmentExtension.esriNoExtension, 0.5, true, currentSegment.Length / 3, normal); 23. /Since each normal vector is not connected to others, create a new path for each one. 24. ISegmentCollection newPath = new PathClass();25. object missing = Type.Missing;26. newPath.AddSegment(normal as ISegment, ref missing, ref missing); 27. /The spatial reference associated with geometryCollection will be assigned to all incoming paths and segments.28. geometryCollection.AddGeometry(newPath as IGeometry, ref missing, ref missing);29. segments.Next(out currentSegment,ref partIndex, ref segmentIndex); 30. 31. /The geometryCollection now contains the new, multipart polyline.32. return geometryCollection as IPolyline;33. 复制代码ISegment接口的QueryNormal方法用来在弧段上的某一点生成该弧段的法线,指定其长度,这样就生成了新的segment,并且多个path添加到geometryCollection中,以IPolyline的形式返回。 Polylines Polylines是有序path组成的集合,可以拥有M、Z和ID属性值。Polyline对象的IPointCollection接口包含了所有节点的复制,IGeometryCollection接口可以获取polyline的paths,ISegmentCollection接口可以获取 polyline的segments。Polyline结构图 Polygons Polygon是一系列rings组成的集合,可以拥有M、Z和ID属性值。每一个ring由一个或多个segment组成,Polygon或ring对象的IPointCollection接口包含了所有节点的复制,IGeometryCollection接口可以获取polygon的rings, ISegmentCollection接口可以获取polygon的segments。 Polygon结构图 Multipatch Multipatch用于描述3D面状几何类型,由一系列的矢量三角形构成,如果其中的part是一个ring,那么它必须是封闭的,第一个节点和最后一个节点相同,另外每个part所包含节点的顺序非常重要,Inner Rings在Outer Rings之后,代表单个表面patch的一系列rings必须由第一个ring开始。在9.0以后的开发包中,使用IGeneralMultiPatchCreator创建新的Multipatch,IGeometryMaterial进行材质贴图。以下为引用的内容:1.2. public IMultiPatch CreateMultipatch()3. 4. /Prepare the geometry material list.5. IGeometryMaterial texture = new GeometryMaterialClass();6. texture.TextureImage = C:TempMyImage.bmp;7. IGeometryMaterialList materialList = new GeometryMaterialListClass();8. materialList.AddMaterial(texture);9. /Create the multipatch.10. IGeneralMultiPatchCreator multiPatchCreator = new GeneralMultiPatchCreatorClass(); 11. multiPatchCreator.Init(4, 1, false, false, false, 4, materialList);12. /Set up part.13. /Could also use a Ring or a TriangleFan.14. multiPatchCreator.SetPatchType(0, esriPatchType.esriPatchTypeTriangleStrip);15. multiPatchCreator.SetMaterialIndex(0, 0);16. multiPatchCreator.SetPatchPointIndex(0, 0);17. multiPatchCreator.SetPatchTexturePointIndex(0, 0); 18. /Set realworld points.19. WKSPointZ upperLeft20. = new WKSPointZ();21. WKSPointZ lowerLeft22. = new WKSPointZ();23. WKSPointZ upperRight = new WKSPointZ(); 24. WKSPointZ lowerRight = new WKSPointZ();25. upperLeft.X = 0;26. upperLeft.Y = 0;27. upperLeft.Z = 0; 28. upperRight.X = 300;29. upperRight.Y = 0;30. upperRight.Z = 0;31. lowerLeft.X = 0; 32. lowerLeft.Y = 0;33. lowerLeft.Z = 100;34. lowerRight.X = 300;35. lowerRight.Y = 1; 36. lowerRight.Z = 100;37. multiPatchCreator.SetWKSPointZ(0, ref upperRight);38. multiPatchCreator.SetWKSPointZ(1, ref lowerRight);39. multiPatchCreator.SetWKSPointZ(2, ref upperLe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论