Skip to content

Commit

Permalink
new area calculation, pretty print area output
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonMinar committed Mar 29, 2013
1 parent 156aa35 commit 7ac7625
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
5 changes: 4 additions & 1 deletion Makefile
Expand Up @@ -9,9 +9,12 @@ osm2pgsql.sh: build-osm2pgsql-script.py cities.txt
coastshapes.sh: build-coastshapes-script.py cities.txt
python build-coastshapes-script.py $@

index.html: build-index.py cities.txt
index.html: build-index.py lib.py cities.txt
python build-index.py $@

previews: compose-city-previews.py cities.txt
python compose-city-previews.py $@
touch previews

test: lib.py
python -m unittest lib
26 changes: 10 additions & 16 deletions build-index.py
Expand Up @@ -14,6 +14,8 @@
from ModestMaps.Geo import Location
from ModestMaps.OpenStreetMap import Provider

import lib

provider = Provider()
dimensions = Point(960, 600)

Expand Down Expand Up @@ -66,18 +68,10 @@ def nice_time(time):
def nice_area(top, left, bottom, right):
'''
'''
latitude = top/2 + bottom/2
ne = provider.locationCoordinate(Location(top, right)).zoomTo(25.256)
sw = provider.locationCoordinate(Location(bottom, left)).zoomTo(25.256)

xspan, yspan = abs(ne.column - sw.column), abs(ne.row - sw.row)
area = '%d' % (xspan * yspan * 0.000001 * cos(latitude * pi/180))
pat = compile(r'(\d)(\d\d\d)\b')

while pat.search(area):
area = pat.sub(r'\1,\2', area)

return area + ' km²'

km2 = lib.area(left, top, right, bottom) / 1000000
area = 100 * round(km2 / 100)
return "{:,.0f} km²".format(area)

if __name__ == '__main__':

Expand Down Expand Up @@ -175,7 +169,7 @@ def nice_area(top, left, bottom, right):
<script src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>
<script type="application/javascript">
"""

map_cities = [{
'name': city['name'],
'slug': city['slug'],
Expand All @@ -187,11 +181,11 @@ def nice_area(top, left, bottom, right):
for city
in cities
if city['slug'] in files]

print >> index, 'var cities = %s;' % json.dumps(map_cities)

print >> index, """
</script>
</script>
<script src="bbmap.js"></script>
</head>
<body>
Expand Down

0 comments on commit 7ac7625

Please sign in to comment.