Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
Building geojson coordinate grid in JS

I’m trying to build a coordinate grid using geojson format. My JS knowledge is a little basic so I’m struggling on how to build the grid not just in the x direction but the y direction, so I end up with a square grid not just a x-axis line.

This is my code:

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);

How do I turn this from an x-axis incrementing loop to both x and y axis so it builds a grid not just a line of coordinates?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

What you're doing is boiling down to the fact that enclosing your coordinate values in parenthesis () is materially different that what is intended or expected as part of GeoJSON. Take the following example - in this instance, what you believe to be the x, y point 1, 2 evaluates to simply 2 in JavaScript:

console.log((1, 2))

It's clear from the documentation on GeoJSON FeatureCollection that the values for "coordinates" of a Polygon are expressed as an Array of Arrays (both enclosed in square brackets):

var newFeature = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Polygon",
    "coordinates": [[i, i]]
  }
}
geojson['features'].push(newFeature);

It's not clear where you got the guidance to the contrary to use parenthesis to enclose your coordinate values. It's also not clear how a single point is meant to create a polygon in this instance, but I can't knock it if it meets your requirements.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!