📄 mainwindow.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.ToolbarControl;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.MapControl;
using ESRI.ArcGIS.DataSourcesFile;
using System.Diagnostics;
namespace D_sanjiao
{
public partial class MainWindow : Form
{
public MainWindow()
{
InitializeComponent();
}
bool sanjiao = true;
DelaunyBuilder test;
string filename;
List<DPoint> points = new List<DPoint>();
private void MainWindow_Load(object sender, EventArgs e)
{
UID uID = new UIDClass();
uID.Value = "esriControlCommands.ControlsSelectFeaturesTool";
axToolbarControl1.AddItem(uID, -1, -1, false, -1, esriCommandStyles.esriCommandStyleIconOnly);
uID.Value = "esriControlCommands.ControlsMapNavigationToolbar";
axToolbarControl1.AddItem(uID, -1, -1, false, -1, esriCommandStyles.esriCommandStyleIconOnly);
}
private IRgbColor GetRGBColor(int red, int green, int blue)
{
//Create rgb color and grab hold of the IRGBColor interface
IRgbColor rGB = new RgbColorClass();
//Set rgb color properties
rGB.Red = red;
rGB.Green = green;
rGB.Blue = blue;
rGB.UseWindowsDithering = true;
return rGB;
}
private void button1_Click(object sender, EventArgs e)
{
test = new DelaunyBuilder(points);
test.BuildTIN();
StartDrawTri = true;
this.Refresh();
button1.Enabled = false;
//ESRI.ArcGIS.Geometry.Point now1=new ESRI.ArcGIS.Geometry.PointClass();
//now1.X = test.TriangleList[0].point1.x;
//now1.Y = test.TriangleList[0].point1.y;
//now1.Z = test.TriangleList[0].point1.z;
//ESRI.ArcGIS.Geometry.Point now2 = new ESRI.ArcGIS.Geometry.PointClass();
//now2.X = test.TriangleList[0].point2.x;
//now2.Y = test.TriangleList[0].point2.y;
//now2.Z=test.TriangleList[0].point2.z;
//ESRI.ArcGIS.Geometry.Point now3 = new ESRI.ArcGIS.Geometry.PointClass();
//now3.X = test.TriangleList[0].point3.x;
//now3.Y = test.TriangleList[0].point3.y;
//now3.Z = test.TriangleList[0].point3.z;
//IPolyline l1 = new PolylineClass();
//l1.FromPoint = now1;
//l1.ToPoint = now2;
//SimpleLineSymbol s1 = new SimpleLineSymbol();
//s1.Color = GetRGBColor(100, 100, 100);
//s1.Width = 3;
//object o = s1;
//axMapControl1.DrawShape(l1, ref o);
//axMapControl1.FlashShape(l1, 1, 2, o);
//ITopologicalOperator topologicalOperator = (ITopologicalOperator)now1;
//IPolygon polygon = (IPolygon)topologicalOperator.Buffer(axMapControl1.Extent.Width * 0.02);
//IRelationalOperator relationalOperator = (IRelationalOperator)polygon;
//object o = null;
//axMapControl1.DrawShape(l1, ref o);
}
bool StartDrawTri = false;
bool StartDrawTaisen = false;
private void axMapControl1_OnAfterDraw(object sender, ESRI.ArcGIS.MapControl.IMapControlEvents2_OnAfterDrawEvent e)
{
if (StartDrawTri == true)
{
foreach (DTiangle temp in test.TriangleList)
{
ESRI.ArcGIS.Geometry.Point now1 = new ESRI.ArcGIS.Geometry.PointClass();
now1.X = temp.point1.x;
now1.Y = temp.point1.y;
now1.Z = temp.point1.z;
ESRI.ArcGIS.Geometry.Point now2 = new ESRI.ArcGIS.Geometry.PointClass();
now2.X = temp.point2.x;
now2.Y = temp.point2.y;
now2.Z = temp.point2.z;
ESRI.ArcGIS.Geometry.Point now3 = new ESRI.ArcGIS.Geometry.PointClass();
now3.X = temp.point3.x;
now3.Y = temp.point3.y;
now3.Z = temp.point3.z;
SimpleLineSymbol s1 = new SimpleLineSymbol();
s1.Color = GetRGBColor(94,198,104);
s1.Width = 1;
object o = s1;
IPolyline l1 = new PolylineClass();
l1.FromPoint = now1;
l1.ToPoint = now2;
axMapControl1.DrawShape(l1, ref o);
l1.FromPoint = now2;
l1.ToPoint = now3;
axMapControl1.DrawShape(l1, ref o);
l1.FromPoint = now3;
l1.ToPoint = now1;
axMapControl1.DrawShape(l1, ref o);
}
#region 一次画一条线,测试的使用用来检查哪一步有问题的
//for (int m = 0; m < thestep; m++)
//{
// ESRI.ArcGIS.Geometry.Point now1 = new ESRI.ArcGIS.Geometry.PointClass();
// now1.X = test.TriangleList[m].point1.x;
// now1.Y = test.TriangleList[m].point1.y;
// now1.Z = test.TriangleList[m].point1.z;
// ESRI.ArcGIS.Geometry.Point now2 = new ESRI.ArcGIS.Geometry.PointClass();
// now2.X = test.TriangleList[m].point2.x;
// now2.Y = test.TriangleList[m].point2.y;
// now2.Z = test.TriangleList[m].point2.z;
// ESRI.ArcGIS.Geometry.Point now3 = new ESRI.ArcGIS.Geometry.PointClass();
// now3.X = test.TriangleList[m].point3.x;
// now3.Y = test.TriangleList[m].point3.y;
// now3.Z = test.TriangleList[m].point3.z;
// ESRI.ArcGIS.Geometry.Point TheC = new ESRI.ArcGIS.Geometry.PointClass();
// TheC.X = test.TriangleList[m].TheC.x;
// TheC.Y = test.TriangleList[m].TheC.y;
// TheC.Z = test.TriangleList[m].TheC.z;
// SimpleLineSymbol s1 = new SimpleLineSymbol();
// s1.Color = GetRGBColor(100, 100, 100);
// s1.Width = 1;
// object o = s1;
// IPolyline l1 = new PolylineClass();
// l1.FromPoint = now1;
// l1.ToPoint = now2;
// axMapControl1.DrawShape(l1, ref o);
// l1.FromPoint = now2;
// l1.ToPoint = now3;
// axMapControl1.DrawShape(l1, ref o);
// l1.FromPoint = now3;
// l1.ToPoint = now1;
// axMapControl1.DrawShape(l1, ref o);
//}
#endregion
}
if (StartDrawTaisen == true)
{
foreach (DPoint temp in test.ThePoints)
{
for (int m = 0; m < temp.UseThis.Count - 1; m++)
{
ESRI.ArcGIS.Geometry.Point now1 = new ESRI.ArcGIS.Geometry.PointClass();
now1.X = temp.UseThis[m].TheC.x;
now1.Y = temp.UseThis[m].TheC.y;
now1.Z = temp.UseThis[m].TheC.z;
ESRI.ArcGIS.Geometry.Point now2 = new ESRI.ArcGIS.Geometry.PointClass();
now2.X = temp.UseThis[m + 1].TheC.x;
now2.Y = temp.UseThis[m + 1].TheC.y;
now2.Z = temp.UseThis[m + 1].TheC.z;
SimpleLineSymbol s1 = new SimpleLineSymbol();
s1.Color = GetRGBColor(234,163,58);
s1.Width = 1;
object o = s1;
IPolyline l1 = new PolylineClass();
l1.FromPoint = now1;
l1.ToPoint = now2;
axMapControl1.DrawShape(l1, ref o);
}
if (temp.IsClosed)
{
ESRI.ArcGIS.Geometry.Point nowlp = new ESRI.ArcGIS.Geometry.PointClass();
nowlp.X = temp.UseThis[temp.UseThis.Count - 1].TheC.x;
nowlp.Y = temp.UseThis[temp.UseThis.Count - 1].TheC.y;
nowlp.Z = temp.UseThis[temp.UseThis.Count - 1].TheC.z;
ESRI.ArcGIS.Geometry.Point nowfp = new ESRI.ArcGIS.Geometry.PointClass();
nowfp.X = temp.UseThis[0].TheC.x;
nowfp.Y = temp.UseThis[0].TheC.y;
nowfp.Z = temp.UseThis[0].TheC.z;
SimpleLineSymbol z1 = new SimpleLineSymbol();
z1.Color = GetRGBColor(234, 163, 58);
z1.Width = 1;
object s = z1;
IPolyline ll1 = new PolylineClass();
ll1.FromPoint = nowlp;
ll1.ToPoint = nowfp;
axMapControl1.DrawShape(ll1, ref s);
}
}
//foreach (DPoint temp in test.ThePoints)
//{
// foreach (DTiangle Ttemp in temp.UseThis)
// {
// SimpleLineSymbol s1 = new SimpleLineSymbol();
// s1.Color = GetRGBColor(60, 200, 100);
// s1.Width = 1;
// object o = s1;
// ESRI.ArcGIS.Geometry.Point nowTheC = new ESRI.ArcGIS.Geometry.PointClass();
// nowTheC.X = Ttemp.TheC.x;
// nowTheC.Y = Ttemp.TheC.y;
// nowTheC.Z = Ttemp.TheC.z;
// Debug.WriteLine(Ttemp.TheC.x + "," + Ttemp.TheC.y + "," + Ttemp.TheC.z);
// DLine theedge;
// theedge = Ttemp.edge1;
// if (theedge.Rtri != null)
// {
// ESRI.ArcGIS.Geometry.Point nebTheC = new ESRI.ArcGIS.Geometry.PointClass();
// nebTheC.X = theedge.Rtri.TheC.x;
// nebTheC.Y = theedge.Rtri.TheC.y;
// nebTheC.Z = theedge.Rtri.TheC.z;
// IPolyline l1 = new PolylineClass();
// l1.FromPoint = nowTheC;
// l1.ToPoint = nebTheC;
// axMapControl1.DrawShape(l1, ref o);
// }
// theedge = Ttemp.edge2;
// if (theedge.Rtri != null)
// {
// ESRI.ArcGIS.Geometry.Point nebTheC = new ESRI.ArcGIS.Geometry.PointClass();
// nebTheC.X = theedge.Rtri.TheC.x;
// nebTheC.Y = theedge.Rtri.TheC.y;
// nebTheC.Z = theedge.Rtri.TheC.z;
// IPolyline l1 = new PolylineClass();
// l1.FromPoint = nowTheC;
// l1.ToPoint = nebTheC;
// axMapControl1.DrawShape(l1, ref o);
// }
// theedge = Ttemp.edge3;
// if (theedge.Rtri != null)
// {
// ESRI.ArcGIS.Geometry.Point nebTheC = new ESRI.ArcGIS.Geometry.PointClass();
// nebTheC.X = theedge.Rtri.TheC.x;
// nebTheC.Y = theedge.Rtri.TheC.y;
// nebTheC.Z = theedge.Rtri.TheC.z;
// IPolyline l1 = new PolylineClass();
// l1.FromPoint = nowTheC;
// l1.ToPoint = nebTheC;
// axMapControl1.DrawShape(l1, ref o);
// }
// }
//}
}
}
private void button2_Click(object sender, EventArgs e)
{
StartDrawTaisen = true;
button2.Enabled = false;
this.Refresh();
}
private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
}
private void ChooseShp_Click(object sender, EventArgs e)
{
axMapControl1.ClearLayers();
FindShp.ShowDialog();
filename = FindShp.FileName;
if (filename == string.Empty)
{
MessageBox.Show("您没有选择一个Shape文件");
return;
}
this.Text += " (" + filename + ")";
axMapControl1.AddShapeFile(filename.Substring(0, filename.LastIndexOf('\\') + 1), filename.Substring(filename.LastIndexOf('\\')+1, filename.Length-filename.LastIndexOf('\\')-1));
try
{
IFeatureLayer temp = (IFeatureLayer)axMapControl1.get_Layer(0);
IFeature pFeature;
IQueryFilter query = new QueryFilterClass();
IQueryFilter query1 = new QueryFilterClass();
IFeatureCursor cur = temp.FeatureClass.Update(query, true);
pFeature = cur.NextFeature();
int sumFeature = temp.FeatureClass.FeatureCount(query1);
for (int x = 0; x < sumFeature; x++)
{
IPoint now = (IPoint)pFeature.get_Value(1);
DPoint tempver = new DPoint();
tempver.x = now.X;
tempver.y = now.Y;
tempver.z = now.Z;
points.Add(tempver);
//Debug.WriteLine(now.X + "," + now.Y);
cur.UpdateFeature(pFeature);
pFeature = cur.NextFeature();
}
button1.Enabled = true;
button2.Enabled = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -