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


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


GeometryEnvironment CHINAZ


GeometryEnvironment提供了从不同的输入、设置或获取全局变量来创建几何图形的方法,以便控制geometry方法的行为。GeometryEnvironment对象是一个单例对象。
CHINAZ

以下为引用的内容:
Geometry 对象浅析public IPolyline TestGeometryEnvironment()
Geometry 对象浅析Geometry 对象浅析
Geometry 对象浅析{ CHINAZ
Geometry 对象浅析    ISpatialReferenceFactory spatialReferenceFactory 
= new SpatialReferenceEnvironmentClass();
Geometry 对象浅析
Geometry 对象浅析    
//Create a projected coordinate system and define its domain, resolution, and x,y tolerance.
Geometry 对象浅析
    ISpatialReferenceResolution spatialReferenceResolution = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_11N) as ISpatialReferenceResolution; CHINAZ
Geometry 对象浅析    spatialReferenceResolution.ConstructFromHorizon();
Geometry 对象浅析    ISpatialReferenceTolerance spatialReferenceTolerance 
= spatialReferenceResolution as ISpatialReferenceTolerance;
Geometry 对象浅析    spatialReferenceTolerance.SetDefaultXYTolerance();
Geometry 对象浅析    ISpatialReference spatialReference 
= spatialReferenceResolution as ISpatialReference;
Geometry 对象浅析
CHINAZ

Geometry 对象浅析    //Create an array of WKSPoint structures starting in the middle of the x,y domain of the 
Geometry 对象浅析    
//projected coordinate system.
Geometry 对象浅析

Geometry 对象浅析    
double xMin;
Geometry 对象浅析    
double xMax;

CHINAZ


Geometry 对象浅析    double yMin;
Geometry 对象浅析    
double yMax;
Geometry 对象浅析    spatialReference.GetDomain(
out xMin, out xMax, out yMin, out yMax);
Geometry 对象浅析
Geometry 对象浅析    
double xFactor = (xMin + xMax) * 0.5; CHINAZ
Geometry 对象浅析    
double yFactor = (yMin + yMax) * 0.5;
Geometry 对象浅析
Geometry 对象浅析    WKSPoint[] wksPoints 
= new WKSPoint[10];
Geometry 对象浅析    
for (int i = 0; i < wksPoints.Length; i++) CHINAZ
Geometry 对象浅析Geometry 对象浅析    
Geometry 对象浅析{ CHINAZ
Geometry 对象浅析        wksPoints[i].X 
= xFactor + i;
Geometry 对象浅析        wksPoints[i].Y 
= yFactor + i;
Geometry 对象浅析    }

Geometry 对象浅析
Geometry 对象浅析    IPointCollection4 pointCollection 
= new PolylineClass();
CHINAZ

Geometry 对象浅析
Geometry 对象浅析    IGeometryBridge2 geometryBridge = new GeometryEnvironmentClass();
Geometry 对象浅析    geometryBridge.AddWKSPoints(pointCollection, 
ref wksPoints);
Geometry 对象浅析
Geometry 对象浅析    IPolyline polyline 
= pointCollection as IPolyline;
Geometry 对象浅析    polyline.SpatialReference 
= spatialReference; CHINAZ
Geometry 对象浅析
Geometry 对象浅析    
return polyline;
Geometry 对象浅析}

CHINAZ

  new GeometryEnvironmentClass仅仅是创建了一个指向已存在的GeometryEnvironmentClass的引用。注意 IGeometryBridge2接口的使用,addWKSPoints方法将WKSPoint二维点添加到PointCollection中,用于构建 path、ring、polyline、polygon,或增加新点到Multipoint、TriangleFan、TriangleStrip。在 Geometry库中,除了IGeometryBridge2还有IGeometryBridge接口,后者继承了前者,增加了一些编辑功能(添加点、插入点、重置点、分段等)。 CHINAZ


GeometryBag CHINAZ


GeometryBag是支持IGeometry接口的几何对象引用的集合,任何几何对象都可以通过IGeometryCollection接口添加到 GeometryBag中,但是在使用拓扑操作的时候,需要注意不同类型的几何类型可能会有相互不兼容的情况。在向GeometryBag中添加几何对象的时候,GeometryBag对象需要指定空间参考,添加到其中的几何对象均拥有和GeometryBag对象一样的空间参考。
CHINAZ

以下为引用的内容:
Geometry 对象浅析private IPolygon GeometryBag_Example(IFeatureClass featureClass)
Geometry 对象浅析Geometry 对象浅析
Geometry 对象浅析{

CHINAZ


Geometry 对象浅析
Geometry 对象浅析    //Check input objects.
Geometry 对象浅析
    if (featureClass == null)
Geometry 对象浅析Geometry 对象浅析    
Geometry 对象浅析{
CHINAZ

Geometry 对象浅析        return null;
Geometry 对象浅析    }

Geometry 对象浅析
Geometry 对象浅析    IGeoDataset geoDataset 
= featureClass as IGeoDataset;
Geometry 对象浅析    ISpatialFilter queryFilter 
= new SpatialFilterClass();
CHINAZ

Geometry 对象浅析
Geometry 对象浅析    //Set the properties of the spatial filter here.
Geometry 对象浅析
    IGeometry geometryBag = new GeometryBagClass();
Geometry 对象浅析
Geometry 对象浅析    
//Define the spatial reference of the bag before adding geometries to it.

CHINAZ


Geometry 对象浅析    geometryBag.SpatialReference = geoDataset.SpatialReference;
Geometry 对象浅析
Geometry 对象浅析    
//Use a nonrecycling cursor so each returned geometry is a separate object. 
Geometry 对象浅析
    IFeatureCursor featureCursor = featureClass.Search(queryFilter, false);
CHINAZ

Geometry 对象浅析
Geometry 对象浅析    IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;
Geometry 对象浅析    IFeature currentFeature 
= featureCursor.NextFeature();
Geometry 对象浅析
Geometry 对象浅析    
while (currentFeature != null) CHINAZ
Geometry 对象浅析Geometry 对象浅析    
Geometry 对象浅析{ CHINAZ
Geometry 对象浅析        
//Add a reference to this feature's geometry into the bag.
Geometry 对象浅析        
//You don't specify the before or after geometry (missing),
Geometry 对象浅析        
//so the currentFeature.Shape IGeometry is added to the end of the geometryCollection.
Geometry 对象浅析
        object missing = Type.Missing; CHINAZ
Geometry 对象浅析        geometryCollection.AddGeometry(currentFeature.Shape, 
ref missing, ref missing);
Geometry 对象浅析
Geometry 对象浅析        currentFeature 
= featureCursor.NextFeature();
Geometry 对象浅析    }

Geometry 对象浅析
Geometry 对象浅析    
// Create the polygon that will be the union of the features returned from the search cursor. CHINAZ
Geometry 对象浅析    
// The spatial reference of this feature does not need to be set ahead of time. The 
Geometry 对象浅析    
// ConstructUnion method defines the constructed polygon's spatial reference to be the same as 
Geometry 对象浅析    
// the input geometry bag.
Geometry 对象浅析
    ITopologicalOperator unionedPolygon = new PolygonClass();

CHINAZ


Geometry 对象浅析    unionedPolygon.ConstructUnion(geometryBag as IEnumGeometry);
Geometry 对象浅析
Geometry 对象浅析    
return unionedPolygon as IPolygon;
Geometry 对象浅析}

CHINAZ

 

  Points

CHINAZ

 


一个点包括X、Y坐标,同时可以增加M、Z值及ID属性来扩展点的功能。 CHINAZ


Multipoints CHINAZ


点的集合,多点组成Multipoint几何类型,使用multipoint对象实现了的IPointCollection接口可以访问所有的点元素,这些点同样可以拥有M、Z值及ID属性来获得更多的地理空间内涵。

CHINAZ

 


下面列举一个例子,通过一个已知的polyline来定义一个新的multipart polyline。
CHINAZ

Geometry 对象浅析CHINAZ

 

CHINAZ

 

