ActiveState Code

Recipe 496966: Download satellite images from NASA's site


This script downloads satellite image of desired position (in degrees) from the NASA's OnEarth site (http://onearth.jpl.nasa.gov/).

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /usr/bin/env python

import urllib

SAT_ZOOM_LEVEL = 0.0001389 #Like in request form

def retrieveImage(coordinates, image_size, name):
	"""Retrieve satellite images from the Nasa's site
	
	coordinates: tuple (longitude, latitude) in decimal degrees
	image_size: tuple (width, height)
	name: output filename
	"""

	request1 = "http://onearth.jpl.nasa.gov/landsat.cgi?" \
		"zoom=%f&x0=%f&y0=%f&x=%i&y=%i&action=pan&layer=modis%%252Cglobal_mosaic&pwidth=%i&pheight=%i" % \
		(SAT_ZOOM_LEVEL,
		coordinates[0],
		coordinates[1],
		image_size[0]/2,
		image_size[1]/2,
		image_size[0],
		image_size[1])
	for line in urllib.urlopen(request1):
		if line.startswith("<td align=left><input type=image src="):
			request2 = "http://onearth.jpl.nasa.gov/%s" % (line.split("\"")[1],)
			break
	urllib.urlretrieve(request2, name)

if __name__ == '__main__':
	retrieveImage((60.7376856, 56.5757572), (800,600), "test.jpg")
	# Specified coordinates is the point accurately at the image center

Discussion

Useful for visualization of GPS waypoints, etc.

Comments

  1. 1. At 12:08 p.m. on 21 aug 2006, Tim Shannon said:

    Blank inages. I changed the coordinates to my home, but I keep getting blank images. Can you supply a little bit of documentation regarding how to change the mosaic sourced, and other parameters from the NASA server.

  2. 2. At 11:58 p.m. on 23 aug 2006, Sergei Vavilov (the author) said:

    First value in first tuple passing to the function is longitude, second is latitude, in decimal degrees. If that's correct and you still getting blank images, you can play with their server's parameters (layers, for example) using the web interface at http://onearth.jpl.nasa.gov/landsat.cgi and then change the value of request1.

Sign in to comment