-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilding_permit_association.py
47 lines (39 loc) · 1.67 KB
/
building_permit_association.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# @Author: Miclain K <user>
# @Date: 03-28-2017
# @Last modified by: user
# @Last modified time: 03-28-2017
#Adds Building Permit Data JSON Information to relevant Apartment Complexes that are within .20 miles of
#a given apartment
from geopy.distance import vincenty
from geopy.geocoders import Nominatim
import json
from pprint import pprint
from string import digits
all_lats = []
all_longs = []
apartments = []
apartments_out = []
outfile = open('apartment_summary_vectors_with_crimes_and_permits.json', 'w+')
with open('building_permit_cleaned_up.json') as building_permits:
permit_data = json.load(building_permits)
with open('apartment_summary_vectors_with_crimes.json') as apartment_data1:
apartment_data = json.load(apartment_data1)
for apartment in apartment_data:
apartment.update({"permits":[]})
apartments.append(apartment)
for permit in permit_data:
latit = (permit['lats'])
print latit[0]
# latter = latit[0:len(latit)]
#print latter
longit = (permit['longs'])
# longer = longit[0:len(longit)]
#print longer
permit_lat_long = tuple((latit[0], longit[0]))
for i, apartment in enumerate(apartment_data):
apartment_long_lat = (apartment['lats'],apartment['longs'])
if (vincenty(permit_lat_long, apartment_long_lat).miles) <= .20:
apartments[i]["permits"].append(permit)
for a in apartments:
json.dump({'name': a["name"], 'address': a["address"], 'lats': a["lats"], 'longs': a["longs"], 'crimes': a["crimes"],'permits': a["permits"]}, outfile)
outfile.write(",")