Skip to content

Commit a486ce4

Browse files
committed
Finish initial typings for turf
1 parent 69609e4 commit a486ce4

File tree

2 files changed

+233
-2
lines changed

2 files changed

+233
-2
lines changed

typings/globals/turf/index.d.ts

Lines changed: 177 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="../geojson/index.d.ts"/>
1+
/// <reference types="geojson"/>
22

33
declare namespace turf {
44
type Units = "miles" | "nauticalmiles" | "degrees" | "radians" | "inches" | "yards" | "meters" | "metres" | "kilometers" | "kilometres";
@@ -204,6 +204,124 @@ declare namespace turf {
204204
*/
205205
export function nearest(target: GeoJSON.Feature<GeoJSON.Point>, points: GeoJSON.FeatureCollection<GeoJSON.Point>): GeoJSON.Feature<GeoJSON.Point>;
206206

207+
/**
208+
* Takes a triangular plane as a Polygon and a Point within that trangle and
209+
* returns the z-value at that point. The Polygon needs to have properties
210+
* `a`, `b` and `c` that define the values at its three corners.
211+
*/
212+
export function planepoint(point: GeoJSON.Feature<GeoJSON.Point>, triangle: GeoJSON.Feature<GeoJSON.Polygon>): number;
213+
214+
/**
215+
* Takes a bounding box and a cell depth and returns a set of Points in a
216+
* grid.
217+
*/
218+
export function pointGrid(bbox: BoundingBox, cellSize: number, units?: Units): GeoJSON.FeatureCollection<GeoJSON.Point>;
219+
220+
/**
221+
* Takes a Point and a LineString and calculates the closest Point on the
222+
* LineString.
223+
*/
224+
export function pointOnLine(line: GeoJSON.Feature<GeoJSON.LineString>, point: GeoJSON.Feature<GeoJSON.Point>, units?: Units): GeoJSON.Feature<GeoJSON.Point>;
225+
226+
/**
227+
* Takes a feature and returns a Point guaranteed to be on the surface
228+
* of the feature.
229+
*
230+
* * Given a Polygon, the point will be in the area of the polygon.
231+
* * Given a LineString, the point will be along the string.
232+
* * Given a Point, the point will the same as the input.
233+
*/
234+
export function pointOnSurface(input: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.LineString | GeoJSON.Point> | GeoJSON.FeatureCollection<GeoJSON.Polygon | GeoJSON.LineString | GeoJSON.Point>): GeoJSON.Feature<GeoJSON.Point>;
235+
236+
interface RandomPointOptions {
237+
bbox?: BoundingBox;
238+
}
239+
240+
interface RandomPolygonOptions {
241+
num_vertices?: number;
242+
max_radial_length?: number;
243+
bbox?: BoundingBox;
244+
}
245+
246+
/**
247+
* Generates random GeoJSON Points.
248+
*/
249+
export function random(type: "point" | "points", count?: number, options?: RandomPointOptions): GeoJSON.FeatureCollection<GeoJSON.Point>;
250+
251+
/**
252+
* Generates random GeoJSON Polygons.
253+
*/
254+
export function random(type: "polygon" | "polygons", count?: number, options?: RandomPolygonOptions): GeoJSON.FeatureCollection<GeoJSON.Polygon>;
255+
256+
/**
257+
* Takes a FeatureCollection and returns a FeatureCollection with given
258+
* number of Features at random.
259+
*/
260+
export function sample<T extends GeoJSON.GeometryObject | GeoJSON.GeometryCollection>(input: GeoJSON.FeatureCollection<T>, number: number): GeoJSON.FeatureCollection<T>;
261+
262+
type SimplifiableGeometry = GeoJSON.LineString | GeoJSON.Polygon | GeoJSON.MultiLineString | GeoJSON.MultiPolygon;
263+
264+
/**
265+
* Takes a LineString or Polygon and returns a simplified version.
266+
* Internally uses simplify-js to perform simplification.
267+
*/
268+
export function simplify<T extends GeoJSON.Feature<SimplifiableGeometry> | GeoJSON.FeatureCollection<SimplifiableGeometry> | GeoJSON.GeometryCollection>(feature: T, tolerance: number, highQuality: boolean): T;
269+
270+
/**
271+
* Takes a bounding box and calculates the minimum square bounding box that
272+
* would contain the input.
273+
*/
274+
export function square(bbox: BoundingBox): BoundingBox;
275+
276+
/**
277+
* Takes a bounding box, a cell depth and returns a set of square Polygons
278+
* in a grid.
279+
*/
280+
export function squareGrid(bbox: BoundingBox, cellSize: number, units?: Units): GeoJSON.FeatureCollection<GeoJSON.Polygon>;
281+
282+
/**
283+
* Takes a set of Points, a set of Polygons and a performs a spatial join.
284+
*/
285+
export function tag(points: GeoJSON.FeatureCollection<GeoJSON.Point>, polygons: GeoJSON.FeatureCollection<GeoJSON.Polygon>, inField: string, outField: string): GeoJSON.FeatureCollection<GeoJSON.Point>;
286+
287+
/**
288+
* Tesselates a Feature<Polygon> into a FeatureCollection<Polygon> of
289+
* triangles using earcut.
290+
*/
291+
export function tesselate(polygon: GeoJSON.Feature<GeoJSON.Polygon>): GeoJSON.FeatureCollection<GeoJSON.Polygon>;
292+
293+
/**
294+
* Takes a set of Points, the name of a z-value property and creates a
295+
* Triangulated Irregular Network (or TIN for short), returned as a
296+
* collection of Polygons. These are often used for developing elevation
297+
* contour maps or stepped heat visualizations.
298+
*
299+
* This triangulates the points, and adds properties called `a`, `b`, and
300+
* `c` representing the value of the given `propertyName` at each of the
301+
* points that represent the corners of the triangle.
302+
*/
303+
export function tin(points: GeoJSON.FeatureCollection<GeoJSON.Point>, zProperty?: string): GeoJSON.FeatureCollection<GeoJSON.Polygon>;
304+
305+
/**
306+
* Takes a bounding box, a cell depth and returns a set of triangular
307+
* Polygons in a grid.
308+
*/
309+
export function triangleGrid(bbox: BoundingBox, cellSize: number, units?: Units): GeoJSON.FeatureCollection<GeoJSON.Polygon>;
310+
311+
312+
/**
313+
* Takes two or more Polygons and returns a combined Polygon. If the input
314+
* Polygons are not contiguous, this function returns a MultiPolygon
315+
* Feature.
316+
*/
317+
export function union(...polygons: GeoJSON.Feature<GeoJSON.Polygon>[]): GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.MultiPolygon>;
318+
319+
/**
320+
* Takes a set of Pionts, a set of Polygons and returns the Points that fall
321+
* within the Polygons.
322+
*/
323+
export function within(points: GeoJSON.FeatureCollection<GeoJSON.Point>, polygons: GeoJSON.FeatureCollection<GeoJSON.Polygon>): GeoJSON.FeatureCollection<GeoJSON.Point>;
324+
207325
export import feature = helpers.feature;
208326
export import point = helpers.point;
209327
export import polygon = helpers.polygon;
@@ -334,7 +452,8 @@ declare namespace meta {
334452
export function featureEach(object: any, callback: (feature: GeoJSON.Feature<any>) => void): void;
335453

336454
/**
337-
* Get all coordinates from any GeoJSNO object, returning an array of coordinate arrays.
455+
* Get all coordinates from any GeoJSNO object, returning an array of
456+
* coordinate arrays.
338457
*/
339458
export function coordAll(object: any): GeoJSON.Position[];
340459
}
@@ -481,4 +600,60 @@ declare module "@turf/midpoint" {
481600

482601
declare module "@turf/nearest" {
483602
export default turf.nearest;
603+
}
604+
605+
declare module "@turf/planepoint" {
606+
export default turf.planepoint;
607+
}
608+
609+
declare module "@turf/point-grid" {
610+
export default turf.pointGrid;
611+
}
612+
613+
declare module "@turf/point-on-line" {
614+
export default turf.pointOnLine;
615+
}
616+
617+
declare module "@turf/point-on-surface" {
618+
export default turf.pointOnSurface;
619+
}
620+
621+
declare module "@turf/random" {
622+
export default turf.random;
623+
}
624+
625+
declare module "@turf/sample" {
626+
export default turf.sample;
627+
}
628+
629+
declare module "@turf/simplify" {
630+
export default turf.simplify;
631+
}
632+
633+
declare module "@turf/square" {
634+
export default turf.square;
635+
}
636+
637+
declare module "@turf/square-grid" {
638+
export default turf.squareGrid;
639+
}
640+
641+
declare module "@turf/tag" {
642+
export default turf.tag;
643+
}
644+
645+
declare module "@turf/tesselate" {
646+
export default turf.tesselate;
647+
}
648+
649+
declare module "@turf/triangle-grid" {
650+
export default turf.triangleGrid;
651+
}
652+
653+
declare module "@turf/union" {
654+
export default turf.union;
655+
}
656+
657+
declare module "@turf/within" {
658+
export default turf.within;
484659
}

typings/globals/turf/turf-test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,59 @@ coordAll(pointFeatureCollection);
424424
turf.midpoint(pointFeature, pointFeature2);
425425

426426
turf.nearest(pointFeature, pointFeatureCollection);
427+
428+
turf.planepoint(pointFeature, triangleFeature);
429+
430+
turf.pointGrid(bbox, 20, "miles");
431+
turf.pointGrid(bbox, 20);
432+
433+
turf.pointOnLine(lineFeature, pointFeature, "nauticalmiles");
434+
turf.pointOnLine(lineFeature, pointFeature);
435+
436+
turf.pointOnSurface(polygonFeature);
437+
turf.pointOnSurface(lineFeature);
438+
turf.pointOnSurface(pointFeature);
439+
turf.pointOnSurface(polygonFeatureCollection);
440+
turf.pointOnSurface(lineFeatureCollection);
441+
turf.pointOnSurface(pointFeatureCollection);
442+
443+
turf.random("points", 10, { bbox: bbox });
444+
turf.random("points", 10, {});
445+
turf.random("points", 10);
446+
turf.random("points");
447+
448+
turf.random("polygon", 10, {
449+
num_vertices: 10,
450+
max_radial_length: 10,
451+
bbox: bbox,
452+
});
453+
turf.random("polygon", 10);
454+
turf.random("polygon");
455+
456+
turf.sample(pointFeatureCollection, 10);
457+
458+
turf.simplify(polygonFeature, 10, false);
459+
turf.simplify(polygonFeatureCollection, 10, false);
460+
turf.simplify(triangleFeature, 10, false);
461+
turf.simplify(lineFeature, 10, false);
462+
turf.simplify(lineFeatureCollection, 10, false);
463+
464+
turf.square(bbox);
465+
466+
turf.squareGrid(bbox, 20, "yards");
467+
turf.squareGrid(bbox, 20);
468+
469+
turf.tag(pointFeatureCollection, polygonFeatureCollection, "inField", "outField");
470+
471+
turf.tesselate(polygonFeature);
472+
473+
turf.tin(pointFeatureCollection, "property");
474+
turf.tin(pointFeatureCollection);
475+
476+
turf.triangleGrid(bbox, 10, "miles");
477+
turf.triangleGrid(bbox, 10);
478+
479+
turf.union(polygonFeature);
480+
turf.union(polygonFeature, polygonFeature2, ...polygonFeatureCollection.features);
481+
482+
turf.within(pointFeatureCollection, polygonFeatureCollection);

0 commit comments

Comments
 (0)