I have tons of pictures which I am showing in markers on a LeafletJs map and currently have a fixed GeoJSON file. So I want to know is there any easy way to dynamically add new features to the GeoJSON file?

I was thinking a script(Php/JS) which scans a folder for new images, then gets the coordinates from a GPX file based on the image name and then add those to the GeoJSON feature collection. Is this kind of solution possible?

  • geojson.io could one of the possibilities – poshan Jul 1 '14 at 5:20
  • @poshan Maybe my question was a bit inaccurate, but I am looking ways to add data to my geojson file without manually adding those – somnium Jul 1 '14 at 5:35
  • @somnium this is a good question - I updated the title slightly to make it more relevant. The main question is how to interact with your GeoJSON file programatically - once you figure this out you can add as much data as necessary – Stephen Lead Jul 1 '14 at 5:43
  • 1
    @somnion, Your question is currently vague. What exactly do you mean when you say that you "want to dynamically add new points to the GeoJSON"? Do you want to save the updated GeoJSON file after you alter it? Where is it being read? What programming API/Language do you want to use? – Devdatta Tengshe Jul 1 '14 at 6:26
  • 1
    @somnium: yes it is possible. I would suggest that you edit this question, and put in the relevant parts of your comments in it. Please see this post on tips to improve the question meta.gis.stackexchange.com/questions/3349/… – Devdatta Tengshe Jul 1 '14 at 7:32

You can write a script that reads the JSON file, appends the new features and write it back. That way when the map is loaded, it reads the new GeoJSON file.

import json

# Load existing data
with open('test.json') as f:
  data = json.load(f)

# Add data 
feature = {}
feature['type'] = 'Feature'
feature['geometry'] = {'type': 'Point',
                       'coordinates': [10, 10],
feature['properties'] =  {'prop0': 'value1'}

# Write JSON file with new data
with open('test.json', 'w') as f:

Not the answer you're looking for? Browse other questions tagged or ask your own question.