以下为引用的内容:
Geometry 对象浅析public IPolyline ConstructMultiPartPolyline(IPolyline inputPolyline)
Geometry 对象浅析Geometry 对象浅析
Geometry 对象浅析{

CHINAZ


Geometry 对象浅析    IGeometry outGeometry = new PolylineClass();
Geometry 对象浅析
Geometry 对象浅析    
//Always associate new, top-level geometries with an appropriate spatial reference.
Geometry 对象浅析
    outGeometry.SpatialReference = inputPolyline.SpatialReference; 
Geometry 对象浅析 

CHINAZ


Geometry 对象浅析    IGeometryCollection geometryCollection = outGeometry as IGeometryCollection;
Geometry 对象浅析
Geometry 对象浅析    ISegmentCollection segmentCollection 
= inputPolyline as ISegmentCollection;
Geometry 对象浅析
Geometry 对象浅析    
//Iterate over existing polyline segments using a segment enumerator. CHINAZ
Geometry 对象浅析
    IEnumSegment segments = segmentCollection.EnumSegments;
Geometry 对象浅析
Geometry 对象浅析    ISegment currentSegment;
Geometry 对象浅析    
int partIndex = 0;;
Geometry 对象浅析    
int segmentIndex = 0;;  

CHINAZ


Geometry 对象浅析    segments.Next(out currentSegment,ref partIndex, ref segmentIndex);
Geometry 对象浅析    
while(currentSegment != null)
Geometry 对象浅析Geometry 对象浅析    
Geometry 对象浅析{
CHINAZ

Geometry 对象浅析        ILine normal = new LineClass();
Geometry 对象浅析
Geometry 对象浅析        
//Geometry methods with _Query_ in their name expect to modify existing geometries. 
Geometry 对象浅析        
//In this case, the QueryNormal method modifies an existing line
Geometry 对象浅析        
//segment (normal) to be the normal vector to 

CHINAZ


Geometry 对象浅析        //currentSegment at the specified location along currentSegment.
Geometry 对象浅析
        currentSegment.QueryNormal(esriSegmentExtension.esriNoExtension, 0.5true, currentSegment.Length / 3, normal); 
Geometry 对象浅析 
Geometry 对象浅析        
//Since each normal vector is not connected to others, create a new path for each one. CHINAZ
Geometry 对象浅析
        ISegmentCollection newPath = new PathClass();
Geometry 对象浅析        
object missing = Type.Missing;
Geometry 对象浅析        newPath.AddSegment(normal 
as ISegment, ref missing, ref missing); CHINAZ
Geometry 对象浅析        
//The spatial reference associated with geometryCollection will be assigned to all incoming paths and segments.
Geometry 对象浅析
        geometryCollection.AddGeometry(newPath as IGeometry, ref missing, ref missing);
Geometry 对象浅析
Geometry 对象浅析        segments.Next(
out currentSegment,ref partIndex, ref segmentIndex); CHINAZ
Geometry 对象浅析    }

Geometry 对象浅析    
//The geometryCollection now contains the new, multipart polyline.
Geometry 对象浅析
    return geometryCollection as IPolyline;
Geometry 对象浅析}

CHINAZ

  ISegment接口的QueryNormal方法用来在弧段上的某一点生成该弧段的法线,指定其长度,这样就生成了新的segment,并且多个path添加到geometryCollection中,以IPolyline的形式返回。

CHINAZ

 


Polylines

CHINAZ

 


Polylines是有序path组成的集合,可以拥有M、Z和ID属性值。Polyline对象的IPointCollection接口包含了所有节点的复制,IGeometryCollection接口可以获取polyline的paths,ISegmentCollection接口可以获取 polyline的segments。 CHINAZ


Polyline结构图 CHINAZ

Geometry 对象浅析

CHINAZ

 

 

CHINAZ

 

  Polygons CHINAZ


Polygon是一系列rings组成的集合,可以拥有M、Z和ID属性值。每一个ring由一个或多个segment组成,Polygon或ring对象的IPointCollection接口包含了所有节点的复制,IGeometryCollection接口可以获取polygon的rings, ISegmentCollection接口可以获取polygon的segments。 CHINAZ


Polygon结构图

CHINAZ

 

Geometry 对象浅析

CHINAZ

 

  CHINAZ

  Multipatch CHINAZ


Multipatch用于描述3D面状几何类型,由一系列的矢量三角形构成,如果其中的part是一个ring,那么它必须是封闭的,第一个节点和最后一个节点相同,另外每个part所包含节点的顺序非常重要,Inner Rings在Outer Rings之后,代表单个表面patch的一系列rings必须由第一个ring开始。

CHINAZ

 

Geometry 对象浅析

CHINAZ

 

 

CHINAZ

 

  在9.0以后的开发包中,使用IGeneralMultiPatchCreator创建新的Multipatch,IGeometryMaterial进行材质贴图。

CHINAZ

 

以下为引用的内容:
Geometry 对象浅析public IMultiPatch CreateMultipatch()
Geometry 对象浅析Geometry 对象浅析
Geometry 对象浅析{

CHINAZ


Geometry 对象浅析    //Prepare the geometry material list.
Geometry 对象浅析
    IGeometryMaterial texture = new GeometryMaterialClass();
Geometry 对象浅析    texture.TextureImage 
= "C:\\Temp\\MyImage.bmp";
Geometry 对象浅析

CHINAZ


Geometry 对象浅析    IGeometryMaterialList materialList = new GeometryMaterialListClass();
Geometry 对象浅析    materialList.AddMaterial(texture);
Geometry 对象浅析
Geometry 对象浅析    
//Create the multipatch.
Geometry 对象浅析
    IGeneralMultiPatchCreator multiPatchCreator = new GeneralMultiPatchCreatorClass();

CHINAZ


Geometry 对象浅析    multiPatchCreator.Init(41falsefalsefalse4, materialList);
Geometry 对象浅析
Geometry 对象浅析    
//Set up part.
Geometry 对象浅析
Geometry 对象浅析    
//Could also use a Ring or a TriangleFan.
CHINAZ

Geometry 对象浅析    multiPatchCreator.SetPatchType(0, esriPatchType.esriPatchTypeTriangleStrip);
Geometry 对象浅析    multiPatchCreator.SetMaterialIndex(
00);
Geometry 对象浅析    multiPatchCreator.SetPatchPointIndex(
00);
Geometry 对象浅析    multiPatchCreator.SetPatchTexturePointIndex(
00);
CHINAZ

Geometry 对象浅析
Geometry 对象浅析    //Set real-world points.
Geometry 对象浅析
    WKSPointZ upperLeft  = new WKSPointZ();
Geometry 对象浅析    WKSPointZ lowerLeft  
= new WKSPointZ();
Geometry 对象浅析    WKSPointZ upperRight 
= new WKSPointZ();
CHINAZ

Geometry 对象浅析    WKSPointZ lowerRight = new WKSPointZ();
Geometry 对象浅析
Geometry 对象浅析    upperLeft.X 
= 0;
Geometry 对象浅析    upperLeft.Y 
= 0;
Geometry 对象浅析    upperLeft.Z 
= 0;

CHINAZ


Geometry 对象浅析    upperRight.X = 300;
Geometry 对象浅析    upperRight.Y 
= 0;
Geometry 对象浅析    upperRight.Z 
= 0;
Geometry 对象浅析    lowerLeft.X 
= 0;
CHINAZ

Geometry 对象浅析    lowerLeft.Y = 0;
Geometry 对象浅析    lowerLeft.Z 
= -100;
Geometry 对象浅析    lowerRight.X 
= 300;
Geometry 对象浅析    lowerRight.Y 
= 1;
CHINAZ

Geometry 对象浅析    lowerRight.Z = -100;
Geometry 对象浅析
Geometry 对象浅析    multiPatchCreator.SetWKSPointZ(
0ref upperRight);
Geometry 对象浅析    multiPatchCreator.SetWKSPointZ(
1ref lowerRight);
Geometry 对象浅析    multiPatchCreator.SetWKSPointZ(
2ref upperLeft); CHINAZ
Geometry 对象浅析    multiPatchCreator.SetWKSPointZ(
3ref lowerLeft);
Geometry 对象浅析
Geometry 对象浅析    
//Set texture points.
Geometry 对象浅析    
//Set the texture coordinates for a panel.
Geometry 对象浅析
    WKSPoint textureUpperLeft  = new WKSPoint();

CHINAZ


Geometry 对象浅析    WKSPoint textureLowerLeft  = new WKSPoint();
Geometry 对象浅析    WKSPoint textureUpperRight 
= new WKSPoint();
Geometry 对象浅析    WKSPoint textureLowerRight 
= new WKSPoint();
Geometry 对象浅析
Geometry 对象浅析    textureUpperLeft.X 
= 0; CHINAZ
Geometry 对象浅析    textureUpperLeft.Y 
= 0;
Geometry 对象浅析    textureUpperRight.X 
= 1;
Geometry 对象浅析    textureUpperRight.Y 
= 0;
Geometry 对象浅析    textureLowerLeft.X 
= 0; CHINAZ
Geometry 对象浅析    textureLowerLeft.Y 
= 1;
Geometry 对象浅析    textureLowerRight.X 
= 1;
Geometry 对象浅析    textureLowerRight.Y 
= 1;
Geometry 对象浅析
Geometry 对象浅析    multiPatchCreator.SetTextureWKSPoint(
0ref textureUpperRight); CHINAZ
Geometry 对象浅析    multiPatchCreator.SetTextureWKSPoint(
1ref textureLowerRight);
Geometry 对象浅析    multiPatchCreator.SetTextureWKSPoint(
2ref textureUpperLeft);
Geometry 对象浅析    multiPatchCreator.SetTextureWKSPoint(
3ref textureLowerLeft);
Geometry 对象浅析    IMultiPatch multiPatch 
= multiPatchCreator.CreateMultiPatch() as IMultiPatch; CHINAZ
Geometry 对象浅析
Geometry 对象浅析    
return multiPatch;
Geometry 对象浅析}

版权说明

  如果标题未标有<转载、转>等字则属于作者原创,欢迎转载,其版权归作者和博客园共有。
  作      者:温景良
  文章出处:http://wenjl520.cnblogs.com/  或  http://www.cnblogs.com/

posted @ 2009-02-10 09:25 温景良(Jason) Views(1903) Comments(0) Edit 收藏
 

公告

 
 
本文转自我的程序人生博客园博客,原文链接:http://www.cnblogs.com/wenjl520/archive/2009/02/10/1387198.html/,如需转载请自行联系原作者
 

相关文章: