7

I want to overlay geospatial data (mostly heatmaps) on top of high resolution satellite images using python. (i am newbie, so be gentle on me ;-) )

Here is my wish list

  • detailed enough to show streets and buildings
  • must be fairly recent (captured within last several years)
  • coordinates and projection of images/maps must be known that heatmaps i created can be overlayed
  • easy retrieval (hopefully, several lines of python codes will take care of getting right images)
  • free

I think google map/earth, yahoo map, bing, etc... could be potential candidates, but I am not sure how to access them easily. Code examples would be very helpful.

Any suggestions?

рüффп
  • 5,172
  • 34
  • 67
  • 113
user186477
  • 1,039
  • 3
  • 11
  • 13

5 Answers5

5

Open Street Map is a good equivalent to Google maps (which I do not know very well).

Their database increases with time. It is an open source map acquisition attempt. They are sometimes a little bit more accurate than Google maps, see the Berlin zoo example.

It has several APIs, which are read-only access: http://wiki.openstreetmap.org/wiki/XAPI.

It appears to use the REST protocol.

For the use of REST and Python, I would suggest this SO link.

Community
  • 1
  • 1
Marc-Olivier Titeux
  • 1,209
  • 3
  • 13
  • 24
3

Google Maps explicitly forbid using map tiles offline or caching them, but I think Microsoft Bing Maps don't say anything explicitly against it, and I guess you are not planning to use your program commercially (?)

Then, you could use this. It creates a cache, first loading a tile from memory, else fom disk, else from the internet, always caching everything to disk for reuse. Of course you'll have to figure out how to tweak it, specifically how to get the tile coordinates and zoom level you need, and for this I suggest strongly this site. Good study!

#!/usr/bin/env python
# coding: utf-8

import os
import Image
import random
import urllib
import cStringIO
import cairo
#from geofunctions import *


class TileServer(object):
    def __init__(self):
        self.imdict = {}
        self.surfdict = {}
        self.layers = 'ROADMAP'
        self.path = './'
        self.urltemplate = 'http://ecn.t{4}.tiles.virtualearth.net/tiles/{3}{5}?g=0'
        self.layerdict = {'SATELLITE': 'a', 'HYBRID': 'h', 'ROADMAP': 'r'}

    def tiletoquadkey(self, xi, yi, z):
        quadKey = ''
        for i in range(z, 0, -1):
            digit = 0
            mask = 1 << (i - 1)
            if(xi & mask) != 0:
                digit += 1
            if(yi & mask) != 0:
                digit += 2
            quadKey += str(digit)
        return quadKey

    def loadimage(self, fullname, tilekey):
        im = Image.open(fullname)
        self.imdict[tilekey] = im
        return self.imdict[tilekey]

    def tile_as_image(self, xi, yi, zoom):
        tilekey = (xi, yi, zoom)
        result = None
        try:
            result = self.imdict[tilekey]
        except:
            filename = '{}_{}_{}_{}.jpg'.format(zoom, xi, yi, self.layerdict[self.layers])
            fullname = self.path + filename
            try:
                result = self.loadimage(fullname, tilekey)
            except:
                server = random.choice(range(1,4))
                quadkey = self.tiletoquadkey(*tilekey)
                print quadkey
                url = self.urltemplate.format(xi, yi, zoom, self.layerdict[self.layers], server, quadkey)
                print "Downloading tile %s to local cache." % filename
                urllib.urlretrieve(url, fullname)
                result = self.loadimage(fullname, tilekey)
        return result

if __name__ == "__main__":
    ts = TileServer()
    im = ts.tile_as_image(5, 9, 4)
    im.show()
heltonbiker
  • 26,657
  • 28
  • 137
  • 252
  • 1
    Can't thank you enough for providing with this answer. This really really helped. This answer deserves some more upvotes. Thanks again : ) – Tanishq Vyas Apr 21 '20 at 04:34
3

So you want to do something almost exactly like this:

http://www.jjguy.com/heatmap/

which I found by googling for "python heatmap".

Now you are a bit unclear about what you want to do with these images, so remember that Google Earth imagery is copyrighted and there's a set of restrictions on what you can do with them.

Spacedman
  • 92,590
  • 12
  • 140
  • 224
1

One possible source is the images from NASA World Wind. You can look at the their source to find out how they access their data sources, and do the same in your application.

Paul Fisher
  • 9,618
  • 5
  • 37
  • 53
0

I have made use of Bing Maps API coupled with the knowledge of Map Tiling. Please find the code for the same in my Github Repository.

You may find this helpful too.

Tanishq Vyas
  • 1,422
  • 1
  • 12
  • 25