ArcEngine实现空间分析

Posted 杨千羽

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ArcEngine实现空间分析相关的知识,希望对你有一定的参考价值。

 ArcEngine实现空间分析

1.熟悉 ITopologicalOperator 接口(用于空间拓扑运算)的使用
2.熟悉 IRelationalOperator 接口(用于空间关联运算)的使用
3.熟悉 IProximityOperator 接口(用于空间距离运算)的使用

●·● 目录:

A1 ………… ITopologicalOperator5 接口

A2 ………… IRelationalOperator 接口

A3 ………… IPoint 接口
A4 ………… ICurve3 接口
A5 ………… ISegment 接口
A6 ………… ICircularArc 接口

---------------------------------------------------------------------------------------------------------

写在前面:

使用空间分析的时候,会提示这样的错误“异常来自 HRESULT:0x80040215”,其原因就是:

在使用 ITopologicalOperator求交集等操作的时候,
有时会出现“ HRESULT:0x80040215”这个异常,
原来是空间参考不一样所致。因此只要SpatialReference 
属性设为同一空间参考就不会出现“ HRESULT:0x80040215”异常。

所以在进行空间分析之前,要保证所建立的shapefile文件具有相同的SpatialReference!

---------------------------------------------------------------------------------------------------------

            ╔════════╗
╠════╣    第A1个    ╠══════════════════════════════════════════════════╣
            ╚════════╝

●·● ITopologicalOperator5 接口

1. Provides additional information on non-simple geometries.【拓扑操作】

  Members

    Description
Boundary
返回值:IGeometry
The boundary of this geometry. A polygon's boundary is a polyline. A polyline's boundary is a multipoint. A point or multipoint's boundary is an empty point or multipoint.
Buffer
(double distance)
返回值:IGeometry
Constructs a polygon that is the locus of points at a distance less than or equal to a specified distance from this geometry.
通过给定距离,得到操作图形的缓冲区,返回得到缓冲区几何图形!
但是这里面的距离很是蹊跷,同时实验发现,我写入 0.01 的时候,大约表示 1km,所以大约是 1:100 000 的关系!
Clip
(IEnvelope clipperEnvelope)
Constructs the intersection of this geometry and the specified envelope.
返回矩形部分的要素,直接作用在要素上面!
ClipDense Constructs the intersection of this geometry and the specified envelope; densifies lines in output contributed by the clipping envelope.
ClipEx Constructs the intersection of this geometry and the specified envelope.
ClipToDomain Clips the geometry to the domain of the spatial reference. Useful for ensuring that buffers can be fit within the spatial domain of the feature class to which they are being added.
ConstructUnion Defines this geometry to be the union of the inputs. More efficient for unioning multiple geometries than calling Union repeatedly.
ConvexHull Constructs the convex hull of this geometry.
Cut Splits this geometry into a part left of the cutting polyline, and a part right of it.
Cut2 Divides a geometry into multiple parts
Difference Constructs the geometry containing points from this geometry but not the other geometry.
GeoNormalizeEx Shifts longitudes, if need be, into a continuous range of 360 degrees.
Intersect Constructs the geometry that is the set-theoretic intersection of the input geometries. Use different resultDimension values to generate results of different dimensions.
IntersectMultidimension Constructs the set-theoretic intersection of the inputs. The results are returned in a geometry bag with one element per result dimension.
IsKnownSimple Indicates whether this geometry is known (or assumed) to be topologically correct.
IsKnownSimple Indicates whether this geometry is known (or assumed) to be topologically correct.
IsSimple Indicates whether this geometry is known (or assumed) to be topologically correct, after explicitly determining this if the geometry is not already known (or assumed) to be simple.
IsSimpleEx Determines why a geometry is not simple. Currently only implemented for polygons.
QueryClipped Redefines clippedGeometry to be the intersection of this geometry and the clipping envelope.
QueryClippedDense Redefines clippedGeometry to be the intersection of this geometry and the clipping envelope; densifies lines in the output contributed by the clipping envelope.
Simplify Makes this geometry topologically correct.
SymmetricDifference Constructs the geometry that contains points from either but not both input geometries.
Union Constructs the geometry that is the set-theoretic union of the input geometries.

  CoClasses that implement ITopologicalOperator

CoClasses and Classes Description
GeoEllipse (esriDefenseSolutions) Its a spheroidal ellipse.
GeometryBag An ordered collection of objects that support the IGeometry interface.
GeoPolygon (esriDefenseSolutions) Its a spheroidal polygon.
GeoPolyline (esriDefenseSolutions) This is a spheroidal polyline.
MultiPatch A collection of surface patches.
Multipoint An ordered collection of points; optionally has measure, height and ID attributes.
Point A two dimensional point, optionally with measure, height, and ID attributes.
Polygon A collection of rings ordered by their containment relationship; optionally has measure, height and ID attributes.
Polyline An ordered collection of paths; optionally has measure, height and ID attributes.

※ | ※ → 公共代码部分:

//公共变量!~

IMap pMap;
IActiveView pActiveView;
IEnvelope pEnv;
ISelectionEnvironment pSelectionEnv;
IEnumFeature pEnumFeature;
IGraphicsContainer pGraphicsContainer;
IFeature pFeature;
IGeometry pGeometry;
IEnvelope pEnvClip;
IPolyline pLineCut;
IPolygon pFirstPolygon;

//鼠标点击事件!~

private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)

    axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
    if (isClip) //此时要拉Clip框
    
        pEnvClip = axMapControl1.TrackRectangle();
        isClip = false;
    
    else if (isCut)
    
        pLineCut = axMapControl1.TrackLine() as IPolyline;
        isCut = false;
    
    else if (isFirstIn)
    
        pMap = axMapControl1.Map;
        pActiveView = pMap as IActiveView;
        pEnv = axMapControl1.TrackRectangle();

        pSelectionEnv = new SelectionEnvironment();
        pSelectionEnv.DefaultColor = GetColor(0, 255, 0);
        pMap.SelectByShape(pEnv, pSelectionEnv, false);
        pActiveView.Refresh();
        pEnumFeature = axMapControl1.Map.FeatureSelection as IEnumFeature;
    
    else
    
        pMap = axMapControl1.Map;
        pActiveView = pMap as IActiveView;
        pEnv = axMapControl1.TrackRectangle();

        pSelectionEnv = new SelectionEnvironment();
        pSelectionEnv.DefaultColor = GetColor(255, 0, 0);
        pMap.SelectByShape(pEnv, pSelectionEnv, false);
        pActiveView.Refresh();
        pEnumFeature = axMapControl1.Map.FeatureSelection as IEnumFeature;
    

//RGB颜色!~

private IRgbColor GetColor(int r, int g, int b)

    IRgbColor pColor = new RgbColor();
    pColor.Red = r;
    pColor.Green = g;
    pColor.Blue = b;
    return pColor;

 

※ | ※ → Buffer:

private void button1_Click(object sender, EventArgs e)

    while (true)
    
        pGraphicsContainer = pMap as IGraphicsContainer;    //定义容器
        pFeature = pEnumFeature.Next();     //遍历要素
        if (pFeature == null)            //若不存在要素,则推出循环
            break;
        pGeometry = pFeature.Shape;     //获取要素的Geometry
        ITopologicalOperator pTopoOperator = pGeometry as ITopologicalOperator; //QI到拓扑操作
        IGeometry pBufferGeo = pTopoOperator.Buffer(2);     //缓冲区分析

        IElement pElement = new PolygonElement();
        pElement.Geometry = pBufferGeo;     //获取得到的缓冲区

        pGraphicsContainer.AddElement(pElement, 0); //显示缓冲区
        pActiveView.Refresh();
    

 

※ | ※ → Boundary:

private void button2_Click(object sender, EventArgs e)

    while (true)
    
        pGraphicsContainer = pMap as IGraphicsContainer;    //定义容器
        pFeature = pEnumFeature.Next();     //遍历要素
        if (pFeature == null)            //若不存在要素,则推出循环
            break;
        pGeometry = pFeature.Shape;     //获取要素的Geometry
        ITopologicalOperator pTopoOperator = pGeometry as ITopologicalOperator; //QI到拓扑操作
        IGeometry pBoundary = pTopoOperator.Boundary;  //获取边界

        ILineElement pLineEle = new LineElementClass();
        ISimpleLineSymbol pSLS = new SimpleLineSymbol();
        IRgbColor pColor = GetColor(0, 255, 0);
        pSLS.Color = pColor;
        pSLS.Width = 5;
        pLineEle.Symbol = pSLS;

        IElement pElement = pLineEle as IElement;
        pElement.Geometry = pBoundary;

        pGraphicsContainer.AddElement(pElement, 0); //显示边界
        pActiveView.Refresh();
    

 

※ | ※ → Clip:

bool isClip = false;
private void button3_Click(object sender, EventArgs e)

    isClip = true;


private void button4_Click(object sender, EventArgs e)

    while (true)
    
        pGraphicsContainer = pMap as IGraphicsContainer;    //定义容器
        pFeature = pEnumFeature.Next();     //遍历要素
        if (pFeature == null)            //若不存在要素,则推出循环
            break;
        pGeometry = pFeature.Shape;     //获取要素的Geometry
        ITopologicalOperator pTopoOperator = pGeometry as ITopologicalOperator; //QI到拓扑操作
        pTopoOperator.Clip(pEnvClip);

        IElement pElement = new PolygonElement();
        pElement.Geometry = pGeometry;     //获取得到的缓冲区

        pGraphicsContainer.AddElement(pElement, 0); //显示缓冲区
        pActiveView.Refresh();
    

 

※ | ※ → ConvexHull:

private void button5_Click(object sender, EventArgs e)

    while (true)
    
        pGraphicsContainer = pMap as IGraphicsContainer;    //定义容器
        pFeature = pEnumFeature.Next();     //遍历要素
        if (pFeature == null)            //若不存在要素,则推出循环
            break;
        pGeometry = pFeature.Shape;     //获取要素的Geometry
        ITopologicalOperator pTopoOperator = pGeometry as ITopologicalOperator; //QI到拓扑操作
        IGeometry pBufferGeo = pTopoOperator.ConvexHull();

        IElement pElement = new PolygonElement();
        pElement.Geometry = pBufferGeo;     //获取得到的缓冲区

        pGraphicsContainer.AddElement(pElement, 0); //显示缓冲区
        pActiveView.Refresh();
    

 

※ | ※ → Cut:

bool isCut = false;

private void button6_Click(object sender, EventArgs e)

    isCut = true;


private void button7_Click(object sender, EventArgs e)

    while (true)
    
        pGraphicsContainer = pMap as IGraphicsContainer;    //定义容器
        pFeature = pEnumFeature.Next();     //遍历要素
        if (pFeature == null)            //若不存在要素,则推出循环
            break;
        pGeometry = pFeature.Shape;     //获取要素的Geometry
        ITopologicalOperator pTopoOperator = pGeometry as ITopologicalOperator; //QI到拓扑操作ry
        IGeometry pGeoRight = new PolygonClass();
        IGeometry pGeoLeft = new PolygonClass();
        pTopoOperator.Cut(pLineCut, out pGeoLeft, out pGeoRight);

        IElement pElement = new PolygonElement();

        IFillShapeElement pFillEle = pElement as IFillShapeElement;
        ISimpleFillSymbol pSFS = new SimpleFillSymbol();
        pSFS.Color = GetColor(255, 255, 0);
        pFillEle.Symbol = pSFS;

        pElement.Geometry = pGeoLeft;     //获取得到的缓冲区
        pGraphicsContainer.AddElement(pElement, 0); //<

以上是关于ArcEngine实现空间分析的主要内容,如果未能解决你的问题,请参考以下文章

ArcEngine实现空间分析

ArcEngine空间分析

ArcEngine查询添加删除要数的方法

arcengine featureclass里怎么添加feature

ArcEngine——获取要素几何(非游标方式)

arcEngine开发之IMapControl接口