Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 生成随机GeoJSON多边形_Mongodb_Geojson - Fatal编程技术网

Mongodb 生成随机GeoJSON多边形

Mongodb 生成随机GeoJSON多边形,mongodb,geojson,Mongodb,Geojson,是否有一种方法或工具可以使用边界框生成特定大小的随机GeoJSON多边形?具体来说,我想用大量随机多边形填充mongodb并测试特定功能。您可以通过编程方式使用边界框坐标为矩形生成随机边界框坐标 例如,如果边界框为[[100100],[200200]],则可以执行以下操作: // generate a random width and height // (e.g. with random numbers between 1 and 50) var width = Math.floor(Mat

是否有一种方法或工具可以使用边界框生成特定大小的随机GeoJSON多边形?具体来说,我想用大量随机多边形填充mongodb并测试特定功能。

您可以通过编程方式使用边界框坐标为矩形生成随机边界框坐标

例如,如果边界框为[[100100],[200200]],则可以执行以下操作:

// generate a random width and height 
// (e.g. with random numbers between 1 and 50)
var width = Math.floor(Math.random() * 50) + 1;
var height = Math.floor(Math.random() * 50) + 1;

// generate a random position that allows the rectangle to fit within the bounding box walls 
// 100 is used in the calculation as 100 is the width and height of the example bounding box 
var upperX = Math.floor(Math.random() * (100-width)) + 1;
var upperY = Math.floor(Math.random() * (100-height)) + 1;
var lowerX = upperX + width;
var lowerY = upperY + height;
var bounds = [[upperX, upperY], [lowerX, lowerY]];

// create rectangle
L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(map);

// loop through above code some chosen number of times