Skip to content

Instantly share code, notes, and snippets.

@Saigesp
Last active October 6, 2017 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Saigesp/8ca8ca2a4ce33e8e9efe8f5752683f88 to your computer and use it in GitHub Desktop.
Save Saigesp/8ca8ca2a4ce33e8e9efe8f5752683f88 to your computer and use it in GitHub Desktop.
Madrid neighborhoods
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
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)
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Saigesp
Copy link
Author

Saigesp commented Oct 6, 2017

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