Skip to content

Instantly share code, notes, and snippets.

@aaronlidman
Created August 6, 2012 21:25
Show Gist options
  • Save aaronlidman/3278567 to your computer and use it in GitHub Desktop.
Save aaronlidman/3278567 to your computer and use it in GitHub Desktop.
simplegeo geojson Features to FeatureCollection from http://gis.stackexchange.com/a/16255
import sys
infile = sys.argv[1]
outfile = sys.argv[2]
## Prepare the input/output for read/write of files
fin = open(infile, 'r')
fout = open(outfile, 'w')
##Prepend the new file with approriate header info
fout.write('{"type":"FeatureCollection","features":[' + '\n')
## Read each line from the input and write to the output
for line in fin:
##write each line in the table, and replace carriage returns with "," + carriage return
fout.write(line.replace("\n",",\n"))
##Append the new file with approriate footer info
fout.write(']}')
##Close the input and output files to release file locking
fin.close()
fout.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment