Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

GDAL

The Geospatial Data Abstraction Library (GDAL) is an open-source software library used to work with raster and vector geospatial data. There are a number of GDAL command line utilities that we can leverage to transform NISAR data.

Using GDAL to Transform NISAR Data

NISAR products are distributed in HDF5 format, and the files can be very large. Many users may want to transform the data by extracting just the datasets of interest from the HDF5 files and/or subsetting the data to a defined spatial extent.

We can use command line utilities from the GDAL software library to transform these files. Leveraging GDAL’s ability to stream data from Earthdata Cloud directly allows us to download only the data we need in the desired format.

Preparing GDAL to Access EDC

If you do not already have GDAL installed you can follow GDAL’s official guide.

In this guide we will be streaming products directly from NASA’s Earthdata Cloud (EDC) without downloading them first. To do so, we must allow GDAL to authenticate to EDC by placing a .netrc file in the home directory of our compute environment containing our Earthdata Login credentials.

~/.netrc
machine urs.earthdata.nasa.gov
    login <username>
    password <password>

Using a gdalrc File

Users can choose to generate a gdalrc file to simplify GDAL commands. This replaces the need to include --config flags for each command.

Create a file in ~/.gdal/gdalrc with the following content:

~/.gdal/gdalrc
[configoptions]
CPL_VSIL_CURL_CHUNK_SIZE=2097152
CPL_VSIL_CURL_CACHE_SIZE=67108864
GDAL_CACHEMAX=64000000
GDAL_DISABLE_READDIR_ON_OPEN=TRUE
GDAL_HTTP_MERGE_CONSECUTIVE_RANGES=YES
GDAL_HTTP_MULTIPLEX=YES
GDAL_NUM_THREADS=ALL_CPUS
CPL_VSIL_CURL_CACHE_SIZE=1GB
GDAL_HTTP_NETRC=YES
GDAL_HTTP_COOKIEFILE=/tmp/gdal_cookies.txt
GDAL_HTTP_COOKIEJAR=/tmp/gdal_cookies.txt

If you have a gdalrc file staged, you can skip all the --config flags included in the sample commands on this page.

Transform NISAR HDF5 Products

Users can transform NISAR data by using the gdal_translate or gdalwarp utility to extract and/or spatially subset data, reproject the data, and change the file format. For the examples provided here, we will output the data as a GeoTIFF.

You will need the download link for a NISAR product to run these commands. Use the Copy URL links available in the search results for Vertex, or use one of the other available search methods to find a NISAR product URL.

Screenshot of the Copy URL link for a NISAR product in Vertex.

Figure 1:Click the Copy URL link to get the download URL for a NISAR product in Vertex.

Extract Datasets

Run the following gdalinfo command, using the download URL for a NISAR product, to view information about the product, including the datasets it contains:

gdalinfo "/vsicurl/https://<DOWNLOAD URL>" \
         --config GDAL_HTTP_NETRC=YES \
         --config GDAL_HTTP_COOKIEFILE=/tmp/gdal_cookies.txt \
         --config GDAL_HTTP_COOKIEJAR=/tmp/gdal_cookies.txt

Refer to the Data Products section for more information about the datasets included in NISAR products.

Utilize the following gdal_translate command to extract a specific dataset from an HDF5 product as a GeoTIFF:

gdal_translate -of GTiff \
                "/vsicurl/https://<DOWNLOAD URL>":<VARIABLE PATH> <OUTPUT FILE>.tif \
                --config CPL_VSIL_CURL_CHUNK_SIZE 2097152 \
                --config CPL_VSIL_CURL_CACHE_SIZE 67108864 \
                --config GDAL_CACHEMAX 64000000 \
                --config GDAL_DISABLE_READDIR_ON_OPEN=TRUE \
                --config GDAL_HTTP_MERGE_CONSECUTIVE_RANGES=YES \
                --config GDAL_HTTP_MULTIPLEX=YES \
                --config GDAL_NUM_THREADS=ALL_CPUS \
                --config CPL_VSIL_CURL_CACHE_SIZE=1GB \
                --config GDAL_HTTP_NETRC=YES \
                --config GDAL_HTTP_COOKIEFILE=/tmp/gdal_cookies.txt \
                --config GDAL_HTTP_COOKIEJAR=/tmp/gdal_cookies.txt

The gdalwarp command is also suitable for this, and can be used as a drop-in replacement. However, using gdal_translate for simple dataset extraction operations may provide up to a 30% improvement in performance.

Spatial Subsetting

GDAL has many utilities which allow for spatial subsetting. In this section we will demonstrate spatial subsetting through the use of the gdalwarp utility with WKT spatial extent strings.

The gdalwarp utility allows describing spatial extents using a type of string known as a Well Known Text (WKT) Polygon or MultiPolygon string (we will refer to them as WKT spatial extent strings), which are utilized widely across geospatial applications (see examples of WKT formulation).

An easy method for defining a WKT spatial extent string is to set an Area of Interest (AOI) in Vertex. Once you’ve drawn an AOI in Vertex, the Area of Interest WKT field displays the WKT spatial extent string, and hovering over the field exposes a copy icon that you can use to capture the WKT.

A screenshot describing the location of the copy AOI string button in Vertex.

Figure 2:Click the Copy to clipboard icon in the Area of Interest WKT field in Vertex to copy the WKT spatial extent string to your system’s clipboard.

To perform spatial subsetting with gdalwarp, utilize the -cutline <WKT> flag alongside the -cutline_srs WGS84, -crop_to_cutline, and -dstalpha flags.

The command below demonstrates the use of these flags:

gdalwarp -of GTiff \
         "/vsicurl/https://<DOWNLOAD URL>":<VARIABLE PATH> <OUTPUT FILE>.tif \
         -cutline <WKT> \
         -cutline_srs WGS84 \
         -crop_to_cutline \
         -dstalpha \
         --config CPL_VSIL_CURL_CHUNK_SIZE 2097152 \
         --config CPL_VSIL_CURL_CACHE_SIZE 67108864 \
         --config GDAL_CACHEMAX 64000000 \
         --config GDAL_DISABLE_READDIR_ON_OPEN=TRUE \
         --config GDAL_HTTP_MERGE_CONSECUTIVE_RANGES=YES \
         --config GDAL_HTTP_MULTIPLEX=YES \
         --config GDAL_NUM_THREADS=ALL_CPUS \
         --config CPL_VSIL_CURL_CACHE_SIZE=1GB \
         --config GDAL_HTTP_NETRC=YES \
         --config GDAL_HTTP_COOKIEFILE=/tmp/gdal_cookies.txt \
         --config GDAL_HTTP_COOKIEJAR=/tmp/gdal_cookies.txt

Reprojection

The gdalwarp utility can also be used to reproject datasets from the projection used for the source NISAR HDF5 product to a different spatial reference system.

In your gdalwarp command, set the -t_srs <SRS> flag, where <SRS> is the EPSG code for the desired output spatial reference system (such as EPSG:3857 for Web Mercator):

gdalwarp -of GTiff \
         "/vsicurl/https://<DOWNLOAD URL>":<VARIABLE PATH> <OUTPUT FILE>.tif \
         -t_srs <SRS> \
         -dstalpha \
         --config CPL_VSIL_CURL_CHUNK_SIZE 2097152 \
         --config CPL_VSIL_CURL_CACHE_SIZE 67108864 \
         --config GDAL_CACHEMAX 64000000 \
         --config GDAL_DISABLE_READDIR_ON_OPEN=TRUE \
         --config GDAL_HTTP_MERGE_CONSECUTIVE_RANGES=YES \
         --config GDAL_HTTP_MULTIPLEX=YES \
         --config GDAL_NUM_THREADS=ALL_CPUS \
         --config CPL_VSIL_CURL_CACHE_SIZE=1GB \
         --config GDAL_HTTP_NETRC=YES \
         --config GDAL_HTTP_COOKIEFILE=/tmp/gdal_cookies.txt \
         --config GDAL_HTTP_COOKIEJAR=/tmp/gdal_cookies.txt