• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript centroid.default函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@turf/centroid.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了default函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: switch

/**
 * Takes any {@link Feature} or a {@link FeatureCollection} and returns its [center of mass](https://en.wikipedia.org/wiki/Center_of_mass) using this formula: [Centroid of Polygon](https://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon).
 *
 * @name centerOfMass
 * @param {GeoJSON} geojson GeoJSON to be centered
 * @param {Object} [options={}] Optional Parameters
 * @param {Object} [options.properties={}] Translate Properties to Feature
 * @returns {Feature<Point>} the center of mass
 * @example
 * var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
 *
 * var center = turf.centerOfMass(polygon);
 *
 * //addToMap
 * var addToMap = [polygon, center]
 */
function centerOfMass<P = Properties>(geojson: any, options: {
    properties?: P,
} = {}): Feature<Point, P> {
    switch (getType(geojson)) {
    case 'Point':
        return point(getCoord(geojson), options.properties);
    case 'Polygon':
        var coords = [];
        coordEach(geojson, function (coord) {
            coords.push(coord);
        });

        // First, we neutralize the feature (set it around coordinates [0,0]) to prevent rounding errors
        // We take any point to translate all the points around 0
        var centre = centroid(geojson, {properties: options.properties});
        var translation = centre.geometry.coordinates;
        var sx = 0;
        var sy = 0;
        var sArea = 0;
        var i, pi, pj, xi, xj, yi, yj, a;

        var neutralizedPoints = coords.map(function (point) {
            return [
                point[0] - translation[0],
                point[1] - translation[1]
            ];
        });

        for (i = 0; i < coords.length - 1; i++) {
            // pi is the current point
            pi = neutralizedPoints[i];
            xi = pi[0];
            yi = pi[1];

            // pj is the next point (pi+1)
            pj = neutralizedPoints[i + 1];
            xj = pj[0];
            yj = pj[1];

            // a is the common factor to compute the signed area and the final coordinates
            a = xi * yj - xj * yi;

            // sArea is the sum used to compute the signed area
            sArea += a;

            // sx and sy are the sums used to compute the final coordinates
            sx += (xi + xj) * a;
            sy += (yi + yj) * a;
        }

        // Shape has no area: fallback on turf.centroid
        if (sArea === 0) {
            return centre;
        } else {
            // Compute the signed area, and factorize 1/6A
            var area = sArea * 0.5;
            var areaFactor = 1 / (6 * area);

            // Compute the final coordinates, adding back the values that have been neutralized
            return point([
                translation[0] + areaFactor * sx,
                translation[1] + areaFactor * sy
            ], options.properties);
        }
    default:
        // Not a polygon: Compute the convex hull and work with that
        var hull = convex(geojson);

        if (hull) return centerOfMass(hull, {properties: options.properties});
        // Hull is empty: fallback on the centroid
        else return centroid(geojson, {properties: options.properties});
    }
}
开发者ID:Turbo87,项目名称:turf,代码行数:89,代码来源:index.ts


示例2: directionalMean

/**
 * @typedef {Object} DirectionalMeanLine
 * @property {number} cartesianAngle the mean angle of all lines. (measure from due earth counterclockwise).
 * @property {number} bearingAngle the mean angle of all lines. (bearing).
 * @property {number} circularVariance the extent to which features all point in the same direction.
 *  the value ranges 0-1, the bigger the value, the more variation in directions between lines.
 * @property {number} averageX the centroid of all lines.
 * @property {number} averageY the centroid of all line.
 * @property {number} averageLength the average length of line.
 * @property {number} countOfLines the count of features.
 */

/**
 * This module calculate the average angle of a set of lines, measuring the trend of it.
 * It can be used in both project coordinate system and geography coordinate system.
 * It can handle segments of line or the whole line.
 * @name directionalMean
 * @param {FeatureCollection<LineString>} lines
 * @param {object} [options={}]
 * @param {boolean} [options.planar=true] whether the spatial reference system is projected or geographical.
 * @param {boolean} [options.segment=false] whether treat a LineString as a whole or a set of segments.
 * @returns {DirectionalMeanLine} Directional Mean Line
 * @example
 *
 * var lines = turf.lineStrings([
 *   [[110, 45], [120, 50]],
 *   [[100, 50], [115, 55]],
 * ])
 * var directionalMeanLine = turf.directionalMean(lines);
 * // => directionalMeanLine
 */
