private static Feature Destination(List <double> from, double distance, double bearing, string units = "kilometers") { var degrees2radians = Math.PI / 180; var radians2degrees = 180 / Math.PI; var coordinates1 = Turf.GetCoord(from); var longitude1 = degrees2radians * coordinates1[0]; var latitude1 = degrees2radians * coordinates1[1]; var bearing_rad = degrees2radians * bearing; var radians = Turf.DistanceToRadians(distance, units); var latitude2 = Math.Asin(Math.Sin(latitude1) * Math.Cos(radians) + Math.Cos(latitude1) * Math.Sin(radians) * Math.Cos(bearing_rad)); var longitude2 = longitude1 + Math.Atan2(Math.Sin(bearing_rad) * Math.Sin(radians) * Math.Cos(latitude1), Math.Cos(radians) - Math.Sin(latitude1) * Math.Sin(latitude2)); return(Turf.Point(new double[] { radians2degrees *longitude2, radians2degrees *latitude2 })); }
/** * Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point resides inside the polygon. The polygon can * be convex or concave. The function accounts for holes. * * @name inside * @param {Feature<Point>} point input point * @param {Feature<(Polygon|MultiPolygon)>} polygon input polygon or multipolygon * @return {boolean} `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon * @example * var pt = point([-77, 44]); * var poly = polygon([[ * [-81, 41], * [-81, 47], * [-72, 47], * [-72, 41], * [-81, 41] * ]]); * * var isInside = turf.inside(pt, poly); * * //=isInside */ static public bool Inside(Feature point, Feature poly) { var type = poly.Geometry.Type; if (type == GeoJSONObjectType.Polygon) { return(Inside_(Turf.GetCoord(point), new List <Polygon>() { (Polygon)poly.Geometry })); } else if (type == GeoJSONObjectType.MultiPolygon) { return(Inside_(Turf.GetCoord(point), ((MultiPolygon)poly.Geometry).Coordinates)); } else { throw new Exception("2nd argument must be Polygon or MultiPolygon"); } }
public static double Bearing(Feature start, Feature end) { return(Bearing(Turf.GetCoord(start), Turf.GetCoord(end))); }
/** * Takes two {@link Point|points} and finds the geographic bearing between them. * * @name bearing * @param {Feature<Point>} start starting Point * @param {Feature<Point>} end ending Point * @returns {number} bearing in decimal degrees * @example * var point1 = { * "type": "Feature", * "properties": { * "marker-color": '#f00' * }, * "geometry": { * "type": "Point", * "coordinates": [-75.343, 39.984] * } * }; * var point2 = { * "type": "Feature", * "properties": { * "marker-color": '#0f0' * }, * "geometry": { * "type": "Point", * "coordinates": [-75.534, 39.123] * } * }; * * var points = { * "type": "FeatureCollection", * "features": [point1, point2] * }; * * //=points * * var bearing = turf.bearing(point1, point2); * * //=bearing */ public static double Bearing(IPosition start, IPosition end) { return(Bearing(Turf.GetCoord(start), Turf.GetCoord(end))); }
public static double Distance(Feature from, Feature to, string units = "kilometers") { return(Distance(Turf.GetCoord(from), Turf.GetCoord(to), units)); }
/** * Calculates the distance between two {@link Point|points} in degrees, radians, * miles, or kilometers. This uses the * [Haversine formula](http://en.wikipedia.org/wiki/Haversine_formula) * to account for global curvature. * * @name distance * @param {Feature<Point>} from origin point * @param {Feature<Point>} to destination point * @param {string} [units=kilometers] can be degrees, radians, miles, or kilometers * @return {number} distance between the two points * @example * var from = { * "type": "Feature", * "properties": {}, * "geometry": { * "type": "Point", * "coordinates": [-75.343, 39.984] * } * }; * var to = { * "type": "Feature", * "properties": {}, * "geometry": { * "type": "Point", * "coordinates": [-75.534, 39.123] * } * }; * var units = "miles"; * * var points = { * "type": "FeatureCollection", * "features": [from, to] * }; * * //=points * * var distance = turf.distance(from, to, units); * * //=distance */ public static double Distance(IPosition from, IPosition to, string units = "kilometers") { return(Distance(Turf.GetCoord(from), Turf.GetCoord(to), units)); }
public static Feature Destination(Feature from, double distance, double bearing, string units = "kilometers") { return(Destination(Turf.GetCoord(from), distance, bearing, units)); }