本文整理汇总了TypeScript中@turf/invariant.getCoord函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getCoord函数的具体用法?TypeScript getCoord怎么用?TypeScript getCoord使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getCoord函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: getMeanLineString
function getMeanLineString(centroidOfLine: number[], angle: number, lenOfLine: number, isPlanar: boolean) {
if (isPlanar) {
const [averageX, averageY]: number[] = centroidOfLine;
let beginX: number;
let beginY: number;
let endX: number;
let endY: number;
const r: number = angle * Math.PI / 180;
const sin: number = Math.sin(r);
const cos: number = Math.cos(r);
beginX = averageX - lenOfLine / 2 * cos;
beginY = averageY - lenOfLine / 2 * sin;
endX = averageX + lenOfLine / 2 * cos;
endY = averageY + lenOfLine / 2 * sin;
return [
[beginX, beginY],
[endX, endY],
];
} else {
const end = destination(point(centroidOfLine), lenOfLine / 2, angle, { units: "meters" });
const begin = destination(point(centroidOfLine), -lenOfLine / 2, angle, { units: "meters" });
return [
getCoord(begin), getCoord(end),
];
}
}
开发者ID:Turbo87,项目名称:turf,代码行数:26,代码来源:index.ts
示例2: rhumbBearing
/**
* Takes two {@link Point|points} and finds the bearing angle between them along a Rhumb line
* i.e. the angle measured in degrees start the north line (0 degrees)
*
* @name rhumbBearing
* @param {Coord} start starting Point
* @param {Coord} end ending Point
* @param {Object} [options] Optional parameters
* @param {boolean} [options.final=false] calculates the final bearing if true
* @returns {number} bearing from north in decimal degrees, between -180 and 180 degrees (positive clockwise)
* @example
* var point1 = turf.point([-75.343, 39.984], {"marker-color": "#F00"});
* var point2 = turf.point([-75.534, 39.123], {"marker-color": "#00F"});
*
* var bearing = turf.rhumbBearing(point1, point2);
*
* //addToMap
* var addToMap = [point1, point2];
* point1.properties.bearing = bearing;
* point2.properties.bearing = bearing;
*/
function rhumbBearing(start: Coord, end: Coord, options: {final?: boolean} = {}): number {
let bear360;
if (options.final) { bear360 = calculateRhumbBearing(getCoord(end), getCoord(start));
} else { bear360 = calculateRhumbBearing(getCoord(start), getCoord(end)); }
const bear180 = (bear360 > 180) ? - (360 - bear360) : bear360;
return bear180;
}
开发者ID:Turbo87,项目名称:turf,代码行数:30,代码来源:index.ts
示例3: pNormDistance
export function pNormDistance(feature1: Feature<Point>, feature2: Feature<Point>, p: number = 2): number {
const coordinate1 = getCoord(feature1);
const coordinate2 = getCoord(feature2);
const xDiff = coordinate1[0] - coordinate2[0];
const yDiff = coordinate1[1] - coordinate2[1];
if (p === 1) {
return Math.abs(xDiff) + Math.abs(yDiff);
}
return Math.pow((Math.pow(xDiff, p) + Math.pow(yDiff, p)), 1 / p);
}
开发者ID:Turbo87,项目名称:turf,代码行数:10,代码来源:index.ts
示例4: rhumbDistance
/**
* Calculates the distance along a rhumb line between two {@link Point|points} in degrees, radians,
* miles, or kilometers.
*
* @name rhumbDistance
* @param {Coord} from origin point
* @param {Coord} to destination point
* @param {Object} [options] Optional parameters
* @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
* @returns {number} distance between the two points
* @example
* var from = turf.point([-75.343, 39.984]);
* var to = turf.point([-75.534, 39.123]);
* var options = {units: 'miles'};
*
* var distance = turf.rhumbDistance(from, to, options);
*
* //addToMap
* var addToMap = [from, to];
* from.properties.distance = distance;
* to.properties.distance = distance;
*/
function rhumbDistance(from: Coord, to: Coord, options: {
units?: Units,
} = {}): number {
const origin = getCoord(from);
const destination = getCoord(to);
// compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)
// solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678
destination[0] += (destination[0] - origin[0] > 180) ? -360 : (origin[0] - destination[0] > 180) ? 360 : 0;
const distanceInMeters = calculateRhumbDistance(origin, destination);
const distance = convertLength(distanceInMeters, "meters", options.units);
return distance;
}
开发者ID:Turbo87,项目名称:turf,代码行数:35,代码来源:index.ts
示例5: distance
//http://en.wikipedia.org/wiki/Haversine_formula
//http://www.movable-type.co.uk/scripts/latlong.html
/**
* 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 {Coord} from origin point
* @param {Coord} to destination point
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
* @returns {number} distance between the two points
* @example
* var from = turf.point([-75.343, 39.984]);
* var to = turf.point([-75.534, 39.123]);
* var options = {units: 'miles'};
*
* var distance = turf.distance(from, to, options);
*
* //addToMap
* var addToMap = [from, to];
* from.properties.distance = distance;
* to.properties.distance = distance;
*/
function distance(from: Coord, to: Coord, options: {
units?: Units,
} = {}) {
var coordinates1 = getCoord(from);
var coordinates2 = getCoord(to);
var dLat = degreesToRadians((coordinates2[1] - coordinates1[1]));
var dLon = degreesToRadians((coordinates2[0] - coordinates1[0]));
var lat1 = degreesToRadians(coordinates1[1]);
var lat2 = degreesToRadians(coordinates2[1]);
var a = Math.pow(Math.sin(dLat / 2), 2) +
Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2);
return radiansToLength(2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)), options.units);
}
开发者ID:Turbo87,项目名称:turf,代码行数:40,代码来源:index.ts
示例6: getCoord
/**
* Takes a {@link Point} and calculates the location of a destination point given a distance in
* degrees, radians, miles, or kilometers; and bearing in degrees.
* This uses the [Haversine formula](http://en.wikipedia.org/wiki/Haversine_formula) to account for global curvature.
*
* @name destination
* @param {Coord} origin starting point
* @param {number} distance distance from the origin point
* @param {number} bearing ranging from -180 to 180
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units='kilometers'] miles, kilometers, degrees, or radians
* @param {Object} [options.properties={}] Translate properties to Point
* @returns {Feature<Point>} destination point
* @example
* var point = turf.point([-75.343, 39.984]);
* var distance = 50;
* var bearing = 90;
* var options = {units: 'miles'};
*
* var destination = turf.destination(point, distance, bearing, options);
*
* //addToMap
* var addToMap = [point, destination]
* destination.properties['marker-color'] = '#f00';
* point.properties['marker-color'] = '#0f0';
*/
export default function destination<P = Properties>(
origin: Coord,
distance: number,
bearing: number,
options: {
units?: Units,
properties?: P,
} = {},
): Feature<Point, P> {
// Handle input
const coordinates1 = getCoord(origin);
const longitude1 = degreesToRadians(coordinates1[0]);
const latitude1 = degreesToRadians(coordinates1[1]);
const bearingRad = degreesToRadians(bearing);
const radians = lengthToRadians(distance, options.units);
// Main
const latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad));
const longitude2 = longitude1 + Math.atan2(Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1),
Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2));
const lng = radiansToDegrees(longitude2);
const lat = radiansToDegrees(latitude2);
return point([lng, lat], options.properties);
}
开发者ID:Turbo87,项目名称:turf,代码行数:52,代码来源:index.ts
示例7: bearing
// http://en.wikipedia.org/wiki/Haversine_formula
// http://www.movable-type.co.uk/scripts/latlong.html
/**
* Takes two {@link Point|points} and finds the geographic bearing between them,
* i.e. the angle measured in degrees from the north line (0 degrees)
*
* @name bearing
* @param {Coord} start starting Point
* @param {Coord} end ending Point
* @param {Object} [options={}] Optional parameters
* @param {boolean} [options.final=false] calculates the final bearing if true
* @returns {number} bearing in decimal degrees, between -180 and 180 degrees (positive clockwise)
* @example
* var point1 = turf.point([-75.343, 39.984]);
* var point2 = turf.point([-75.534, 39.123]);
*
* var bearing = turf.bearing(point1, point2);
*
* //addToMap
* var addToMap = [point1, point2]
* point1.properties['marker-color'] = '#f00'
* point2.properties['marker-color'] = '#0f0'
* point1.properties.bearing = bearing
*/
export default function bearing(start: Coord, end: Coord, options: {
final?: boolean,
} = {}): number {
// Reverse calculation
if (options.final === true) { return calculateFinalBearing(start, end); }
const coordinates1 = getCoord(start);
const coordinates2 = getCoord(end);
const lon1 = degreesToRadians(coordinates1[0]);
const lon2 = degreesToRadians(coordinates2[0]);
const lat1 = degreesToRadians(coordinates1[1]);
const lat2 = degreesToRadians(coordinates2[1]);
const a = Math.sin(lon2 - lon1) * Math.cos(lat2);
const b = Math.cos(lat1) * Math.sin(lat2) -
Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);
return radiansToDegrees(Math.atan2(a, b));
}
开发者ID:Turbo87,项目名称:turf,代码行数:44,代码来源:index.ts
示例8: convertLength
/**
* Returns the destination {@link Point} having travelled the given distance along a Rhumb line from the
* origin Point with the (varant) given bearing.
*
* @name rhumbDestination
* @param {Coord} origin starting point
* @param {number} distance distance from the starting point
* @param {number} bearing varant bearing angle ranging from -180 to 180 degrees from north
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
* @param {Object} [options.properties={}] translate properties to destination point
* @returns {Feature<Point>} Destination point.
* @example
* var pt = turf.point([-75.343, 39.984], {"marker-color": "F00"});
* var distance = 50;
* var bearing = 90;
* var options = {units: 'miles'};
*
* var destination = turf.rhumbDestination(pt, distance, bearing, options);
*
* //addToMap
* var addToMap = [pt, destination]
* destination.properties['marker-color'] = '#00F';
*/
function rhumbDestination<P = Properties>(origin: Coord, distance: number, bearing: number, options: {
units?: Units,
properties?: P,
} = {}): Feature<Point, P> {
const wasNegativeDistance = distance < 0;
let distanceInMeters = convertLength(Math.abs(distance), options.units, "meters");
if (wasNegativeDistance) distanceInMeters = -Math.abs(distanceInMeters);
const coords = getCoord(origin);
const destination = calculateRhumbDestination(coords, distanceInMeters, bearing);
// compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)
// solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678
destination[0] += (destination[0] - coords[0] > 180) ? -360 : (coords[0] - destination[0] > 180) ? 360 : 0;
return point(destination, options.properties);
}
开发者ID:Turbo87,项目名称:turf,代码行数:40,代码来源:index.ts
示例9: booleanPointOnLine
/**
* Returns true if a point is on a line. Accepts a optional parameter to ignore the
* start and end vertices of the linestring.
*
* @name booleanPointOnLine
* @param {Coord} pt GeoJSON Point
* @param {Feature<LineString>} line GeoJSON LineString
* @param {Object} [options={}] Optional parameters
* @param {boolean} [options.ignoreEndVertices=false] whether to ignore the start and end vertices.
* @returns {boolean} true/false
* @example
* var pt = turf.point([0, 0]);
* var line = turf.lineString([[-1, -1],[1, 1],[1.5, 2.2]]);
* var isPointOnLine = turf.booleanPointOnLine(pt, line);
* //=true
*/
function booleanPointOnLine(pt: Coord, line: Feature<LineString> | LineString, options: {
ignoreEndVertices?: boolean,
} = {}): boolean {
// Normalize inputs
const ptCoords = getCoord(pt);
const lineCoords = getCoords(line);
// Main
for (let i = 0; i < lineCoords.length - 1; i++) {
let ignoreBoundary: boolean|string = false;
if (options.ignoreEndVertices) {
if (i === 0) { ignoreBoundary = "start"; }
if (i === lineCoords.length - 2) { ignoreBoundary = "end"; }
if (i === 0 && i + 1 === lineCoords.length - 1) { ignoreBoundary = "both"; }
}
if (isPointOnLineSegment(lineCoords[i], lineCoords[i + 1], ptCoords, ignoreBoundary)) { return true; }
}
return false;
}
开发者ID:Turbo87,项目名称:turf,代码行数:35,代码来源:index.ts
注:本文中的@turf/invariant.getCoord函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论