Skip to content

Instantly share code, notes, and snippets.

@roberto-butti
Last active July 2, 2019 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roberto-butti/114205ca3f370062887a954925c04413 to your computer and use it in GitHub Desktop.
Save roberto-butti/114205ca3f370062887a954925c04413 to your computer and use it in GitHub Desktop.
JS script without dependencies to generate a geojson file with a grid for latitude and longitude
var geojson = {};
geojson.type = "FeatureCollection";
var features = [];
const step = 1;
var i=0;
var feature = {};
for(i=-180;i<=180;i=i+step){
feature = {};
feature.type = "Feature";
feature.properties = {};
feature.properties.title = "Longitude " + i;
feature.geometry = {};
feature.geometry.type = "LineString";
feature.geometry.coordinates = [];
feature.geometry.coordinates.push([ i, 89 ]);
feature.geometry.coordinates.push([ i, -89 ]);
features.push(feature);
}
for (i = -90; i <= 90; i = i+step) {
feature = {};
feature.type = "Feature";
feature.properties = {};
feature.properties.title = "Latitude " + i;
feature.geometry = {};
feature.geometry.type = "LineString";
feature.geometry.coordinates = [];
feature.geometry.coordinates.push([ 179, i ]);
feature.geometry.coordinates.push([ -179, i ]);
features.push(feature);
}
geojson.features = features;
console.log(JSON.stringify(geojson));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment