Instantly share code, notes, and snippets.

Embed
What would you like to do?
Madrid neighborhoods
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# -*- coding: UTF-8 -*-
import os, json, time
from area import area
from termcolor import colored
# python3 -c "from fix_geojson import *; fix_geojson('ESP_MAD_adm6.json')"
def fix_geojson(filename):
try:
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)) as jsonfile:
jsonfile = json.load(jsonfile)
polygons = []
for polygon in jsonfile[u'features']:
ctemp = []
for coor in polygon['geometry']['coordinates'][0][0]:
ctemp.append([round(coor[0]-0.001368,6),round(coor[1]-0.0012047,6)])
polygon['geometry']['coordinates'][0][0] = ctemp
polygons.append(polygon)
jsonfile[u'features'] = polygons
f = open(os.path.join(os.path.dirname(os.path.abspath(__file__)),'fixed_'+filename),'w')
f.write(json.dumps(jsonfile))
f.close()
except Exception as e:
print(time.strftime("%Y-%m-%d %H:%M:%S"),colored('Error general:','red'), e)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Saigesp

This comment has been minimized.

Owner

Saigesp commented Oct 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment