Exploring NASA’s Earth Imagery API in R

Author

Mick Clines

Published

April 14, 2025

Introduction

The NASA Earth Imagery API provides access to satellite imagery from NASA’s Earth observing systems. With this API, users can retrieve satellite images for any given location on Earth by specifying coordinates and a date. This is useful for researchers, educators, or anyone interested in environmental monitoring, climate studies, or urban development.

In this tutorial, we’ll demonstrate how to interact with NASA’s Earth Imagery API using R. We’ll retrieve an image of Cincinnati, Ohio, for a specific date and download it.

Setting Up the NASA API

Get a Free NASA API Key

To use the NASA Earth API, you need an API key:

  • Visit https://api.nasa.gov
  • Fill out the form to get your own key
  • You’ll receive a personal API key, which you’ll use to authenticate your requests

# Load necessary libraries
library(readr)
library(httr)
library(jsonlite)
library(dplyr)

# Retrieve satellite imagery over Cincinnati, Ohio on July 1, 2020

# Set parameters
api_key <- "zBc8QgFlGvhtRLowuliHMZ3tG56KX79PKVQ4RGtc"
lon <- -84.51     # Longitude for Cincinnati
lat <- 39.103     # Latitude for Cincinnati
date <- "2020-07-01"  # The date for the retrieved image
dim <- 0.1        # Image size

# Build the API URL
url <- paste0("https://api.nasa.gov/planetary/earth/assets?",
              "lon=", lon, "&lat=", lat,
              "&date=", date, "&dim=", dim,
              "&api_key=", api_key)

# Make the GET request
response <- GET(url)

# Parse the JSON response
data <- fromJSON(content(response, "text", encoding = "UTF-8"))
print(data)
$date
[1] "2020-06-30T16:17:07.742000"

$id
[1] "LANDSAT/LC08/C02/T1_L2/LC08_020033_20200630"

$resource
$resource$dataset
[1] "LANDSAT/LC08/C02/T1_L2"

$resource$planet
[1] "earth"


$service_version
[1] "v5000"

$url
[1] "https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/21b220057dfaab657ad443bece22bd7a-afe935e8fec66a2191213b8ee2e82b25:getPixels"
# Check if image is available and download
if (!is.null(data$url)) {
  download.file(data$url, destfile = "cincinnati_satellite_image.png", mode = "wb")
  cat("Image downloaded successfully and saved as 'cincinnati_satellite_image.png'\n")
} else {
  cat("No imagery available for the specified date and location.\n")
}
Image downloaded successfully and saved as 'cincinnati_satellite_image.png'
getwd()
[1] "C:/Users/mclin/OneDrive - Xavier University/BAIS 462 Spring 2025"

Summary

  • The NASA Earth Imagery API provides free access to historical and current satellite imagery.

  • We walked through setting up the API in R and retrieving an image for Cincinnati.

  • This data is useful for geographic, environmental, and educational analysis.