5

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?

2 Answers 2

12

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.

6
  • what do you mean "navegate to a folder you have a raster"? Just open the folder? > gdalinfodoesn't work, but when I type C:\Program Files\QGIS 2.18\bin\gdalinfo, it seems to be "working". However, it (naturally) yields an error: FAILURE: No datasource specified.. I seem not to be able to specifiy the data source. Further explication on this would be appreciated.
    – yenats
    Commented Feb 11, 2018 at 12:26
  • No. These are command-line utilities, meaning you have yo use them through CMD (Windows) or Terminal (Linux/Mac). When you open them, they'll be at your user home folder, but you need yo go to the folder in which your rasters are. You can just google "how to navigate through cmd" or "how to navigate through terminal" to see how to do it. Commented Feb 11, 2018 at 12:32
  • Ok, I understand. However, I can either navegate to the folder with the gdal - utilities or to the folder with the raster image. Seems to me like the gdal-commands are only usable when I navegate to the gdal-utilities-folder - but then, the image is not found I suppose. I am sorry for those noobish questions, it's just that all of this is so new and confusing.
    – yenats
    Commented Feb 11, 2018 at 15:00
  • @yenats Don't be sorry for asking questions, this is what this site is for. I updated my answer to address how to deal with this problem. Commented Feb 11, 2018 at 16:35
  • wow, it worked. thumbs up, @Roberto Ribeiro
    – yenats
    Commented Feb 12, 2018 at 14:55
2

It's not really a code example, but rather a command line. Under windows, open the command prompt (type cmd in start if you can't find it), and type the Gdal command you want to use. If it says the command is not recognized,

'gdalinfo' is not recognized as an internal or external command, operable program or batch file.

you would need to browse to the folder containing the commands, such as C:\Program Files\QGIS 2.18\bin\ (search in your computer for gdal*.exe). If you don't have any, you can download them here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.