(轉載)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();
}
}
}