本文整理汇总了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;未经允许,请勿转载。 |
请发表评论