Skip to content

Instantly share code, notes, and snippets.

@springmeyer
Created June 13, 2011 18:18
Show Gist options
  • Save springmeyer/1023352 to your computer and use it in GitHub Desktop.
Save springmeyer/1023352 to your computer and use it in GitHub Desktop.
generate a gridded set of points in geojson format
import json
def feat(x,y):
feat = { "type": "Feature",
"geometry" : { "type": "Point", "coordinates": [ x, y ] },
"properties": { "label": "%s,%s" % (x,y) }
}
return feat
def grid(minx,miny,maxx,maxy,increment):
geojson = {
"type": "FeatureCollection",
}
features = []
for x in range(minx,maxx,increment):
for y in range(miny,maxy,increment):
features.append(feat(x,y))
features.append(feat(x,y+increment))
features.append(feat(x+increment,y))
features.append(feat(x+increment,y+increment))
geojson["features"] = features
return json.dumps(geojson, indent=4)
if __name__ == "__main__":
print grid(-180,-90,180,90,10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment