Created
August 7, 2012 18:43
-
-
Save mlevans/3288218 to your computer and use it in GitHub Desktop.
Find Random Map Tiles in the United States
This file contains hidden or 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
import random | |
import ModestMaps | |
# import whereami # this script borrows bits from whereami: https://github.com/migurski/whereami | |
# Using rough boundaries of the United States | |
lat_bounds = [32,41.5] | |
lng_bounds = [-116.5,-80] | |
num_of_places = 1000 | |
def get_tiles(): | |
""" | |
Returns a list of 1000 random tiles within the specified bounds | |
""" | |
tiles = [] | |
for i in range(num_of_places): | |
lat = random.uniform(lat_bounds[0], lat_bounds[1]) | |
lon = random.uniform(lng_bounds[0], lng_bounds[1]) | |
zoom = round(random.uniform(1,18)) | |
# print [lat, lon, zoom] | |
# info = whereami.do_latlon_point(lat, lon, zoom) | |
provider = ModestMaps.OpenStreetMap.Provider() | |
location = ModestMaps.Geo.Location(lat, lon) | |
coord = provider.locationCoordinate(location).zoomTo(zoom).container() | |
#print '%(zoom)d/%(column)d/%(row)d' % coord.__dict__ | |
if coord.__dict__ is not None: | |
tiles.append('%(zoom)d/%(column)d/%(row)d' % coord.__dict__) | |
return tiles | |
tiles = get_tiles() | |
print tiles |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment