当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript helpers.featureCollection函数代码示例

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


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

示例1: filterSpotsNearDestination

 public filterSpotsNearDestination(spots: Spots, destination: GeoJSON.Position, distance: number): Spots {
   if (!(destination && spots && distance)) {
     return [];
   }
   // Create a circle of 200m and get the spots within it
   const nearbyBounds = turfHelper.featureCollection([turfCircle(turfHelper.point(destination), 0.2)]);
   const searchSpots = turfHelper.featureCollection(spots);
   return turfWithin(searchSpots, nearbyBounds).features;
 }
开发者ID:christinakayastha,项目名称:parkabler,代码行数:9,代码来源:distance.service.ts

示例2: centerMedian

/**
 * Takes a {@link FeatureCollection} of points and calculates the median center,
 * algorithimically. The median center is understood as the point that is
 * requires the least total travel from all other points.
 *
 * Turfjs has four different functions for calculating the center of a set of
 * data. Each is useful depending on circumstance.
 *
 * `@turf/center` finds the simple center of a dataset, by finding the
 * midpoint between the extents of the data. That is, it divides in half the
 * farthest east and farthest west point as well as the farthest north and
 * farthest south.
 *
 * `@turf/center-of-mass` imagines that the dataset is a sheet of paper.
 * The center of mass is where the sheet would balance on a fingertip.
 *
 * `@turf/center-mean` takes the averages of all the coordinates and
 * produces a value that respects that. Unlike `@turf/center`, it is
 * sensitive to clusters and outliers. It lands in the statistical middle of a
 * dataset, not the geographical. It can also be weighted, meaning certain
 * points are more important than others.
 *
 * `@turf/center-median` takes the mean center and tries to find, iteratively,
 * a new point that requires the least amount of travel from all the points in
 * the dataset. It is not as sensitive to outliers as `@turf/center-mean`, but it is
 * attracted to clustered data. It, too, can be weighted.
 *
 * **Bibliography**
 *
 * Harold W. Kuhn and Robert E. Kuenne, “An Efficient Algorithm for the
 * Numerical Solution of the Generalized Weber Problem in Spatial
 * Economics,” _Journal of Regional Science_ 4, no. 2 (1962): 21–33,
 * doi:{@link https://doi.org/10.1111/j.1467-9787.1962.tb00902.x}.
 *
 * James E. Burt, Gerald M. Barber, and David L. Rigby, _Elementary
 * Statistics for Geographers_, 3rd ed., New York: The Guilford
 * Press, 2009, 150–151.
 *
 * @name centerMedian
 * @param {FeatureCollection<any>} features Any GeoJSON Feature Collection
 * @param {Object} [options={}] Optional parameters
 * @param {string} [options.weight] the property name used to weight the center
 * @param {number} [options.tolerance=0.001] the difference in distance between candidate medians at which point the algorighim stops iterating.
 * @param {number} [options.counter=10] how many attempts to find the median, should the tolerance be insufficient.
 * @returns {Feature<Point>} The median center of the collection
 * @example
 * var points = turf.points([[0, 0], [1, 0], [0, 1], [5, 8]]);
 * var medianCenter = turf.centerMedian(points);
 *
 * //addToMap
 * var addToMap = [points, medianCenter]
 */
function centerMedian(
    features: FeatureCollection<any>,
    options: { weight?: string, tolerance?: number, counter?: number} = {}
): Feature<Point, {
    medianCandidates: Array<Position>,
    [key: string]: any
}> {
    // Optional params
    options = options || {};
    if (!isObject(options)) throw new Error('options is invalid');
    var counter = options.counter || 10;
    if (!isNumber(counter)) throw new Error('counter must be a number');
    var weightTerm = options.weight;

    // Calculate mean center:
    var meanCenter = centerMean(features, {weight: options.weight});

    // Calculate center of every feature:
    var centroids: any = featureCollection([]);
    featureEach(features, function (feature) {
        centroids.features.push(centroid(feature, {properties: {weight: feature.properties[weightTerm]}}));
    });

    centroids.properties = {
        tolerance: options.tolerance,
        medianCandidates: []
    };
    return findMedian(meanCenter.geometry.coordinates, [0, 0], centroids, counter);
}
开发者ID:Turbo87,项目名称:turf,代码行数:81,代码来源:index.ts

示例3: distance

 const observedMeanDistance = features.map((feature, index) => {
     const otherFeatures = featureCollection<Point>(features.filter((f, i) => {
         return i !== index;
     }));
     // Have to add the ! to make typescript validation pass
     // see https://stackoverflow.com/a/40350534/1979085
     return distance(feature, nearestPoint(feature, otherFeatures).geometry!.coordinates, {units});
 }).reduce((sum, value) => { return sum + value; }, 0) / n;
开发者ID:Turbo87,项目名称:turf,代码行数:8,代码来源:index.ts

示例4: 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

示例5: randomPoint

export function randomPoint(count?: number, options: {
    bbox?: BBox,
} = {}): FeatureCollection<Point, any> {
    if (count === undefined || count === null) { count = 1; }
    const features = [];
    for (let i = 0; i < count; i++) {
        features.push(point(randomPosition(options.bbox)));
    }
    return featureCollection(features);
}
开发者ID:Turbo87,项目名称:turf,代码行数:10,代码来源:index.ts

示例6: while

/**
 * Creates a {@link Point} grid from a bounding box, {@link FeatureCollection} or {@link Feature}.
 *
 * @name pointGrid
 * @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
 * @param {number} cellSide the distance between points, in units
 * @param {Object} [options={}] Optional parameters
 * @param {string} [options.units='kilometers'] used in calculating cellSide, can be degrees, radians, miles, or kilometers
 * @param {Feature<Polygon|MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
 * @param {Object} [options.properties={}] passed to each point of the grid
 * @returns {FeatureCollection<Point>} grid of points
 * @example
 * var extent = [-70.823364, -33.553984, -70.473175, -33.302986];
 * var cellSide = 3;
 * var options = {units: 'miles'};
 *
 * var grid = turf.pointGrid(extent, cellSide, options);
 *
 * //addToMap
 * var addToMap = [grid];
 */
function pointGrid<P = Properties>(bbox: BBox, cellSide: number, options: {
    units?: Units,
    mask?: Feature<Polygon | MultiPolygon>,
    properties?: P,
} = {}): FeatureCollection<Point, P> {
    // Default parameters
    if (options.mask && !options.units) options.units = 'kilometers';

    // Containers
    var results = [];

    // Typescript handles the Type Validation
    // if (cellSide === null || cellSide === undefined) throw new Error('cellSide is required');
    // if (!isNumber(cellSide)) throw new Error('cellSide is invalid');
    // if (!bbox) throw new Error('bbox is required');
    // if (!Array.isArray(bbox)) throw new Error('bbox must be array');
    // if (bbox.length !== 4) throw new Error('bbox must contain 4 numbers');
    // if (mask && ['Polygon', 'MultiPolygon'].indexOf(getType(mask)) === -1) throw new Error('options.mask must be a (Multi)Polygon');

    var west = bbox[0];
    var south = bbox[1];
    var east = bbox[2];
    var north = bbox[3];

    var xFraction = cellSide / (distance([west, south], [east, south], options));
    var cellWidth = xFraction * (east - west);
    var yFraction = cellSide / (distance([west, south], [west, north], options));
    var cellHeight = yFraction * (north - south);

    var bboxWidth = (east - west);
    var bboxHeight = (north - south);
    var columns = Math.floor(bboxWidth / cellWidth);
    var rows = Math.floor(bboxHeight / cellHeight);

    // adjust origin of the grid
    var deltaX = (bboxWidth - columns * cellWidth) / 2;
    var deltaY = (bboxHeight - rows * cellHeight) / 2;

    var currentX = west + deltaX;
    while (currentX <= east) {
        var currentY = south + deltaY;
        while (currentY <= north) {
            var cellPt = point([currentX, currentY], options.properties);
            if (options.mask) {
                if (within(cellPt, options.mask)) results.push(cellPt);
            } else {
                results.push(cellPt);
            }
            currentY += cellHeight;
        }
        currentX += cellWidth;
    }

    return featureCollection(results);
}
开发者ID:Turbo87,项目名称:turf,代码行数:76,代码来源:index.ts

示例7: flattenEach

/**
 * Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a
 * {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.
 *
 * @name lineSegment
 * @param {GeoJSON} geojson GeoJSON Polygon or LineString
 * @returns {FeatureCollection<LineString>} 2-vertex line segments
 * @example
 * var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
 * var segments = turf.lineSegment(polygon);
 *
 * //addToMap
 * var addToMap = [polygon, segments]
 */
function lineSegment<G extends LineString | MultiLineString | Polygon | MultiPolygon>(
    geojson: Feature<G> | FeatureCollection<G> | G,
): FeatureCollection<LineString> {
    if (!geojson) { throw new Error("geojson is required"); }

    const results: Array<Feature<LineString>> = [];
    flattenEach(geojson, (feature: Feature<any>) => {
        lineSegmentFeature(feature, results);
    });
    return featureCollection(results);
}
开发者ID:Turbo87,项目名称:turf,代码行数:25,代码来源:index.ts

示例8: flattenEach

/**
 * Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.
 *
 * @name lineSegment
 * @param {Geometry|FeatureCollection|Feature<LineString|MultiLineString|MultiPolygon|Polygon>} geojson GeoJSON Polygon or LineString
 * @returns {FeatureCollection<LineString>} 2-vertex line segments
 * @example
 * var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
 * var segments = turf.lineSegment(polygon);
 *
 * //addToMap
 * var addToMap = [polygon, segments]
 */
function lineSegment<G extends LineString | MultiLineString | Polygon | MultiPolygon>(
    geojson: Feature<G> | FeatureCollection<G> | G
): FeatureCollection<LineString> {
    if (!geojson) throw new Error('geojson is required');

    var results: Feature<LineString>[] = [];
    flattenEach(geojson, function (feature) {
        lineSegmentFeature(feature, results);
    });
    return featureCollection(results);
}
开发者ID:OlympicsORG,项目名称:turf,代码行数:24,代码来源:index.ts

示例9: 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

示例10: polygon

/**
 * Creates a square grid from a bounding box, {@link Feature} or {@link FeatureCollection}.
 *
 * @name squareGrid
 * @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
 * @param {number} cellSide of each cell, in units
 * @param {Object} [options={}] Optional parameters
 * @param {string} [options.units='kilometers'] used in calculating cellSide, can be degrees,
 * radians, miles, or kilometers
 * @param {Feature<Polygon|MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon,
 * the grid Points will be created only inside it
 * @param {Object} [options.properties={}] passed to each point of the grid
 * @returns {FeatureCollection<Polygon>} grid a grid of polygons
 * @example
 * var bbox = [-95, 30 ,-85, 40];
 * var cellSide = 50;
 * var options = {units: 'miles'};
 *
 * var squareGrid = turf.squareGrid(bbox, cellSide, options);
 *
 * //addToMap
 * var addToMap = [squareGrid]
 */
function squareGrid<P = Properties>(bbox: BBox, cellSide: number, options: {
    units?: Units,
    properties?: P,
    mask?: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon,
} = {}): FeatureCollection<Polygon, P> {
    // Containers
    const results = [];
    const west = bbox[0];
    const south = bbox[1];
    const east = bbox[2];
    const north = bbox[3];

    const xFraction = cellSide / (distance([west, south], [east, south], options));
    const cellWidth = xFraction * (east - west);
    const yFraction = cellSide / (distance([west, south], [west, north], options));
    const cellHeight = yFraction * (north - south);

    // rows & columns
    const bboxWidth = (east - west);
    const bboxHeight = (north - south);
    const columns = Math.floor(bboxWidth / cellWidth);
    const rows = Math.floor(bboxHeight / cellHeight);

    // adjust origin of the grid
    const deltaX = (bboxWidth - columns * cellWidth) / 2;
    const deltaY = (bboxHeight - rows * cellHeight) / 2;

    // iterate over columns & rows
    let currentX = west + deltaX;
    for (let column = 0; column < columns; column++) {
        let currentY = south + deltaY;
        for (let row = 0; row < rows; row++) {
            const cellPoly = polygon([[
                [currentX, currentY],
                [currentX, currentY + cellHeight],
                [currentX + cellWidth, currentY + cellHeight],
                [currentX + cellWidth, currentY],
                [currentX, currentY],
            ]], options.properties);
            if (options.mask) {
                if (intersect(options.mask, cellPoly)) { results.push(cellPoly); }
            } else {
                results.push(cellPoly);
            }

            currentY += cellHeight;
        }
        currentX += cellWidth;
    }
    return featureCollection(results);
}
开发者ID:antonsimola,项目名称:turf,代码行数:74,代码来源:index.ts


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