Ejemplo n.º 1
0
        /// <summary>
        /// Finds the shortest distance between any line segment of the polyline
        /// and the point.
        /// </summary>
        /// <param name="polyLine">PolyLine.</param>
        /// <param name="point">Point</param>
        /// <returns>
        ///	<p>Length of the shortest path between the polyline and the point.</p>
        /// </returns>
        public static double CalculatePolylineToPointDistance(XYPolyline polyLine, XYPoint point)
        {
            double dist = 0;
            int    i    = 0;

            while (i < polyLine.Points.Count - 1)
            {
                if (i == 0)
                {
                    dist = CalculateLineToPointDistance(polyLine.GetLine(0), point);
                }
                else
                {
                    dist = Math.Min(dist, CalculateLineToPointDistance(polyLine.GetLine(i), point));
                }
                i++;
            }
            return(dist);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculates the length of polyline inside polygon. Lines segments on the edges of
        /// polygons are included with half their length.
        /// </summary>
        /// <param name="polyline">Polyline</param>
        /// <param name="polygon">Polygon</param>
        /// <returns>
        /// Length of polyline inside polygon.
        /// </returns>
        public static double CalculateLengthOfPolylineInsidePolygon(XYPolyline polyline, XYPolygon polygon)
        {
            double lengthInside         = 0;
            int    numberOfLineSegments = polyline.Points.Count - 1;

            for (int i = 0; i < numberOfLineSegments; i++)
            {
                XYLine line = new XYLine(polyline.GetLine(i));
                lengthInside += CalculateLengthOfLineInsidePolygon(line, polygon);
            }
            return(lengthInside);
        }
Ejemplo n.º 3
0
		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));
		}
Ejemplo n.º 4
0
 /// <summary>
 /// Finds the shortest distance between any line segment of the polyline 
 /// and the point.
 /// </summary>
 /// <param name="polyLine">PolyLine.</param>
 /// <param name="point">Point</param>
 /// <returns>
 ///	<p>Length of the shortest path between the polyline and the point.</p>
 /// </returns>
 public static double CalculatePolylineToPointDistance (XYPolyline polyLine, XYPoint point)
 {
   double dist = 0;
   int i = 0;
   while (i < polyLine.Points.Count - 1) 
   {
     if (i == 0) 
     {
       dist = CalculateLineToPointDistance (polyLine.GetLine(0), point);
     }
     else
     {
       dist = Math.Min(dist, CalculateLineToPointDistance (polyLine.GetLine(i), point));
     }
     i++;
   }
   return dist;
 }
Ejemplo n.º 5
0
		/// <summary>
		/// Calculates the length of polyline inside polygon. Lines segments on the edges of 
		/// polygons are included with half their length.
		/// </summary>
		/// <param name="polyline">Polyline</param>
		/// <param name="polygon">Polygon</param>
		/// <returns>
		/// Length of polyline inside polygon.
		/// </returns>
		public static double CalculateLengthOfPolylineInsidePolygon(XYPolyline polyline, XYPolygon polygon)
		{
			double lengthInside = 0;
			int numberOfLineSegments = polyline.Points.Count - 1;
			for (int i = 0; i < numberOfLineSegments; i++)
			{
				XYLine line = new XYLine(polyline.GetLine(i));
				lengthInside += CalculateLengthOfLineInsidePolygon(line,polygon);
			}
			return lengthInside;
		}