Completed the Measurement definitions.

This commit is contained in:
gcroteau
2015-11-24 19:52:59 -05:00
parent 9488d2229f
commit 848b9d8467
2 changed files with 259 additions and 33 deletions
+146 -11
View File
@@ -71,6 +71,112 @@ var polygons = {
]
};
var polygon = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[
[105.818939,21.004714],
[105.818939,21.061754],
[105.890007,21.061754],
[105.890007,21.004714],
[105.818939,21.004714]
]]
}
};
var features = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-97.522259, 35.4691]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-97.502754, 35.463455]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-97.508269, 35.463245]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-97.516809, 35.465779]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-97.515372, 35.467072]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-97.509363, 35.463053]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-97.511123, 35.466601]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-97.518547, 35.469327]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-97.519706, 35.469659]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-97.517839, 35.466998]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-97.508678, 35.464942]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-97.514914, 35.463453]
}
}
]
};
//////////////////////////////////////////////////////////////////////////
// Tests Aggregation
//////////////////////////////////////////////////////////////////////////
@@ -82,18 +188,53 @@ var polygons = {
// -- Test along --
var along = turf.along(line, 1, 'miles');
var result = {
"type": "FeatureCollection",
"features": [line, along]
};
// -- Test area --
var area = turf.area(polygons);
// -- Test bboxPolygon --
var bbox = [0, 0, 10, 10];
var poly = turf.bboxPolygon(bbox);
// -- Test bearing --
var bearing = turf.bearing(point1, point2);
// -- Test center
var centerPt = turf.center(features);
// -- Test centroid --
var centroidPt = turf.centroid(poly);
// -- Test destination --
var distance = 50;
var bearing = 90;
var units = 'miles';
var destination = turf.destination(point1, distance, bearing, units);
// -- Test distance --
var units = "miles";
var distance = turf.distance(point1, point2, units);
// -- Test envelope --
var enveloped = turf.envelope(polygons);
// -- Test extent --
var bbox = turf.extent(polygons);
// -- Test lineDistance
var length = turf.lineDistance(line, 'miles');
// -- Test midpoint --
var midpointed = turf.midpoint(point1, point2);
// -- Test pointOnSurface --
var pointOnPolygon = turf.pointOnSurface(polygon);
// -- Test size --
var resized = turf.size(bbox, 2);
// -- Test square --
var squared = turf.square(bbox);
//////////////////////////////////////////////////////////////////////////
// Tests Transformation
//////////////////////////////////////////////////////////////////////////
@@ -104,12 +245,6 @@ var distance = turf.distance(point1, point2, units);
// -- Test pointOnLine --
var snapped = turf.pointOnLine(line, point1);
snapped.properties['marker-color'] = '#00f'
result = {
"type": "FeatureCollection",
"features": [line, point1, snapped]
};
//////////////////////////////////////////////////////////////////////////
// Tests Helper
+113 -22
View File
@@ -6,13 +6,13 @@
/// <reference path="../geojson/geojson.d.ts" />
declare module turf {
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// Aggregation
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// Measurement
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
/**
* Takes a line and returns a point at a specified distance along the line.
@@ -29,7 +29,46 @@ declare module turf {
* @returns Area in square meters
*/
function area(input: GeoJSON.Feature | GeoJSON.FeatureCollection): number;
/**
* Takes a bbox and returns an equivalent polygon.
* @param bbox An Array of bounding box coordinates in the form: [xLow, yLow, xHigh, yHigh]
* @returns A Polygon representation of the bounding box
*/
function bboxPolygon(bbox: Array<number>): GeoJSON.Feature;
/**
* Takes two points and finds the geographic bearing between them.
* @param start Starting Point
* @param end Ending point
* @returns Bearing in decimal degrees
*/
function bearing(start: GeoJSON.Feature, end: GeoJSON.Feature): number;
/**
* Takes a FeatureCollection and returns the absolute center point of all features.
* @param features Input features
* @returns A Point feature at the absolute center point of all input features
*/
function center(features: GeoJSON.FeatureCollection): GeoJSON.Feature;
/**
* Takes one or more features and calculates the centroid using the arithmetic mean of all vertices. This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.
* @param features Input features
* @returns The centroid of the input features
*/
function centroid(features: GeoJSON.Feature | GeoJSON.FeatureCollection): GeoJSON.Feature;
/**
* Takes a Point and calculates the location of a destination point given a distance in degrees, radians, miles, or kilometers; and bearing in degrees. This uses the Haversine formula to account for global curvature.
* @param start Starting point
* @param distance Distance from the starting point
* @param bearing Ranging from -180 and 180
* @param units Miles, kilometers, degrees or radians
* @returns Destination point
*/
function destination(start: GeoJSON.Feature, distance: number, bearing: number, units: string): GeoJSON.Feature;
/**
* 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
@@ -39,13 +78,65 @@ declare module turf {
*/
function distance(from: GeoJSON.Feature, to: GeoJSON.Feature, units?: string): number;
//////////////////////////////////////////////////////////////////////////
// Transformation
//////////////////////////////////////////////////////////////////////////
/**
* Takes any number of features and returns a rectangular Polygon that encompasses all vertices.
* @param fc Input features
* @returns A rectangular Polygon feature that encompasses all vertices
*/
function envelope(fc: GeoJSON.FeatureCollection): GeoJSON.Feature;
//////////////////////////////////////////////////////////////////////////
/**
* Takes a set of features, calculates the extent of all input features, and returns a bounding box.
* @param input Input features
* @returns The bounding box of input given as an array in WSEN order (west, south, east, north)
*/
function extent(input: GeoJSON.Feature | GeoJSON.FeatureCollection): Array<number>;
/**
* Takes a line and measures its length in the specified units.
* @param line Line to measure
* @param units Can be degrees, radians, miles, or kilometers
* @returns Length of the input line
*/
function lineDistance(line: GeoJSON.Feature, units: string): number;
/**
* Takes two points and returns a point midway between them.
* @param pt1 First point
* @param pt2 Second point
* @returns A point midway between pt1 and pt2
*/
function midpoint(pt1: GeoJSON.Feature, pt2: GeoJSON.Feature): GeoJSON.Feature;
/**
* Takes a feature and returns a Point guaranteed to be on the surface of the feature. Given a Polygon, the point will be in the area of the polygon. Given a LineString, the point will be along the string. Given a Point, the point will the same as the input.
* @param input Any feature or set of features
* @returns A point on the surface of input
*/
function pointOnSurface(input: GeoJSON.Feature | GeoJSON.FeatureCollection): GeoJSON.Feature;
/**
* Takes a bounding box and returns a new bounding box with a size expanded or contracted by a factor of X.
* @param bbox A bounding box
* @param factor The ratio of the new bbox to the input bbox
* @returns The resized bbox
*/
function size(bbox: Array<number>, factor: number): Array<number>;
/**
* Takes a bounding box and calculates the minimum square bounding box that would contain the input.
* @param bbox A bounding box
* @returns A square surrounding bbox
*/
function square(bbox: Array<number>): Array<number>;
//////////////////////////////////////////////////////
// Transformation
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// Misc
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
/**
* Takes a Point and a LineString and calculates the closest Point on the LineString.
@@ -55,27 +146,27 @@ declare module turf {
*/
function pointOnLine(line: GeoJSON.Feature, point: GeoJSON.Feature): GeoJSON.Feature;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// Helper
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// Data
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// Interpolation
//////////////////////////////////////////////////////////////////////////;
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// Joins
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// Classification
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// Types
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
}