當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript clone.default函數代碼示例

本文整理匯總了TypeScript中@turf/clone.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了default函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: polygonDissolve

/**
 * Dissolves all overlapping (Multi)Polygon
 *
 * @param {FeatureCollection<Polygon|MultiPolygon>} geojson Polygons to dissolve
 * @param {Object} [options={}] Optional parameters
 * @param {boolean} [options.mutate=false] Prevent input mutation
 * @returns {Feature<Polygon|MultiPolygon>} Dissolved Polygons
 */
export default function polygonDissolve(
    geojson: FeatureCollection<Polygon|MultiPolygon>,
    options: {mutate?: boolean} = {},
): Feature<Polygon|MultiPolygon> | null {
    // Validation
    if (getType(geojson) !== "FeatureCollection") { throw new Error("geojson must be a FeatureCollection"); }
    if (!geojson.features.length) { throw new Error("geojson is empty"); }

    // Clone geojson to avoid side effects
    // Topojson modifies in place, so we need to deep clone first
    if (options.mutate === false || options.mutate === undefined) { geojson = clone(geojson); }

    const geoms: any[] = [];
    flattenEach(geojson, (feature) => {
        geoms.push(feature.geometry);
    });
    const topo: any = topology({geoms: geometryCollection(geoms).geometry});
    const merged: any = merge(topo, topo.objects.geoms.geometries);
    return merged;
}
開發者ID:Turbo87,項目名稱:turf,代碼行數:28,代碼來源:turf-polygon-dissolve.ts

示例2: clustersKmeans

/**
 * Takes a set of {@link Point|points} and partition them into clusters using the k-mean .
 * It uses the [k-means algorithm](https://en.wikipedia.org/wiki/K-means_clustering)
 *
 * @name clustersKmeans
 * @param {FeatureCollection<Point>} points to be clustered
 * @param {Object} [options={}] Optional parameters
 * @param {number} [options.numberOfClusters=Math.sqrt(numberOfPoints/2)] numberOfClusters that will be generated
 * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
 * @returns {FeatureCollection<Point>} Clustered Points with an additional two properties associated to each Feature:
 * - {number} cluster - the associated clusterId
 * - {[number, number]} centroid - Centroid of the cluster [Longitude, Latitude]
 * @example
 * // create random points with random z-values in their properties
 * var points = turf.randomPoint(100, {bbox: [0, 30, 20, 50]});
 * var options = {numberOfClusters: 7};
 * var clustered = turf.clustersKmeans(points, options);
 *
 * //addToMap
 * var addToMap = [clustered];
 */
function clustersKmeans(points: FeatureCollection<Point>, options: {
    numberOfClusters?: number,
    mutate?: boolean
} = {}): FeatureCollection<Point, KmeansProps> {
    // Default Params
    var count = points.features.length;
    options.numberOfClusters = options.numberOfClusters || Math.round(Math.sqrt(count / 2));

    // numberOfClusters can't be greater than the number of points
    // fallbacks to count
    if (options.numberOfClusters > count) options.numberOfClusters = count;

    // Clone points to prevent any mutations (enabled by default)
    if (options.mutate !== true) points = clone(points);

    // collect points coordinates
    var data = coordAll(points);

    // create seed to avoid skmeans to drift
    var initialCentroids = data.slice(0, options.numberOfClusters);

    // create skmeans clusters
    var skmeansResult = skmeans(data, options.numberOfClusters, initialCentroids);

    // store centroids {clusterId: [number, number]}
    var centroids = {};
    skmeansResult.centroids.forEach(function (coord, idx) {
        centroids[idx] = coord;
    });

    // add associated cluster number
    featureEach(points, function (point, index) {
        var clusterId = skmeansResult.idxs[index];
        point.properties.cluster = clusterId;
        point.properties.centroid = centroids[clusterId];
    });

    return points;
}
開發者ID:Turbo87,項目名稱:turf,代碼行數:60,代碼來源:index.ts

示例3: lineDissolve

/**
 * Merges all connected (non-forking, non-junctioning) line strings into single lineStrings.
 * [LineString] -> LineString|MultiLineString
 *
 * @param {FeatureCollection<LineString|MultiLineString>} geojson Lines to dissolve
 * @param {Object} [options={}] Optional parameters
 * @param {boolean} [options.mutate=false] Prevent input mutation
 * @returns {Feature<LineString|MultiLineString>} Dissolved lines
 */
