Coder Social home page Coder Social logo

geojson-random's Introduction

geojson-random

CircleCI

Generate random GeoJSON features.

Usable in node.js and in browsers with browserify.

npm install -g geojson-random
geojson-random

# special fast-mode for points
geojson-random 10000 point-stream

api

var random = require('geojson-random');

random.point(count, bbox)

Return count points wrapped in a FeatureCollection.

An optional bbox parameter should be an array of numbers representing a bbox in WSEN order, and if given, the point will reside within its bounds.

random.position(bbox?)

Return a single GeoJSON Position as a 2-element array of numbers in longitude, latitude order.

An optional bbox parameter should be an array of numbers representing a bbox in WSEN order, and if given, the position will reside within its bounds.

random.polygon(count, num_vertices, max_radial_length, bbox)

Return count polygons wrapped in a FeatureCollection.

  • num_vertices is default 10 and is how many coordinates each Polygon will contain.
  • max_radial_length is the maximum number of decimal degrees latitude or longitude that a vertex can reach out of the center of the Polygon. Default is 10.
  • 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.

geojson-random's People

Contributors

bjoernschilberg avatar deniscarriere avatar dependabot-preview[bot] avatar drewbo avatar greenkeeper[bot] avatar sbma44 avatar tmcw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

geojson-random's Issues

New release?

Is there anything preventing a new release version? I was initially confused when my npm install did not include the point-stream parameter as shown in the master README.

Existing fixtures.

I encountered your project while preparing my next release of gjtk for npm.
It seems we have some common interest in generating random, valid GeoJSON object, in my case, for testing.
This is what I came up with, which I'm sure could be improved (especially to exercise the properties of Features):

var valid = {

  Position: function () {
    var length = (Math.round(Math.random()*100)%6)+2;
    var Position = [];
    for (var i=0; i < length ;++i) {
        Position.push((Math.random()-0.5)*100);
    };
    return Position;
  },

  PointCoordinates: function () {
      return valid.Position();
  },

  MultiPointCoordinates: function () {
    var length = Math.round(Math.random()*100)%6;
    var MultiPointCoordinates = [];
    for (var i=0; i < length ;++i) {
        MultiPointCoordinates.push(valid.Position());
    };
    return MultiPointCoordinates;
  },

  LineStringCoordinates: function () {
    var length = (Math.round(Math.random()*100)%6)+2;
    var LineStringCoordinates = [];
    for (var i=0; i < length ;++i) {
        LineStringCoordinates.push(valid.Position());
    };
    return LineStringCoordinates;
  },

  LinearRingCoordinates: function () {
    var LinearRingCoordinates = [];
    var origin = valid.Position();
    LinearRingCoordinates.push(origin);
    LinearRingCoordinates = LinearRingCoordinates.concat(valid.LineStringCoordinates());
    LinearRingCoordinates.push(origin);
    return LinearRingCoordinates;
  },

  MultiLineStringCoordinates: function () {
    var length = Math.round(Math.random()*100)%6;
    var MultiLineStringCoordinates = [];
    for (var i=0; i < length ;++i) {
        MultiLineStringCoordinates.push(valid.LineStringCoordinates());
    };
    return MultiLineStringCoordinates;
  },

  PolygonCoordinates: function () {
    var PolygonCoordinates = [
      [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ],
      [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
    ];
    if (Math.random() < 0.5) {
      PolygonCoordinates = [valid.LinearRingCoordinates()];
    }
    return PolygonCoordinates;
  },

  MultiPolygonCoordinates: function () {
    var length = Math.round(Math.random()*100)%6;
    var MultiPolygonCoordinates = [];
    for (var i=0; i < length ;++i) {
        MultiPolygonCoordinates.push(valid.PolygonCoordinates());
    };
    return MultiPolygonCoordinates;
  },

  Geometry: function () {
    var Geometries = [
      valid.Point(),
      valid.MultiPoint(),
      valid.LineString(),
      valid.MultiLineString(),
      valid.Polygon(),
      valid.MultiPolygon(),
      valid.GeometryCollection()
    ];
    return Geometries[Math.floor(Math.random()*Geometries.length)];
  },

  Point: function () {
    return {
      "type": "Point",
      "coordinates": valid.PointCoordinates()
    };
  },

  MultiPoint: function () {
    return {
      "type": "MultiPoint",
      "coordinates": valid.MultiPointCoordinates()
    };
  },

  LineString: function () {
    return {
      "type": "LineString",
      "coordinates": valid.LineStringCoordinates()
    };
  },

  MultiLineString: function () {
    return {
      "type": "MultiLineString",
      "coordinates": valid.MultiLineStringCoordinates()
    };
  },

  Polygon: function () {
    return {
      "type": "Polygon",
      "coordinates": valid.PolygonCoordinates()
    };
  },

  MultiPolygon: function () {
    return {
      "type": "MultiPolygon",
      "coordinates": valid.MultiPolygonCoordinates()
    };
  },

  GeometryCollection: function () {
    var length = Math.round(Math.random()*100)%3;
    var geometries = [];
    for (var i=0; i < length ;++i) {
        geometries.push(valid.Geometry());
    };
    return {
      "type": "GeometryCollection",
      "geometries": geometries
    };
  },

  Feature: function () {
    return {
      "type": "Feature",
      "geometry": valid.Geometry(),
      "properties": null
    }
  },

  FeatureCollection: function () {
    var length = Math.round(Math.random()*100)%6;
    var features = [];
    for (var i=0; i < length ;++i) {
        features.push(valid.Feature());
    };
    return {
      "type": "FeatureCollection",
      "features": features
    };
  },

  CRS: function () {
    var crs = {
      "type": "name",
      "properties": {
        "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
      }
    };
    if (Math.random() < 0.5) {
      crs = {
        "type": "link",
        "properties": valid.Link()
      };
    };
    return crs;
  },

  Link: function () {
    return {
      "href": "data.crs",
      "type": "ogcwkt"
    };
  },

  Bbox: function () {
    return [-180.0, -90.0, 180.0, 90.0];
  }

};

(See https://github.com/dmtucker/gjtk-js/blob/master/test/test_gjtk.js for usage.)

I would like to be able to import these using geojson-random if you find them applicable to your project.

Polygons not inside BBOX

Hi

I am trying to generate random polygons within a BBOX, however the FeatureCollection it creates do not fit inside it.

random.polygon(1000, 10, 10, [-3.3097644861485325,55.034693716915193,-2.5877407986874017,55.376606303270222])

But the results cover a huge area beyond the BBOX

Why would this happen?

stream output

This dies if you try to generate a >200mb geojson file. I need one.

Generating empty features

Script is generating a FeatureCollection of 'count' items, but each item is empty, regardless of parameters. True for all functions; tested random.point, random.polygon, random.lineString. Example input and output:

console.log(random.point(10))

{ type: 'FeatureCollection',
features:
[ { type: 'Feature', geometry: [Object], properties: {} },
{ type: 'Feature', geometry: [Object], properties: {} },
{ type: 'Feature', geometry: [Object], properties: {} },
{ type: 'Feature', geometry: [Object], properties: {} },
{ type: 'Feature', geometry: [Object], properties: {} },
{ type: 'Feature', geometry: [Object], properties: {} },
{ type: 'Feature', geometry: [Object], properties: {} },
{ type: 'Feature', geometry: [Object], properties: {} },
{ type: 'Feature', geometry: [Object], properties: {} },
{ type: 'Feature', geometry: [Object], properties: {} } ] }

Note: pointstream seems to be working. Anyway to apply a bbox to a pointstream?

polygon

like linestring, would be great if it fit the simple features spec and was non-self-intersecting, but that's a nice-to-have.

linestring

while not technically necessary, it'd be great if this was non-self-intersecting by default. but I don't know offhand how to math that

how to include?

Hi - would love to use this, but I wasn't sure how to get it going in a standard implementation of mapboxjs without adding requirejs(?) / node / etc. Is that possible?

random points inside polygon bounds

Gauging interest for this feature. Would just generate the points inside a specific polygon instead of anywhere in the world. Could also be used for lines, polygons in the future.

I have a need for this so I'm working on in it my fork right now

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.