本文整理汇总了TypeScript中@turf/helpers.multiLineString函数的典型用法代码示例。如果您正苦于以下问题:TypeScript multiLineString函数的具体用法?TypeScript multiLineString怎么用?TypeScript multiLineString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了multiLineString函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getGeom
/**
* Takes a {@link Feature} and a bbox and clips the feature to the bbox using
* [lineclip](https://github.com/mapbox/lineclip).
* May result in degenerate edges when clipping Polygons.
*
* @name bboxClip
* @param {Feature<LineString|MultiLineString|Polygon|MultiPolygon>} feature feature to clip to the bbox
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Feature<LineString|MultiLineString|Polygon|MultiPolygon>} clipped Feature
* @example
* var bbox = [0, 0, 10, 10];
* var poly = turf.polygon([[[2, 2], [8, 4], [12, 8], [3, 7], [2, 2]]]);
*
* var clipped = turf.bboxClip(poly, bbox);
*
* //addToMap
* var addToMap = [bbox, poly, clipped]
*/
export default function bboxClip<G extends Polygon | MultiPolygon | LineString | MultiLineString, P = Properties>(
feature: Feature<G, P> | G,
bbox: BBox,
) {
const geom = getGeom(feature);
const type = geom.type;
const properties = feature.type === "Feature" ? feature.properties : {};
let coords: any[] = geom.coordinates;
switch (type) {
case "LineString":
case "MultiLineString":
const lines: any[] = [];
if (type === "LineString") { coords = [coords]; }
coords.forEach((line) => {
lineclip.polyline(line, bbox, lines);
});
if (lines.length === 1) { return lineString(lines[0], properties); }
return multiLineString(lines, properties);
case "Polygon":
return polygon(clipPolygon(coords, bbox), properties);
case "MultiPolygon":
return multiPolygon(coords.map((poly) => {
return clipPolygon(poly, bbox);
}), properties);
default:
throw new Error("geometry " + type + " not supported");
}
}
示例2: lineString
export function coordsToLine<P = Properties>(
coords: number[][][],
properties: P,
): Feature<LineString | MultiLineString, P> {
if (coords.length > 1) { return multiLineString(coords, properties); }
return lineString(coords[0], properties);
}
示例3: getGeom
/**
* Takes a {@link Feature} and a bbox and clips the feature to the bbox using [lineclip](https://github.com/mapbox/lineclip).
* May result in degenerate edges when clipping Polygons.
*
* @name bboxClip
* @param {Feature<LineString|MultiLineString|Polygon|MultiPolygon>} feature feature to clip to the bbox
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Feature<LineString|MultiLineString|Polygon|MultiPolygon>} clipped Feature
* @example
* var bbox = [0, 0, 10, 10];
* var poly = turf.polygon([[[2, 2], [8, 4], [12, 8], [3, 7], [2, 2]]]);
*
* var clipped = turf.bboxClip(poly, bbox);
*
* //addToMap
* var addToMap = [bbox, poly, clipped]
*/
function bboxClip<G extends Polygon | MultiPolygon | LineString | MultiLineString, P = Properties>(
feature: Feature<G, P> | G,
bbox: BBox
) {
const geom = getGeom(feature);
const type = geom.type;
const properties = feature.type === 'Feature' ? feature.properties : {};
let coords: any[] = geom.coordinates;
switch (type) {
case 'LineString':
case 'MultiLineString':
const lines = [];
if (type === 'LineString') coords = [coords];
coords.forEach(function (line) {
lineclip.polyline(line, bbox, lines);
});
if (lines.length === 1) return lineString(lines[0], properties);
return multiLineString(lines, properties);
case 'Polygon':
return polygon(clipPolygon(coords, bbox), properties);
case 'MultiPolygon':
return multiPolygon(coords.map((polygon) => {
return clipPolygon(polygon, bbox);
}), properties);
default:
throw new Error('geometry ' + type + ' not supported');
}
}
示例4: 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;
})); }
}
示例5: polygon
import {polygon, lineString, multiLineString, multiPolygon} from '@turf/helpers'
import * as rewind from './'
const coords = [[121, -29], [138, -29], [138, -18], [121, -18], [121, -29]]
const poly = polygon([coords])
const line = lineString(coords)
const multiPoly = multiPolygon([[coords], [coords]])
const multiLine = multiLineString([coords, coords])
rewind(line)
rewind(poly)
rewind(multiPoly)
rewind(multiLine)
rewind(poly, true)
rewind(poly, true, true)
示例6: point
import buffer from './'
// Standard Geometry
const pt = point([100, 0]);
const line = lineString([[100, 0], [50, 0]]);
const poly = polygon([[[100, 0], [50, 0], [0, 50], [100, 0]]]);
buffer(pt, 5);
buffer(line, 5);
buffer(poly, 5);
buffer(pt, 5, {units: 'miles'});
buffer(pt, 10, {units: 'meters', steps: 64});
// Multi Geometry
const multiPt = multiPoint([[100, 0], [0, 100]]);
const multiLine = multiLineString([[[100, 0], [50, 0]], [[100, 0], [50, 0]]]);
const multiPoly = multiPolygon([[[[100, 0], [50, 0], [0, 50], [100, 0]]], [[[100, 0], [50, 0], [0, 50], [100, 0]]]]);
buffer(multiPt, 5);
buffer(multiLine, 5);
buffer(multiPoly, 5);
// Collections
const fc = featureCollection<Point|LineString>([pt, line]);
const gc = geometryCollection([pt.geometry, line.geometry]);
buffer(fc, 5);
buffer(gc, 5);
// Mixed Collections
const fcMixed = featureCollection<any>([pt, line, multiPt, multiLine]);
示例7: lineString
import * as lineOffset from '../'
import {lineString, multiLineString} from '@turf/helpers'
const line = lineString([[0, 0], [10, 10]])
const multiLine = multiLineString([[[0, 0], [10, 10]], [[5, 5], [15, 15]]])
lineOffset(line, 50)
lineOffset(line.geometry, 50)
lineOffset(multiLine, 50)
lineOffset(multiLine.geometry, 50)
lineOffset(line, 50, 'miles')
示例8: lineString
import {lineString, multiLineString, polygon, multiPolygon} from '@turf/helpers'
import * as lineOverlap from './'
const line = lineString([[0, 0], [10, 10]]);
const multiLine = multiLineString([[[0, 0], [10, 10]], [[30, 30], [50, 50]]]);
const poly = polygon([[[0, 0], [10, 10], [15, 15], [0, 0]]]);
const multiPoly = multiPolygon([
[[[0, 0], [10, 10], [15, 15], [0, 0]]],
[[[5, 5], [30, 30], [45, 45], [5, 5]]]
])
lineOverlap(line, poly)
lineOverlap(line, line)
lineOverlap(multiPoly, line)
lineOverlap(multiPoly, multiLine)
示例9: point
geomReduce,
geomEach,
flattenReduce,
flattenEach,
segmentReduce,
segmentEach,
lineReduce,
lineEach
} from './'
// Fixtures
const pt = helpers.point([0, 0])
const line = helpers.lineString([[0, 0], [1, 1]])
const poly = helpers.polygon([[[0, 0], [1, 1], [0, 1], [0, 0]]])
const multiPoly = helpers.multiPolygon([[[[0, 0], [1, 1], [0, 1], [0, 0]]]])
const multiLine = helpers.multiLineString([[[0, 0], [1, 1], [0, 1], [0, 0]], [[2, 2], [3, 3]]])
const geomCollection = helpers.geometryCollection([pt.geometry, line.geometry])
const features = helpers.featureCollection([pt, line])
const customPoint = point([10, 20], {foo: 'abc', bar: 123})
const customPoints = featureCollection([customPoint])
const customLineString = lineString([[0, 0], [10, 20]], {foo: 'abc', bar: 123})
const customLineStrings = featureCollection([customLineString])
/**
* meta.coordEach
*/
const coordEachValue: void = meta.coordEach(pt, coords => coords)
coordEach(pt, (coords, index) => coords)
meta.coordEach(pt, (coords, index) => coords)
meta.coordEach(pt.geometry, coords => { const equal: number[] = coords })
示例10: multiPoint
import {multiPoint, multiLineString, geometryCollection} from '@turf/helpers'
import * as flatten from './'
const multiPt = multiPoint([[0, 0], [10, 10]])
const multiLine = multiLineString([[[20, 20], [30, 30]], [[0, 0], [10, 10]]])
flatten(multiPt);
flatten(multiLine);
flatten(multiPt.geometry);
flatten(multiLine.geometry);
flatten(geometryCollection([multiPt.geometry, multiLine.geometry]));