Is it possible to convert regular JSON to GeoJSON?
So this python script will take a json input file as detailed above and write properly formatted geojson to the output file.
run the script in terminal by doing python scriptname.py input_file.json output_file.json
#! usr/bin/env python
from sys import argv
from os.path import exists
import simplejson as json
script, in_file, out_file = argv
data = json.load(open(in_file))
geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry" : {
"type": "Point",
"coordinates": [d["lon"], d["lat"]],
},
"properties" : d,
} for d in data]
}
output = open(out_file, 'w')
json.dump(geojson, output)
print geojson
I would recommend you to follow:
1- Convert your json into csv using http://www.danmandle.com/blog/json-to-csv-conversion-utility/
2- Create a vrt file for your csv data using http://www.gdal.org/ogr/drv_csv.html
3- Use GDAL (ogr2ogr -f 'GeoJSON' output_file input_file)
4- Load output geojson file to your map using leaflet library
I hope it will help.