本文整理汇总了TypeScript中@turf/line-segment.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: featureCollection
/**
* 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
示例2: booleanParallel
/**
* Boolean-Parallel returns True if each segment of `line1` is parallel to the correspondent segment of `line2`
*
* @name booleanParallel
* @param {Geometry|Feature<LineString>} line1 GeoJSON Feature or Geometry
* @param {Geometry|Feature<LineString>} line2 GeoJSON Feature or Geometry
* @returns {boolean} true/false if the lines are parallel
* @example
* var line1 = turf.lineString([[0, 0], [0, 1]]);
* var line2 = turf.lineString([[1, 0], [1, 1]]);
*
* turf.booleanParallel(line1, line2);
* //=true
*/
function booleanParallel(line1: Feature<LineString> | LineString, line2: Feature<LineString> | LineString): boolean {
// validation
if (!line1) throw new Error('line1 is required');
if (!line2) throw new Error('line2 is required');
var type1 = getType(line1, 'line1');
if (type1 !== 'LineString') throw new Error('line1 must be a LineString');
var type2 = getType(line2, 'line2');
if (type2 !== 'LineString') throw new Error('line2 must be a LineString');
var segments1 = lineSegment(cleanCoords(line1)).features;
var segments2 = lineSegment(cleanCoords(line2)).features;
for (var i = 0; i < segments1.length; i++) {
var segment1 = segments1[i].geometry.coordinates;
if (!segments2[i]) break;
var segment2 = segments2[i].geometry.coordinates;
if (!isParallel(segment1, segment2)) return false;
}
return true;
}
开发者ID:OlympicsORG,项目名称:turf,代码行数:34,代码来源:index.ts
示例3: featureCollection
/**
* 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
注:本文中的@turf/line-segment.default函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论