internal M11Branch(branch BranchFromPFS, SortedDictionary <int, point> Points) { _pfsdata = BranchFromPFS; //Loop the POINTS for (int i = 0; i < _pfsdata.points.NumberOfParameters; i++) { M11Point mp = new M11Point(Points[_pfsdata.points.GetValue(i)]); _points.Add(mp); } //Sort by chainage _points.Sort(new Comparison <M11Point>((var1, var2) => var1.Chainage.CompareTo(var2.Chainage))); //Add to polyline Line = new XYPolyline(); foreach (var mp in _points) { Line.Points.Add(mp); } ID = new BranchID { Branchname = Name, StartChainage = ChainageStart }; CrossSections = new ObservableCollection <CrossSection>(); }
/// <summary> /// Method splitted to permit testing without reading DHI CrossSection /// </summary> /// <param name="P1"></param> /// <param name="P2"></param> /// <param name="Chainage"></param> public void SetPoints(IXYPoint P1, IXYPoint P2, double Chainage1, double Chainage2, double Chainage) { double dx = P2.X - P1.X; double dy = P2.Y - P1.Y; double dchainage = (Chainage - Chainage1) / (Chainage2 - Chainage1); MidStreamLocation = new XYPoint(P1.X + dchainage * dx, P1.Y + dchainage * dy); double lenght = Math.Pow(Math.Pow(dx, 2) + Math.Pow(dy, 2), 0.5); UnityVector = new XYPoint(dx / lenght, dy / lenght); //Now build the line where the cross section is located. if (_cs != null) { Line = new XYPolyline(); //MidPoint is set to where Marker 2 is placed double xOffset = _xsec.LowestPoint.X; for (int i = 0; i < _xsec.Points.Count(); i++) { Line.Points.Add(new XYPoint(MidStreamLocation.X - UnityVector.Y * (_xsec.Points[i].X - xOffset), MidStreamLocation.Y + UnityVector.X * (_xsec.Points[i].X - xOffset))); } } }
public MixingStream(string name, XYPolyline length, double width, double depth, int mixfactor) : base(name, length, width, depth) { for (int i = 0; i < mixfactor; i++) { _wbs.Add(new Stream(name + i.ToString(), Length / mixfactor, Width, Depth)); } }
public Stream(string name, double Length, double Width, double Depth) : base(name) { Line = new XYPolyline(); Line.Points.Add(new XYPoint(0, 0)); Line.Points.Add(new XYPoint(Length, 0)); this.Width = Width; this.Depth = Depth; }
public static XYExtent GetExtent(XYPolyline polyline) { XYExtent res = new XYExtent(); foreach (XYPoint point in polyline.Points) { res.Include(point.X, point.Y); } return(res); }
public void GetLength() { XYPolyline xyPolyline = new XYPolyline(); xyPolyline.Points.Add(new XYPoint(6, 2)); xyPolyline.Points.Add(new XYPoint(2, 2)); xyPolyline.Points.Add(new XYPoint(8, 2)); xyPolyline.Points.Add(new XYPoint(8, 4)); xyPolyline.Points.Add(new XYPoint(5, 4)); xyPolyline.Points.Add(new XYPoint(9, 7)); Assert.AreEqual((double)20, xyPolyline.GetLength()); }
public void SaveToShape(string ShapeFileName) { using (ShapeWriter sw = new ShapeWriter(ShapeFileName)) { DataTable dt = new DataTable(); dt.Columns.Add("LinkID", typeof(string)); dt.Columns.Add("FromNode", typeof(string)); dt.Columns.Add("ToNode", typeof(string)); dt.Columns.Add("SpecifiedLength", typeof(double)); foreach (var b in Links.Values) { GeoRefData grf = new GeoRefData(); var l = new XYPolyline(); l.Points.Add(new XYPoint(b.UpstreamNode.pfsnode.X, b.UpstreamNode.pfsnode.Y)); l.Points.Add(new XYPoint(b.DownstreamNode.pfsnode.X, b.DownstreamNode.pfsnode.Y)); grf.Geometry = l; grf.Data = dt.NewRow(); grf.Data[0] = b.pfslink.LinkID; grf.Data[1] = b.pfslink.FromNode; grf.Data[2] = b.pfslink.ToNode; grf.Data[3] = b.pfslink.SpecifiedLength; sw.Write(grf); } } if (Branches != null && Branches.Count > 0) { using (ShapeWriter sw = new ShapeWriter(Path.Combine(Path.GetDirectoryName(ShapeFileName), Path.GetFileNameWithoutExtension(ShapeFileName) + "_branches.shp"))) { DataTable dt = new DataTable(); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Length", typeof(double)); foreach (var b in Branches) { var line = new XYPolyline(); line.Points.AddRange(b.Links.Select(p => p.UpstreamNode.Location)); line.Points.Add(b.Links.Last().DownstreamNode.Location); GeoRefData grf = new GeoRefData(); grf.Geometry = line; grf.Data = dt.NewRow(); grf.Data[0] = b.Name; grf.Data[1] = line.GetLength(); sw.Write(grf); } } } }
public void Equals() { XYLine l1 = new XYLine(0, 3, 3, 0); XYLine l2 = new XYLine(0, 3, 3, 0); XYLine l3 = new XYLine(3, 3, 3, 0); XYPolyline pl1 = new XYPolyline(); pl1.Points.Add(new XYPoint(0, 3)); pl1.Points.Add(new XYPoint(3, 0)); Assert.AreEqual(true, l1.Equals(l1), "Test1"); Assert.AreEqual(true, l1.Equals(l2), "Test2"); Assert.AreEqual(false, l1.Equals(l3), "Test3"); Assert.AreEqual(false, l1.Equals(pl1), "Test4"); }
public static List <Stream> CreateBranch(int numberofWbs) { List <Stream> Branch = new List <Stream>(); for (int i = 0; i < numberofWbs; i++) { XYPolyline line = new XYPolyline(); line.Points.Add(new XYPoint(i, i)); line.Points.Add(new XYPoint(i + 1, i + 1)); Branch.Add(new Stream(i.ToString(), line, 1, 1)); if (i > 0) { Branch[i - 1].AddDownStreamWaterBody(Branch[i]); } } return(Branch); }
public void CalculatePolylineToPointDistance() { XYPolyline polyline = new XYPolyline(); polyline.Points.Add(new XYPoint(0, 0)); polyline.Points.Add(new XYPoint(1, 1)); polyline.Points.Add(new XYPoint(2, 2)); polyline.Points.Add(new XYPoint(4, 2)); polyline.Points.Add(new XYPoint(6, 0)); Assert.AreEqual(Math.Sqrt(2), XYGeometryTools.CalculatePolylineToPointDistance(polyline, new XYPoint(-1, -1)), 1e-12, "Test1"); Assert.AreEqual(Math.Sqrt(2), XYGeometryTools.CalculatePolylineToPointDistance(polyline, new XYPoint(2, 0)), 1e-12, "Test2"); Assert.AreEqual(0, XYGeometryTools.CalculatePolylineToPointDistance(polyline, new XYPoint(2, 2)), 1e-12, "Test3"); Assert.AreEqual(1, XYGeometryTools.CalculatePolylineToPointDistance(polyline, new XYPoint(3, 1)), 1e-12, "Test4"); Assert.AreEqual(1, XYGeometryTools.CalculatePolylineToPointDistance(polyline, new XYPoint(3, 3)), 1e-12, "Test5"); Assert.AreEqual(2, XYGeometryTools.CalculatePolylineToPointDistance(polyline, new XYPoint(3, 4)), 1e-12, "Test6"); Assert.AreEqual(0, XYGeometryTools.CalculatePolylineToPointDistance(polyline, new XYPoint(6, 0)), 1e-12, "Test7"); }
public void GetLine() { XYPolyline xyPolyline = new XYPolyline(); xyPolyline.Points.Add(new XYPoint(6, 2)); xyPolyline.Points.Add(new XYPoint(2, 2)); xyPolyline.Points.Add(new XYPoint(8, 2)); xyPolyline.Points.Add(new XYPoint(8, 4)); xyPolyline.Points.Add(new XYPoint(5, 4)); xyPolyline.Points.Add(new XYPoint(9, 7)); Assert.AreEqual(new XYLine(6, 2, 2, 2), xyPolyline.GetLine(0)); Assert.AreEqual(new XYLine(2, 2, 8, 2), xyPolyline.GetLine(1)); Assert.AreEqual(new XYLine(8, 2, 8, 4), xyPolyline.GetLine(2)); Assert.AreEqual(new XYLine(8, 4, 5, 4), xyPolyline.GetLine(3)); Assert.AreEqual(new XYLine(5, 4, 9, 7), xyPolyline.GetLine(4)); }
public void WritePolyLineTest() { string File = @"..\..\..\TestData\PolyLineTest.Shp"; XYPolyline line = new XYPolyline(); line.Points.Add(new XYPoint(0, 0)); line.Points.Add(new XYPoint(2, 2)); line.Points.Add(new XYPoint(4, 5)); DataTable dt = new DataTable(); dt.Columns.Add("tekst", typeof(string)); GeoRefData grf = new GeoRefData(); grf.Geometry = line; grf.Data = dt.NewRow(); grf.Data[0] = "Her er værdien"; ShapeWriter sp = new ShapeWriter(File); sp.Write(grf); sp.Dispose(); }
public static List <IWaterBody> CreateCombo(int númberofWbs, double vol) { List <IWaterBody> wbs = new List <IWaterBody>(); XYPolyline line = new XYPolyline(); line.Points.Add(new XYPoint(0, 0)); line.Points.Add(new XYPoint(1, 1)); wbs.Add(new Stream("0", line, 1, 1)); for (int i = 1; i < númberofWbs;) { wbs.Add(new Lake(i.ToString(), vol)); wbs[i - 1].AddDownStreamWaterBody(wbs[i]); line = new XYPolyline(); line.Points.Add(new XYPoint(i, i)); line.Points.Add(new XYPoint(i + 1, i + 1)); wbs.Add(new Stream(i.ToString(), line, 1, 1)); wbs[i].AddDownStreamWaterBody(wbs[i + 1]); i = i + 2; } return(wbs); }
public void WritePolyLineTest() { string File = @"..\..\..\TestData\PolyLineTest.Shp"; XYPolyline line = new XYPolyline(); line.Points.Add(new XYPoint(0, 0)); line.Points.Add(new XYPoint(2, 2)); line.Points.Add(new XYPoint(4, 5)); DataTable dt = new DataTable(); dt.Columns.Add("tekst", typeof(string)); GeoRefData grf = new GeoRefData(); grf.Geometry = line; grf.Data = dt.NewRow(); grf.Data[0] = "Her er værdien"; ShapeWriter sp = new ShapeWriter(File); sp.Write(grf); sp.Dispose(); }
public void CalculateLengthOfPolylineInsidePolygon() { XYPolygon xypolygon = new XYPolygon(); xypolygon.Points.Add(new XYPoint(1, 1)); xypolygon.Points.Add(new XYPoint(9, 1)); xypolygon.Points.Add(new XYPoint(5, 5)); xypolygon.Points.Add(new XYPoint(5, 3)); xypolygon.Points.Add(new XYPoint(3, 3)); xypolygon.Points.Add(new XYPoint(3, 8)); xypolygon.Points.Add(new XYPoint(9, 8)); xypolygon.Points.Add(new XYPoint(9, 11)); xypolygon.Points.Add(new XYPoint(1, 11)); XYPolyline xypolyline = new XYPolyline(); xypolyline.Points.Add(new XYPoint(9, 13)); xypolyline.Points.Add(new XYPoint(7, 12)); xypolyline.Points.Add(new XYPoint(7, 10)); xypolyline.Points.Add(new XYPoint(2, 10)); xypolyline.Points.Add(new XYPoint(2, 3)); Assert.AreEqual(13, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(xypolyline, xypolygon)); XYPolygon rectangle = new XYPolygon(); rectangle.Points.Add(new XYPoint(10, 10)); rectangle.Points.Add(new XYPoint(20, 10)); rectangle.Points.Add(new XYPoint(20, 40)); rectangle.Points.Add(new XYPoint(10, 40)); XYPolyline line1 = new XYPolyline(); line1.Points.Add(new XYPoint(0, 20)); line1.Points.Add(new XYPoint(30, 20)); Assert.AreEqual(10, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(line1, rectangle)); // horizontal line crossing XYPolyline line2 = new XYPolyline(); line2.Points.Add(new XYPoint(10, 20)); line2.Points.Add(new XYPoint(20, 20)); Assert.AreEqual(10, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(line2, rectangle)); // fits inside XYPolyline line3 = new XYPolyline(); line3.Points.Add(new XYPoint(0, 40)); line3.Points.Add(new XYPoint(30, 40)); Assert.AreEqual(5, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(line3, rectangle)); XYPolyline line4 = new XYPolyline(); line4.Points.Add(new XYPoint(20, 40)); line4.Points.Add(new XYPoint(20, 0)); Assert.AreEqual(15, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(line4, rectangle)); XYPolyline line5 = new XYPolyline(); line5.Points.Add(new XYPoint(20, 40)); line5.Points.Add(new XYPoint(20, 10)); Assert.AreEqual(15, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(line5, rectangle)); XYPolyline line6 = new XYPolyline(); line6.Points.Add(new XYPoint(10, 40)); line6.Points.Add(new XYPoint(30, 40)); Assert.AreEqual(5, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(line6, rectangle)); XYPolyline line7 = new XYPolyline(); line7.Points.Add(new XYPoint(10, 20)); line7.Points.Add(new XYPoint(30, 20)); Assert.AreEqual(10, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(line7, rectangle)); }
public void Equals() { XYPolygon p1 = new XYPolygon(); p1.Points.Add(new XYPoint(0, 3)); p1.Points.Add(new XYPoint(3, 0)); p1.Points.Add(new XYPoint(8, 0)); p1.Points.Add(new XYPoint(8, 2)); p1.Points.Add(new XYPoint(3, 1)); p1.Points.Add(new XYPoint(3, 3)); p1.Points.Add(new XYPoint(8, 3)); p1.Points.Add(new XYPoint(4, 7)); XYPolygon p2 = new XYPolygon(); p2.Points.Add(new XYPoint(0, 3)); p2.Points.Add(new XYPoint(3, 0)); p2.Points.Add(new XYPoint(8, 0)); p2.Points.Add(new XYPoint(8, 2)); p2.Points.Add(new XYPoint(3, 1)); p2.Points.Add(new XYPoint(3, 3)); p2.Points.Add(new XYPoint(8, 3)); p2.Points.Add(new XYPoint(4, 7)); XYPolygon p3 = new XYPolygon(); p3.Points.Add(new XYPoint(0, 3)); p3.Points.Add(new XYPoint(3, 0)); p3.Points.Add(new XYPoint(8, 0)); p3.Points.Add(new XYPoint(8, 2)); p3.Points.Add(new XYPoint(3, 1.1)); p3.Points.Add(new XYPoint(3, 3)); p3.Points.Add(new XYPoint(8, 3)); p3.Points.Add(new XYPoint(4, 7)); XYPolygon p4 = new XYPolygon(); p4.Points.Add(new XYPoint(0, 3)); p4.Points.Add(new XYPoint(3, 0)); p4.Points.Add(new XYPoint(8, 0)); p4.Points.Add(new XYPoint(8, 2)); p4.Points.Add(new XYPoint(3, 1)); p4.Points.Add(new XYPoint(3, 3)); p4.Points.Add(new XYPoint(8, 3)); XYPolyline p5 = new XYPolyline(); p5.Points.Add(new XYPoint(0, 3)); p5.Points.Add(new XYPoint(3, 0)); p5.Points.Add(new XYPoint(8, 0)); p5.Points.Add(new XYPoint(8, 2)); p5.Points.Add(new XYPoint(3, 1.1)); p5.Points.Add(new XYPoint(3, 3)); p5.Points.Add(new XYPoint(8, 3)); p5.Points.Add(new XYPoint(4, 7)); Assert.AreEqual(true, p1.Equals(p1), "Test1"); Assert.AreEqual(true, p1.Equals(p2), "Test2"); Assert.AreEqual(false, p1.Equals(p3), "Test3"); Assert.AreEqual(false, p1.Equals(p4), "Test4"); Assert.AreEqual(false, p1.Equals(p5), "Test5"); }
public Stream(string name, XYPolyline Line, double Width, double Depth) : base(name) { this.Line = Line; this.Width = Width; this.Depth = Depth; }
internal CrossSection(ICrossSection cs) { _cs = cs; _xsec = (XSOpen)_cs.BaseCrossSection; Line = new XYPolyline(); }
public void Write(GeoRefData geodata) { double[] Xs = null; double[] Ys = null; ShapeLib.ShapeType type = ShapeLib.ShapeType.NullShape; if (geodata.Geometry is IXYPoint) { IXYPoint p = (IXYPoint)geodata.Geometry; type = ShapeLib.ShapeType.Point; Xs = new double[] { p.X }; Ys = new double[] { p.Y }; } else if (geodata.Geometry.GetType().Equals(typeof(XYPolyline))) { XYPolyline p = (XYPolyline)geodata.Geometry; type = ShapeLib.ShapeType.PolyLine; int npoints = p.Points.Count; Xs = new double[npoints]; Ys = new double[npoints]; for (int i = 0; i < npoints; i++) { Xs[i] = p.Points[i].X; Ys[i] = p.Points[i].Y; } } else if (geodata.Geometry.GetType().Equals(typeof(XYLine))) { XYLine p = (XYLine)geodata.Geometry; type = ShapeLib.ShapeType.PolyLine; int npoints = 2; Xs = new double[] { p.P1.X, p.P2.X }; Ys = new double[] { p.P1.Y, p.P2.Y };; } else if (geodata.Geometry.GetType().Equals(typeof(XYPolygon))) { XYPolygon p = (XYPolygon)geodata.Geometry; type = ShapeLib.ShapeType.Polygon; int npoints = p.Points.Count; Xs = new double[npoints]; Ys = new double[npoints]; p.Points.Reverse(); for (int i = 0; i < npoints; i++) { Xs[i] = p.Points[i].X; Ys[i] = p.Points[i].Y; } p.Points.Reverse(); } else if (geodata.Geometry.GetType().Equals(typeof(MultiPartPolygon))) { MultiPartPolygon p = (MultiPartPolygon)geodata.Geometry; type = ShapeLib.ShapeType.Polygon; int npoints = p.Polygons.Sum(pol => pol.Points.Count); foreach (var poly in p.Polygons) { poly.Points.Reverse(); } Xs = new double[npoints]; Ys = new double[npoints]; int i = 0; foreach (var point in p.Polygons.SelectMany(pol => pol.Points)) { Xs[i] = point.X; Ys[i] = point.Y; i++; } foreach (var poly in p.Polygons) { poly.Points.Reverse(); } } if (_shapePointer == IntPtr.Zero) { _shapePointer = ShapeLib.SHPCreate(_fileName, type); } if (_shapePointer == IntPtr.Zero) { throw new Exception("Could not create: " + Path.GetFullPath(_fileName) + "\nMake sure directory exists."); } IntPtr obj; if (geodata.Geometry.GetType().Equals(typeof(MultiPartPolygon))) { MultiPartPolygon p = (MultiPartPolygon)geodata.Geometry; int[] partstarts = new int[p.Polygons.Count]; partstarts[0] = 0; ShapeLib.PartType[] partype = new ShapeLib.PartType[p.Polygons.Count]; for (int i = 0; i < partype.Count(); i++) { partype[i] = ShapeLib.PartType.Ring; } for (int i = 1; i < partstarts.Count(); i++) { partstarts[i] = partstarts[i - 1] + p.Polygons[i - 1].Points.Count; } obj = ShapeLib.SHPCreateObject(type, -1, partstarts.Count(), partstarts, partype, Xs.Count(), Xs, Ys, null, null); } else { obj = ShapeLib.SHPCreateSimpleObject(type, Xs.Count(), Xs, Ys, null); } ShapeLib.SHPWriteObject(_shapePointer, -1, obj); ShapeLib.SHPDestroyObject(obj); _dbf.WriteData(geodata.Data); NoOfEntries++; }
/// <summary> /// Reads the next shape /// </summary> /// <returns></returns> public IGeometry ReadNext(int RecordNumber) { IntPtr pShape = ShapeLib.SHPReadObject(_shapePointer, RecordNumber); ShapeLib.SHPObject shpObject = new ShapeLib.SHPObject(); Marshal.PtrToStructure(pShape, shpObject); double[] x = new double[shpObject.nVertices]; Marshal.Copy(shpObject.padfX, x, 0, x.Length); double[] y = new double[shpObject.nVertices]; Marshal.Copy(shpObject.padfY, y, 0, y.Length); double[] z = new double[shpObject.nVertices]; Marshal.Copy(shpObject.padfZ, z, 0, z.Length); int[] partstarts = null; if (shpObject.nParts > 0) { partstarts = new int[shpObject.nParts]; Marshal.Copy(shpObject.paPartStart, partstarts, 0, partstarts.Length); } ShapeLib.SHPDestroyObject(pShape); IGeometry geom = null; switch (type) { case ShapeLib.ShapeType.NullShape: break; case ShapeLib.ShapeType.MultiPoint: case ShapeLib.ShapeType.MultiPointZ: case ShapeLib.ShapeType.MultiPointM: case ShapeLib.ShapeType.PointM: case ShapeLib.ShapeType.PointZ: case ShapeLib.ShapeType.Point: geom = new XYPoint(x[0], y[0]); break; case ShapeLib.ShapeType.PolyLineM: case ShapeLib.ShapeType.PolyLineZ: case ShapeLib.ShapeType.PolyLine: geom = new XYPolyline(); for (int i = 0; i < x.Length; i++) { ((XYPolyline)geom).Points.Add(new XYPoint(x[i], y[i])); } break; case ShapeLib.ShapeType.PolygonM: case ShapeLib.ShapeType.PolygonZ: case ShapeLib.ShapeType.Polygon: if (partstarts.Count() == 1) { geom = new XYPolygon(); for (int i = 0; i < x.Length; i++) { ((XYPolygon)geom).Points.Add(new XYPoint(x[i], y[i])); } ((XYPolygon)geom).Points.Reverse(); } else { geom = new MultiPartPolygon(); //foreach (var partstart in partstarts.Reverse()) //{ // var poly = new XYPolygon(); // for (int i = end; i > partstart; i--) // poly.Points.Add(new XYPoint(x[i], y[i])); // end = partstart; // ((MultiPartPolygon)geom).Polygons.Add(poly); //} for (int j = 0; j < partstarts.Count(); j++) { int end; if (j < partstarts.Count() - 1) { end = partstarts[j + 1]; } else { end = x.Length; } var poly = new XYPolygon(); for (int i = partstarts[j]; i < end; i++) { poly.Points.Add(new XYPoint(x[i], y[i])); } poly.Points.Reverse(); ((MultiPartPolygon)geom).Polygons.Add(poly); } } break; case ShapeLib.ShapeType.MultiPatch: break; default: break; } return(geom); }
private void panelViewer_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { // write x and y coordinates double x = ((e.X - _margin) / _scale) + _minX; double y = _minY - (e.Y + _margin - panelViewer.ClientSize.Height) / _scale; if (_scale != double.MaxValue) { this.label3.Text = "(" + x.ToString("F3") + ", " + y.ToString("F3") + ")"; } else { this.label3.Text = ""; } // write elementSet ID and element index this.label4.Text = " "; this.label7.Text = " "; this.label8.Text = " "; this.label9.Text = " "; this.label10.Text = " "; this.label11.Text = " "; for (int elementSetNumber = 0; elementSetNumber < this._elementSets.Count; elementSetNumber++) { string elementID = " "; int elementIndex = -9; double distance = 10e30; IElementSet elementSet = (IElementSet)_elementSets[elementSetNumber]; if (elementSetNumber == 0) { this.label7.Text = elementSet.Caption.Substring(0, Math.Min(20, elementSet.Caption.Length)); } if (elementSetNumber == 1) { this.label9.Text = elementSet.Caption.Substring(0, Math.Min(20, elementSet.Caption.Length)); } for (int index = 0; index < elementSet.ElementCount; index++) { if (((IElementSet)_elementSets[elementSetNumber]).ElementType == ElementType.Polygon) { XYPolygon xyPolygon = new XYPolygon(); for (int i = 0; i < elementSet.GetVertexCount(index); i++) { xyPolygon.Points.Add(new XYPoint(elementSet.GetVertexXCoordinate(index, i), elementSet.GetVertexYCoordinate(index, i))); } if (XYGeometryTools.IsPointInPolygon(x, y, xyPolygon)) { elementID = elementSet.GetElementId(index).Id; elementIndex = index; } } if (((IElementSet)_elementSets[elementSetNumber]).ElementType == ElementType.PolyLine) { XYPolyline xyPolyline = new XYPolyline(); for (int i = 0; i < elementSet.GetVertexCount(index); i++) { xyPolyline.Points.Add(new XYPoint(elementSet.GetVertexXCoordinate(index, i), elementSet.GetVertexYCoordinate(index, i))); } double xx = XYGeometryTools.CalculatePolylineToPointDistance(xyPolyline, new XYPoint(x, y)); if (xx < distance) { distance = xx; if (xx < 0.3 * xyPolyline.GetLength()) { elementIndex = index; elementID = elementSet.GetElementId(index).Id; } } } if (elementSetNumber == 0 && elementIndex >= 0) { this.label4.Text = "Index: " + elementIndex.ToString(); this.label8.Text = "ID: " + elementID.Substring(0, Math.Min(17, elementID.Length)); } if (elementSetNumber == 1 && elementIndex >= 0) { this.label10.Text = "Index: " + elementIndex.ToString(); this.label11.Text = "ID: " + elementID.Substring(0, Math.Min(17, elementID.Length)); } } } }