Last active
October 6, 2017 18:30
-
-
Save Saigesp/8ca8ca2a4ce33e8e9efe8f5752683f88 to your computer and use it in GitHub Desktop.
Madrid neighborhoods
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
# -*- 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
Madrid neighborhoods fixed!
Original source: https://github.com/codeforamerica/click_that_hood/blob/master/public/data/madrid-districts.geojson