Created
June 13, 2011 18:18
-
-
Save springmeyer/1023352 to your computer and use it in GitHub Desktop.
generate a gridded set of points in geojson format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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