Socket
Socket
Sign inDemoInstall

geojson-random

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geojson-random - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

.circleci/config.yml

10

CHANGELOG.md

@@ -5,2 +5,12 @@ # Change Log

<a name="0.5.0"></a>
# [0.5.0](https://github.com/node-geojson/geojson-random/compare/v0.4.0...v0.5.0) (2019-01-29)
### Features
* Added bbox as command line argument. ([#19](https://github.com/node-geojson/geojson-random/issues/19)) ([d65f6bc](https://github.com/node-geojson/geojson-random/commit/d65f6bc))
<a name="0.4.0"></a>

@@ -7,0 +17,0 @@ # [0.4.0](https://github.com/tmcw/geojson-random/compare/v0.3.0...v0.4.0) (2017-04-25)

204

index.js

@@ -1,10 +0,10 @@

var from = require('from2');
const from = require("from2");
module.exports = function() {
throw new Error('call .point(), .lineString(), or .polygon() instead');
throw new Error("call .point(), .lineString(), or .polygon() instead");
};
function position(bbox) {
if (bbox) return coordInBBBOX(bbox);
else return [lon(), lat()];
if (bbox) return coordInBBBOX(bbox);
else return [lon(), lat()];
}

@@ -15,7 +15,7 @@

module.exports.point = function(count, bbox) {
var features = [];
for (var i = 0; i < count; i++) {
features.push(feature(bbox ? point(position(bbox)) : point()));
}
return collection(features);
const features = [];
for (let i = 0; i < count; i++) {
features.push(feature(bbox ? point(position(bbox)) : point()));
}
return collection(features);
};

@@ -33,121 +33,131 @@

module.exports.polygon = function(count, num_vertices, max_radial_length, bbox) {
if (typeof num_vertices !== 'number') num_vertices = 10;
if (typeof max_radial_length !== 'number') max_radial_length = 10;
var features = [];
for (i = 0; i < count; i++) {
var vertices = [],
circle_offsets = Array.apply(null,
new Array(num_vertices + 1)).map(Math.random);
module.exports.polygon = function(
count,
num_vertices,
max_radial_length,
bbox
) {
if (typeof num_vertices !== "number") num_vertices = 10;
if (typeof max_radial_length !== "number") max_radial_length = 10;
const features = [];
for (let i = 0; i < count; i++) {
let vertices = [];
const circle_offsets = Array.apply(null, new Array(num_vertices + 1)).map(
Math.random
);
circle_offsets.forEach(sumOffsets);
circle_offsets.forEach(scaleOffsets);
vertices[vertices.length - 1] = vertices[0]; // close the ring
circle_offsets.forEach(function sumOffsets(cur, index, arr) {
arr[index] = index > 0 ? cur + arr[index - 1] : cur;
});
circle_offsets.forEach(function scaleOffsets(cur) {
cur = (cur * 2 * Math.PI) / circle_offsets[circle_offsets.length - 1];
const radial_scaler = Math.random();
vertices.push([
radial_scaler * max_radial_length * Math.sin(cur),
radial_scaler * max_radial_length * Math.cos(cur)
]);
});
vertices[vertices.length - 1] = vertices[0]; // close the ring
// center the polygon around something
vertices = vertices.map(vertexToCoordinate(position(bbox)));
features.push(feature(polygon([vertices])));
}
// center the polygon around something
vertices = vertices.map(vertexToCoordinate(position(bbox)));
features.push(feature(polygon([vertices])));
}
function sumOffsets(cur, index, arr) {
arr[index] = (index > 0) ? cur + arr[index - 1] : cur;
}
function scaleOffsets(cur, index) {
cur = cur * 2 * Math.PI / circle_offsets[circle_offsets.length - 1];
var radial_scaler = Math.random();
vertices.push([
radial_scaler * max_radial_length * Math.sin(cur),
radial_scaler * max_radial_length * Math.cos(cur)
]);
}
return collection(features);
return collection(features);
};
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;
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(
const features = [];
for (let i = 0; i < count; i++) {
const startingPoint = position(bbox);
const vertices = [startingPoint];
for (let j = 0; j < num_vertices - 1; j++) {
const 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)));
(vertices[j][0] - vertices[j - 1][0])
);
const angle = priorAngle + (Math.random() - 0.5) * max_rotation * 2;
const 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);
return collection(features);
};
function vertexToCoordinate(hub) {
return function(cur, index) { return [cur[0] + hub[0], cur[1] + hub[1]]; };
return function(cur) {
return [cur[0] + hub[0], cur[1] + hub[1]];
};
}
function rnd() { return Math.random() - 0.5; }
function lon() { return rnd() * 360; }
function lat() { return rnd() * 180; }
function rnd() {
return Math.random() - 0.5;
}
function lon() {
return rnd() * 360;
}
function lat() {
return rnd() * 180;
}
function point(coordinates) {
return {
type: 'Point',
coordinates: coordinates || [lon(), lat()]
};
return {
type: "Point",
coordinates: coordinates || [lon(), lat()]
};
}
function coordInBBBOX(bbox) {
return [
(Math.random() * (bbox[2] - bbox[0])) + bbox[0],
(Math.random() * (bbox[3] - bbox[1])) + bbox[1]];
return [
Math.random() * (bbox[2] - bbox[0]) + bbox[0],
Math.random() * (bbox[3] - bbox[1]) + bbox[1]
];
}
function pointInBBBOX() {
return {
type: 'Point',
coordinates: [lon(), lat()]
};
}
function polygon(coordinates) {
return {
type: 'Polygon',
coordinates: coordinates
};
return {
type: "Polygon",
coordinates: coordinates
};
}
function feature(geom) {
return {
type: 'Feature',
geometry: geom,
properties: {}
};
return {
type: "Feature",
geometry: geom,
properties: {}
};
}
function collection(f) {
return {
type: 'FeatureCollection',
features: f
};
return {
type: "FeatureCollection",
features: f
};
}
function lineString(coordinates) {
return {
type: 'LineString',
coordinates: coordinates
};
return {
type: "LineString",
coordinates: coordinates
};
}
{
"name": "geojson-random",
"version": "0.4.0",
"version": "0.5.0",
"description": "generate random geojson features",

@@ -10,3 +10,3 @@ "main": "index.js",

"scripts": {
"test": "tap test.js",
"test": "eslint . && tap test.js",
"release": "standard-version"

@@ -16,3 +16,3 @@ },

"type": "git",
"url": "git@github.com:tmcw/geojson-random.git"
"url": "https://github.com/node-geojson/geojson-random.git"
},

@@ -26,13 +26,13 @@ "keywords": [

"bugs": {
"url": "https://github.com/tmcw/geojson-random/issues"
"url": "https://github.com/node-geojson/geojson-random/issues"
},
"homepage": "https://github.com/tmcw/geojson-random",
"homepage": "https://github.com/node-geojson/geojson-random",
"devDependencies": {
"cz-conventional-changelog": "^2.0.0",
"eslint": "^5.12.1",
"standard-version": "^4.0.0",
"tap": "^10.3.2"
"tap": "^12.4.0"
},
"dependencies": {
"from2": "^2.1.0",
"geojson-stream": "0.0.1"
"geojson-stream": "0.1.0"
},

@@ -39,0 +39,0 @@ "config": {

# 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/)
[![CircleCI](https://circleci.com/gh/node-geojson/geojson-random.svg?style=svg)](https://circleci.com/gh/node-geojson/geojson-random)

@@ -6,0 +5,0 @@ Generate random [GeoJSON](http://geojson.org/) features.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc