Created
July 7, 2022 12:37
-
-
Save GGontijo/f394cc8ff817ee797b9f18397b054286 to your computer and use it in GitHub Desktop.
Simple geojson builder from a python dictionary, it works.
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
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