(转载)ArcGIS Engine中各种点的创建方法

点(Point)代表了一个0纬的具有X、Y坐标的几何对象。点是没有任何形状的,可用于描述点类型的要素,而且Geometry中的任何类型都是用点来产生的。

   构成几何形状的顶点存在3种可以选择的属性,即Z、M和ID。Z值在大多数情况下都可用于表示一个点的Z坐标,还可以将Z值作为一个点的辅助值来使用;M即度量值,可以一个路径对象的线性度量,用于交通工程中一条公路的不同点的位置;ID值即作为一个点的唯一标识值。

  点击(Multipoint)是具有相同属性的点的集合,用于构建高级几何对象、几何对象动态模拟等。

  IPoint接口定义了Point对象的属性和方法,点(Point)可以使用PutCoods方法创建,也可以使用IConstructPoint借口来创建。IConstructPoint接口提供了10种创建点的方法,下面分别介绍:

   (1) ConstructAlong 沿线创建法:基于一个曲线上的起始点对象,通过给定距离、比例和扩展类型,沿着曲线创建一个新点。如果距离比曲线的长度长,那么点将沿着它的切线生成。其扩展参数如下:

   EsriNoExtension:没有扩展。在这种方式下构建点将始终在输入曲线上。如果距离小于0,则构建点在曲线的起点;如果输入距离大于曲线的长度,则构建点在曲线的终点。

   EsriExtendTangentAtFrom:起点切线。在这种方式下,如果输入距离小于0,则构建点在曲线起点的切线且与曲线反方向的距离位置上。

  EsriExtendTangentAtTo:终点切线。在这种方式下,如果距离大于曲线,则构建点放在曲线终点的切线且与曲线反方向的距离位置上。

  EsriExtendEmbeddedAtFrom:与起点切线类似,但使用嵌入几何不是切线。

  EsriExtendEmbeddedAtTo:与终点切线类似,但使用嵌入几何不是切线。

   EsriExtendEmbedded:在这种方式下,根据输入距离自动使用esriExtendEmbeddedAtFrom或esriExtendEmbeddedAtTo创建构建点。

 EsriExtendTranGents:在这种方式下,根据输入距离自动使用esriExtendTangentAtFrom或esriExtendTangentAtTo创建构建点。

(2)ConstructAngleBisector 角平分线构建法:这种方法使用3个点,即起点(FromPoint)、经由点(Through Point)和终止点(ToPoint)。该方法通过平分3点形成的夹角,并设置一个距离在平分线上寻找一个点。

 (3)ConstructAngleDistance 构造角度距离法:通过一个给定点和一个相对点的绝对角度和距离构建一个点。

(4)ConstructAngleIntersection构建角度交点法:通过给定的两个点和两个角度产生两条线,然后在两条射线的焦点产生了一个焦点。

(5)ConstructDeflection构造偏转角度法:通过给一条基准线、一个偏转角度和一个距离,沿着线的偏转角度的射线方向一给定距离为之构建一个点。

(6)ConstructDeflectionIntersection构造偏转角交点法:通过指定一条线段作为基线,从该线段的起点和终点的偏转角度引出连个射线,然后再两条射线的焦点构建一个点。该方法的bRightSide指定偏转角在线段的左边或右边。

(7)ConstructOffset构造偏移点法:该方法通过指定一条曲线,沿着曲线的距离或比例进行水平偏移。可以设置参数Offset的值,如果值为正,则该点向右偏移;如果值为负,则向左偏移。其扩展参数如下:

   EsriNoExtension:没有扩展。在这种方式下构建点将始终再输入曲线上。如果输入距离小于0,则构建点在区县的起点;如果输入距离大于曲线的长度,则构建点在曲线的终点。

  EsriExtendTangentAtFrom:起点切线。在这种方式下,如果距离小于0,这构建点在曲线起点的切线且与·曲线同方向的距离位置上。

  EsriExtendTangentAfTo:终点切线。在这种方式下,输入距离大于曲线长度,则构建点放在曲线终点的切线且与曲线同方向的距离位置上。

  EsriExtendEmbeddedAtFrom:与起点切线类似,但使用嵌入几何不是切线。

  EsriExtendEmbeddedAtTo:与终点切线类似,但是用嵌入几何不是切线。

   EsriExtendEmbedded:在这种方式下,根据输入距离自动使用esriExtendEmbeddedAtFrom或esriExtendEmbeddedAtTo。

   EsriExtendTangents:在这种方式下,根据输入距离自动使用esriExtendTangentAtFrom或esriExtendTangentAtTo创建构建点。

   EsriExtendAtFrom:在这种方下,包括esriExtendTangentAtFrom和esriExtendEmbeddedAtFrom。

   EsriExtendAtTo:在这种方式下,包括了esriExtendTrangentAtTo和esriExtendEmbeddedAtTo。

   EsriExtendEmbeddedAtTo:在这种方式下,包括了esriExtendTangentAtTo和EsriExtendEmbeddedAtTo.

(8) ConstructParallel 构造平行线上的点:该方法是给一条路径Path、一个参考点Point以及一个距离或比率,在平行线上构建一个点。其扩展参数同ConstructOffset。

(9)ConstructPerpendicular  构造垂直线上点法:通过给定一条路径Path、一个参考点Point以及一个距离,在参考点与路径垂直的方向上,在给定距离为之构建一个点。

(10)ConstructThreePointResection  后方交会定点法:该方法即测量学中的后方交会定点法,即构建点对3个已知点进行观测,得到两个角度,然后确定构建点的位置。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Geometry;
namespace WindowsFormsApplication11
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void axLicenseControl1_Enter(object sender, EventArgs e)
        {
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            loadMapDocument();
        }
        //加载地图文档
        private void loadMapDocument()
        {
            OpenFileDialog openFileDialog;
            openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "打开地图文档";
            openFileDialog.Filter = "map document(*.mxd)|*.mxd";
            openFileDialog.ShowDialog();
            string filepath = openFileDialog.FileName;
            if (axMapControl1.CheckMxFile(filepath))
            {
                axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerArrowHourglass;
                axMapControl1.LoadMxFile(filepath);
          
                axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerDefault;
            }
            else
            {
                MessageBox.Show(filepath + "不是有效的地图文档");
            }
        }
        //获取线实体
        private ESRI.ArcGIS.Geodatabase.IFeature getPolylineFeature(string layerName)
        {
            int i = 0;
            ESRI.ArcGIS.Carto.ILayer layer = null;
            for ( i = 0; i < axMapControl1.LayerCount; i++)
            {
                layer = axMapControl1.Map.get_Layer(i);
                if (layer.Name.ToLower() == layerName)
                    break;
            }
            ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = layer as ESRI.ArcGIS.Carto.IFeatureLayer;
            ESRI.ArcGIS.Geodatabase.IFeatureClass featureclass = featureLayer.FeatureClass;
            ESRI.ArcGIS.Geodatabase.IQueryFilter queryfilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
            queryfilter.WhereClause = "";
            ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = featureclass.Search(queryfilter, true);
            ESRI.ArcGIS.Geodatabase.IFeature feature= featureCursor.NextFeature();
            if (feature != null)
            {
                return feature;
            }
            return null;
        }
        //获取所有的实体点
        private System.Collections.ArrayList getPointFeature(string layerName)
        {
            int i = 0;
            ESRI.ArcGIS.Carto.ILayer layer = null;
            for ( i = 0; i < axMapControl1.LayerCount; i++)
            {
                layer = axMapControl1.Map.get_Layer(i);
                if (layer.Name.ToLower() == layerName)
                {
                    break;
                }
            }
            ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = layer as ESRI.ArcGIS.Carto.IFeatureLayer;
            ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureLayer.FeatureClass;
            ESRI.ArcGIS.Geodatabase.IQueryFilter queryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
            queryFilter.WhereClause = "";
            ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = featureClass.Search(queryFilter, true);
            ESRI.ArcGIS.Geodatabase.IFeature feature = featureCursor.NextFeature();
            System.Collections.ArrayList features = new System.Collections.ArrayList();
            while (feature != null)
            {
                features.Add(feature as object);
                feature = featureCursor.NextFeature();
            }
            return features;
        }
        //添加实体点
        private void addFeature(string layername, ESRI.ArcGIS.Geometry.IPoint point)
        {
            int i = 0;
            ESRI.ArcGIS.Carto.ILayer layer = null;
            for ( i = 0; i < axMapControl1.LayerCount; i++)
            {
                layer = axMapControl1.Map.get_Layer(i);
                if (layer.Name.ToLower() == layername)
                {
                    break;
                }
            }
            ESRI.ArcGIS.Carto.IFeatureLayer featureLayer=layer as ESRI.ArcGIS.Carto.IFeatureLayer;
            ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureLayer.FeatureClass;
            ESRI.ArcGIS.Geodatabase.IDataset dataset = (ESRI.ArcGIS.Geodatabase.IDataset)featureClass;
            ESRI.ArcGIS.Geodatabase.IWorkspace workspace = dataset.Workspace;
            ESRI.ArcGIS.Geodatabase.IWorkspaceEdit workspaceEdit = (ESRI.ArcGIS.Geodatabase.IWorkspaceEdit)workspace;
            workspaceEdit.StartEditing(true);
            workspaceEdit.StartEditOperation();
            ESRI.ArcGIS.Geodatabase.IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
            ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = featureClass.Insert(true);
            featureBuffer.Shape = point;
            object featureOID = featureCursor.InsertFeature(featureBuffer);
            featureCursor.Flush();
            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
        }
        //构造偏移点法
        private void button7_Click(object sender, EventArgs e)
        {
            IPoint[] points = new IPoint[4];
            for (int i = 0; i < 4; i++)
                points[i] = new PointClass();
            points[0].PutCoords(0, 0);
            points[1].PutCoords(10, 0);
            points[2].PutCoords(20, 0);
            points[3].PutCoords(30, 0);
            IPointCollection polyline = new PolylineClass();
            IGeometryBridge geometryBridge = new GeometryEnvironmentClass();
            geometryBridge.AddPoints(polyline as IPointCollection4, ref points);
            IConstructPoint constructPointRight = new PointClass();
            IConstructPoint constructionPointLeft = new PointClass();
            constructPointRight.ConstructOffset(polyline as ICurve, esriSegmentExtension.esriNoExtension, 15, false, 5);
            IPoint outPoint1 = constructPointRight as IPoint;
            constructionPointLeft.ConstructOffset(polyline as ICurve, esriSegmentExtension.esriNoExtension, 1, false, -5);
            IPoint outPoint2 = constructionPointLeft as IPoint;
            addFeature("point", points[0]);
            addFeature("point", points[1]);
            addFeature("point", points[2]);
            addFeature("point", points[3]);
            addFeature("point", outPoint1);
            addFeature("point", outPoint2);
            axMapControl1.Refresh();
 
        }
        private void button11_Click(object sender, EventArgs e)
        {
          
            ESRI.ArcGIS.Carto.ILayer layer = null;
           
                layer = axMapControl1.Map.get_Layer(0);
             
            ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = layer as ESRI.ArcGIS.Carto.IFeatureLayer;
            ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureLayer.FeatureClass;
            ESRI.ArcGIS.Geodatabase.IQueryFilter queryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
            queryFilter.WhereClause = "";
            ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = featureClass.Search(queryFilter, true);
            ESRI.ArcGIS.Geodatabase.IFeature feature = featureCursor.NextFeature();
           // System.Collections.ArrayList features = new System.Collections.ArrayList();
            while (feature != null)
            {
                textBox1.Text = "搜索到" + feature.get_Value(25).ToString();
                Search(layer, feature.get_Value(0).ToString(), feature.get_Value(1) as ESRI.ArcGIS.Geometry.IPoint, feature.get_Value(25).ToString());
                feature = featureCursor.NextFeature();
            }
             
        }
         private void Search( ESRI.ArcGIS.Carto.ILayer layer,string FID,  ESRI.ArcGIS.Geometry.IPoint point,string name )
        {
     
         
            ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = layer as ESRI.ArcGIS.Carto.IFeatureLayer;
            ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureLayer.FeatureClass;
            ESRI.ArcGIS.Geodatabase.IQueryFilter queryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
            queryFilter.WhereClause = "";
            ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = featureClass.Search(queryFilter, true);
            ESRI.ArcGIS.Geodatabase.IFeature feature = featureCursor.NextFeature();
           // System.Collections.ArrayList features = new System.Collections.ArrayList();
            while (feature != null)
            {
               // features.Add(feature as object);
                if((feature.get_Value(0).ToString()!=FID))
                {
                    ESRI.ArcGIS.Geometry.IPoint pt=feature.get_Value(1) as ESRI.ArcGIS.Geometry.IPoint;
                    if(point.X==pt.X&& point.Y==pt.Y)
                    {
                         if(feature.get_Value(25).ToString()==name)
                        {
                             textBox1.Text = "删除" + feature.get_Value(0).ToString();
                             feature.Delete();
                            break;
                        }
                    }
                }
                feature = featureCursor.NextFeature();
               
                //feature.get_Value(0).ToString()
              
            }
             
        }
        //沿线创建点
         private void button1_Click(object sender, EventArgs e)
         {
             ESRI.ArcGIS.Geodatabase.IFeature polylineFeature;
             polylineFeature = getPolylineFeature("polyline");
             if (polylineFeature != null)
             {
                 ESRI.ArcGIS.Geometry.ICurve cure = polylineFeature.Shape as ESRI.ArcGIS.Geometry.ICurve;
                 ESRI.ArcGIS.Geometry.IConstructPoint constructPoint = new ESRI.ArcGIS.Geometry.PointClass();
                 constructPoint.ConstructAlong(cure, ESRI.ArcGIS.Geometry.esriSegmentExtension.esriNoExtension, 10, true);
                 ESRI.ArcGIS.Geometry.IPoint point1 = constructPoint as ESRI.ArcGIS.Geometry.IPoint;
                 constructPoint = new ESRI.ArcGIS.Geometry.PointClass();
                 constructPoint.ConstructAlong(cure, ESRI.ArcGIS.Geometry.esriSegmentExtension.esriNoExtension, 20, false);
                 ESRI.ArcGIS.Geometry.IPoint point2 = constructPoint as ESRI.ArcGIS.Geometry.IPoint;
                 addFeature("point", point1);
                 addFeature("point", point2);
             }
         }
        //角平分线创建法
         private void button2_Click(object sender, EventArgs e)
         {
             ESRI.ArcGIS.Geometry.IPoint point1, point2, point3, point4;
             point1 = new ESRI.ArcGIS.Geometry.PointClass();
             point2 = new ESRI.ArcGIS.Geometry.PointClass();
             point3 = new ESRI.ArcGIS.Geometry.PointClass();
             point1.PutCoords(0, 0);
             point2.PutCoords(0, 20);
             point3.PutCoords(20, 20);
             ESRI.ArcGIS.Geometry.IConstructPoint constructPoint = new ESRI.ArcGIS.Geometry.PointClass();
             constructPoint.ConstructAngleBisector(point1, point2, point3, 50, true);
             point4 = constructPoint as ESRI.ArcGIS.Geometry.IPoint;
             addFeature("point", point1);
             addFeature("point", point2);
             addFeature("point", point3);
             addFeature("point", point4);
             axMapControl1.Refresh();

         }
