Mongodb 生成随机GeoJSON多边形
是否有一种方法或工具可以使用边界框生成特定大小的随机GeoJSON多边形?具体来说,我想用大量随机多边形填充mongodb并测试特定功能。您可以通过编程方式使用边界框坐标为矩形生成随机边界框坐标 例如,如果边界框为[[100100],[200200]],则可以执行以下操作: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
// 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