Skip to content

Commit

Permalink
Merge pull request #352 from Turfjs/simplifications
Browse files Browse the repository at this point in the history
Mass simplifications.
  • Loading branch information
tmcw committed Apr 23, 2016
2 parents 38ca998 + a4813f3 commit eeccdff
Show file tree
Hide file tree
Showing 33 changed files with 1,210 additions and 1,153 deletions.
4 changes: 2 additions & 2 deletions packages/turf-along/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var line = {
}
};

var route = JSON.parse(fs.readFileSync(__dirname + '/fixtures/route.geojson'));
var route = JSON.parse(fs.readFileSync(__dirname + '/test/fixtures/route.geojson'));

var suite = new Benchmark.Suite('turf-along');
suite
Expand All @@ -61,4 +61,4 @@ suite
.on('complete', function () {

})
.run();
.run();
2 changes: 1 addition & 1 deletion packages/turf-along/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var fs = require('fs');
var along = require('./');
var featurecollection = require('turf-helpers').featureCollection;

var line = JSON.parse(fs.readFileSync(__dirname + '/fixtures/dc-line.geojson'));
var line = JSON.parse(fs.readFileSync(__dirname + '/test/fixtures/dc-line.geojson'));

test('turf-along', function (t) {
var pt1 = along(line, 1, 'miles');
Expand Down
File renamed without changes.
20 changes: 7 additions & 13 deletions packages/turf-bearing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,20 @@ var getCoord = require('turf-invariant').getCoord;
* //=bearing
*/
module.exports = function (p1, p2) {
var degrees2radians = Math.PI / 180;
var radians2degrees = 180 / Math.PI;
var coordinates1 = getCoord(p1);
var coordinates2 = getCoord(p2);

var lon1 = toRad(coordinates1[0]);
var lon2 = toRad(coordinates2[0]);
var lat1 = toRad(coordinates1[1]);
var lat2 = toRad(coordinates2[1]);
var lon1 = degrees2radians * coordinates1[0];
var lon2 = degrees2radians * coordinates2[0];
var lat1 = degrees2radians * coordinates1[1];
var lat2 = degrees2radians * coordinates2[1];
var a = Math.sin(lon2 - lon1) * Math.cos(lat2);
var b = Math.cos(lat1) * Math.sin(lat2) -
Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);

var bearing = toDeg(Math.atan2(a, b));
var bearing = radians2degrees * Math.atan2(a, b);

return bearing;
};

function toRad(degree) {
return degree * Math.PI / 180;
}

function toDeg(radian) {
return radian * 180 / Math.PI;
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"MultiPolygon","coordinates":[[[[89.89731732659948,15.25511944762563],[97.38214618074592,16.052811357262158],[98.68399695599587,16.06322503685403],[99.96286464174749,15.819460133552113],[101.16960307003463,15.33088439588537],[102.25783795980492,14.616273515455905],[103.18574905453363,13.703089587640223],[103.91767725122888,12.626425758664833],[104.42549495976174,11.427657615677226],[104.68968703038074,10.1528531461355],[104.7001007099726,8.85100237088556],[104.4563358066707,7.572134685133932],[103.96776006900396,6.365396256846794],[103.25314918857448,5.277161367076509],[102.3399652607588,4.3492502723477955],[101.2633014317834,3.61732207565254],[100.0645332887958,3.10950436711968],[98.78972881925408,2.8453122965006834],[75.93816631925408,0.40991839718590484],[74.65084855956395,0.39820672109182453],[73.38545793294124,0.6350837774436675],[72.18954393625445,1.1116484533263717],[71.10804534780976,1.8099929105698287],[70.18160156595783,2.703875507356708],[69.44502550520684,3.759706878598864],[68.9259954337194,4.937812121207628],[68.64401490892635,6.193921655208537],[68.60967989368582,7.480834738714557],[68.82428059251274,8.75019312696964],[69.27975296965231,9.954298226798285],[69.95898177079903,11.047903463372862],[91.05273177079903,38.631277051950384],[91.94113728223016,39.58293851118907],[92.99813227140413,40.34299474503142],[94.1830970136566,40.882237218655334],[95.45049397847872,41.1799431462101],[96.75161781127673,41.2246718558552],[98.03646705283488,41.01470444836311],[99.25566566735186,40.55810985345269],[100.36236053580622,39.872434745345146],[101.3140219950449,38.98402923391401],[102.07407822888726,37.927034244740035],[102.61332070251116,36.74206950248756],[102.91102663006593,35.474672537665455],[102.95575533971103,34.173548704867436],[102.74578793221895,32.88869946330928],[102.28919333730853,31.669500848792307],[101.60351822920097,30.56280598033795],[89.89731732659948,15.25511944762563]]],[[[61.31969885815106,44.2992050898548],[63.87285949164982,43.493829595013054],[65.0236475479399,43.00761068162628],[66.06301552998079,42.314475644174586],[66.95418369155826,41.43895220643832],[67.6656165809523,40.41202220584269],[68.17213897478437,39.270025250163066],[68.45582674471991,38.05337278071096],[70.56520174471993,22.509635570714792],[70.61297963236974,21.20862013683507],[70.4060239613619,19.923282346221566],[69.95228792207115,18.703017009341814],[69.26920833602932,17.59471823875942],[68.38303556865257,16.640977334686752],[67.32782474241976,15.878446025203267],[66.14412701761398,15.336427960899927],[64.87743123397419,15.035752592020678],[63.576415800094466,14.987974704370856],[62.29107800948096,15.194930375378704],[61.07081267260121,15.648666414669458],[59.96251390201881,16.331746000711284],[59.00877299794615,17.217918768088037],[58.24624168846266,18.273129594320842],[57.704223624159326,19.45682731912662],[57.40354825528007,20.723523102766414],[55.860534320344016,32.09381198739247],[36.32245300835017,38.25695413303255],[35.123779549702626,38.76921240431063],[34.04825890214669,39.505746133096864],[33.13732764499912,40.43817888762152],[32.4260812228473,41.53058683520114],[31.941921823508114,42.74088277958433],[31.703502654056884,44.02243765417889],[31.72000928879947,45.32587699989788],[31.990805776690838,46.60098321473043],[32.50545914261823,47.798630287076236],[33.24414133858802,48.872676473381155],[34.17839315884462,49.781742000890645],[35.27222068756704,50.49080330597498],[36.483482036307336,50.97254238681306],[63.90535703630734,58.864855427582455],[65.18573232558697,59.100573488714026],[66.48749187515563,59.08197346591001],[67.76060979555858,58.809770147615744],[68.95616087908746,58.294424154699904],[70.02820076807505,57.55573994466087],[70.93553157079445,56.622104737431584],[71.64328507333414,55.529397610437194],[72.12426270550422,54.31961068577088],[72.3599807666358,53.03923539649126],[72.34138074383179,51.73747584692259],[72.06917742553752,50.464357926519654],[71.55383143262168,49.26880684299076],[70.81514722258265,48.19676695400317],[69.88151201535335,47.289436151283766],[68.78880488835897,46.58168264874409],[67.57901796369265,46.100705016574],[61.31969885815106,44.2992050898548]]]]},"properties":{"fill":"#000","fill-opacity":0.3,"stroke":"#0ff"}},{"type":"Feature","properties":{},"geometry":{"type":"MultiLineString","coordinates":[[[65.7421875,52.482780222078226],[38.3203125,44.59046718130883],[61.87499999999999,37.16031654673677],[63.984375,21.616579336740603]],[[96.328125,34.59704151614417],[75.234375,7.013667927566642],[98.0859375,9.44906182688142]]]}}]}
{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"MultiPolygon","coordinates":[[[[89.89731732659948,15.25511944762563],[97.38214618074592,16.052811357262158],[98.68399695599587,16.06322503685403],[99.96286464174749,15.81946013355211],[101.16960307003463,15.33088439588537],[102.25783795980492,14.616273515455903],[103.18574905453363,13.703089587640221],[103.91767725122888,12.626425758664832],[104.42549495976174,11.427657615677226],[104.68968703038074,10.1528531461355],[104.7001007099726,8.85100237088556],[104.4563358066707,7.572134685133933],[103.96776006900394,6.365396256846795],[103.25314918857448,5.27716136707651],[102.3399652607588,4.349250272347797],[101.2633014317834,3.6173220756525417],[100.0645332887958,3.1095043671196816],[98.78972881925408,2.8453122965006843],[75.93816631925408,0.4099183971859057],[74.65084855956395,0.3982067210918263],[73.38545793294124,0.6350837774436693],[72.18954393625445,1.1116484533263735],[71.10804534780976,1.8099929105698305],[70.18160156595783,2.7038755073567087],[69.44502550520684,3.7597068785988648],[68.9259954337194,4.937812121207628],[68.64401490892635,6.193921655208537],[68.60967989368582,7.480834738714557],[68.82428059251274,8.75019312696964],[69.27975296965231,9.954298226798283],[69.95898177079903,11.04790346337286],[91.05273177079903,38.631277051950384],[91.94113728223016,39.58293851118907],[92.99813227140413,40.34299474503142],[94.1830970136566,40.882237218655334],[95.45049397847872,41.1799431462101],[96.75161781127673,41.22467185585519],[98.03646705283488,41.01470444836311],[99.25566566735186,40.55810985345269],[100.36236053580622,39.872434745345146],[101.3140219950449,38.98402923391401],[102.07407822888726,37.927034244740035],[102.61332070251116,36.74206950248756],[102.91102663006593,35.474672537665455],[102.95575533971103,34.173548704867436],[102.74578793221895,32.88869946330928],[102.28919333730852,31.669500848792307],[101.60351822920097,30.56280598033795],[89.89731732659948,15.25511944762563]]],[[[61.31969885815106,44.2992050898548],[63.87285949164981,43.493829595013054],[65.02364754793989,43.00761068162628],[66.06301552998077,42.314475644174586],[66.95418369155826,41.43895220643832],[67.6656165809523,40.41202220584269],[68.17213897478437,39.270025250163066],[68.45582674471991,38.05337278071096],[70.56520174471993,22.509635570714792],[70.61297963236974,21.20862013683507],[70.4060239613619,19.923282346221566],[69.95228792207115,18.703017009341814],[69.26920833602932,17.59471823875942],[68.38303556865257,16.640977334686756],[67.32782474241976,15.878446025203269],[66.14412701761398,15.336427960899929],[64.87743123397419,15.035752592020678],[63.576415800094466,14.98797470437086],[62.29107800948096,15.194930375378704],[61.07081267260121,15.64866641466946],[59.96251390201881,16.331746000711284],[59.00877299794615,17.217918768088037],[58.24624168846266,18.273129594320842],[57.704223624159326,19.456827319126624],[57.40354825528008,20.723523102766414],[55.86053432034402,32.09381198739247],[36.32245300835018,38.25695413303255],[35.12377954970263,38.76921240431063],[34.0482589021467,39.505746133096864],[33.137327644999125,40.43817888762152],[32.42608122284731,41.53058683520114],[31.941921823508114,42.74088277958433],[31.703502654056887,44.02243765417889],[31.72000928879947,45.32587699989788],[31.99080577669084,46.600983214730434],[32.505459142618236,47.79863028707624],[33.24414133858802,48.87267647338116],[34.17839315884463,49.781742000890645],[35.27222068756704,50.49080330597498],[36.48348203630734,50.97254238681306],[63.90535703630734,58.864855427582455],[65.18573232558697,59.100573488714026],[66.48749187515563,59.08197346591001],[67.76060979555858,58.809770147615744],[68.95616087908746,58.2944241546999],[70.02820076807505,57.55573994466087],[70.93553157079445,56.62210473743158],[71.64328507333413,55.529397610437194],[72.12426270550422,54.31961068577088],[72.3599807666358,53.03923539649126],[72.34138074383178,51.73747584692259],[72.06917742553752,50.464357926519654],[71.55383143262168,49.26880684299076],[70.81514722258265,48.196766954003174],[69.88151201535335,47.289436151283766],[68.78880488835895,46.58168264874409],[67.57901796369265,46.100705016574],[61.31969885815106,44.2992050898548]]]]},"properties":{"fill":"#000","fill-opacity":0.3,"stroke":"#0ff"}},{"type":"Feature","properties":{},"geometry":{"type":"MultiLineString","coordinates":[[[65.7421875,52.482780222078226],[38.3203125,44.59046718130883],[61.87499999999999,37.16031654673677],[63.984375,21.616579336740603]],[[96.328125,34.59704151614417],[75.234375,7.013667927566642],[98.0859375,9.44906182688142]]]}}]}
3 changes: 2 additions & 1 deletion packages/turf-centroid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var each = require('turf-meta').coordEach;
var point = require('turf-helpers').point;

/**
* Takes one or more features and calculates the centroid using the arithmetic mean of all vertices.
* Takes one or more features and calculates the centroid using
* the mean of all vertices.
* This lessens the effect of small islands and artifacts when calculating
* the centroid of a set of polygons.
*
Expand Down
298 changes: 151 additions & 147 deletions packages/turf-collect/index.js
Original file line number Diff line number Diff line change
@@ -1,153 +1,157 @@
var inside = require('turf-inside');

/**
* Calculates a series of aggregations for a set of {@link Point|points} within a set of {@link Polygon|polygons}. Sum, average, count, min, max, and deviation are supported.
*
* @module turf/aggregate
* @category aggregation
* @param {FeatureCollection<Polygon>} polygons polygons with values on which to aggregate
* @param {FeatureCollection<Point>} points points to be aggregated
* @param {Array} aggregations an array of aggregation objects
* @return {FeatureCollection<Polygon>} polygons with properties listed based on `outField` values in `aggregations`
* @example
* var polygons = {
* "type": "FeatureCollection",
* "features": [
* {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Polygon",
* "coordinates": [[
* [1.669921, 48.632908],
* [1.669921, 49.382372],
* [3.636474, 49.382372],
* [3.636474, 48.632908],
* [1.669921, 48.632908]
* ]]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Polygon",
* "coordinates": [[
* [2.230224, 47.85003],
* [2.230224, 48.611121],
* [4.361572, 48.611121],
* [4.361572, 47.85003],
* [2.230224, 47.85003]
* ]]
* }
* }
* ]
* };
* var points = {
* "type": "FeatureCollection",
* "features": [
* {
* "type": "Feature",
* "properties": {
* "population": 200
* },
* "geometry": {
* "type": "Point",
* "coordinates": [2.054443,49.138596]
* }
* },
* {
* "type": "Feature",
* "properties": {
* "population": 600
* },
* "geometry": {
* "type": "Point",
* "coordinates": [3.065185,48.850258]
* }
* },
* {
* "type": "Feature",
* "properties": {
* "population": 100
* },
* "geometry": {
* "type": "Point",
* "coordinates": [2.329101,48.79239]
* }
* },
* {
* "type": "Feature",
* "properties": {
* "population": 200
* },
* "geometry": {
* "type": "Point",
* "coordinates": [2.614746,48.334343]
* }
* },
* {
* "type": "Feature",
* "properties": {
* "population": 300
* },
* "geometry": {
* "type": "Point",
* "coordinates": [3.416748,48.056053]
* }
* }
* ]
* };
* var aggregations = [
* {
* aggregation: 'sum',
* inField: 'population',
* outField: 'pop_sum'
* },
* {
* aggregation: 'average',
* inField: 'population',
* outField: 'pop_avg'
* },
* {
* aggregation: 'median',
* inField: 'population',
* outField: 'pop_median'
* },
* {
* aggregation: 'min',
* inField: 'population',
* outField: 'pop_min'
* },
* {
* aggregation: 'max',
* inField: 'population',
* outField: 'pop_max'
* },
* {
* aggregation: 'deviation',
* inField: 'population',
* outField: 'pop_deviation'
* },
* {
* aggregation: 'variance',
* inField: 'population',
* outField: 'pop_variance'
* },
* {
* aggregation: 'count',
* inField: '',
* outField: 'point_count'
* }
* ];
*
* var aggregated = turf.aggregate(
* polygons, points, statsProperty);
*
* var result = turf.featurecollection(
* points.features.concat(aggregated.features));
*
* //=result
*/
* Joins attributes FeatureCollection of polygons with a FeatureCollection of
* points. Given an `inProperty` on points and an `outProperty` for polygons,
* this finds every point that lies within each polygon, collects the `inProperty`
* values from those points, and adds them as an array to `outProperty` on the
* polygon.
*
* @module turf/aggregate
* @category aggregation
* @param {FeatureCollection<Polygon>} polygons polygons with values on which to aggregate
* @param {FeatureCollection<Point>} points points to be aggregated
* @param {Array} aggregations an array of aggregation objects
* @return {FeatureCollection<Polygon>} polygons with properties listed based on `outField` values in `aggregations`
* @example
* var polygons = {
* "type": "FeatureCollection",
* "features": [
* {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Polygon",
* "coordinates": [[
* [1.669921, 48.632908],
* [1.669921, 49.382372],
* [3.636474, 49.382372],
* [3.636474, 48.632908],
* [1.669921, 48.632908]
* ]]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Polygon",
* "coordinates": [[
* [2.230224, 47.85003],
* [2.230224, 48.611121],
* [4.361572, 48.611121],
* [4.361572, 47.85003],
* [2.230224, 47.85003]
* ]]
* }
* }
* ]
* };
* var points = {
* "type": "FeatureCollection",
* "features": [
* {
* "type": "Feature",
* "properties": {
* "population": 200
* },
* "geometry": {
* "type": "Point",
* "coordinates": [2.054443,49.138596]
* }
* },
* {
* "type": "Feature",
* "properties": {
* "population": 600
* },
* "geometry": {
* "type": "Point",
* "coordinates": [3.065185,48.850258]
* }
* },
* {
* "type": "Feature",
* "properties": {
* "population": 100
* },
* "geometry": {
* "type": "Point",
* "coordinates": [2.329101,48.79239]
* }
* },
* {
* "type": "Feature",
* "properties": {
* "population": 200
* },
* "geometry": {
* "type": "Point",
* "coordinates": [2.614746,48.334343]
* }
* },
* {
* "type": "Feature",
* "properties": {
* "population": 300
* },
* "geometry": {
* "type": "Point",
* "coordinates": [3.416748,48.056053]
* }
* }
* ]
* };
* var aggregations = [
* {
* aggregation: 'sum',
* inField: 'population',
* outField: 'pop_sum'
* },
* {
* aggregation: 'average',
* inField: 'population',
* outField: 'pop_avg'
* },
* {
* aggregation: 'median',
* inField: 'population',
* outField: 'pop_median'
* },
* {
* aggregation: 'min',
* inField: 'population',
* outField: 'pop_min'
* },
* {
* aggregation: 'max',
* inField: 'population',
* outField: 'pop_max'
* },
* {
* aggregation: 'deviation',
* inField: 'population',
* outField: 'pop_deviation'
* },
* {
* aggregation: 'variance',
* inField: 'population',
* outField: 'pop_variance'
* },
* {
* aggregation: 'count',
* inField: '',
* outField: 'point_count'
* }
* ];
*
* var aggregated = turf.aggregate(
* polygons, points, statsProperty);
*
* var result = turf.featurecollection(
* points.features.concat(aggregated.features));
*
* //=result
*/
module.exports = function (polyFC, ptFC, inProperty, outProperty) {
polyFC.features.forEach(function (poly) {
var values = ptFC.features.filter(function (pt) {
Expand Down
Loading

0 comments on commit eeccdff

Please sign in to comment.