Giter Site home page Giter Site logo

gmap_tiles's Introduction

Download Google Maps tiles

Edit download_tiles.py to specify the area and the zoom level you want.

zoom = 15

lat_start, lon_start = 46.53, 6.6
lat_stop, lon_stop = 46.49, 6.7

satellite = True    # roads if false

You can easily find coordinates with https://getlatlong.net/.

Then, run $ python download_tiles.py and get individual tiles:

...
15_16989_11588_s.jpg
15_16989_11589_s.jpg
15_16989_11590_s.jpg
...

Merge Google Maps tiles

Edit merge_tiles.py to specify the area and the zoom level you want, it's just the same as before.

zoom = 15

lat_start, lon_start = 46.53, 6.6
lat_stop, lon_stop = 46.49, 6.7

satellite = True    # roads if false

Then, run $ python merge_tiles.py and get map_s.jpg for satellite or map_r.png for roads.

Google Maps Tiles

Note: merging the tiles requires Python Image Library.

Swiss Topo Tiles

You can do the same with Swiss Topo maps: https://www.github.com/nst/swiss_topo_tiles.

gmap_tiles's People

Contributors

nst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gmap_tiles's Issues

wrong url : Error 404 / line 28

Instead of (line 28) :
url = "http://khm1.google.com/kh?v=87&hl=en&x=%d&y=%d&z=%d" % (x, y, zoom)

Replace it by (line 28) :
url = "http://khm2.google.com/kh/v=708&s=Gal&x=%d&y=%d&z=%d" % (x, y, zoom)

No License Specified

Could you please add a license to the repo so others can contribute to it? :)

Merge Tiles not working for zoom level >=18

Hi I tried your code merge_tiles.py it is working just fine till zoom level 17 but for zoom level 18 the code is giving memory errors.
Kindly guide me on how to resolve this issue.

Error is:
Traceback (most recent call last):
File "E:\maps\merge_tiles.py", line 58, in
merge_tiles(zoom, lat_start, lat_stop, lon_start, lon_stop, satellite=True)
File "E:\maps\merge_tiles.py", line 24, in merge_tiles
result = Image.new("RGB", (w, h))
File "C:\Users...\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\Image.py", line 2505, in new
return im._new(core.fill(mode, size, color))
MemoryError

[UPDATE] Working for Python3

Here is download_tiles.py for Python3:

#!/usr/bin/python

import urllib.request as urllib2
import os, sys
from gmap_utils import *

import time
import random

def download_tiles(zoom, lat_start, lat_stop, lon_start, lon_stop, satellite=True):

    start_x, start_y = latlon2xy(zoom, lat_start, lon_start)
    stop_x, stop_y = latlon2xy(zoom, lat_stop, lon_stop)
    
    print ("x range", start_x, stop_x)
    print ("y range", start_y, stop_y)
    
    user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1'
    headers = { 'User-Agent' : user_agent }
    
    for x in range(start_x, stop_x):
        for y in range(start_y, stop_y):
            
            url = None
            filename = None
            
            if satellite:        
                url = "http://khm2.google.com/kh/v=708&s=Gal&x=%d&y=%d&z=%d" % (x, y, zoom)
                filename = "%d_%d_%d_s.jpg" % (zoom, x, y)
            else:
                url = "http://mt1.google.com/vt/lyrs=h@162000000&hl=en&x=%d&s=&y=%d&z=%d" % (x, y, zoom)
                filename = "%d_%d_%d_r.png" % (zoom, x, y)    
    
            if not os.path.exists(filename):
                
                bytes = None
                
                try:
                    req = urllib2.Request(url, data=None, headers=headers)
                    response = urllib2.urlopen(req)
                    bytes = response.read()
                except Exception as e:
                    print ("--", filename, "->", e)
                    sys.exit(1)
                
                if bytes.startswith(b"<html>"):
                    print ("-- forbidden", filename)
                    sys.exit(1)
                
                print ("-- saving", filename)
                
                f = open(filename,'wb')
                f.write(bytes)
                f.close()
                
                time.sleep(1 + random.random())

if __name__ == "__main__":
    
    zoom = 15

    lat_start, lon_start = 46.53, 6.6
    lat_stop, lon_stop = 46.49, 6.7
        
    download_tiles(zoom, lat_start, lat_stop, lon_start, lon_stop, satellite=True)

invalid syntax

when I run the script I get following error:
$ python download_tiles.py
File "download_tiles.py", line 42
except Exception, e:
^

I'm on py3, maybe that's the issue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.