Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turf/meta

Package Overview
Dependencies
Maintainers
4
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/meta - npm Package Compare versions

Comparing version 5.1.6 to 5.2.0

35

index.d.ts

@@ -108,3 +108,3 @@ import {

*/
export function geomEach<G extends Geometries, P = Properties>(
export function geomEach<G extends (Geometries | null), P = Properties>(
geojson: Feature<G, P> | FeatureCollection<G, P> | G | GeometryCollection | Feature<GeometryCollection, P>,

@@ -189,1 +189,34 @@ callback: (currentGeometry: G,

): void;
/**
* http://turfjs.org/docs/#findsegment
*/
export function findSegment<G extends LineString | MultiLineString | Polygon | MultiPolygon, P = Properties>(
geojson: Feature<G, P> | FeatureCollection<G, P> | G,
options?: {
featureIndex?: number,
multiFeatureIndex?: number,
geometryIndex?: number,
segmentIndex?: number,
properties?: P,
bbox?: BBox,
id?: Id
}
): Feature<LineString, P>;
/**
* http://turfjs.org/docs/#findpoint
*/
export function findPoint<G extends GeometryObject, P = Properties>(
geojson: Feature<G, P> | FeatureCollection<G, P> | G,
options?: {
featureIndex?: number,
multiFeatureIndex?: number,
geometryIndex?: number,
coordIndex?: number,
properties?: P,
bbox?: BBox,
id?: Id
}
): Feature<Point, P>;

@@ -1,2 +0,2 @@

import { feature, lineString } from '@turf/helpers';
import { feature, point, lineString, isObject } from '@turf/helpers';

@@ -21,2 +21,3 @@ /**

* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
* @returns {void}
* @example

@@ -84,3 +85,3 @@ * var features = turf.featureCollection([

case 'Point':
callback(coords, coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
if (callback(coords, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;

@@ -92,3 +93,3 @@ multiFeatureIndex++;

for (j = 0; j < coords.length; j++) {
callback(coords[j], coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
if (callback(coords[j], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;

@@ -103,3 +104,3 @@ if (geomType === 'MultiPoint') multiFeatureIndex++;

for (k = 0; k < coords[j].length - wrapShrink; k++) {
callback(coords[j][k], coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
if (callback(coords[j][k], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;

@@ -117,3 +118,3 @@ }

for (l = 0; l < coords[j][k].length - wrapShrink; l++) {
callback(coords[j][k][l], coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
if (callback(coords[j][k][l], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;

@@ -128,3 +129,3 @@ }

for (j = 0; j < geometry.geometries.length; j++)
coordEach(geometry.geometries[j], callback, excludeWrapCoord);
if (coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false) return false;
break;

@@ -211,2 +212,3 @@ default:

* @param {Function} callback a method that takes (currentProperties, featureIndex)
* @returns {void}
* @example

@@ -228,3 +230,3 @@ * var features = turf.featureCollection([

for (i = 0; i < geojson.features.length; i++) {
callback(geojson.features[i].properties, i);
if (callback(geojson.features[i].properties, i) === false) break;
}

@@ -307,2 +309,3 @@ break;

* @param {Function} callback a method that takes (currentFeature, featureIndex)
* @returns {void}
* @example

@@ -324,3 +327,3 @@ * var features = turf.featureCollection([

for (var i = 0; i < geojson.features.length; i++) {
callback(geojson.features[i], i);
if (callback(geojson.features[i], i) === false) break;
}

@@ -421,2 +424,3 @@ }

* @param {Function} callback a method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
* @returns {void}
* @example

@@ -479,3 +483,3 @@ * var features = turf.featureCollection([

if (geometry === null) {
callback(null, featureIndex, featureProperties, featureBBox, featureId);
if (callback(null, featureIndex, featureProperties, featureBBox, featureId) === false) return false;
continue;

@@ -490,3 +494,3 @@ }

case 'MultiPolygon': {
callback(geometry, featureIndex, featureProperties, featureBBox, featureId);
if (callback(geometry, featureIndex, featureProperties, featureBBox, featureId) === false) return false;
break;

@@ -496,3 +500,3 @@ }

for (j = 0; j < geometry.geometries.length; j++) {
callback(geometry.geometries[j], featureIndex, featureProperties, featureBBox, featureId);
if (callback(geometry.geometries[j], featureIndex, featureProperties, featureBBox, featureId) === false) return false;
}

@@ -604,3 +608,3 @@ break;

case 'Polygon':
callback(feature(geometry, properties, {bbox: bbox, id: id}), featureIndex, 0);
if (callback(feature(geometry, properties, {bbox: bbox, id: id}), featureIndex, 0) === false) return false;
return;

@@ -624,3 +628,4 @@ }

geometry.coordinates.forEach(function (coordinate, multiFeatureIndex) {
for (var multiFeatureIndex = 0; multiFeatureIndex < geometry.coordinates.length; multiFeatureIndex++) {
var coordinate = geometry.coordinates[multiFeatureIndex];
var geom = {

@@ -630,5 +635,4 @@ type: geomType,

};
callback(feature(geom, properties), featureIndex, multiFeatureIndex);
});
if (callback(feature(geom, properties), featureIndex, multiFeatureIndex) === false) return false;
}
});

@@ -738,8 +742,14 @@ }

// Generate 2-vertex line segments
coordReduce(feature, function (previousCoords, currentCoord, coordIndex, featureIndexCoord, mutliPartIndexCoord, geometryIndex) {
var previousCoords;
if (coordEach(feature, function (currentCoord, coordIndex, featureIndexCoord, mutliPartIndexCoord, geometryIndex) {
// Simulating a meta.coordReduce() since `reduce` operations cannot be stopped by returning `false`
if (previousCoords === undefined) {
previousCoords = currentCoord;
return;
}
var currentSegment = lineString([previousCoords, currentCoord], feature.properties);
callback(currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex);
if (callback(currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) === false) return false;
segmentIndex++;
return currentCoord;
});
previousCoords = currentCoord;
}) === false) return false;
});

@@ -852,7 +862,7 @@ }

case 'LineString':
callback(feature, featureIndex, multiFeatureIndex, 0, 0);
if (callback(feature, featureIndex, multiFeatureIndex, 0, 0) === false) return false;
break;
case 'Polygon':
for (var geometryIndex = 0; geometryIndex < coords.length; geometryIndex++) {
callback(lineString(coords[geometryIndex], feature.properties), featureIndex, multiFeatureIndex, geometryIndex);
if (callback(lineString(coords[geometryIndex], feature.properties), featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
}

@@ -918,1 +928,196 @@ break;

}
/**
* Finds a particular 2-vertex LineString Segment from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
* Point & MultiPoint will always return null.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.segmentIndex=0] Segment Index
* @param {Object} [options.properties={}] Translate Properties to output LineString
* @param {BBox} [options.bbox={}] Translate BBox to output LineString
* @param {number|string} [options.id={}] Translate Id to output LineString
* @returns {Feature<LineString>} 2-vertex GeoJSON Feature LineString
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findSegment(multiLine);
* // => Feature<LineString<[[10, 10], [50, 30]]>>
*
* // First Segment of 2nd Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: 1});
* // => Feature<LineString<[[-10, -10], [-50, -30]]>>
*
* // Last Segment of Last Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: -1, segmentIndex: -1});
* // => Feature<LineString<[[-50, -30], [-30, -40]]>>
*/
export function findSegment(geojson, options) {
// Optional Parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var featureIndex = options.featureIndex || 0;
var multiFeatureIndex = options.multiFeatureIndex || 0;
var geometryIndex = options.geometryIndex || 0;
var segmentIndex = options.segmentIndex || 0;
// Find FeatureIndex
var properties = options.properties;
var geometry;
switch (geojson.type) {
case 'FeatureCollection':
if (featureIndex < 0) featureIndex = geojson.features.length + featureIndex;
properties = properties || geojson.features[featureIndex].properties;
geometry = geojson.features[featureIndex].geometry;
break;
case 'Feature':
properties = properties || geojson.properties;
geometry = geojson.geometry;
break;
case 'Point':
case 'MultiPoint':
return null;
case 'LineString':
case 'Polygon':
case 'MultiLineString':
case 'MultiPolygon':
geometry = geojson;
break;
default:
throw new Error('geojson is invalid');
}
// Find SegmentIndex
if (geometry === null) return null;
var coords = geometry.coordinates;
switch (geometry.type) {
case 'Point':
case 'MultiPoint':
return null;
case 'LineString':
if (segmentIndex < 0) segmentIndex = coords.length + segmentIndex - 1;
return lineString([coords[segmentIndex], coords[segmentIndex + 1]], properties, options);
case 'Polygon':
if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;
if (segmentIndex < 0) segmentIndex = coords[geometryIndex].length + segmentIndex - 1;
return lineString([coords[geometryIndex][segmentIndex], coords[geometryIndex][segmentIndex + 1]], properties, options);
case 'MultiLineString':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (segmentIndex < 0) segmentIndex = coords[multiFeatureIndex].length + segmentIndex - 1;
return lineString([coords[multiFeatureIndex][segmentIndex], coords[multiFeatureIndex][segmentIndex + 1]], properties, options);
case 'MultiPolygon':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (geometryIndex < 0) geometryIndex = coords[multiFeatureIndex].length + geometryIndex;
if (segmentIndex < 0) segmentIndex = coords[multiFeatureIndex][geometryIndex].length - segmentIndex - 1;
return lineString([coords[multiFeatureIndex][geometryIndex][segmentIndex], coords[multiFeatureIndex][geometryIndex][segmentIndex + 1]], properties, options);
}
throw new Error('geojson is invalid');
}
/**
* Finds a particular Point from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.coordIndex=0] Coord Index
* @param {Object} [options.properties={}] Translate Properties to output Point
* @param {BBox} [options.bbox={}] Translate BBox to output Point
* @param {number|string} [options.id={}] Translate Id to output Point
* @returns {Feature<Point>} 2-vertex GeoJSON Feature Point
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findPoint(multiLine);
* // => Feature<Point<[10, 10]>>
*
* // First Segment of the 2nd Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: 1});
* // => Feature<Point<[-10, -10]>>
*
* // Last Segment of last Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: -1, coordIndex: -1});
* // => Feature<Point<[-30, -40]>>
*/
export function findPoint(geojson, options) {
// Optional Parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var featureIndex = options.featureIndex || 0;
var multiFeatureIndex = options.multiFeatureIndex || 0;
var geometryIndex = options.geometryIndex || 0;
var coordIndex = options.coordIndex || 0;
// Find FeatureIndex
var properties = options.properties;
var geometry;
switch (geojson.type) {
case 'FeatureCollection':
if (featureIndex < 0) featureIndex = geojson.features.length + featureIndex;
properties = properties || geojson.features[featureIndex].properties;
geometry = geojson.features[featureIndex].geometry;
break;
case 'Feature':
properties = properties || geojson.properties;
geometry = geojson.geometry;
break;
case 'Point':
case 'MultiPoint':
return null;
case 'LineString':
case 'Polygon':
case 'MultiLineString':
case 'MultiPolygon':
geometry = geojson;
break;
default:
throw new Error('geojson is invalid');
}
// Find Coord Index
if (geometry === null) return null;
var coords = geometry.coordinates;
switch (geometry.type) {
case 'Point':
return point(coords, properties, options);
case 'MultiPoint':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
return point(coords[multiFeatureIndex], properties, options);
case 'LineString':
if (coordIndex < 0) coordIndex = coords.length + coordIndex;
return point(coords[coordIndex], properties, options);
case 'Polygon':
if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;
if (coordIndex < 0) coordIndex = coords[geometryIndex].length + coordIndex;
return point(coords[geometryIndex][coordIndex], properties, options);
case 'MultiLineString':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (coordIndex < 0) coordIndex = coords[multiFeatureIndex].length + coordIndex;
return point(coords[multiFeatureIndex][coordIndex], properties, options);
case 'MultiPolygon':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (geometryIndex < 0) geometryIndex = coords[multiFeatureIndex].length + geometryIndex;
if (coordIndex < 0) coordIndex = coords[multiFeatureIndex][geometryIndex].length - coordIndex;
return point(coords[multiFeatureIndex][geometryIndex][coordIndex], properties, options);
}
throw new Error('geojson is invalid');
}

@@ -1,2 +0,2 @@

import { feature, lineString } from '@turf/helpers';
import { feature, isObject, lineString, point } from '@turf/helpers';

@@ -21,2 +21,3 @@ /**

* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
* @returns {void}
* @example

@@ -84,3 +85,3 @@ * var features = turf.featureCollection([

case 'Point':
callback(coords, coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
if (callback(coords, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;

@@ -92,3 +93,3 @@ multiFeatureIndex++;

for (j = 0; j < coords.length; j++) {
callback(coords[j], coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
if (callback(coords[j], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;

@@ -103,3 +104,3 @@ if (geomType === 'MultiPoint') multiFeatureIndex++;

for (k = 0; k < coords[j].length - wrapShrink; k++) {
callback(coords[j][k], coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
if (callback(coords[j][k], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;

@@ -117,3 +118,3 @@ }

for (l = 0; l < coords[j][k].length - wrapShrink; l++) {
callback(coords[j][k][l], coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
if (callback(coords[j][k][l], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;

@@ -128,3 +129,3 @@ }

for (j = 0; j < geometry.geometries.length; j++)
coordEach(geometry.geometries[j], callback, excludeWrapCoord);
if (coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false) return false;
break;

@@ -211,2 +212,3 @@ default:

* @param {Function} callback a method that takes (currentProperties, featureIndex)
* @returns {void}
* @example

@@ -228,3 +230,3 @@ * var features = turf.featureCollection([

for (i = 0; i < geojson.features.length; i++) {
callback(geojson.features[i].properties, i);
if (callback(geojson.features[i].properties, i) === false) break;
}

@@ -307,2 +309,3 @@ break;

* @param {Function} callback a method that takes (currentFeature, featureIndex)
* @returns {void}
* @example

@@ -324,3 +327,3 @@ * var features = turf.featureCollection([

for (var i = 0; i < geojson.features.length; i++) {
callback(geojson.features[i], i);
if (callback(geojson.features[i], i) === false) break;
}

@@ -421,2 +424,3 @@ }

* @param {Function} callback a method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
* @returns {void}
* @example

@@ -479,3 +483,3 @@ * var features = turf.featureCollection([

if (geometry === null) {
callback(null, featureIndex, featureProperties, featureBBox, featureId);
if (callback(null, featureIndex, featureProperties, featureBBox, featureId) === false) return false;
continue;

@@ -490,3 +494,3 @@ }

case 'MultiPolygon': {
callback(geometry, featureIndex, featureProperties, featureBBox, featureId);
if (callback(geometry, featureIndex, featureProperties, featureBBox, featureId) === false) return false;
break;

@@ -496,3 +500,3 @@ }

for (j = 0; j < geometry.geometries.length; j++) {
callback(geometry.geometries[j], featureIndex, featureProperties, featureBBox, featureId);
if (callback(geometry.geometries[j], featureIndex, featureProperties, featureBBox, featureId) === false) return false;
}

@@ -604,3 +608,3 @@ break;

case 'Polygon':
callback(feature(geometry, properties, {bbox: bbox, id: id}), featureIndex, 0);
if (callback(feature(geometry, properties, {bbox: bbox, id: id}), featureIndex, 0) === false) return false;
return;

@@ -624,3 +628,4 @@ }

geometry.coordinates.forEach(function (coordinate, multiFeatureIndex) {
for (var multiFeatureIndex = 0; multiFeatureIndex < geometry.coordinates.length; multiFeatureIndex++) {
var coordinate = geometry.coordinates[multiFeatureIndex];
var geom = {

@@ -630,5 +635,4 @@ type: geomType,

};
callback(feature(geom, properties), featureIndex, multiFeatureIndex);
});
if (callback(feature(geom, properties), featureIndex, multiFeatureIndex) === false) return false;
}
});

@@ -738,8 +742,14 @@ }

// Generate 2-vertex line segments
coordReduce(feature$$1, function (previousCoords, currentCoord, coordIndex, featureIndexCoord, mutliPartIndexCoord, geometryIndex) {
var previousCoords;
if (coordEach(feature$$1, function (currentCoord, coordIndex, featureIndexCoord, mutliPartIndexCoord, geometryIndex) {
// Simulating a meta.coordReduce() since `reduce` operations cannot be stopped by returning `false`
if (previousCoords === undefined) {
previousCoords = currentCoord;
return;
}
var currentSegment = lineString([previousCoords, currentCoord], feature$$1.properties);
callback(currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex);
if (callback(currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) === false) return false;
segmentIndex++;
return currentCoord;
});
previousCoords = currentCoord;
}) === false) return false;
});

@@ -852,7 +862,7 @@ }

case 'LineString':
callback(feature$$1, featureIndex, multiFeatureIndex, 0, 0);
if (callback(feature$$1, featureIndex, multiFeatureIndex, 0, 0) === false) return false;
break;
case 'Polygon':
for (var geometryIndex = 0; geometryIndex < coords.length; geometryIndex++) {
callback(lineString(coords[geometryIndex], feature$$1.properties), featureIndex, multiFeatureIndex, geometryIndex);
if (callback(lineString(coords[geometryIndex], feature$$1.properties), featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
}

@@ -919,2 +929,197 @@ break;

export { coordEach, coordReduce, propEach, propReduce, featureEach, featureReduce, coordAll, geomEach, geomReduce, flattenEach, flattenReduce, segmentEach, segmentReduce, lineEach, lineReduce };
/**
* Finds a particular 2-vertex LineString Segment from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
* Point & MultiPoint will always return null.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.segmentIndex=0] Segment Index
* @param {Object} [options.properties={}] Translate Properties to output LineString
* @param {BBox} [options.bbox={}] Translate BBox to output LineString
* @param {number|string} [options.id={}] Translate Id to output LineString
* @returns {Feature<LineString>} 2-vertex GeoJSON Feature LineString
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findSegment(multiLine);
* // => Feature<LineString<[[10, 10], [50, 30]]>>
*
* // First Segment of 2nd Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: 1});
* // => Feature<LineString<[[-10, -10], [-50, -30]]>>
*
* // Last Segment of Last Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: -1, segmentIndex: -1});
* // => Feature<LineString<[[-50, -30], [-30, -40]]>>
*/
function findSegment(geojson, options) {
// Optional Parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var featureIndex = options.featureIndex || 0;
var multiFeatureIndex = options.multiFeatureIndex || 0;
var geometryIndex = options.geometryIndex || 0;
var segmentIndex = options.segmentIndex || 0;
// Find FeatureIndex
var properties = options.properties;
var geometry;
switch (geojson.type) {
case 'FeatureCollection':
if (featureIndex < 0) featureIndex = geojson.features.length + featureIndex;
properties = properties || geojson.features[featureIndex].properties;
geometry = geojson.features[featureIndex].geometry;
break;
case 'Feature':
properties = properties || geojson.properties;
geometry = geojson.geometry;
break;
case 'Point':
case 'MultiPoint':
return null;
case 'LineString':
case 'Polygon':
case 'MultiLineString':
case 'MultiPolygon':
geometry = geojson;
break;
default:
throw new Error('geojson is invalid');
}
// Find SegmentIndex
if (geometry === null) return null;
var coords = geometry.coordinates;
switch (geometry.type) {
case 'Point':
case 'MultiPoint':
return null;
case 'LineString':
if (segmentIndex < 0) segmentIndex = coords.length + segmentIndex - 1;
return lineString([coords[segmentIndex], coords[segmentIndex + 1]], properties, options);
case 'Polygon':
if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;
if (segmentIndex < 0) segmentIndex = coords[geometryIndex].length + segmentIndex - 1;
return lineString([coords[geometryIndex][segmentIndex], coords[geometryIndex][segmentIndex + 1]], properties, options);
case 'MultiLineString':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (segmentIndex < 0) segmentIndex = coords[multiFeatureIndex].length + segmentIndex - 1;
return lineString([coords[multiFeatureIndex][segmentIndex], coords[multiFeatureIndex][segmentIndex + 1]], properties, options);
case 'MultiPolygon':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (geometryIndex < 0) geometryIndex = coords[multiFeatureIndex].length + geometryIndex;
if (segmentIndex < 0) segmentIndex = coords[multiFeatureIndex][geometryIndex].length - segmentIndex - 1;
return lineString([coords[multiFeatureIndex][geometryIndex][segmentIndex], coords[multiFeatureIndex][geometryIndex][segmentIndex + 1]], properties, options);
}
throw new Error('geojson is invalid');
}
/**
* Finds a particular Point from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.coordIndex=0] Coord Index
* @param {Object} [options.properties={}] Translate Properties to output Point
* @param {BBox} [options.bbox={}] Translate BBox to output Point
* @param {number|string} [options.id={}] Translate Id to output Point
* @returns {Feature<Point>} 2-vertex GeoJSON Feature Point
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findPoint(multiLine);
* // => Feature<Point<[10, 10]>>
*
* // First Segment of the 2nd Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: 1});
* // => Feature<Point<[-10, -10]>>
*
* // Last Segment of last Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: -1, coordIndex: -1});
* // => Feature<Point<[-30, -40]>>
*/
function findPoint(geojson, options) {
// Optional Parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var featureIndex = options.featureIndex || 0;
var multiFeatureIndex = options.multiFeatureIndex || 0;
var geometryIndex = options.geometryIndex || 0;
var coordIndex = options.coordIndex || 0;
// Find FeatureIndex
var properties = options.properties;
var geometry;
switch (geojson.type) {
case 'FeatureCollection':
if (featureIndex < 0) featureIndex = geojson.features.length + featureIndex;
properties = properties || geojson.features[featureIndex].properties;
geometry = geojson.features[featureIndex].geometry;
break;
case 'Feature':
properties = properties || geojson.properties;
geometry = geojson.geometry;
break;
case 'Point':
case 'MultiPoint':
return null;
case 'LineString':
case 'Polygon':
case 'MultiLineString':
case 'MultiPolygon':
geometry = geojson;
break;
default:
throw new Error('geojson is invalid');
}
// Find Coord Index
if (geometry === null) return null;
var coords = geometry.coordinates;
switch (geometry.type) {
case 'Point':
return point(coords, properties, options);
case 'MultiPoint':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
return point(coords[multiFeatureIndex], properties, options);
case 'LineString':
if (coordIndex < 0) coordIndex = coords.length + coordIndex;
return point(coords[coordIndex], properties, options);
case 'Polygon':
if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;
if (coordIndex < 0) coordIndex = coords[geometryIndex].length + coordIndex;
return point(coords[geometryIndex][coordIndex], properties, options);
case 'MultiLineString':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (coordIndex < 0) coordIndex = coords[multiFeatureIndex].length + coordIndex;
return point(coords[multiFeatureIndex][coordIndex], properties, options);
case 'MultiPolygon':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (geometryIndex < 0) geometryIndex = coords[multiFeatureIndex].length + geometryIndex;
if (coordIndex < 0) coordIndex = coords[multiFeatureIndex][geometryIndex].length - coordIndex;
return point(coords[multiFeatureIndex][geometryIndex][coordIndex], properties, options);
}
throw new Error('geojson is invalid');
}
export { coordEach, coordReduce, propEach, propReduce, featureEach, featureReduce, coordAll, geomEach, geomReduce, flattenEach, flattenReduce, segmentEach, segmentReduce, lineEach, lineReduce, findSegment, findPoint };

@@ -25,2 +25,3 @@ 'use strict';

* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
* @returns {void}
* @example

@@ -88,3 +89,3 @@ * var features = turf.featureCollection([

case 'Point':
callback(coords, coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
if (callback(coords, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;

@@ -96,3 +97,3 @@ multiFeatureIndex++;

for (j = 0; j < coords.length; j++) {
callback(coords[j], coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
if (callback(coords[j], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;

@@ -107,3 +108,3 @@ if (geomType === 'MultiPoint') multiFeatureIndex++;

for (k = 0; k < coords[j].length - wrapShrink; k++) {
callback(coords[j][k], coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
if (callback(coords[j][k], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;

@@ -121,3 +122,3 @@ }

for (l = 0; l < coords[j][k].length - wrapShrink; l++) {
callback(coords[j][k][l], coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
if (callback(coords[j][k][l], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;

@@ -132,3 +133,3 @@ }

for (j = 0; j < geometry.geometries.length; j++)
coordEach(geometry.geometries[j], callback, excludeWrapCoord);
if (coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false) return false;
break;

@@ -215,2 +216,3 @@ default:

* @param {Function} callback a method that takes (currentProperties, featureIndex)
* @returns {void}
* @example

@@ -232,3 +234,3 @@ * var features = turf.featureCollection([

for (i = 0; i < geojson.features.length; i++) {
callback(geojson.features[i].properties, i);
if (callback(geojson.features[i].properties, i) === false) break;
}

@@ -311,2 +313,3 @@ break;

* @param {Function} callback a method that takes (currentFeature, featureIndex)
* @returns {void}
* @example

@@ -328,3 +331,3 @@ * var features = turf.featureCollection([

for (var i = 0; i < geojson.features.length; i++) {
callback(geojson.features[i], i);
if (callback(geojson.features[i], i) === false) break;
}

@@ -425,2 +428,3 @@ }

* @param {Function} callback a method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
* @returns {void}
* @example

@@ -483,3 +487,3 @@ * var features = turf.featureCollection([

if (geometry === null) {
callback(null, featureIndex, featureProperties, featureBBox, featureId);
if (callback(null, featureIndex, featureProperties, featureBBox, featureId) === false) return false;
continue;

@@ -494,3 +498,3 @@ }

case 'MultiPolygon': {
callback(geometry, featureIndex, featureProperties, featureBBox, featureId);
if (callback(geometry, featureIndex, featureProperties, featureBBox, featureId) === false) return false;
break;

@@ -500,3 +504,3 @@ }

for (j = 0; j < geometry.geometries.length; j++) {
callback(geometry.geometries[j], featureIndex, featureProperties, featureBBox, featureId);
if (callback(geometry.geometries[j], featureIndex, featureProperties, featureBBox, featureId) === false) return false;
}

@@ -608,3 +612,3 @@ break;

case 'Polygon':
callback(helpers.feature(geometry, properties, {bbox: bbox, id: id}), featureIndex, 0);
if (callback(helpers.feature(geometry, properties, {bbox: bbox, id: id}), featureIndex, 0) === false) return false;
return;

@@ -628,3 +632,4 @@ }

geometry.coordinates.forEach(function (coordinate, multiFeatureIndex) {
for (var multiFeatureIndex = 0; multiFeatureIndex < geometry.coordinates.length; multiFeatureIndex++) {
var coordinate = geometry.coordinates[multiFeatureIndex];
var geom = {

@@ -634,5 +639,4 @@ type: geomType,

};
callback(helpers.feature(geom, properties), featureIndex, multiFeatureIndex);
});
if (callback(helpers.feature(geom, properties), featureIndex, multiFeatureIndex) === false) return false;
}
});

@@ -742,8 +746,14 @@ }

// Generate 2-vertex line segments
coordReduce(feature$$1, function (previousCoords, currentCoord, coordIndex, featureIndexCoord, mutliPartIndexCoord, geometryIndex) {
var previousCoords;
if (coordEach(feature$$1, function (currentCoord, coordIndex, featureIndexCoord, mutliPartIndexCoord, geometryIndex) {
// Simulating a meta.coordReduce() since `reduce` operations cannot be stopped by returning `false`
if (previousCoords === undefined) {
previousCoords = currentCoord;
return;
}
var currentSegment = helpers.lineString([previousCoords, currentCoord], feature$$1.properties);
callback(currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex);
if (callback(currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) === false) return false;
segmentIndex++;
return currentCoord;
});
previousCoords = currentCoord;
}) === false) return false;
});

@@ -856,7 +866,7 @@ }

case 'LineString':
callback(feature$$1, featureIndex, multiFeatureIndex, 0, 0);
if (callback(feature$$1, featureIndex, multiFeatureIndex, 0, 0) === false) return false;
break;
case 'Polygon':
for (var geometryIndex = 0; geometryIndex < coords.length; geometryIndex++) {
callback(helpers.lineString(coords[geometryIndex], feature$$1.properties), featureIndex, multiFeatureIndex, geometryIndex);
if (callback(helpers.lineString(coords[geometryIndex], feature$$1.properties), featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
}

@@ -923,2 +933,197 @@ break;

/**
* Finds a particular 2-vertex LineString Segment from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
* Point & MultiPoint will always return null.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.segmentIndex=0] Segment Index
* @param {Object} [options.properties={}] Translate Properties to output LineString
* @param {BBox} [options.bbox={}] Translate BBox to output LineString
* @param {number|string} [options.id={}] Translate Id to output LineString
* @returns {Feature<LineString>} 2-vertex GeoJSON Feature LineString
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findSegment(multiLine);
* // => Feature<LineString<[[10, 10], [50, 30]]>>
*
* // First Segment of 2nd Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: 1});
* // => Feature<LineString<[[-10, -10], [-50, -30]]>>
*
* // Last Segment of Last Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: -1, segmentIndex: -1});
* // => Feature<LineString<[[-50, -30], [-30, -40]]>>
*/
function findSegment(geojson, options) {
// Optional Parameters
options = options || {};
if (!helpers.isObject(options)) throw new Error('options is invalid');
var featureIndex = options.featureIndex || 0;
var multiFeatureIndex = options.multiFeatureIndex || 0;
var geometryIndex = options.geometryIndex || 0;
var segmentIndex = options.segmentIndex || 0;
// Find FeatureIndex
var properties = options.properties;
var geometry;
switch (geojson.type) {
case 'FeatureCollection':
if (featureIndex < 0) featureIndex = geojson.features.length + featureIndex;
properties = properties || geojson.features[featureIndex].properties;
geometry = geojson.features[featureIndex].geometry;
break;
case 'Feature':
properties = properties || geojson.properties;
geometry = geojson.geometry;
break;
case 'Point':
case 'MultiPoint':
return null;
case 'LineString':
case 'Polygon':
case 'MultiLineString':
case 'MultiPolygon':
geometry = geojson;
break;
default:
throw new Error('geojson is invalid');
}
// Find SegmentIndex
if (geometry === null) return null;
var coords = geometry.coordinates;
switch (geometry.type) {
case 'Point':
case 'MultiPoint':
return null;
case 'LineString':
if (segmentIndex < 0) segmentIndex = coords.length + segmentIndex - 1;
return helpers.lineString([coords[segmentIndex], coords[segmentIndex + 1]], properties, options);
case 'Polygon':
if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;
if (segmentIndex < 0) segmentIndex = coords[geometryIndex].length + segmentIndex - 1;
return helpers.lineString([coords[geometryIndex][segmentIndex], coords[geometryIndex][segmentIndex + 1]], properties, options);
case 'MultiLineString':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (segmentIndex < 0) segmentIndex = coords[multiFeatureIndex].length + segmentIndex - 1;
return helpers.lineString([coords[multiFeatureIndex][segmentIndex], coords[multiFeatureIndex][segmentIndex + 1]], properties, options);
case 'MultiPolygon':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (geometryIndex < 0) geometryIndex = coords[multiFeatureIndex].length + geometryIndex;
if (segmentIndex < 0) segmentIndex = coords[multiFeatureIndex][geometryIndex].length - segmentIndex - 1;
return helpers.lineString([coords[multiFeatureIndex][geometryIndex][segmentIndex], coords[multiFeatureIndex][geometryIndex][segmentIndex + 1]], properties, options);
}
throw new Error('geojson is invalid');
}
/**
* Finds a particular Point from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.coordIndex=0] Coord Index
* @param {Object} [options.properties={}] Translate Properties to output Point
* @param {BBox} [options.bbox={}] Translate BBox to output Point
* @param {number|string} [options.id={}] Translate Id to output Point
* @returns {Feature<Point>} 2-vertex GeoJSON Feature Point
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findPoint(multiLine);
* // => Feature<Point<[10, 10]>>
*
* // First Segment of the 2nd Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: 1});
* // => Feature<Point<[-10, -10]>>
*
* // Last Segment of last Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: -1, coordIndex: -1});
* // => Feature<Point<[-30, -40]>>
*/
function findPoint(geojson, options) {
// Optional Parameters
options = options || {};
if (!helpers.isObject(options)) throw new Error('options is invalid');
var featureIndex = options.featureIndex || 0;
var multiFeatureIndex = options.multiFeatureIndex || 0;
var geometryIndex = options.geometryIndex || 0;
var coordIndex = options.coordIndex || 0;
// Find FeatureIndex
var properties = options.properties;
var geometry;
switch (geojson.type) {
case 'FeatureCollection':
if (featureIndex < 0) featureIndex = geojson.features.length + featureIndex;
properties = properties || geojson.features[featureIndex].properties;
geometry = geojson.features[featureIndex].geometry;
break;
case 'Feature':
properties = properties || geojson.properties;
geometry = geojson.geometry;
break;
case 'Point':
case 'MultiPoint':
return null;
case 'LineString':
case 'Polygon':
case 'MultiLineString':
case 'MultiPolygon':
geometry = geojson;
break;
default:
throw new Error('geojson is invalid');
}
// Find Coord Index
if (geometry === null) return null;
var coords = geometry.coordinates;
switch (geometry.type) {
case 'Point':
return helpers.point(coords, properties, options);
case 'MultiPoint':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
return helpers.point(coords[multiFeatureIndex], properties, options);
case 'LineString':
if (coordIndex < 0) coordIndex = coords.length + coordIndex;
return helpers.point(coords[coordIndex], properties, options);
case 'Polygon':
if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;
if (coordIndex < 0) coordIndex = coords[geometryIndex].length + coordIndex;
return helpers.point(coords[geometryIndex][coordIndex], properties, options);
case 'MultiLineString':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (coordIndex < 0) coordIndex = coords[multiFeatureIndex].length + coordIndex;
return helpers.point(coords[multiFeatureIndex][coordIndex], properties, options);
case 'MultiPolygon':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (geometryIndex < 0) geometryIndex = coords[multiFeatureIndex].length + geometryIndex;
if (coordIndex < 0) coordIndex = coords[multiFeatureIndex][geometryIndex].length - coordIndex;
return helpers.point(coords[multiFeatureIndex][geometryIndex][coordIndex], properties, options);
}
throw new Error('geojson is invalid');
}
exports.coordEach = coordEach;

@@ -939,1 +1144,3 @@ exports.coordReduce = coordReduce;

exports.lineReduce = lineReduce;
exports.findSegment = findSegment;
exports.findPoint = findPoint;

2

package.json
{
"name": "@turf/meta",
"version": "5.1.6",
"version": "5.2.0",
"description": "turf meta module",

@@ -5,0 +5,0 @@ "main": "main.js",

@@ -46,2 +46,4 @@ # @turf/meta

Returns **void**
## coordReduce

@@ -132,2 +134,4 @@

Returns **void**
## propEachCallback

@@ -144,2 +148,28 @@

## propReduceCallback
Callback for propReduce
The first time the callback function is called, the values provided as arguments depend
on whether the reduce method has an initialValue argument.
If an initialValue is provided to the reduce method:
- The previousValue argument is initialValue.
- The currentValue argument is the value of the first element present in the array.
If an initialValue is not provided:
- The previousValue argument is the value of the first element present in the array.
- The currentValue argument is the value of the second element present in the array.
Type: [Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)
**Parameters**
- `previousValue` **any** The accumulated value previously returned in the last invocation
of the callback, or initialValue, if supplied.
- `currentProperties` **any** The current Properties being processed.
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed.
## propReduce

@@ -175,19 +205,6 @@

## propReduceCallback
## featureEachCallback
Callback for propReduce
Callback for featureEach
The first time the callback function is called, the values provided as arguments depend
on whether the reduce method has an initialValue argument.
If an initialValue is provided to the reduce method:
- The previousValue argument is initialValue.
- The currentValue argument is the value of the first element present in the array.
If an initialValue is not provided:
- The previousValue argument is the value of the first element present in the array.
- The currentValue argument is the value of the second element present in the array.
Type: [Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)

@@ -197,5 +214,3 @@

- `previousValue` **any** The accumulated value previously returned in the last invocation
of the callback, or initialValue, if supplied.
- `currentProperties` **any** The current Properties being processed.
- `currentFeature` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;any>** The current Feature being processed.
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed.

@@ -227,13 +242,4 @@

## featureEachCallback
Returns **void**
Callback for featureEach
Type: [Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)
**Parameters**
- `currentFeature` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;any>** The current Feature being processed.
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed.
## featureReduceCallback

@@ -355,2 +361,4 @@

Returns **void**
## geomReduceCallback

@@ -721,2 +729,85 @@

## findSegment
Finds a particular 2-vertex LineString Segment from a GeoJSON using `@turf/meta` indexes.
Negative indexes are permitted.
Point & MultiPoint will always return null.
**Parameters**
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) \| [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1))** Any GeoJSON Feature or Geometry
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`)
- `options.featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Feature Index (optional, default `0`)
- `options.multiFeatureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Multi-Feature Index (optional, default `0`)
- `options.geometryIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Geometry Index (optional, default `0`)
- `options.segmentIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Segment Index (optional, default `0`)
- `options.properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Translate Properties to output LineString (optional, default `{}`)
- `options.bbox` **[BBox](https://tools.ietf.org/html/rfc7946#section-5)** Translate BBox to output LineString (optional, default `{}`)
- `options.id` **([number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) \| [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** Translate Id to output LineString (optional, default `{}`)
**Examples**
```javascript
var multiLine = turf.multiLineString([
[[10, 10], [50, 30], [30, 40]],
[[-10, -10], [-50, -30], [-30, -40]]
]);
// First Segment (defaults are 0)
turf.findSegment(multiLine);
// => Feature<LineString<[[10, 10], [50, 30]]>>
// First Segment of 2nd Multi Feature
turf.findSegment(multiLine, {multiFeatureIndex: 1});
// => Feature<LineString<[[-10, -10], [-50, -30]]>>
// Last Segment of Last Multi Feature
turf.findSegment(multiLine, {multiFeatureIndex: -1, segmentIndex: -1});
// => Feature<LineString<[[-50, -30], [-30, -40]]>>
```
Returns **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;[LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4)>** 2-vertex GeoJSON Feature LineString
## findPoint
Finds a particular Point from a GeoJSON using `@turf/meta` indexes.
Negative indexes are permitted.
**Parameters**
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) \| [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1))** Any GeoJSON Feature or Geometry
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`)
- `options.featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Feature Index (optional, default `0`)
- `options.multiFeatureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Multi-Feature Index (optional, default `0`)
- `options.geometryIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Geometry Index (optional, default `0`)
- `options.coordIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Coord Index (optional, default `0`)
- `options.properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Translate Properties to output Point (optional, default `{}`)
- `options.bbox` **[BBox](https://tools.ietf.org/html/rfc7946#section-5)** Translate BBox to output Point (optional, default `{}`)
- `options.id` **([number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) \| [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** Translate Id to output Point (optional, default `{}`)
**Examples**
```javascript
var multiLine = turf.multiLineString([
[[10, 10], [50, 30], [30, 40]],
[[-10, -10], [-50, -30], [-30, -40]]
]);
// First Segment (defaults are 0)
turf.findPoint(multiLine);
// => Feature<Point<[10, 10]>>
// First Segment of the 2nd Multi-Feature
turf.findPoint(multiLine, {multiFeatureIndex: 1});
// => Feature<Point<[-10, -10]>>
// Last Segment of last Multi-Feature
turf.findPoint(multiLine, {multiFeatureIndex: -1, coordIndex: -1});
// => Feature<Point<[-30, -40]>>
```
Returns **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;[Point](https://tools.ietf.org/html/rfc7946#section-3.1.2)>** 2-vertex GeoJSON Feature Point
<!-- This file is automatically generated. Please don't edit it directly:

@@ -723,0 +814,0 @@ if you find an error, edit the source file (likely index.js), and re-run

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc