Skip to content

Instantly share code, notes, and snippets.

@loganwilliams
Last active May 23, 2016 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loganwilliams/3ddda4bdbd507fc06037931424b8010e to your computer and use it in GitHub Desktop.
Save loganwilliams/3ddda4bdbd507fc06037931424b8010e to your computer and use it in GitHub Desktop.
import urllib
from PIL import Image
import cStringIO as StringIO
import numpy as np
import time
# index for naming images
n = 0
# iterate over the x/y locations of the map tiles
for x in range(2585, 2685, 2):
print("Starting row: " + str(x))
for y in range(6136, 6236, 2):
try:
# accumulator array for 2x2 tiles
bigimg = np.zeros((512, 512, 3), np.uint8)
for dx in range(2):
for dy in range(2):
# url format for scraping planet labs images
url = "http://pm4.planet-labs.com/open_california_re_20130901_20131130/gmap/14/" + str(x + dx) + "/" + str(y + dy) + ".png"
data = urllib.urlopen(url).read()
stream = StringIO.StringIO(data)
img = np.asarray(Image.open(stream))
# place in 2x2 tile array
bigimg[dy*256:(dy+1)*256, dx*256:(dx+1)*256] = img
# save 2x2 tile image
img = Image.fromarray(bigimg)
img.save(str(n) + ".png", "PNG")
# increment label iterator
n = n + 1
# let the server have a tiny little break
time.sleep(0.01)
except ValueError:
print "ValueError, map tile unexpected size."
except IOError:
print "IOError, map tile missing."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment