-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewEngland.py
66 lines (49 loc) · 1.64 KB
/
NewEngland.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'''Very simple script to read Laurenslist.txt and reformat it to value
geojson.'''
from __future__ import print_function
from collections import OrderedDict
import json
from geopy.geocoders import Nominatim
geolocator = Nominatim()
out = {'type': "FeatureCollection", 'features': []}
def item_to_json(item):
if len(item) > 4:
raise ValueError()
name = item[0]
loc = geolocator.geocode(item[1] + ', USA')
print(loc.address)
prop = OrderedDict({"marker-color": "#f00"})
# If sq ft is not given, treat it as a small home
sqft = 0
sqft_txt = ''
# default URL
url = 'http://lowcarbonproductions.net/phne-2017-flipbook/index.html'
for i in item:
if 'sq ft' in i:
# If sqft given use that value
sqft = int(i.split()[0].replace(',', ''))
sqft_txt = i
if 'http' in i:
url = i
if sqft > 10000:
prop["marker-size"] = "large"
else:
prop["marker-symbol"] = "building"
prop['name'] = "<a href='{}'>{}</a>".format(url, name)
if sqft_txt != '':
prop['description'] = sqft_txt
out['features'].append({"type": "Feature",
"geometry": {"type": "Point",
"coordinates": [loc.longitude, loc.latitude]},
"properties": prop})
item = []
with open("Laurenslist.txt") as f:
for line in f:
line = line[:-1]
if line == "":
item_to_json(item)
item = []
else:
item.append(line)
with open("NewEngland.geojson", 'w') as f:
json.dump(out, f, indent=2, separators=(',', ': '))