function lineDissolve(
    geojson: FeatureCollection<LineString|MultiLineString>,
    options: {mutate?: boolean} = {},
): Feature<LineString|MultiLineString> | null {
    // Optional parameters
    options = options || {};
    if (!isObject(options)) { throw new Error("options is invalid"); }
    const mutate = options.mutate;

    // Validation
    if (getType(geojson) !== "FeatureCollection") { throw new Error("geojson must be a FeatureCollection"); }
    if (!geojson.features.length) { throw new Error("geojson is empty"); }

    // Clone geojson to avoid side effects
    if (mutate === false || mutate === undefined) { geojson = clone(geojson); }

    const result: any[] = [];
    const lastLine = lineReduce(geojson, (previousLine: any, currentLine: any) => {
        // Attempt to merge this LineString with the other LineStrings, updating
        // the reference as it is merged with others and grows.
        const merged = mergeLineStrings(previousLine, currentLine);

        // Accumulate the merged LineString
        if (merged) { return merged;
        // Put the unmerged LineString back into the list
        } else {
            result.push(previousLine);
            return currentLine;
        }
    });
    // Append the last line
    if (lastLine) { result.push(lastLine); }

    // Return null if no lines were dissolved
    if (!result.length) {
        return null;
    // Return LineString if only 1 line was dissolved
    } else if (result.length === 1) {
        return result[0];
    // Return MultiLineString if multiple lines were dissolved with gaps
    } else { return multiLineString(result.map((line) => {
        return line.coordinates;
    })); }
}
開發者ID:Turbo87,項目名稱:turf,代碼行數:53,代碼來源:turf-line-dissolve.ts

示例4: nearestPoint

/**
 * Takes a reference {@link Point|point} and a FeatureCollection of Features
 * with Point geometries and returns the
 * point from the FeatureCollection closest to the reference. This calculation
 * is geodesic.
 *
 * @name nearestPoint
 * @param {Coord} targetPoint the reference point
 * @param {FeatureCollection<Point>} points against input point set
 * @returns {Feature<Point>} the closest point in the set to the reference point
 * @example
 * var targetPoint = turf.point([28.965797, 41.010086], {"marker-color": "#0F0"});
 * var points = turf.featureCollection([
 *     turf.point([28.973865, 41.011122]),
 *     turf.point([28.948459, 41.024204]),
 *     turf.point([28.938674, 41.013324])
 * ]);
 *
 * var nearest = turf.nearestPoint(targetPoint, points);
 *
 * //addToMap
 * var addToMap = [targetPoint, points, nearest];
 * nearest.properties['marker-color'] = '#F00';
 */
function nearestPoint(targetPoint: Coord, points: FeatureCollection<Point>): NearestPoint {
    // Input validation
    if (!targetPoint) throw new Error('targetPoint is required');
    if (!points) throw new Error('points is required');

    let nearest: NearestPoint;
    let minDist: number = Infinity;
    let bestFeatureIndex: number = 0;
    featureEach(points,  (pt, featureIndex) => {
        const distanceToPoint = distance(targetPoint, pt);
        if (distanceToPoint < minDist) {
            bestFeatureIndex = featureIndex;
            minDist = distanceToPoint;
        }
    });
    nearest = clone(points.features[bestFeatureIndex]);
    nearest.properties.featureIndex = bestFeatureIndex;
    nearest.properties.distanceToPoint = minDist;
    return nearest;
}
開發者ID:Turbo87,項目名稱:turf,代碼行數:44,代碼來源:index.ts

示例5: convert

/**
 * Converts a GeoJSON coordinates to the defined `projection`
 *
 * @private
 * @param {GeoJSON} geojson GeoJSON Feature or Geometry
 * @param {string} projection defines the projection system to convert the coordinates to
 * @param {Object} [options] Optional parameters
 * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
 * @returns {GeoJSON} Converted GeoJSON
 */
function convert(geojson: any, projection: string, options: {mutate?: boolean} = {}): any {
    // Optional parameters
    options = options || {};
    var mutate = options.mutate;

    // Validation
    if (!geojson) throw new Error('geojson is required');

    // Handle Position
    if (Array.isArray(geojson) && isNumber(geojson[0])) geojson = (projection === 'mercator') ? convertToMercator(geojson) : convertToWgs84(geojson);

    // Handle GeoJSON
    else {
        // Handle possible data mutation
        if (mutate !== true) geojson = clone(geojson);

        coordEach(geojson, function (coord) {
            var newCoord = (projection === 'mercator') ? convertToMercator(coord) : convertToWgs84(coord);
            coord[0] = newCoord[0];
            coord[1] = newCoord[1];
        });
    }
    return geojson;
}
開發者ID:Turbo87,項目名稱:turf,代碼行數:34,代碼來源:index.ts


注:本文中的@turf/clone.default函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。