I am trying to get the length of a drawn line to a textbox but its throwing an NullReferenceException at var length = f.ToShape().ToGeometry().Length;. what else should i use in the code to finish this exception. ? Any way to fix it and get the length of the line to a textbox? I am using Dot-Spatial 1.70
Code:
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); myDigitizedPoints.Add(c); } } 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); 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); fs.Projection = map1.Projection; fs.Name = "Mine"; //fs.SaveAs(GraphicsPathExt, true); //LineLyr = (DotSpatial.Controls.MapLineLayer)map1.AddLayer(GraphicsPathExt); LineLyr = (MapLineLayer)map1.Layers.Add(fs); var length = f.ToShape().ToGeometry().Length; textBox1.Text = length.ToString(); } }
أكثر...
Code:
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); myDigitizedPoints.Add(c); } } 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); 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); fs.Projection = map1.Projection; fs.Name = "Mine"; //fs.SaveAs(GraphicsPathExt, true); //LineLyr = (DotSpatial.Controls.MapLineLayer)map1.AddLayer(GraphicsPathExt); LineLyr = (MapLineLayer)map1.Layers.Add(fs); var length = f.ToShape().ToGeometry().Length; textBox1.Text = length.ToString(); } }
أكثر...