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


TypeScript meta.coordEach函數代碼示例

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


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

示例1: isNaN

/**
 * Takes a GeoJSON Feature or FeatureCollection and truncates the precision of the geometry.
 *
 * @name truncate
 * @param {GeoJSON} geojson any GeoJSON Feature, FeatureCollection, Geometry or GeometryCollection.
 * @param {Object} [options={}] Optional parameters
 * @param {number} [options.precision=6] coordinate decimal precision
 * @param {number} [options.coordinates=3] maximum number of coordinates (primarly used to remove z coordinates)
 * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
 * @returns {GeoJSON} layer with truncated geometry
 * @example
 * var point = turf.point([
 *     70.46923055566859,
 *     58.11088890802906,
 *     1508
 * ]);
 * var options = {precision: 3, coordinates: 2};
 * var truncated = turf.truncate(point, options);
 * //=truncated.geometry.coordinates => [70.469, 58.111]
 *
 * //addToMap
 * var addToMap = [truncated];
 */
function truncate<T extends AllGeoJSON>(geojson: T, options: {
    precision?: number,
    coordinates?: number,
    mutate?: boolean
} = {}): T {
    // Optional parameters
    var precision = options.precision;
    var coordinates = options.coordinates;
    var mutate = options.mutate;

    // default params
    precision = (precision === undefined || precision === null || isNaN(precision)) ? 6 : precision;
    coordinates = (coordinates === undefined || coordinates === null || isNaN(coordinates)) ? 3 : coordinates;

    // validation
    if (!geojson) throw new Error('<geojson> is required');
    if (typeof precision !== 'number') throw new Error('<precision> must be a number');
    if (typeof coordinates !== 'number') throw new Error('<coordinates> must be a number');

    // prevent input mutation
    if (mutate === false || mutate === undefined) geojson = JSON.parse(JSON.stringify(geojson));

    var factor = Math.pow(10, precision);

    // Truncate Coordinates
    coordEach(geojson, function (coords) {
        truncateCoords(coords, factor, coordinates);
    });
    return geojson;
}
開發者ID:OlympicsORG,項目名稱:turf,代碼行數:53,代碼來源:index.ts

示例2: bbox

/**
 * Takes a set of features, calculates the bbox of all input features, and returns a bounding box.
 *
 * @name bbox
 * @param {GeoJSON} geojson any GeoJSON object
 * @returns {BBox} bbox extent in [minX, minY, maxX, maxY] order
 * @example
 * var line = turf.lineString([[-74, 40], [-78, 42], [-82, 35]]);
 * var bbox = turf.bbox(line);
 * var bboxPolygon = turf.bboxPolygon(bbox);
 *
 * //addToMap
 * var addToMap = [line, bboxPolygon]
 */
function bbox(geojson: AllGeoJSON) {
    const BBox = [Infinity, Infinity, -Infinity, -Infinity];
    coordEach(geojson, coord => {
        if (BBox[0] > coord[0]) BBox[0] = coord[0];
        if (BBox[1] > coord[1]) BBox[1] = coord[1];
        if (BBox[2] < coord[0]) BBox[2] = coord[0];
        if (BBox[3] < coord[1]) BBox[3] = coord[1];
    });
    return BBox;
}
開發者ID:OlympicsORG,項目名稱:turf,代碼行數:24,代碼來源:index.ts

示例3: bbox

/**
 * Takes a set of features, calculates the bbox of all input features, and returns a bounding box.
 *
 * @name bbox
 * @param {GeoJSON} geojson any GeoJSON object
 * @returns {BBox} bbox extent in [minX, minY, maxX, maxY] order
 * @example
 * var line = turf.lineString([[-74, 40], [-78, 42], [-82, 35]]);
 * var bbox = turf.bbox(line);
 * var bboxPolygon = turf.bboxPolygon(bbox);
 *
 * //addToMap
 * var addToMap = [line, bboxPolygon]
 */
export default function bbox(geojson: any): BBox {
    const result: BBox = [Infinity, Infinity, -Infinity, -Infinity];
    coordEach(geojson, (coord) => {
        if (result[0] > coord[0]) { result[0] = coord[0]; }
        if (result[1] > coord[1]) { result[1] = coord[1]; }
        if (result[2] < coord[0]) { result[2] = coord[0]; }
        if (result[3] < coord[1]) { result[3] = coord[1]; }
    });
    return result;
}
開發者ID:Turbo87,項目名稱:turf,代碼行數:24,代碼來源:index.ts

示例4: geomEach

 geomEach(geojson, function (geom, featureIndex, properties) {
     let weight = properties[options.weight];
     weight = (weight === undefined || weight === null) ? 1 : weight;
     if (!isNumber(weight)) throw new Error('weight value must be a number for feature index ' + featureIndex);
     weight = Number(weight);
     if (weight > 0) {
         coordEach(geom, function (coord) {
             sumXs += coord[0] * weight;
             sumYs += coord[1] * weight;
             sumNs += weight;
         });
     }
 });
開發者ID:Turbo87,項目名稱:turf,代碼行數:13,代碼來源:index.ts

示例5: coordEach

/**
 * Takes one or more features and calculates the centroid using the mean of all vertices.
 * This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.
 *
 * @name centroid
 * @param {GeoJSON} geojson GeoJSON to be centered
 * @param {Object} [options={}] Optional Parameters
 * @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties
 * @returns {Feature<Point>} the centroid of the input features
 * @example
 * var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
 *
 * var centroid = turf.centroid(polygon);
 *
 * //addToMap
 * var addToMap = [polygon, centroid]
 */
function centroid<P = Properties>(geojson: AllGeoJSON, options: {
    properties?: P
} = {}): Feature<Point, P> {
    let xSum = 0;
    let ySum = 0;
    let len = 0;
    coordEach(geojson, function (coord) {
        xSum += coord[0];
        ySum += coord[1];
        len++;
    });
    return point([xSum / len, ySum / len], options.properties);
}
開發者ID:Turbo87,項目名稱:turf,代碼行數:30,代碼來源:index.ts

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

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

示例8: coordEach

turf.kinks(polygonFeature);
turf.kinks(polygonGeometry);

turf.lineDistance(lineFeature, "yards");
turf.lineDistance(lineFeature);

turf.lineSlice(pointFeature, pointFeature2, lineFeature);
turf.lineSlice(pointFeature, pointFeature2, lineStringGeometry);

turf.lineSliceAlong(lineFeature, 0, 100, "yards");
turf.lineSliceAlong(lineFeature, 0, 100);

import { coordEach, coordReduce, propEach, propReduce, featureEach, coordAll } from "@turf/meta";

coordEach(pointFeature, (coord) => console.log(coord[0], coord[1]), false);

let arrayReduce: number[] = coordReduce(pointFeatureCollection, (prev, curr) => {
  prev.push(curr);
  return prev;
}, [], false);
let stringReduce: string = coordReduce(pointFeatureCollection, (prev, curr) => prev + curr.toString(), "", false);

propEach(pointFeatureCollection, prop => console.log(prop));

let propCombine: any = propReduce(pointFeatureCollection, (prev, curr) => {
  for (let key in curr) {
    prev[key] = curr[key];
  }
  return prev;
}, {});
開發者ID:arrayjam,項目名稱:auspostcodes,代碼行數:30,代碼來源:turf-test.ts

示例9: reader

const data: GeoJSON.FeatureCollection<GeoJSON.Polygon> = reader('ottawa-parcels.geojson')

let count = 0

console.log('start')
for (let feature of data.features) {
  const road: string = feature.properties['ROAD_NAME']
  const suffix: string = feature.properties['SUFFIX']
  const street = (road && suffix) ? road + ' ' + suffix : road
  const housenumber = feature.properties['ADDRESS_NU']

  feature.properties = {
    'addr:housenumber': housenumber,
    'addr:street': street,
    ref: feature.properties['PI_PARCEL_'],
    source: 'City of Ottawa'
  }

  const unique: any = {}
  meta.coordEach(feature, coord => unique[coord.join(',')] = true)
  if (Object.keys(unique).length > 2) {
    feature = turf.simplify(feature, 0.000001, true)
    collection.push(feature)
  }
  count ++
  if (count % 1000 === 0) { console.log('processed', count, feature.geometry.coordinates[0].length) }
}

console.log('writting')
writer('ottawa-parcels-simplify.geojson', turf.featureCollection(collection))
開發者ID:osmottawa,項目名稱:imports,代碼行數:30,代碼來源:clean-parcels-geojson.ts


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