Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const pt = point([15, 15]);
const poly = polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
// Does not mutate Geometry type
const rotatedPoly: Feature
point,
lineString,
Point
} from '@turf/helpers'
import nearestPointToLine from './'
const points = featureCollection([point([0, 0]), point([0.5, 0.5])]);
const line = lineString([[1,1], [-1,1]]);
const nearest = nearestPointToLine<{foo: string, dist: number}>(points, line, {properties: {foo: 'bar'}})
nearest.properties.foo
nearest.properties.dist
// nearest.properties.bar // [ts] Property 'bar' does not exist on type '{ dist?: number; foo: string; }'.
// GeometryCollection
const geomPoints = geometryCollection([point([0, 0]).geometry, point([0.5, 0.5]).geometry]);
nearestPointToLine(geomPoints, line)
GeometryTypes,
LineString,
Point,
Polygon,
Position,
Types,
} from "@turf/helpers";
import * as invariant from "./";
/**
* Fixtures
*/
const pt = helpers.point([0, 0]);
const line = helpers.lineString([[0, 0], [1, 1]]);
const poly = helpers.polygon([[[0, 0], [1, 1], [2, 2], [0, 0]]]);
const gc = helpers.geometryCollection([pt.geometry, line.geometry, poly.geometry]);
const fc = helpers.featureCollection([pt, line, poly]);
/**
* invariant.getGeom
*/
// invariant.getGeom(fc); // Argument of type 'FeatureCollection' is not assignable to parameter of type
const gcGeom: GeometryCollection = invariant.getGeom(gc);
const pointGeom: Point = invariant.getGeom(pt);
const lineGeom: LineString = invariant.getGeom(line);
const polyGeom: Polygon = invariant.getGeom(poly);
/**
* invariant.getType
*/
const type = invariant.getType(pt);
geojson: FeatureCollection,
options: {mutate?: boolean} = {},
): Feature | 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;
}
if (invariant_1.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_1.default(geojson);
}
var geoms = [];
meta_1.flattenEach(geojson, function (feature) {
geoms.push(feature.geometry);
});
var topo = topojson_1.topology({ geoms: helpers_1.geometryCollection(geoms).geometry });
var merged = topojson_1.merge(topo, topo.objects.geoms.geometries);
return merged;
}
exports.default = polygonDissolve;
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([pt, line]);
const gc = geometryCollection([pt.geometry, line.geometry]);
buffer(fc, 5);
buffer(gc, 5);
// Mixed Collections
const fcMixed = featureCollection([pt, line, multiPt, multiLine]);
const gcMixed = geometryCollection([pt.geometry, line.geometry, multiPt.geometry, multiLine.geometry]);
buffer(fcMixed, 5);
buffer(gcMixed, 5);
import {lineString, polygon, featureCollection, geometryCollection} from '@turf/helpers'
import lineSegment from './'
const poly = polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
const line = lineString([[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]);
const collection = featureCollection([poly, line]);
const geomCollection = geometryCollection([poly.geometry, line.geometry]);
// Test Types
lineSegment(poly)
lineSegment(line)
lineSegment(collection)
lineSegment(geomCollection)
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]));
import {featureCollection, point, lineString, geometryCollection} from '@turf/helpers'
import * as truncate from './'
const pt = point([120.1234567, 40.1234567])
const ptGeom = pt.geometry
const line = lineString([[20,80], [50, 40]])
const lineGeom = line.geometry
const points = featureCollection([pt])
const lines = featureCollection([line])
const geomCollection = geometryCollection([ptGeom, lineGeom])
truncate(pt)
truncate(ptGeom)
truncate(line)
truncate(lineGeom)
truncate(lines)
truncate(points)
truncate(geomCollection)
truncate(pt, 6)
truncate(pt, 3, 2)
truncate(pt, 3, 2, false)
truncate(pt, 3, 2, true)
truncate(points, 6)
import { lineString, geometryCollection, featureCollection } from '@turf/helpers'
import lineChunk from './'
const line = lineString([[0, 0], [1, 1], [2, 2]]);
const collection = featureCollection([line]);
const geomCollection = geometryCollection([line.geometry]);
lineChunk(line, 2)
lineChunk(line, 2, 'kilometers')
lineChunk(line.geometry, 2)
lineChunk(collection, 2)
lineChunk(geomCollection, 2)