Created
June 10, 2016 20:00
-
-
Save zmpeg/f047cb8aa0e3cf058fe4710cd30d251d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import argparse | |
import math | |
def deg2num(lat_deg, lon_deg, zoom): | |
lat_rad = math.radians(lat_deg) | |
n = 2.0 ** zoom | |
xtile = int((lon_deg + 180.0) / 360.0 * n) | |
ytile = int((1.0 - math.log(math.tan(lat_rad) + (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n) | |
return (xtile, ytile) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser('tiles-in-coords.py', description='Generate a list of tiles within lat/lng coordinate bounds.') | |
parser.add_argument('-z', '--zoom', help='Tile Zoom Level', type=int, required=True) | |
parser.add_argument('--min-lat', help='Minimum Latitude', type=float, required=True) | |
parser.add_argument('--max-lat', help='Maximum Latitude', type=float, required=True) | |
parser.add_argument('--min-lng', help='Minimum Longitude', type=float, required=True) | |
parser.add_argument('--max-lng', help='Maximum Longitude', type=float, required=True) | |
args = parser.parse_args() | |
minX, maxY = deg2num(args.min_lat, args.min_lng, args.zoom); | |
maxX, minY = deg2num(args.max_lat, args.max_lng, args.zoom); | |
for tileX in range(minX, maxX): | |
for tileY in range(minY, maxY): | |
print tileX, tileY, args.zoom |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment