Skip to content

Instantly share code, notes, and snippets.

@cinquemb
Last active January 30, 2018 06:41
Show Gist options
  • Save cinquemb/ea639f76bcc40a30dfbef8ea6b977218 to your computer and use it in GitHub Desktop.
Save cinquemb/ea639f76bcc40a30dfbef8ea6b977218 to your computer and use it in GitHub Desktop.
Strava Tile Mine
#import requests
import os
import math
import csv
'''
https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Resolution_and_Scale
https://en.wikipedia.org/wiki/Tiled_web_map
zoom resolution, m/px scale 96 dpi 1 screen cm is scale 120 dpi
0 156543.03 1 : 554 678 932 5547 km 1 : 739 571 909
1 78271.52 1 : 277 339 466 2773 km 1 : 369 785 954
2 39135.76 1 : 138 669 733 1337 km 1 : 184 892 977
3 19567.88 1 : 69 334 866 693 km 1 : 92 446 488
4 9783.94 1 : 34 667 433 347 km 1 : 46 223 244
5 4891.97 1 : 17 333 716 173 km 1 : 23 111 622
6 2445.98 1 : 8 666 858 86.7 km 1 : 11 555 811
7 1222.99 1 : 4 333 429 43.3 km 1 : 5 777 905
8 611.50 1 : 2 166 714 21.7 km 1 : 2 888 952
9 305.75 1 : 1 083 357 10.8 km 1 : 1 444 476
10 152.87 1 : 541 678 5.4 km 1 : 722 238
11 76.437 1 : 270 839 2.7 km 1 : 361 119
12 38.219 1 : 135 419 1.35 km 1 : 180 559
13 19.109 1 : 67 709 677 m 1 : 90 279
14 9.5546 1 : 33 854 339 m 1 : 45 139
15 4.7773 1 : 16 927 169 m 1 : 22 569
16 2.3887 1 : 8 463 84.6 m 1 : 11 284
17 1.1943 1 : 4 231 42.3 m 1 : 5 642
18 0.5972 1 : 2 115 21.2 m 1 : 2 821
'''
'''
curl -O 'https://data.humdata.org/dataset/6992403a-d9dc-4962-b97e-c30abd1feefc/resource/aec5d77d-095a-4d42-8a13-5193ec18a6a9/download/country-boundingboxes.csv'
curl -O 'http://web.archive.org/web/20090223071631if_/http://gothos.info:80/resource_files/country_centroids.txt'
'''
def deg2num(lat_deg, lon_deg, zoom):
lat_rad = math.radians(lat_deg)
max_lat_rad = math.radians(-85.0511)
max_lat_inner = (math.tan(max_lat_rad) + (1 / math.cos(max_lat_rad)))
n = 2.0 ** zoom
xtile = int((lon_deg + 180.0) / 360.0 * n)
real_inner = (math.tan(lat_rad) + (1 / math.cos(lat_rad)))
inner = max([max_lat_inner, real_inner])
print '\t\t\t\t--', real_inner, inner
ytile = int(
(1.0 -
math.log(
real_inner
) / math.pi
) / 2.0 * n)
return (xtile, ytile)
zoom = 15
#lon = -73.96162
lon = -73.95162
#lat = 40.73006
lat = 40.73006
#for x in range(-180, 181, 1):
# for y in range(-180, 181, 1):
x_tile, y_tile = deg2num(lat, lon, zoom)
#(0 to 2zoom-1, 0 to 2zoom-1)
#country,ISO3166 country code,longmin,latmin,longmax,latmax,Wrapped
t_file1 = open('country-boundingboxes.csv', 'rU')
temp_data = t_file1.read().split('\n')
t_file1.close()
country_bounds_data = csv.DictReader(temp_data, delimiter=',')
country_sum = 0
for country in country_bounds_data:
print country['country']
x_long_min = float(country['longmin'])
x_long_max = float(country['longmax'])
y_lat_min = float(country['latmin'])
y_lat_max = float(country['latmax'])
#try:
print '\t\tx:', x_long_min, x_long_max
print '\t\ty:', y_lat_min, y_lat_max
x_min, y_min = deg2num(y_lat_min, x_long_min, zoom)
x_max, y_max = deg2num(y_lat_max, x_long_max, zoom)
print '\t\tx2:', x_min, x_max
print '\t\ty2:', y_min, y_max
x_ord = 1 if x_min <= x_max else -1
y_ord = 1 if y_min <= y_max else -1
x_data = list(range(x_min, x_max, x_ord))
y_data = list(range(y_min, y_max, y_ord))
print '\t\t\t', len(x_data), len(y_data), '%.2f' % (len(x_data) * len(y_data))
country_sum += (len(x_data) * len(y_data))
#except:
# pass
'''
for x in x_data:
for y in y_data:
url = 'https://heatmap-external-c.strava.com/tiles/all/hot/%s/%s/%s' % (zoom, x, y)
print url
'''
print country_sum
#url = 'https://heatmap-external-c.strava.com/tiles/all/hot/%s/%s/%s' % (zoom, x_tile, y_tile)
#print x_tile, y_tile
#print url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment