本文整理汇总了TypeScript中@turf/meta.flattenEach函数的典型用法代码示例。如果您正苦于以下问题:TypeScript flattenEach函数的具体用法?TypeScript flattenEach怎么用?TypeScript flattenEach使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flattenEach函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: point
/**
* Takes a {@link Point} and a {@link LineString} and calculates the closest Point on the (Multi)LineString.
*
* @name nearestPointOnLine
* @param {Geometry|Feature<LineString|MultiLineString>} lines lines to snap to
* @param {Geometry|Feature<Point>|number[]} pt point to snap from
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
* @returns {Feature<Point>} closest point on the `line` to `point`. The properties object will contain three values: `index`: closest point was found on nth line part, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point.
* @example
* var line = turf.lineString([
* [-77.031669, 38.878605],
* [-77.029609, 38.881946],
* [-77.020339, 38.884084],
* [-77.025661, 38.885821],
* [-77.021884, 38.889563],
* [-77.019824, 38.892368]
* ]);
* var pt = turf.point([-77.037076, 38.884017]);
*
* var snapped = turf.nearestPointOnLine(line, pt, {units: 'miles'});
*
* //addToMap
* var addToMap = [line, pt, snapped];
* snapped.properties['marker-color'] = '#00f';
*/
function nearestPointOnLine<G extends LineString|MultiLineString>(
lines: Feature<G> | G,
pt: Coord,
options: {units?: Units} = {}
): NearestPointOnLine {
let closestPt: any = point([Infinity, Infinity], {
dist: Infinity
});
let length = 0.0;
flattenEach(lines, function (line: any) {
const coords: any = getCoords(line);
for (let i = 0; i < coords.length - 1; i++) {
//start
const start = point(coords[i]);
start.properties.dist = distance(pt, start, options);
//stop
const stop = point(coords[i + 1]);
stop.properties.dist = distance(pt, stop, options);
// sectionLength
const sectionLength = distance(start, stop, options);
//perpendicular
const heightDistance = Math.max(start.properties.dist, stop.properties.dist);
const direction = bearing(start, stop);
const perpendicularPt1 = destination(pt, heightDistance, direction + 90, options);
const perpendicularPt2 = destination(pt, heightDistance, direction - 90, options);
const intersect = lineIntersects(
lineString([perpendicularPt1.geometry.coordinates, perpendicularPt2.geometry.coordinates]),
lineString([start.geometry.coordinates, stop.geometry.coordinates])
);
let intersectPt = null;
if (intersect.features.length > 0) {
intersectPt = intersect.features[0];
intersectPt.properties.dist = distance(pt, intersectPt, options);
intersectPt.properties.location = length + distance(start, intersectPt, options);
}
if (start.properties.dist < closestPt.properties.dist) {
closestPt = start;
closestPt.properties.index = i;
closestPt.properties.location = length;
}
if (stop.properties.dist < closestPt.properties.dist) {
closestPt = stop;
closestPt.properties.index = i + 1;
closestPt.properties.location = length + sectionLength;
}
if (intersectPt && intersectPt.properties.dist < closestPt.properties.dist) {
closestPt = intersectPt;
closestPt.properties.index = i;
}
// update length
length += sectionLength;
}
});
return closestPt;
}
示例2: getHomogenousType
/**
* Checks if GeoJSON is Homogenous
*
* @private
* @param {GeoJSON} geojson GeoJSON
* @returns {string|null} Homogenous type or null if multiple types
*/
function getHomogenousType(geojson: any) {
const types: {[key: string]: boolean} = {};
flattenEach(geojson, (feature) => {
types[feature.geometry.type] = true;
});
const keys = Object.keys(types);
if (keys.length === 1) { return keys[0]; }
return null;
}
示例3: booleanDisjoint
/**
* Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set.
*
* @name booleanDisjoint
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
* @returns {boolean} true/false
* @example
* var point = turf.point([2, 2]);
* var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
*
* turf.booleanDisjoint(line, point);
* //=true
*/
function booleanDisjoint(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean {
var boolean;
flattenEach(feature1, function (flatten1) {
flattenEach(feature2, function (flatten2) {
if (boolean === false) return false;
boolean = disjoint(flatten1.geometry, flatten2.geometry);
});
});
return boolean;
}
示例4: booleanDisjoint
/**
* Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set.
*
* @name booleanDisjoint
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
* @returns {boolean} true/false
* @example
* var point = turf.point([2, 2]);
* var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
*
* turf.booleanDisjoint(line, point);
* //=true
*/
function booleanDisjoint(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean {
let bool = true;
flattenEach(feature1, (flatten1) => {
flattenEach(feature2, (flatten2) => {
if (bool === false) { return false; }
bool = disjoint(flatten1.geometry, flatten2.geometry);
});
});
return bool;
}
示例5: booleanIntersects
/**
* Boolean-intersects returns (TRUE) two geometries intersect.
*
* @name booleanIntersects
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
* @returns {boolean} true/false
* @example
* var point = turf.point([2, 2]);
* var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
*
* turf.booleanIntersects(line, point);
* //=true
*/
function booleanIntersects(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry) {
var boolean;
flattenEach(feature1, function (flatten1) {
flattenEach(feature2, function (flatten2) {
if (boolean === true) return true;
boolean = !booleanDisjoint(flatten1.geometry, flatten2.geometry);
});
});
return boolean;
}
示例6: booleanIntersects
/**
* Boolean-intersects returns (TRUE) two geometries intersect.
*
* @name booleanIntersects
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
* @returns {boolean} true/false
* @example
* var point = turf.point([2, 2]);
* var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
*
* turf.booleanIntersects(line, point);
* //=true
*/
export default function booleanIntersects(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry) {
let bool = false;
flattenEach(feature1, (flatten1) => {
flattenEach(feature2, (flatten2) => {
if (bool === true) { return true; }
bool = !booleanDisjoint(flatten1.geometry, flatten2.geometry);
});
});
return bool;
}
示例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 {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);
}
示例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 {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);
}
示例9: 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;
}