Ejemplo n.º 1
0
        public static Feature Along(LineString line, double distance, string units = "kilometers")
        {
            var    coords    = line.Coordinates;
            double travelled = 0;

            for (var i = 0; i < coords.Count; i++)
            {
                if (distance >= travelled && i == coords.Count - 1)
                {
                    break;
                }
                else if (travelled >= distance)
                {
                    var overshot = distance - travelled;
                    if (Math.Abs(overshot) < double.Epsilon)
                    {
                        return(Turf.Point(coords[i]));
                    }
                    else
                    {
                        var direction    = Turf.Bearing(coords[i], coords[i - 1]) - 180;
                        var interpolated = Turf.Destination(coords[i], overshot, direction, units);
                        return(interpolated);
                    }
                }
                else
                {
                    travelled += Turf.Distance(coords[i], coords[i + 1], units);
                }
            }
            return(Turf.Point(coords[coords.Count - 1]));
        }
Ejemplo n.º 2
0
        /**
         * Takes a {@link Point} and calculates the circle polygon given a radius in degrees, radians, miles, or kilometers; and steps for precision.
         *
         * @name circle
         * @param {Feature<Point>} center center point
         * @param {number} radius radius of the circle
         * @param {number} [steps=64] number of steps
         * @param {string} [units=kilometers] miles, kilometers, degrees, or radians
         * @returns {Feature<Polygon>} circle polygon
         * @example
         * var center = point([-75.343, 39.984]);
         * var radius = 5;
         * var steps = 10;
         * var units = 'kilometers';
         *
         * var circle = turf.circle(center, radius, steps, units);
         *
         * //=circle
         */
        public static Feature Circle(Feature center, double radius, int steps = 64, string units = "kilometers")
        {
            List <IPosition> coordinates = new List <IPosition>();

            for (var i = 0; i < steps; i++)
            {
                coordinates.Add(((Point)Turf.Destination(center, radius, i * 360 / steps, units).Geometry).Coordinates);
            }

            coordinates.Add(coordinates[0]);

            return(new Feature(
                       new Polygon(new List <LineString>()
            {
                new LineString(coordinates)
            })
                       ));
        }