Welcome, guest | Sign In | My Account | Store | Cart

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

Python, 32 lines
 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

Useful for visualization of GPS waypoints, etc.

2 comments

Tim Shannon 17 years, 7 months ago  # | flag

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.

Sergei Vavilov (author) 17 years, 7 months ago  # | flag

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.

Created by Sergei Vavilov on Tue, 15 Aug 2006 (PSF)
Python recipes (4591)
Sergei Vavilov's recipes (1)

Required Modules

Other Information and Tasks