Beispiel #1
0
        /// <summary>
        /// Determine if a coordinate is next to the given range (in meters) of the polyline.
        /// </summary>
        /// <param name="point">Point to test</param>
        /// <param name="range">Range in meters</param>
        /// <returns>bool</returns>
        /// <example>
        /// The following example shows how to determine if a coordinate is within 1000 meters of
        /// the edge of the specified polygon.
        /// <code>
        /// List&lt;GeoFence.Point&gt; points = new List&lt;GeoFence.Point&gt;();
        ///
        /// //Points specified manually to create a square in the USA.
        /// //First and last points should be identical if creating a polygon boundary.
        /// points.Add(new GeoFence.Point(31.65, -106.52));
        /// points.Add(new GeoFence.Point(31.65, -84.02));
        /// points.Add(new GeoFence.Point(42.03, -84.02));
        /// points.Add(new GeoFence.Point(42.03, -106.52));
        /// points.Add(new GeoFence.Point(31.65, -106.52));
        ///
        /// GeoFence gf = new GeoFence(points);
        ///
        /// Coordinate c = new Coordinate(36.67, -101.51);
        ///
        /// //Determine if Coordinate is within specific range of shapes line.
        /// Console.WriteLine(gf.IsPointInRangeOfLine(c, 1000)); //False (coordinate is not within 1000 meters of the edge of the polygon)
        /// </code>
        /// </example>
        public bool IsPointInRangeOfLine(Coordinate point, double range)
        {
            if (point == null)
            {
                return(false);
            }

            for (int i = 0; i < _points.Count - 1; i++)
            {
                Coordinate c = ClosestPointOnSegment(_points[i], _points[i + 1], point);
                if (c.Get_Distance_From_Coordinate(point).Meters <= range)
                {
                    return(true);
                }
            }

            return(false);
        }