Below, arrays x and y are decimal longitude and latitude respectively. The code would have to be modified to include a description for each coordinate, which could be included easily on line 15 if in the form of an iterable list.
This file contains 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
f = open('points.geojson', 'w') | |
f.write('\n') | |
f.write('{\n') | |
f.write(' "type": "FeatureCollection",\n') | |
f.write(' "features": [\n') | |
for k in range(len(x)): | |
f.write('\n') | |
f.write(' {\n') | |
f.write(' "type": "Feature",\n') | |
f.write(' "geometry": {\n') | |
f.write(' "type": "Point",\n') | |
f.write(' "coordinates": ['+str(y[k])+', '+str(x[k])+']\n') | |
f.write(' },\n') | |
f.write(' "properties": {\n') | |
f.write(' "'+str(k)+'": "description here"\n') | |
f.write(' }\n') | |
if k==len(x)-1: | |
f.write(' }\n') | |
else: | |
f.write(' },\n') | |
f.write('\n') | |
f.write('\n') | |
f.write(' ]\n') | |
f.write('}\n') | |
f.close() |
No comments:
Post a Comment