GDAL – What Are GDAL Utilities?

command linegdal

I often come across code examples when searching for something like
GeoTiff size – what to do?.

Sometimes, the presented code examples seem to do exactly what I was searching for. There is just one big drawback which is that I just don't know which type of console is to be used.

In the example, it says:

You may try out something like the following, using the GDAL
utilities:

gdal_translate -co "TILED=YES" -co "COMPRESS=JPEG" -co "PHOTOMETRIC=YCBCR" input.tiff output.tiff

gdaladdo -r average --config COMPRESS_OVERVIEW JPEG --config PHOTOMETRIC_OVERVIEW YCBCR output

So I googled GDAL utilities, but that didn't help. I am used to R, but apart from that, I am quite unfamiliar with coding.

Which program do I use with such code examples?

Best Answer

What is GDAL?

GDAL (Geospatial Data Abstraction Library) is a library for reading and processing raster and vector geographical data. It's the backbone of many GIS software, including ArcGIS and QGIS. In fact, there is a GDAL Package for R, in which you have access to many of the GDAL functionalities.

GDAL is written in a programming language called C++, which is great for building systems and big software, but not so practical when dealing with day-to-day analysis. Hence, to facilitate usage of the GDAL tools, there are bindings to other platforms which are better suited to simpler tasks. The aforementioned R-GDAL package is one such binding.

To further facilitate usage, there are also special programs called GDAL Utilities, which are basically specific tools built with GDAL for doing specific tasks. Many GDAL installations (such as Tamas Szekeres's binaries) already come with these, so you don't really have to do anything else.

How to use the GDAL Utilities?

You can call them directly from a command-line console, such as CMD in Windows or Terminal in Linux/Mac. Just pop the console open, type the name of the utility, and you'll be using it. As an example, try using the simplest of utilities, gdalinfo. Navigate to a folder you have a raster, say the raster is called "my_raster.tiff", then just type:

> gdalinfo my_raster.tiff

You'll see printed on the console all sorts of metadata on that raster, including Spatial Reference System, extension, statistics, etc. Different utilities may require different flags, which are those letters following a slash, such as -co, -r, or --config in your examples. These allow you to configure special behaviour to the utility. But they all work the same way, you call them directly from the command line.

Taking another example, from one you have posted: say you want to create a compressed and tiled version of a geotiff you have (let's say the same from above), and call it "my_compressed_raster.tiff". You'd use gdal_translate, which is the utility for converting raster into other types of raster. Then you'd go:

> gdal_translate -co "TILED=YES" -co "COMPRESS=JPEG" -co "PHOTOMETRIC=YCBCR" my_raster.tiff my_compressed_raster.tiff

It'd go beyond the scope of this answer to specify the behaviour of each utility, as well as its many options, but hopefully this give you an idea of what's going on. You can always research it more in the GDAL main website.

UPDATE

To use the utilities from anywhere, you need first set a few system variables. In Windows, you go to Control Panel -> System -> Advanced System Settings -> Environment Variables (shortcut: Windows key + Break).

Then, in the System Variables frame, you should see a variable called Path. Click on it and edit it, adding a new path:

C:\Program Files\QGIS 2.18\bin

Or wherever else your gdal install would be. Then you'll be able to call GDAL utilities from any folder in the cmd.

Related Question