Skip to content

Instantly share code, notes, and snippets.

@Saigesp
Created October 8, 2017 21:35
Show Gist options
  • Save Saigesp/ceb4324a251616647099cb3055f25d09 to your computer and use it in GitHub Desktop.
Save Saigesp/ceb4324a251616647099cb3055f25d09 to your computer and use it in GitHub Desktop.
# -*- 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment