geojson-random
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -0,1 +1,15 @@ | ||
# Change Log | ||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
<a name="0.4.0"></a> | ||
# [0.4.0](https://github.com/tmcw/geojson-random/compare/v0.3.0...v0.4.0) (2017-04-25) | ||
### Features | ||
* lineString, generates linestrings ([cc7f1e7](https://github.com/tmcw/geojson-random/commit/cc7f1e7)), closes [#13](https://github.com/tmcw/geojson-random/issues/13) | ||
# 0.3.0 | ||
@@ -2,0 +16,0 @@ |
38
index.js
var from = require('from2'); | ||
module.exports = function() { | ||
throw new Error('call .point() or .polygon() instead'); | ||
throw new Error('call .point(), .lineString(), or .polygon() instead'); | ||
}; | ||
@@ -66,3 +66,32 @@ | ||
module.exports.lineString = function(count, num_vertices, max_length, max_rotation, bbox) { | ||
if (typeof num_vertices !== 'number' || num_vertices < 2) num_vertices = 10; | ||
if (typeof max_length !== 'number') max_length = 0.0001; | ||
if (typeof max_rotation !== 'number') max_rotation = Math.PI / 8; | ||
var features = []; | ||
for (i = 0; i < count; i++) { | ||
var startingPoint = position(bbox); | ||
var vertices = [startingPoint]; | ||
for (var j = 0; j < num_vertices - 1; j++) { | ||
var priorAngle = (j === 0) | ||
? Math.random() * 2 * Math.PI | ||
: Math.tan( | ||
(vertices[j][1] - vertices[j - 1][1]) / | ||
(vertices[j][0] - vertices[j - 1][0]) | ||
) | ||
var angle = priorAngle + (Math.random() - 0.5) * max_rotation * 2; | ||
var distance = Math.random() * max_length; | ||
vertices.push([ | ||
vertices[j][0] + distance * Math.cos(angle), | ||
vertices[j][1] + distance * Math.sin(angle) | ||
]); | ||
} | ||
features.push(feature(lineString(vertices))); | ||
} | ||
return collection(features); | ||
}; | ||
function vertexToCoordinate(hub) { | ||
@@ -117,1 +146,8 @@ return function(cur, index) { return [cur[0] + hub[0], cur[1] + hub[1]]; }; | ||
} | ||
function lineString(coordinates) { | ||
return { | ||
type: 'LineString', | ||
coordinates: coordinates | ||
}; | ||
} |
{ | ||
"name": "geojson-random", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "generate random geojson features", | ||
@@ -10,3 +10,4 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "tape test.js" | ||
"test": "tap test.js", | ||
"release": "standard-version" | ||
}, | ||
@@ -28,8 +29,15 @@ "repository": { | ||
"devDependencies": { | ||
"tape": "~2.13.4" | ||
"cz-conventional-changelog": "^2.0.0", | ||
"standard-version": "^4.0.0", | ||
"tap": "^10.3.2" | ||
}, | ||
"dependencies": { | ||
"from2": "^2.1.0", | ||
"geojson-stream": "0.0.0" | ||
"geojson-stream": "0.0.1" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
} | ||
} |
# geojson-random | ||
[![build status](https://secure.travis-ci.org/mapbox/geojson-random.png)](http://travis-ci.org/mapbox/geojson-random) | ||
[![build status](https://secure.travis-ci.org/tmcw/geojson-random.svg)](http://travis-ci.org/tmcw/geojson-random) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/tmcw/geojson-random.svg)](https://greenkeeper.io/) | ||
@@ -48,1 +49,16 @@ Generate random [GeoJSON](http://geojson.org/) features. | ||
* `bbox` (Optional) Bounding box in [minX, minY, maxX, maxY] order. | ||
### `random.lineString(count, num_vertices, max_length, max_rotation, bbox)` | ||
Return `count` line strings wrapped in a FeatureCollection. | ||
* `num_vertices` is default `10` and is how many coordinates each LineString | ||
will contain. | ||
* `max_length` is the maximum number of decimal degrees that a vertex can be | ||
from its predecessor | ||
Default is `0.0001`. | ||
* `max_rotation` is the maximum number of radians that a line segment can turn | ||
from the previous segment. | ||
Default is `Math.PI / 8`. | ||
* `bbox` (Optional) Bounding box in [minX, minY, maxX, maxY] order. This | ||
parameter is only applied to the starting point of the line. |
@@ -1,2 +0,2 @@ | ||
var test = require('tape'), | ||
var test = require('tap').test, | ||
geojsonRandom = require('./'); | ||
@@ -3,0 +3,0 @@ |
Sorry, the diff of this file is not supported yet
84340
10
181
64
3
+ AddedJSONStream@1.3.5(transitive)
+ Addedgeojson-stream@0.0.1(transitive)
+ Addedjsonparse@1.3.1(transitive)
- RemovedJSONStream@0.7.4(transitive)
- Removedgeojson-stream@0.0.0(transitive)
- Removedjsonparse@0.0.5(transitive)
Updatedgeojson-stream@0.0.1