//构造角度距离法
         private void button3_Click(object sender, EventArgs e)
         {
             ESRI.ArcGIS.Geometry.IPoint point1, point2;
             point1 = new ESRI.ArcGIS.Geometry.PointClass();
             point1.PutCoords(0, 0);
             double distance = 20;
             double angle = 60;
             ESRI.ArcGIS.Geometry.IConstructPoint constructPoint = new ESRI.ArcGIS.Geometry.PointClass();
             double angleRad = angle * 2 * Math.PI / 360;
             constructPoint.ConstructAngleDistance(point1, angleRad, distance);
             point2 = constructPoint as ESRI.ArcGIS.Geometry.IPoint;
             addFeature("point", point1);
             addFeature("point", point2);
             axMapControl1.Refresh();
         }
//构造角度交点法
         private void button4_Click(object sender, EventArgs e)
         {
             ESRI.ArcGIS.Geometry.IPoint point1, point2;
             point1 = new ESRI.ArcGIS.Geometry.PointClass();
             point2 = new ESRI.ArcGIS.Geometry.PointClass();
             point1.PutCoords(0, 0);
             point2.PutCoords(10, 0);
             double angleRed1 = 45 * 2 * Math.PI / 360;
             double angleRed2 = 60 * 2 * Math.PI / 360;
             ESRI.ArcGIS.Geometry.IConstructPoint constructPoint = new ESRI.ArcGIS.Geometry.PointClass();
             constructPoint.ConstructAngleIntersection(point1, angleRed1, point2, angleRed2);
             addFeature("point", point1);
             addFeature("point", point2);
             addFeature("point", constructPoint as ESRI.ArcGIS.Geometry.IPoint);
             axMapControl1.Refresh();
         }
//构造偏转角度发
         private void button5_Click(object sender, EventArgs e)
         {
             IPoint fromPoint = new PointClass();
             fromPoint.PutCoords(0, 0);
             IPoint toPoint = new PointClass();
             toPoint.PutCoords(1, 1);
             ILine line = new LineClass();
             line.PutCoords(fromPoint, toPoint);
             double distance = 1.4142135623731;
             double angle = Math.PI / 4;
             IConstructPoint constructPoint = new PointClass();
             constructPoint.ConstructDeflection(line, distance, angle);
             IPoint point = constructPoint as IPoint;
             addFeature("point", fromPoint);
             addFeature("point", toPoint);
             addFeature("point", point);
             axMapControl1.Refresh();
         }
//构造偏转交点法
         private void button6_Click(object sender, EventArgs e)
         {
             IPoint fromPoint = new PointClass();
             fromPoint.PutCoords(0, 0);
             IPoint toPoint = new PointClass();
             toPoint.PutCoords(1,1);
             ILine line=new LineClass();
             line.PutCoords(fromPoint,toPoint);
             double startAnale=Math.PI/4;
             double endAngle=Math.PI/4;
             IConstructPoint constructPoint=new PointClass();
             constructPoint.ConstructDeflectionIntersection(line,startAnale,endAngle,false);
             IPoint point=constructPoint as IPoint;
             addFeature("point",fromPoint);
             addFeature("point",toPoint);
             addFeature("point",point);
             axMapControl1.Refresh();
         }
        //构造平行线上点法
         private void button8_Click(object sender, EventArgs e)
         {
             IPoint[] points = new IPoint[2];
             for (int i = 0; i < 2; i++)
             {
                 points[i] = new PointClass();
             }
             points[0].PutCoords(0, 0);
             points[1].PutCoords(20, 0);
             ISegment segment;
             ILine line = new LineClass();
             line.FromPoint = points[0];
             line.ToPoint = points[1];
             segment = line as ISegment;
             IPoint fromPoint = new PointClass();
             fromPoint.X = points[0].X + 10;
             fromPoint.Y = points[0].Y + 5;
             IConstructPoint constructPoint = new PointClass();
             constructPoint.ConstructParallel(segment, esriSegmentExtension.esriNoExtension, fromPoint, segment.Length);
             addFeature("point", points[0]);
             addFeature("point", points[1]);
             addFeature("point", constructPoint as IPoint);
             axMapControl1.Refresh();
         }
        //构造垂直线上点法
         private void button9_Click(object sender, EventArgs e)
         {
             IPoint[] points = new IPoint[2];
             for (int i = 0; i < 2; i++)
             {
                 points[i] = new PointClass();
             }
             points[0].PutCoords(0, 0);
             points[1].PutCoords(20, 0);
             ISegment segment;
             ILine line = new LineClass();
             line.FromPoint = points[0];
             line.ToPoint = points[1];
             segment = line as ISegment;
             IPoint fromPoint = new PointClass();
             fromPoint.X = points[0].X + 10;
             fromPoint.Y = points[0].Y + 10;
             IConstructPoint constructPoint = new PointClass();
             constructPoint.ConstructPerpendicular(segment, esriSegmentExtension.esriNoExtension, fromPoint, 3, false);
             addFeature("point", points[0]);
             addFeature("point", points[1]);
             addFeature("point", constructPoint as IPoint);
             axMapControl1.Refresh();
         }
        //后方交会定点法
         private void button10_Click(object sender, EventArgs e)
         {
             IPoint[] points = new IPoint[3];
             for (int i = 0; i < 3; i++)
             {
                 points[i] = new PointClass();
             }
             IConstructPoint constructPoint = new PointClass();
             points[0].PutCoords(0, 10);
             points[1].PutCoords(20, 20);
             points[2].PutCoords(0, 0);
             double angle1 = Math.PI / 4;
             double angle2 = Math.PI / 4;
             double angle3;
             try
             {
                 constructPoint.ConstructThreePointResection(points[0], angle1, points[1], angle2, points[2], out angle3);
                 addFeature("point", points[0]);
                 addFeature("point", points[1]);
                 addFeature("point", points[2]);
                 addFeature("point", constructPoint as IPoint);
             }
             catch (Exception ex)
             {
             }
             axMapControl1.Refresh();
         }
    }
}
 Multipoint对象是一个具有相同结构的点的集合,通过使用Add方法来添加一个点到集合中。这个过程需要使用IPointCollection接口完成,在IConstructMultipoint接口中定义了“ConstructArcPoints”、“ConstructDivideEqual”、“ConstructDivideLength”、“ConstructIntersection”、“ConstructTangent”等5种构造方法。
  (1)ConstructArcPoints构造圆弧点:通过给定的一段圆弧,返回该圆弧的起点、终点、圆心和切线的交点。
  (2)ConstructDivideEqual构造等分点法:通过一条曲线和需要返回的点数来产生一个点集合。
  (3)ConstructDivideLength构造等长点法:通过给定的一条曲线对象和已经定义的间距长度,返回所有处于这条曲线上的点。
  (4)ConstructIntersection构造交点法:通过给定的两条曲线对象,以及这两条曲线的延长线、切线,计算这些线的交点。
  (5)ConstructTangent构造切线点:通过一条曲线和一个指定的点,产生指定的点到曲线的切线。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
namespace WindowsFormsApplication12
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //加载地图文档
        private void loadMapDocument()
        {
            OpenFileDialog openFileDialog;
            openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "打开地图文档";
            openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
            openFileDialog.ShowDialog();
            string filepath = openFileDialog.FileName;
            if (axMapControl1.CheckMxFile(filepath))
            {
                axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerArrowHourglass;
                axMapControl1.LoadMxFile(filepath, 0, Type.Missing);
                axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerDefault;
            }
            else
            {
                MessageBox.Show(filepath + "不是有效的地图文档");
            }
        }
        //添加实体点
        private void addFeature(string layerName, ESRI.ArcGIS.Geometry.IPoint point)
        {
            int i = 0;
            ESRI.ArcGIS.Carto.ILayer layer = null;
            for (i = 0; i < axMapControl1.LayerCount; i++)
            {
                layer = axMapControl1.Map.get_Layer(i);
                if (layer.Name.ToLower() == layerName)
                {
                    break;
                }
            }
            ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = layer as ESRI.ArcGIS.Carto.IFeatureLayer;
            IFeatureClass featureClass = featureLayer.FeatureClass;
            IDataset dataset = (IDataset)featureClass;
            IWorkspace workspace = dataset.Workspace;
            IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;
            workspaceEdit.StartEditing(true);
            workspaceEdit.StartEditOperation();
            IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
            IFeatureCursor featureCursor = featureClass.Insert(true);
            featureBuffer.Shape = point;
            object featureOID = featureCursor.InsertFeature(featureBuffer);
            featureCursor.Flush();
            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
        }
        //构造圆弧点
        private void button1_Click(object sender, EventArgs e)
        {
            IPoint centerPoint = new PointClass();
            centerPoint.PutCoords(10, 0);
            IPoint fromPoint = new PointClass();
            fromPoint.PutCoords(0, 0);
            IPoint toPoint = new PointClass();
            toPoint.PutCoords(0, 20);
            IConstructCircularArc circularArcConstruction = new CircularArcClass();
            circularArcConstruction.ConstructThreePoints(fromPoint, centerPoint, toPoint, false);
            //勾画圆弧
            IConstructMultipoint constructMultipoint = new MultipointClass();
            constructMultipoint.ConstructArcPoints(circularArcConstruction as ICircularArc);
            IPointCollection pointCollection = constructMultipoint as IPointCollection;
            for (int i = 0; i < pointCollection.PointCount; i++)
            {
                addFeature("point", pointCollection.get_Point(i));
            }
            axMapControl1.Refresh();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            loadMapDocument();
        }
        //构造等分点
        private void button2_Click(object sender, EventArgs e)
        {
            IPoint centerPoint = new PointClass();
            centerPoint.PutCoords(10, 0);
            IPoint fromPoint = new PointClass();
            fromPoint.PutCoords(0, 0);
            IPoint toPoint = new PointClass();
            toPoint.PutCoords(0, 20);
            ICircularArc circularArcConstruction = new CircularArcClass();
            circularArcConstruction.PutCoords(fromPoint, centerPoint, toPoint, esriArcOrientation.esriArcClockwise);
            //勾画圆弧
            IConstructMultipoint constructMultipoint = new MultipointClass();
            constructMultipoint.ConstructDivideEqual(circularArcConstruction as ICurve, (int)circularArcConstruction.Length / 5);
            IPointCollection pointCollection = constructMultipoint as IPointCollection;
            for (int i = 0; i < pointCollection.PointCount; i++)
            {
                addFeature("point", pointCollection.get_Point(i));
            }
            axMapControl1.Refresh();
        }
        //构造等长点
        private void button3_Click(object sender, EventArgs e)
        {
            IPoint centerPoint = new PointClass();
            centerPoint.PutCoords(10, 0);
            IPoint fromPoint = new PointClass();
            fromPoint.PutCoords(0, 0);
            IPoint toPoint = new PointClass();
            toPoint.PutCoords(0, 20);
            ICircularArc circularArcConstruction = new CircularArcClass();
            circularArcConstruction.PutCoords(fromPoint, centerPoint, toPoint, esriArcOrientation.esriArcClockwise);
            //勾画圆弧
            IConstructMultipoint constructMultipoint = new MultipointClass();
            constructMultipoint.ConstructDivideLength(circularArcConstruction as ICurve, 10);
            IPointCollection pointCollection = constructMultipoint as IPointCollection;
            for (int i = 0; i < pointCollection.PointCount; i++)
            {
                addFeature("point", pointCollection.get_Point(i));
            }
            axMapControl1.Refresh();
        }
        //构造交点
        private void button4_Click(object sender, EventArgs e)
        {
            IPoint[] points = new IPoint[4];
            for (int i = 0; i < 4; i++)
            {
                points[i] = new PointClass();
            }
            points[0].PutCoords(15, 10);
            points[1].PutCoords(20, 60);
            points[2].PutCoords(40, 60);
            points[3].PutCoords(45, 10);
            //构造Bezier曲线
            IBezierCurveGEN bezierCurve = new BezierCurveClass();
            bezierCurve.PutCoords(ref points);
            IPoint centerPoint = new PointClass();
            centerPoint.PutCoords(30, 30);
            IPoint fromPoint = new PointClass();
            fromPoint.PutCoords(10, 10);
            IPoint toPoint = new PointClass();
            toPoint.PutCoords(50, 10);
            //勾画圆弧
            IConstructCircularArc circularArcConstruction = new CircularArcClass();
            circularArcConstruction.ConstructThreePoints(fromPoint, centerPoint, toPoint, false);
            object param0, param1, isTangentPoint;
            IConstructMultipoint constructMultipoint = new MultipointClass();
            constructMultipoint.ConstructIntersection(circularArcConstruction as ISegment, esriSegmentExtension.esriNoExtension, bezierCurve as ISegment, esriSegmentExtension.esriNoExtension, out param0, out param1, out isTangentPoint);
            IMultipoint multipoint = constructMultipoint as IMultipoint;
            IPointCollection pointCollection = multipoint as IPointCollection;
            for (int i = 0; i < pointCollection.PointCount; i++)
            {
                addFeature("point", pointCollection.get_Point(i));
            }
            axMapControl1.Extent = multipoint.Envelope;
            axMapControl1.Refresh();
        }
        //构造切线点
        private void button5_Click(object sender, EventArgs e)
        {
             IPoint[] points = new IPoint[4];
            for (int i = 0; i < 4; i++)
            {
                points[i] = new PointClass();
            }
            points[0].PutCoords(15, 10);
            points[1].PutCoords(20, 60);
            points[2].PutCoords(40, 60);
            points[3].PutCoords(45, 10);
            //构造Bezier曲线
            IBezierCurveGEN bezierCurve = new BezierCurveClass();
            bezierCurve.PutCoords(ref points);
            IPoint centerPoint = new PointClass();
           
            //勾画圆弧

            IConstructMultipoint constructMultipoint = new MultipointClass();
            constructMultipoint.ConstructTangent( bezierCurve as ICurve, points[1]);
            IMultipoint multipoint = constructMultipoint as IMultipoint;
            IPointCollection pointCollection = multipoint as IPointCollection;
            for (int i = 0; i < pointCollection.PointCount; i++)
            {
                addFeature("point", pointCollection.get_Point(i));
            }
          
            axMapControl1.Refresh();
        
        }
    }
}

你可能感兴趣的:(GIS,ArcGIS,Engine,点,创建,交点)