export default function directionalMean(lines: FeatureCollection<LineString>, options: {
    planar?: boolean;
    segment?: boolean;
} = {}): DirectionalMeanLine {

    const isPlanar: boolean = !!options.planar; // you can't use options.planar || true here.
    const isSegment: boolean = options.segment || false;
    let sigmaSin: number = 0;
    let sigmaCos: number = 0;
    let countOfLines: number = 0;
    let sumOfLen: number = 0;
    const centroidList: Array<Feature<Point>> = [];

    if (isSegment) {
        segmentEach(lines, (currentSegment: any) => { // todo fix turf-meta's declaration file
            const [sin1, cos1]: [number, number] = getCosAndSin(currentSegment.geometry.coordinates, isPlanar);
            const lenOfLine = getLengthOfLineString(currentSegment, isPlanar);
            if (isNaN(sin1) || isNaN(cos1)) {
                return;
            } else {
                sigmaSin += sin1;
                sigmaCos += cos1;
                countOfLines += 1;
                sumOfLen += lenOfLine;
                centroidList.push(centroid(currentSegment));
            }
        });
        // planar and segment
    } else {
        // planar and non-segment
        featureEach(lines, (currentFeature: Feature<LineString>, featureIndex: number) => {
            if (currentFeature.geometry.type !== "LineString") {
                throw new Error("shold to support MultiLineString?");
            }
            const [sin1, cos1]: [number, number] = getCosAndSin(currentFeature.geometry.coordinates, isPlanar);
            const lenOfLine = getLengthOfLineString(currentFeature, isPlanar);
            if (isNaN(sin1) || isNaN(cos1)) {
                return;
            } else {
                sigmaSin += sin1;
                sigmaCos += cos1;
                countOfLines += 1;
                sumOfLen += lenOfLine;
                centroidList.push(centroid(currentFeature));
            }
        });
    }

    const cartesianAngle: number = getAngleBySinAndCos(sigmaSin, sigmaCos);
    const bearingAngle: number = bearingToCartesian(cartesianAngle);
    const circularVariance = getCircularVariance(sigmaSin, sigmaCos, countOfLines);
    const averageLength = sumOfLen / countOfLines;
    const centroidOfLines = centroid(featureCollection(centroidList));
    const [averageX, averageY]: number[] = getCoord(centroidOfLines);
    let meanLinestring;
    if (isPlanar) {
        meanLinestring = getMeanLineString([averageX, averageY], cartesianAngle, averageLength, isPlanar);
    } else {
        meanLinestring = getMeanLineString([averageX, averageY], bearingAngle, averageLength, isPlanar);
    }

    return lineString(meanLinestring, {
        averageLength,
        averageX,
        averageY,
        bearingAngle,
        cartesianAngle,
        circularVariance,
        countOfLines,
//.........这里部分代码省略.........
开发者ID:Turbo87,项目名称:turf,代码行数:101,代码来源:index.ts


示例3: segmentEach

 segmentEach(lines, (currentSegment: any) => { // todo fix turf-meta's declaration file
     const [sin1, cos1]: [number, number] = getCosAndSin(currentSegment.geometry.coordinates, isPlanar);
     const lenOfLine = getLengthOfLineString(currentSegment, isPlanar);
     if (isNaN(sin1) || isNaN(cos1)) {
         return;
     } else {
         sigmaSin += sin1;
         sigmaCos += cos1;
         countOfLines += 1;
         sumOfLen += lenOfLine;
         centroidList.push(centroid(currentSegment));
     }
 });
开发者ID:Turbo87,项目名称:turf,代码行数:13,代码来源:index.ts


示例4: Error

 featureEach(lines, (currentFeature: Feature<LineString>, featureIndex: number) => {
     if (currentFeature.geometry.type !== "LineString") {
         throw new Error("shold to support MultiLineString?");
     }
     const [sin1, cos1]: [number, number] = getCosAndSin(currentFeature.geometry.coordinates, isPlanar);
     const lenOfLine = getLengthOfLineString(currentFeature, isPlanar);
     if (isNaN(sin1) || isNaN(cos1)) {
         return;
     } else {
         sigmaSin += sin1;
         sigmaCos += cos1;
         countOfLines += 1;
         sumOfLen += lenOfLine;
         centroidList.push(centroid(currentFeature));
     }
 });
开发者ID:Turbo87,项目名称:turf,代码行数:16,代码来源:index.ts


示例5: featureEach

 featureEach(dataset, (feature) => {
     features.push(centroid(feature));
 });
开发者ID:Turbo87,项目名称:turf,代码行数:3,代码来源:index.ts



注:本文中的@turf/centroid.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript clone.default函数代码示例发布时间:2022-05-28
下一篇:
TypeScript boolean-point-on-line.default函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap