我正在开发一个GIS应用程序。我想用绘制的线条打开一个特定的表单。将打开的表单包含一个显示行长度的文本框。我可以选择该行。我能够得到线的长度。
我想将表单与每一行链接起来。并且只要选择该行,就应显示相同的表格。我该怎么做? 我应该去序列化吗?或者有什么好的解决方案吗?
我知道这是与GIS有关的事情,但它更像是一个C#问题。
代码:
private bool amDigitizing = false;
//Coordiant
private List<DotSpatial.Topology.Coordinate> myDigitizedPoints = new List<DotSpatial.Topology.Coordinate>();
private List<DotSpatial.Topology.Coordinate> myExtractedPoints = new List<DotSpatial.Topology.Coordinate>();
// DEM Layer
private DotSpatial.Controls.MapRasterLayer demLyr;
// Line Layer
private DotSpatial.Controls.MapLineLayer LineLyr;
FormTableEditor ft = new FormTableEditor();
public Form1()
{
InitializeComponent();
appManager1.LoadExtensions();
appManager1.CompositionContainer.ComposeParts(toolManager1);
}
private void map1_MouseMove(object sender, MouseEventArgs e)
{
Coordinate c_mouse = map1.PixelToProj(new System.Drawing.Point(e.X, e.Y));
Xstrip.Text = "X:" + Convert.ToString(c_mouse.X);
Ystrip.Text = "Y:" + Convert.ToString(c_mouse.Y);
}
private void btnDraw_Click(object sender, EventArgs e)
{
try
{
//map1.Layers.Remove(LineLyr);
}
catch
{
// do nothing
}
// Start a Drawing
MessageBox.Show(" Click on the map to draw, double click to stop drawing");
amDigitizing = true;
myDigitizedPoints = new List<DotSpatial.Topology.Coordinate>();
map1.FunctionMode = DotSpatial.Controls.FunctionMode.None;
}
private void map1_MouseClick_1(object sender, MouseEventArgs e)
{
// digitizing
if (amDigitizing == true)
{
DotSpatial.Topology.Coordinate c = new DotSpatial.Topology.Coordinate();
System.Drawing.Point p = new System.Drawing.Point();
p.X = e.X;
p.Y = e.Y;
c = map1.PixelToProj(p);
//double[] s = c.ToArray();
//StartX = s[0];
//StartY = s[1];
myDigitizedPoints.Add(c);
}
}
int NoOfMines = 0;
private void map1_MouseDoubleClick_1(object sender, MouseEventArgs e)
{
// Double click ends digitizing
if (amDigitizing == true)
{
DotSpatial.Topology.Coordinate c = new DotSpatial.Topology.Coordinate();
System.Drawing.Point p = new System.Drawing.Point();
p.X = e.X;
p.Y = e.Y;
c = map1.PixelToProj(p);
myDigitizedPoints.Add(c);
//double[] s = c.ToArray();
//EndX = s[0];
//EndY = s[1];
amDigitizing = false;
DotSpatial.Data.Feature f = new DotSpatial.Data.Feature(DotSpatial.Topology.FeatureType.Line, myDigitizedPoints);
DotSpatial.Data.FeatureSet fs = new DotSpatial.Data.FeatureSet();
fs.AddFeature(f);
NoOfMines = NoOfMines +1 ;
fs.Projection = map1.Projection;
for (int i = 0; i < NoOfMines; i++)
{
fs.Name = "Mine Field" + NoOfMines.ToString();
}
//fs.SaveAs(GraphicsPathExt, true);
//LineLyr = (DotSpatial.Controls.MapLineLayer)map1.AddLayer(GraphicsPathExt);
LineLyr = (MapLineLayer)map1.Layers.Add(fs);
}
}
// Length of the line
private void mnuThin_Click(object sender, EventArgs e)
{
LineLyr.Symbolizer.SetFillColor(Color.Red);
LineLyr.Symbolizer.SetWidth(5.0);
LineLyr.Symbolizer.SetOutline(Color.White, 1.0);
map1.Refresh();
IRaster r = (IRaster)map1.Layers[0].DataSet;
IFeatureSet fs = LineLyr.DataSet;
int np = 0;
try
{
foreach (IFeature f in fs.Features)
{
np += f.Coordinates.Count * 100;
}
}
catch
{
}
double[] plotX = new double[np - 99];
double[] plotY = new double[np - 99];
double x1= 0, y1 = 0, x2 = 0 , y2 = 0 , dx = 0 , dy = 0, newx = 0, newy = 0;
double z = 0;
double TotalLength = 0.0;
int i = 0;
double[] Slope = new double[np / 100];
foreach (IFeature f in fs.Features)
{
foreach (DotSpatial.Topology.Coordinate c in f.Coordinates)
{
x2 = c.X;
y2 = c.Y;
if (i > 0)
{
dx = (x2 - x1) / 100;
dy = (y2 - y1) / 100;
newx = x1;
newy = y1;
for (int j = 0; j < 100; j++)
{
TotalLength += Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));
z = demLyr.DataSet.GetNearestValue(newx, newy);
i += 1;
}
}
x1 = x2;
y1 = y2;
if (i == 0)
{
z = demLyr.DataSet.GetNearestValue(newx, newy);
i += 1;
x1 = x2;
y1 = y2;
}
}
}
//Length of the line
ft.textBox1.Text = TotalLength.ToString();
}
//Selection of layer
private void customizeToolStripMenuItem_Click(object sender, EventArgs e)
{
IMapLayer layerSelect = appManager1.Map.Layers.SelectedLayer;
if (layerSelect == LineLyr)
{
ft.Show();
}
}