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

TypeScript helpers.feature函数代码示例

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

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



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

示例1: pointToLineDistance

/**
 * Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the
 * minimum distance between the point and any segment of the `LineString`.
 *
 * @name pointToLineDistance
 * @param {Feature<Point>|Array<number>} pt Feature or Geometry
 * @param {Feature<LineString>} line GeoJSON Feature or Geometry
 * @param {Object} [options={}] Optional parameters
 * @param {string} [options.units="kilometers"] can be anything supported by turf/convertLength
 * (ex: degrees, radians, miles, or kilometers)
 * @param {string} [options.method="geodesic"] wether to calculate the distance based on geodesic (spheroid) or
 * planar (flat) method. Valid options are 'geodesic' or 'planar'.
 * @returns {number} distance between point and line
 * @example
 * var pt = turf.point([0, 0]);
 * var line = turf.lineString([[1, 1],[-1, 1]]);
 *
 * var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});
 * //=69.11854715938406
 */
function pointToLineDistance(pt: Coord, line: Feature<LineString> | LineString, options: {
    units?: Units,
    method?: "geodesic" | "planar",
} = {}): number {
    // Optional parameters
    if (!options.method) { options.method = "geodesic"; }
    if (!options.units) { options.units = "kilometers"; }

    // validation
    if (!pt) { throw new Error("pt is required"); }
    if (Array.isArray(pt)) { pt = point(pt);
    } else if (pt.type === "Point") { pt = feature(pt);
    } else { featureOf(pt, "Point", "point"); }

    if (!line) { throw new Error("line is required"); }
    if (Array.isArray(line)) { line = lineString(line);
    } else if (line.type === "LineString") { line = feature(line);
    } else { featureOf(line, "LineString", "line"); }

    let distance = Infinity;
    const p = pt.geometry.coordinates;
    segmentEach(line, (segment) => {
        const a = segment!.geometry.coordinates[0];
        const b = segment!.geometry.coordinates[1];
        const d = distanceToSegment(p, a, b, options);
        if (d < distance) { distance = d; }
    });
    return convertLength(distance, "degrees", options.units);
}
开发者ID:Turbo87,项目名称:turf,代码行数:49,代码来源:index.ts


示例2: concave

/**
 * Takes a set of {@link Point|points} and returns a concave hull Polygon or MultiPolygon.
 * Internally, this uses [turf-tin](https://github.com/Turfjs/turf-tin) to generate geometries.
 *
 * @name concave
 * @param {FeatureCollection<Point>} points input points
 * @param {Object} [options={}] Optional parameters
 * @param {number} [options.maxEdge=Infinity] the length (in 'units') of an edge necessary for part of the
 * hull to become concave.
 * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
 * @returns {Feature<(Polygon|MultiPolygon)>|null} a concave hull (null value is returned if unable to compute hull)
 * @example
 * var points = turf.featureCollection([
 *   turf.point([-63.601226, 44.642643]),
 *   turf.point([-63.591442, 44.651436]),
 *   turf.point([-63.580799, 44.648749]),
 *   turf.point([-63.573589, 44.641788]),
 *   turf.point([-63.587665, 44.64533]),
 *   turf.point([-63.595218, 44.64765])
 * ]);
 * var options = {units: 'miles', maxEdge: 1};
 *
 * var hull = turf.concave(points, options);
 *
 * //addToMap
 * var addToMap = [points, hull]
 */
function concave(
    points: FeatureCollection<Point>,
    options: {maxEdge?: number, units?: Units} = {},
): Feature<Polygon | MultiPolygon> | null {
    const maxEdge = options.maxEdge || Infinity;

    const cleaned = removeDuplicates(points);

    const tinPolys = tin(cleaned);
    // calculate length of all edges and area of all triangles
    // and remove triangles that fail the max length test
    tinPolys.features = tinPolys.features.filter((triangle) => {
        const pt1 = triangle.geometry.coordinates[0][0];
        const pt2 = triangle.geometry.coordinates[0][1];
        const pt3 = triangle.geometry.coordinates[0][2];
        const dist1 = distance(pt1, pt2, options);
        const dist2 = distance(pt2, pt3, options);
        const dist3 = distance(pt1, pt3, options);
        return (dist1 <= maxEdge && dist2 <= maxEdge && dist3 <= maxEdge);
    });

    if (tinPolys.features.length < 1) { return null; }

    // merge the adjacent triangles
    const dissolved: any = dissolve(tinPolys);

    // geojson-dissolve always returns a MultiPolygon
    if (dissolved.coordinates.length === 1) {
        dissolved.coordinates = dissolved.coordinates[0];
        dissolved.type = "Polygon";
    }
    return feature(dissolved);
}
开发者ID:Turbo87,项目名称:turf,代码行数:60,代码来源:index.ts


示例3: intersects

/**
 * Takes any LineString or Polygon GeoJSON and returns the intersecting point(s).
 *
 * @name lineIntersect
 * @param {GeoJSON} line1 any LineString or Polygon
 * @param {GeoJSON} line2 any LineString or Polygon
 * @returns {FeatureCollection<Point>} point(s) that intersect both
 * @example
 * var line1 = turf.lineString([[126, -11], [129, -21]]);
 * var line2 = turf.lineString([[123, -18], [131, -14]]);
 * var intersects = turf.lineIntersect(line1, line2);
 *
 * //addToMap
 * var addToMap = [line1, line2, intersects]
 */
function lineIntersect<
    G1 extends LineString|MultiLineString|Polygon|MultiPolygon,
    G2 extends LineString|MultiLineString|Polygon|MultiPolygon
>(
    line1: FeatureCollection<G1> | Feature<G1> | G1,
    line2: FeatureCollection<G2> | Feature<G2> | G2,
): FeatureCollection<Point> {
    const unique: any = {};
    const results: any[] = [];

    // First, normalize geometries to features
    // Then, handle simple 2-vertex segments
    if (line1.type === "LineString") { line1 = feature(line1); }
    if (line2.type === "LineString") { line2 = feature(line2); }
    if (line1.type === "Feature" &&
        line2.type === "Feature" &&
        line1.geometry !== null &&
        line2.geometry !== null &&
        line1.geometry.type === "LineString" &&
        line2.geometry.type === "LineString" &&
        line1.geometry.coordinates.length === 2 &&
        line2.geometry.coordinates.length === 2) {
        const intersect = intersects(line1, line2);
        if (intersect) { results.push(intersect); }
        return featureCollection(results);
    }

    // Handles complex GeoJSON Geometries
    const tree = rbush();
    tree.load(lineSegment(line2));
    featureEach(lineSegment(line1), (segment) => {
        featureEach(tree.search(segment), (match) => {
            const intersect = intersects(segment, match);
            if (intersect) {
                // prevent duplicate points https://github.com/Turfjs/turf/issues/688
                const key = getCoords(intersect).join(",");
                if (!unique[key]) {
                    unique[key] = true;
                    results.push(intersect);
                }
            }
        });
    });
    return featureCollection(results);
}
开发者ID:Turbo87,项目名称:turf,代码行数:60,代码来源:index.ts


示例4: intersects

/**
 * Takes any LineString or Polygon GeoJSON and returns the intersecting point(s).
 *
 * @name lineIntersect
 * @param {Geometry|FeatureCollection|Feature<LineString|MultiLineString|Polygon|MultiPolygon>} line1 any LineString or Polygon
 * @param {Geometry|FeatureCollection|Feature<LineString|MultiLineString|Polygon|MultiPolygon>} line2 any LineString or Polygon
 * @returns {FeatureCollection<Point>} point(s) that intersect both
 * @example
 * var line1 = turf.lineString([[126, -11], [129, -21]]);
 * var line2 = turf.lineString([[123, -18], [131, -14]]);
 * var intersects = turf.lineIntersect(line1, line2);
 *
 * //addToMap
 * var addToMap = [line1, line2, intersects]
 */
function lineIntersect<G1 extends LineString|MultiLineString|Polygon|MultiPolygon, G2 extends LineString|MultiLineString|Polygon|MultiPolygon>(
    line1: FeatureCollection<G1> | Feature<G1> | G1,
    line2: FeatureCollection<G2> | Feature<G2> | G2,
): FeatureCollection<Point> {
    var unique = {};
    var results = [];

    // First, normalize geometries to features
    // Then, handle simple 2-vertex segments
    if (line1.type === 'LineString') line1 = feature(line1);
    if (line2.type === 'LineString') line2 = feature(line2);
    if (line1.type === 'Feature' &&
        line2.type === 'Feature' &&
        line1.geometry.type === 'LineString' &&
        line2.geometry.type === 'LineString' &&
        line1.geometry.coordinates.length === 2 &&
        line2.geometry.coordinates.length === 2) {
        var intersect = intersects(line1, line2);
        if (intersect) results.push(intersect);
        return featureCollection(results);
    }

    // Handles complex GeoJSON Geometries
    var tree = rbush();
    tree.load(lineSegment(line2));
    featureEach(lineSegment(line1), function (segment) {
        featureEach(tree.search(segment), function (match) {
            var intersect = intersects(segment, match);
            if (intersect) {
                // prevent duplicate points https://github.com/Turfjs/turf/issues/688
                var key = getCoords(intersect).join(',');
                if (!unique[key]) {
                    unique[key] = true;
                    results.push(intersect);
                }
            }
        });
    });
    return featureCollection(results);
}
开发者ID:OlympicsORG,项目名称:turf,代码行数:55,代码来源:index.ts


示例5: cleanCoords

// To-Do => Improve Typescript GeoJSON handling

/**
 * Removes redundant coordinates from any GeoJSON Geometry.
 *
 * @name cleanCoords
 * @param {Geometry|Feature} geojson Feature or Geometry
 * @param {Object} [options={}] Optional parameters
 * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated
 * @returns {Geometry|Feature} the cleaned input Feature/Geometry
 * @example
 * var line = turf.lineString([[0, 0], [0, 2], [0, 5], [0, 8], [0, 8], [0, 10]]);
 * var multiPoint = turf.multiPoint([[0, 0], [0, 0], [2, 2]]);
 *
 * turf.cleanCoords(line).geometry.coordinates;
 * //= [[0, 0], [0, 10]]
 *
 * turf.cleanCoords(multiPoint).geometry.coordinates;
 * //= [[0, 0], [2, 2]]
 */
function cleanCoords(geojson: any, options: {
    mutate?: boolean,
} = {}) {
    // Backwards compatible with v4.0
    var mutate = (typeof options === 'object') ? options.mutate : options;
    if (!geojson) throw new Error('geojson is required');
    var type = getType(geojson);

    // Store new "clean" points in this Array
    var newCoords = [];

    switch (type) {
    case 'LineString':
        newCoords = cleanLine(geojson);
        break;
    case 'MultiLineString':
    case 'Polygon':
        getCoords(geojson).forEach(function (line) {
            newCoords.push(cleanLine(line));
        });
        break;
    case 'MultiPolygon':
        getCoords(geojson).forEach(function (polygons: any) {
            var polyPoints = [];
            polygons.forEach(function (ring) {
                polyPoints.push(cleanLine(ring));
            });
            newCoords.push(polyPoints);
        });
        break;
    case 'Point':
        return geojson;
    case 'MultiPoint':
        var existing = {};
        getCoords(geojson).forEach(function (coord: any) {
            var key = coord.join('-');
            if (!existing.hasOwnProperty(key)) {
                newCoords.push(coord);
                existing[key] = true;
            }
        });
        break;
    default:
        throw new Error(type + ' geometry not supported');
    }

    // Support input mutation
    if (geojson.coordinates) {
        if (mutate === true) {
            geojson.coordinates = newCoords;
            return geojson;
        }
        return {type: type, coordinates: newCoords};
    } else {
        if (mutate === true) {
            geojson.geometry.coordinates = newCoords;
            return geojson;
        }
        return feature({type: type, coordinates: newCoords}, geojson.properties, {bbox: geojson.bbox, id: geojson.id});
    }
}
开发者ID:Turbo87,项目名称:turf,代码行数:81,代码来源:index.ts


示例6: feature

 .map(function (key) {
     var geometry = { type: key, coordinates: groups[key].coordinates };
     var properties = { collectedProperties: groups[key].properties };
     return feature(geometry, properties);
 }));
开发者ID:Turbo87,项目名称:turf,代码行数:5,代码来源:index.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript helpers.featureCollection函数代码示例发布时间:2022-05-28
下一篇:
TypeScript helpers.degreesToRadians函数代码示例发布时间: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