Estoy tratando de tomar una cuadrícula rectangular y dividirla en cuadrículas cuadradas de igual tamaño y generar las coordenadas en JavaScript json.
Hasta ahora, he podido trazar coordenadas para que llenen la primera línea, pero no estoy seguro de cómo puedo llenar todo el rectángulo (es decir, extendiendo hacia abajo varias líneas, no solo una).
Me imagino que es probable que necesite un segundo ciclo dentro del primero, pero me está costando mucho lograr que esto se transmita a la salida json.
var geojson = {}; var xStart = -180; var yStart = -90; // Start coodinatate on y-axis var xEnd = 180; // End point on x-axis var yEnd = 90; // End point on y-axis var gridSize = 10; // Size of the grid increments geojson['type'] = 'FeatureCollection'; geojson['features'] = []; for (let i = xStart; i <= xEnd; i += gridSize) { var newFeature = { "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [[i, i]] } } geojson['features'].push(newFeature); } console.log(geojson);Como mencionaste, solo poner otro bucle te dará el mapeo completo.
var geojson = {}; var xStart = -180; var yStart = -90; // Start coodinatate on y-axis var xEnd = 180; // End point on x-axis var yEnd = 90; // End point on y-axis var gridSize = 10; // Size of the grid increments geojson['type'] = 'FeatureCollection'; geojson['features'] = []; for (let i = xStart; i <= xEnd; i += gridSize) { for (let j = yStart; j <= yEnd; j += gridSize) { var newFeature = { "type": "Feature", "properties": {}, "geometry": { "type": "Polygon", "coordinates": [ [i, j] ] } } geojson['features'].push(newFeature); } } console.log(geojson);