Added definition for distance and pointOnLine. Added related tests.

This commit is contained in:
gcroteau
2015-11-24 14:54:21 -05:00
parent 97d7377cf8
commit 8ccfe0dd01
2 changed files with 159 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
/// <reference path="turf.d.ts"/>
//////////////////////////////////////////////////////////////////////////
// Tests Aggregation
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Tests Measurement
//////////////////////////////////////////////////////////////////////////
var point1 = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-75.343, 39.984]
}
};
var point2 = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-75.534, 39.123]
}
};
var units = "miles";
var points = {
"type": "FeatureCollection",
"features": [point1, point2]
};
var distance = turf.distance(point1, point2, units);
//////////////////////////////////////////////////////////////////////////
// Tests Transformation
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Tests Misc
//////////////////////////////////////////////////////////////////////////
var line = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[-77.031669, 38.878605],
[-77.029609, 38.881946],
[-77.020339, 38.884084],
[-77.025661, 38.885821],
[-77.021884, 38.889563],
[-77.019824, 38.892368]
]
}
};
var pt = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-77.037076, 38.884017]
}
};
var snapped = turf.pointOnLine(line, pt);
snapped.properties['marker-color'] = '#00f'
var result = {
"type": "FeatureCollection",
"features": [line, pt, snapped]
};
//////////////////////////////////////////////////////////////////////////
// Tests Helper
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Tests Data
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Tests Interpolation
//////////////////////////////////////////////////////////////////////////;
//////////////////////////////////////////////////////////////////////////
// Tests Joins
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Tests Classification
//////////////////////////////////////////////////////////////////////////

65
turf/turf.d.ts vendored
View File

@@ -0,0 +1,65 @@
// Type definitions for Turf 2.0
// Project: http://turfjs.org/
// Definitions by: Guillaume Croteau <https://github.com/gcroteau>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../geojson/geojson.d.ts" />
declare module turf {
//////////////////////////////////////////////////////////////////////////
// Aggregation
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Measurement
//////////////////////////////////////////////////////////////////////////
/**
* Calculates the distance between two points in degress, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature.
* @param from Origin point
* @param to Destination point
* @param units Can be degrees, radians, miles, or kilometers. Default is kilometers.
* @returns Distance between the two points
*/
function distance(from: GeoJSON.Feature, to: GeoJSON.Feature, units?: string): number;
//////////////////////////////////////////////////////////////////////////
// Transformation
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Misc
//////////////////////////////////////////////////////////////////////////
/**
* Takes a Point and a LineString and calculates the closest Point on the LineString.
* @param line Line to snap to
* @param point Point to snap from
* @returns Closest point on the line to point
*/
function pointOnLine(line: GeoJSON.Feature, point: GeoJSON.Feature): GeoJSON.Feature;
//////////////////////////////////////////////////////////////////////////
// Helper
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Data
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Interpolation
//////////////////////////////////////////////////////////////////////////;
//////////////////////////////////////////////////////////////////////////
// Joins
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Classification
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Types
//////////////////////////////////////////////////////////////////////////
}