ArcEngine实现空间分析

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

●·● 目录:

A1 ………… ITopologicalOperator5 接口

A2 ………… IRelationalOperator 接口

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

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

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

●·● ITopologicalOperator5 接口

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

  Members
  Description
Read-only propertyBoundary
返回值: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.
MethodBuffer
(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 的关系!
MethodClip
(IEnvelope clipperEnvelope)
Constructs the intersection of this geometry and the specified envelope.
返回矩形部分的要素,直接作用在要素上面!
MethodClipDenseConstructs the intersection of this geometry and the specified envelope; densifies lines in output contributed by the clipping envelope.
MethodClipExConstructs the intersection of this geometry and the specified envelope.
MethodClipToDomainClips 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.
MethodConstructUnionDefines this geometry to be the union of the inputs. More efficient for unioning multiple geometries than calling Union repeatedly.
MethodConvexHullConstructs the convex hull of this geometry.
MethodCutSplits this geometry into a part left of the cutting polyline, and a part right of it.
MethodCut2Divides a geometry into multiple parts
MethodDifferenceConstructs the geometry containing points from this geometry but not the other geometry.
MethodGeoNormalizeExShifts longitudes, if need be, into a continuous range of 360 degrees.
MethodIntersectConstructs the geometry that is the set-theoretic intersection of the input geometries. Use different resultDimension values to generate results of different dimensions.
MethodIntersectMultidimensionConstructs the set-theoretic intersection of the inputs. The results are returned in a geometry bag with one element per result dimension.
Read-only propertyIsKnownSimpleIndicates whether this geometry is known (or assumed) to be topologically correct.
Write-only propertyIsKnownSimpleIndicates whether this geometry is known (or assumed) to be topologically correct.
Read-only propertyIsSimpleIndicates 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.
Read-only propertyIsSimpleExDetermines why a geometry is not simple. Currently only implemented for polygons.
MethodQueryClippedRedefines clippedGeometry to be the intersection of this geometry and the clipping envelope.
MethodQueryClippedDenseRedefines clippedGeometry to be the intersection of this geometry and the clipping envelope; densifies lines in the output contributed by the clipping envelope.
MethodSimplifyMakes this geometry topologically correct.
MethodSymmetricDifferenceConstructs the geometry that contains points from either but not both input geometries.
MethodUnionConstructs the geometry that is the set-theoretic union of the input geometries.
  CoClasses that implement ITopologicalOperator
CoClasses and ClassesDescription
GeoEllipse (esriDefenseSolutions)Its a spheroidal ellipse.
GeometryBagAn ordered collection of objects that support the IGeometry interface.
GeoPolygon (esriDefenseSolutions)Its a spheroidal polygon.
GeoPolyline (esriDefenseSolutions)This is a spheroidal polyline.
MultiPatchA collection of surface patches.
MultipointAn ordered collection of points; optionally has measure, height and ID attributes.
PointA two dimensional point, optionally with measure, height, and ID attributes.
PolygonA collection of rings ordered by their containment relationship; optionally has measure, height and ID attributes.
PolylineAn 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); //显示缓冲区

        pSFS = new SimpleFillSymbol();
        pSFS.Color = GetColor(255, 0, 255);
        pFillEle.Symbol = pSFS;

        pElement = new PolygonElement();
        pElement.Geometry = pGeoRight;     //获取得到的缓冲区
        pGraphicsContainer.AddElement(pElement, 0); //显示缓冲区

        pActiveView.Refresh();
    }
}
复制代码

 

※ | ※ → Union:

复制代码
private void button8_Click(object sender, EventArgs e)
{
    IGeometry pUnionGeo = new PolygonClass();
    pGraphicsContainer = pMap as IGraphicsContainer;    //定义容器

    while (true)
    {
        pFeature = pEnumFeature.Next();     //遍历要素
        if (pFeature == null)            //若不存在要素,则推出循环
            break;
        pGeometry = pFeature.Shape;     //获取要素的Geometry
        ITopologicalOperator pTopoOperator = pUnionGeo as ITopologicalOperator; //QI到拓扑操作ry
        pUnionGeo = pTopoOperator.Union(pGeometry);
    }

    IElement pElement = new PolygonElement();

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

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

    pActiveView.Refresh();
}
复制代码

 

※ | ※ → Intersect:

复制代码
bool isFirstIn = false;

private void button10_Click(object sender, EventArgs e)
{
    isFirstIn = true;
}

private void button11_Click(object sender, EventArgs e)
{
    isFirstIn = false;
    pFirstPolygon = new PolygonClass();
    while (true)
    {
        pFeature = pEnumFeature.Next();
        if (pFeature == null)
            break;
        pGeometry = pFeature.Shape;
        ITopologicalOperator pTopoOperator = pFirstPolygon as ITopologicalOperator;
        pFirstPolygon = pTopoOperator.Union(pGeometry) as IPolygon;
    }
}

private void button12_Click(object sender, EventArgs e)
{
    IGeometry pIntersectGeo = new PolygonClass();
    IGeometry pSecondPolygon = new PolygonClass();
    pGraphicsContainer = pMap as IGraphicsContainer;

    while (true)
    {
        pFeature = pEnumFeature.Next();
        if (pFeature == null)
            break;
        pGeometry = pFeature.Shape;
        ITopologicalOperator pTopoOperator = pSecondPolygon as ITopologicalOperator;
        pSecondPolygon = pTopoOperator.Union(pGeometry) as IPolygon;
    }

    ITopologicalOperator pTopo = pSecondPolygon as ITopologicalOperator;
    pIntersectGeo = pTopo.Intersect(pFirstPolygon, esriGeometryDimension.esriGeometry2Dimension) as  IPolygon;
    IElement pElement = new PolygonElementClass();
    pElement.Geometry = pIntersectGeo;
    pGraphicsContainer.AddElement(pElement, 0);
    IFeatureLayer pFeatureLayer = pMap.get_Layer(0) as IFeatureLayer;
    pFeatureLayer.Visible = false;
    pFeatureLayer = pMap.get_Layer(1) as IFeatureLayer;
    pFeatureLayer.Visible = false;
    pActiveView.Refresh();
}
复制代码

 

※ | ※ → Difference:(需要前面两部分)

复制代码
private void button13_Click(object sender, EventArgs e)
{
    IGeometry pIntersectGeo = new PolygonClass();
    IGeometry pSecondPolygon = new PolygonClass();
    pGraphicsContainer = pMap as IGraphicsContainer;

    while (true)
    {
        pFeature = pEnumFeature.Next();
        if (pFeature == null)
            break;
        pGeometry = pFeature.Shape;
        ITopologicalOperator pTopoOperator = pSecondPolygon as ITopologicalOperator;
        pSecondPolygon = pTopoOperator.Union(pGeometry) as IPolygon;
    }

    ITopologicalOperator pTopo = pSecondPolygon as ITopologicalOperator;
    pIntersectGeo = pTopo.Difference(pFirstPolygon) as IPolygon;
    IElement pElement = new PolygonElementClass();
    pElement.Geometry = pIntersectGeo;
    pGraphicsContainer.AddElement(pElement, 0);
    IFeatureLayer pFeatureLayer = pMap.get_Layer(0) as IFeatureLayer;
    pFeatureLayer.Visible = false;
    pFeatureLayer = pMap.get_Layer(1) as IFeatureLayer;
    pFeatureLayer.Visible = false;
    pActiveView.Refresh();
}
复制代码

 

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

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

●·● IRelationalOperator 接口

1. Provides access to members that determine if a certain spatial relationship exists between two geometries.

  Members
  Description
MethodContainsIndicates if this geometry contains the other geometry.
前者是否包含后者!
MethodCrossesIndicates if the two geometries intersect in a geometry of lesser dimension.
MethodDisjointIndicates if the two geometries share no points in common. Negate this result to compute the Intersect relation.
MethodEqualsIndicates if the two geometries are of the same type and define the same set of points in the plane.
MethodOverlapsIndicates if the intersection of the two geometries has the same dimension as one of the input geometries.
前者和后者是否有重叠!不包括包含关系!
MethodRelationIndicates if the defined relationship exists.
MethodTouchesIndicates if the boundaries of the geometries intersect.
MethodWithinIndicates if this geometry is contained (is within) another geometry.
前者是否在后者内部!
  CoClasses that implement IRelationalOperator
CoClasses and ClassesDescription
EnvelopeA rectangle with sides parallel to a coordinate system defining the extent of another geometry; optionally has min and max measure, height and ID attributes.
GeometryBagAn ordered collection of objects that support the IGeometry interface.
MultiPatchA collection of surface patches.
MultipointAn ordered collection of points; optionally has measure, height and ID attributes.
PointA two dimensional point, optionally with measure, height, and ID attributes.
PolygonA collection of rings ordered by their containment relationship; optionally has measure, height and ID attributes.
PolylineAn ordered collection of paths; optionally has measure, height and ID attributes.

※ | ※ → 公共代码部分:

复制代码
IMap pMap;
IActiveView pActiveView;
IEnvelope pEnv;
ISelectionEnvironment pSelectionEnv;
IEnumFeature pEnumFeature;
IFeature pFeature;
IGeometry pGeometry;
IGeometry pBasicGeo;
复制代码
复制代码
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
    axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
    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 = pMap.FeatureSelection as IEnumFeature;
}
复制代码
复制代码
private IRgbColor GetColor(int r, int g, int b)
{
    IRgbColor pColor = new RgbColor();
    pColor.Red = r;
    pColor.Green = g;
    pColor.Blue = b;
    return pColor;
}
复制代码
复制代码
private IGeometry GetBasicGeometry()
{
    IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(1) as IFeatureLayer;
    IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
    IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
    IFeature pF = pFeatureCursor.NextFeature();
    IGeometry pUnionGeo = new PolygonClass();
    pUnionGeo = pF.Shape;
    while(pF != null)
    {
        ITopologicalOperator pUnionTopo = pUnionGeo as ITopologicalOperator;
        pUnionGeo = pUnionTopo.Union(pF.Shape);
        pF = pFeatureCursor.NextFeature();
    }
    return pUnionGeo;
}
复制代码
private void Form1_Load(object sender, EventArgs e)
{
    (axMapControl1.get_Layer(1) as IFeatureLayer).Selectable = false;
}

 

※ | ※ → Contains:

复制代码
private void button5_Click(object sender, EventArgs e)
{
    pBasicGeo = GetBasicGeometry();
    pGeometry = new PolygonClass();
    while (true)
    {
        pFeature = pEnumFeature.Next();
        if (pFeature == null)
            break;
        ITopologicalOperator pTopo = pGeometry as ITopologicalOperator;
        pGeometry = pTopo.Union(pFeature.Shape);
    }

    IRelationalOperator pRO = pBasicGeo as IRelationalOperator;
    bool IsContains = pRO.Contains(pGeometry);
    if (IsContains)
    {
        MessageBox.Show("Basic图层数据 包含 选中数据!");
    }
    else
    {
        MessageBox.Show("Basic图层数据 不包含 选中数据!");
    }
}
复制代码

 

※ | ※ → Overlaps:

复制代码
private void button2_Click(object sender, EventArgs e)
{
    pBasicGeo = GetBasicGeometry();
    pGeometry = new PolygonClass();
    while (true)
    {
        pFeature = pEnumFeature.Next();
        if (pFeature == null)
            break;
        ITopologicalOperator pTopo = pGeometry as ITopologicalOperator;
        pGeometry = pTopo.Union(pFeature.Shape);
    }

    IRelationalOperator pRO = pGeometry as IRelationalOperator;
    bool IsContains = pRO.Overlaps(pBasicGeo);
    if (IsContains)
    {
        MessageBox.Show("选中数据 重叠 Basic图层数据!");
    }
    else
    {
        MessageBox.Show("选中数据 不重叠 Basic图层数据!");
    }
}
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ArcEngine是Esri公司基于ArcGIS平台开发的一套GIS开发工具包。其中的缓冲区分析是指在地理空间数据中根据一定的距离或者区域范围,在目标要素周围生成一个特定的缓冲区,用于分析和描述目标要素周围的空间关系和属性。 缓冲区分析在许多GIS应用中都是一个非常重要的功能,它可以通过计算和定义缓冲区范围,帮助用户理解和分析地理空间数据。在ArcEngine中,通过使用BufferGeoprocessor类可以实现缓冲区分析。 在进行缓冲区分析之前,首先需要将目标要素加载到ArcEngine中,并确定所需的缓冲区距离或者区域范围。然后通过BufferGeoprocessor类的方法,设置缓冲区的参数和属性,如距离单位、缓冲区类型等。 通过调用BufferGeoprocessor类的execute方法,可以开始进行缓冲区分析操作。在执行过程中,ArcEngine会根据所设置的参数将缓冲区应用到目标要素周围,并生成新的几何要素,形成缓冲区图形。用户可以根据需要保存缓冲区的结果或者将结果用于后续的空间分析和地图展示等操作。 缓冲区分析可以广泛应用于不同的领域,比如环境规划、交通规划、土地利用规划等。通过ArcEngine提供的缓冲区分析功能,用户可以更加直观地分析和描述地理空间数据,帮助做出科学决策。同时,ArcEngine还提供了许多其他的地理空间分析工具和功能,可以进一步扩展和应用缓冲区分析的功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值