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.
You’ll receive a personal API key, which you’ll use to authenticate your requests
# Load necessary librarieslibrary(readr)library(httr)library(jsonlite)library(dplyr)# Retrieve satellite imagery over Cincinnati, Ohio on July 1, 2020# Set parametersapi_key <-"zBc8QgFlGvhtRLowuliHMZ3tG56KX79PKVQ4RGtc"lon <--84.51# Longitude for Cincinnatilat <-39.103# Latitude for Cincinnatidate <-"2020-07-01"# The date for the retrieved imagedim <-0.1# Image size# Build the API URLurl <-paste0("https://api.nasa.gov/planetary/earth/assets?","lon=", lon, "&lat=", lat,"&date=", date, "&dim=", dim,"&api_key=", api_key)# Make the GET requestresponse <-GET(url)# Parse the JSON responsedata <-fromJSON(content(response, "text", encoding ="UTF-8"))print(data)
# Check if image is available and downloadif (!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.