Skip to content

Instantly share code, notes, and snippets.

@GGontijo
Created July 7, 2022 12:37
Show Gist options
  • Save GGontijo/f394cc8ff817ee797b9f18397b054286 to your computer and use it in GitHub Desktop.
Save GGontijo/f394cc8ff817ee797b9f18397b054286 to your computer and use it in GitHub Desktop.
Simple geojson builder from a python dictionary, it works.
import json
class Core:
def json_gen(self, items_list: list):
self.geojson = {}
self.geojson['type'] = 'FeatureCollection'
self.features = []
for item in items_list:
self.feature = {}
self.properties = {}
self.geometry = {}
self.coordinates = []
self.coordinates.append(item['lon'])
self.coordinates.append(item['lat'])
self.geometry['type'] = 'Point'
self.geometry['coordinates'] = self.coordinates
self.feature['type'] = 'Feature'
self.feature['properties'] = self.properties
self.feature['geometry'] = self.geometry
self.features.append(self.feature)
self.geojson['features'] = self.features
with open('a.txt', 'w') as f:
json.dump(self.geojson, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment