Change in rainfall 2001-2016, global tropics

Map: Change in rainfall 2001-2016, global tropics

Install GDAL, QGIS and GRASS

Thomas Gumbricht bio photo By Thomas Gumbricht

Contents - Geospatial data processing engines - Installations - GDAL - QGIS - GRASS - Resources

Geospatial data processing engines

Working with geospatial data requires a Geographic Information System (GIS). There are several commercial packages available, but I only use Open Source (OS) GIS. The Open Source Geospatial Foundation OSGeo site contains a lot of OS alternatives.

Most of my GeoImagine processing I do using Python and the Geospatial Data Abstraction Library (GDAL). For specific tasks I use Geographic Resources Analysis Support System (GRASS) and for viewing maps, setting colors and creating map layouts I use Quantum GIS (QGIS). QGIS actually contains GRASS and SAGA GIS, and if you prefer a graphical user interface (GUI) you can use GRASS under QGIS. That is, however, not covered in this blog; it is covered in the QGIS manual Module: GRASS.

Installations

Working with GDAL, QGIS and GRASS on MacOS is not more complex compared to other operating systems. To get the components setup and working together, might, however, be a bit more complex. Historically, William Kyngesburye (KyngChaos page) has maintained installers and instructions. But then QGIS set up their own installer for some versions, and then returned to letting William Kyngesburye do it. You just have to check out and read the instructions both on the official QGIS site and at KyngChaos to make sure how to do at this point in time (when you read this).

GDAL

If you intend to install both GDAL and QGIS on a mac, first check out if the QGIS installer maintained by William Kyngesburye (KyngChaos page) also contains the complete GDAL package. If so, you can skip installing GDAL separately and jump directly to the QGIS installation. Otherwise install GDAL from (KyngChaos). If you are installing a stand alone binary version of GRASS below, you might need several versions of GDAL. There is no problem installing parallel versions of GDAL.

GDAL is a powerful translator library for creating, modifying and managing geospatial data, and is also at the core of many commercial GIS software packages. GDAL can be downloaded via links on the GDAL official homepage. Here I will only cover how to install GDAL on macOS.

GDAL is dependent on several frameworks, including:

  • PROJ
  • UnixImageIO
  • GEOS
  • SQLite3

The GDAL convenience installer offered on the KyngChaos page includes all the necessary frameworks (and is, or was, also the official installation site for GDAL on macOS). Go ahead and download the convenience installer for the latest version of GDAL (3.2 when updating in October 2021). The installer comes as a diskimage (.dmg). Open it by double clicking. The diskimage contains two package installer (.pkg) and several ReadMe files in Rich Textformat (.rtf).

For version 3.2 you first have to install a predefined version of Python - that will be installed as an Application (under the application fodler).

The installer GDAL Complete.pkg, installs both GDAL and the necessary dependencies.

Go ahead and install the complete GDAL package by double clicking GDAL Complete.pkg. You will most likely be denied installing GDAL due to the macOS security settings. To allow installation, go via the mac main menu, click the apple (absolute top left of the computer screen), select System Preferences….

Mac OSX System Preferences window, Security and Privacy is in the top row.

In the top row of the System Preferences window (see figure above), click the Security & Privacy icon. In the window that open, under the General tab (usually in front by default), you should see a paragraph towards the bottom:

Mac OSX Security & Privacy window, requiring that you allow installing download from unidentified developer.
"GDAL Complete.pkg" was blocked from opening...

Click the button Open Anyway, and try to install again. The installation should come one step further, but you still have to confirm that you want to to go ahead with the installation in a pop-up window. The .pkg installer will guide you through the installation. Finally you have to give your user password, and the package will install.

You should also install the NumPy.pkg available on the GDAl Complete diskimage. You have to follow the same procedure with bypassing the macOS security settings.

If you intend to install GRASS as a stand alone package (GRASS is otherwise included in QGIS), also download and install GDAL 1.11. No need to re-install the NumPy.pkg if you did that while installing the later GDAL version.

On macOS, GDAL and its dependencies are installed in the Frameworks Library:

/Library/Frameworks

If you want to have access to GDAL without specifying the full path, add the path in the system file .bash_profile under your user. To do that, open a Terminal window and make sure you are in your home directory by printing pwd (print working directory) at the prompt:

$ pwd

You should then get a tilde(~) followed by your username in return.

Computername:~ youruser$

If you are not in your home directory, execute the following command at the Terminal prompt:

$ cd ~

You can add the path directly by writing at the command line, or by editing the file .bash_profile. I prefer editing the file, as I can then comment what I have done. As you are about the edit a system file, you have to use the command sudo (superuser do or substitute user do) together with a text editor. I use the very basic Terminal text editor pico, and the command for opening .bash_profile in edit mode thus becomes:

$ sudo pico .bash_profile

If you already installed Anaconda as described in this blog post you will see that the PATH to Anaconda is already given in .bash_profile. Now you need to add the path to GDAL, below any other PATHS already given.

PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH

The ‘:$PATH’ at the end adds existing PATHS, and if you do not add it the PATHS above will be lost to the system. I also comment (by starting the line with #) what I have done, and when I did it. Close and save the edits by holding down ctrl-X at the same time, and then click Y when asked to save changes.

Alternative you can write the PATH command directly at the prompt (as one single line):

$ echo ‘export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH’

GDAL is now ready for use, and if you gave the PATH, the GDAL commands are directly accessible from the command line.

QGIS

Quantum GIS is a popular, and powerful, Open Source GIS software. Download QGIS from the official download page. When updating this (December 2019), the official download page includes a official all-in-one installers for Mac OSX. If your Mac OSX version is not supported you can find alternative options with William Kyngesburye´s KyngChaos QGIS insallaers, as outlined in the sub-section below.

QGIS should now be available in your Applications folder:

/Applications/QGIS

I am not a fluent user in QGIS, I mostly use it to view maps, test different color ramps, and create map layouts.

KyngChaos

At time of writing this, the latest QGIS versions available from KyngChaos requires a sequence of instalaltions, including of a particular python version. Read the instructions carefully, and the installation will work fine.

Download the QGIS diskimage (.dmg) installation file. Open the QGIS-‘version’.dmg file. Apart from the package installer (.pkg) for QGIS it also contains .pkg’s for GDAL, NumPy and matplotlib. If you installed GDAL and NumPy above, no need to repeat that. But you need to install matplotlib before installing QGIS. If you are denied installing you have to bypass the macOS security settings as explained in the previous section on GDAL.

GRASS

As mentioned above, GRASS is included in QGIS. The path to the QGIS internal GRASS package is: /Applications/QGIS.app/Contents/MacOS/grass7 or /Applications/QGIS3.4.app/Contents/Resources/grass7 or similar.

Later versions of GRASS (7.2 and higher) can be downloaded via the offical homepage. Another page for accessing GRASS 7 binaries is Michael Barton’s GRASS page.. GRASS version 6 is the last version maintained by KyngChaos. Updating this page in January 2020, I also discovered that you can install GRASS using HomeBrew. How to install and use HomeBrew - the missing package manager for OS X is covered in this post in my repo on Setup Jekyll Theme Blog. But in the end I did not manage to get the Homebrew installation up and running, detailed at the very end of this post.

In January 2020 I did install the GRASS 7.2.2 binary package from the official download page. After some initial trouble with some dependencies - as detailed below. GRASS 7.2.2 worked fine with raster layers, but failed to processes vector data (missing link to sqlite lib).

In October 2020 I installed GRASS 7.8.3 (latest stable version in October 2020) from the official download page that is a completely stand alone package not having any dependencies. It worked beautifully. In October 2021 I upgraded to GRASS 7.8.5, which also worked flawless.

7.2.2 Binary installation (redundant)

With GRASS version 7.8.3 being the latest stable version as of September 2020, these instructions are redundant.

To install GRASS as a binary (not with HomeBrew) on Mac OS X you must first install GDAL and the dependencies listed above, plus some additional dependencies. In January 2020 I got GRASS 7.2 started after installing the following dependencies:

  • GDAL Complete 2.1
  • GDAL Complete 1.11
  • FreeType 2.4.12-1
  • Cairo 1.12.2-1 (Install AFTER GDAL and FreeType)
  • Numpy 1.8.0-1
  • MatPlotLib 1.3.0-3 (32bit)
  • pandoc 1.13.1
  • PIL 1.1.7-4

The frameworks are available via the KyngChaos site. And also listed on the GRASS GIS for Mac Framework page. As with the other installations from KyngChaos, they come as diskimages (.dmg) and include package installers (.pkg), and you must bypass the security settings as explained above.

The first four (non-python) frameworks will be installed under the path /Macintosh HD⁩/⁨Library⁩/Frameworks⁩⁩. There is no problem installing parallel versions of GDAL. The only thing to keep in mind is which version you want to access by default (if that is required), and state that in .bash_profile.

Install GRASS after all the required dependencies are installed. When starting grass you must have at least one Terminal window open. I anyway got an error starting GRASS 7.2.

raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

Searching the internet, this error can be solved by adding two lines to your .bash_profile:

$ sudo pico .bash_profile

and add the following two lines:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

Close Terminal and all its windows, restart Terminal and then start GRASS. Alternatively you can start GRASS from the Terminal

$ /Applications/GRASS-7.2.2.app/Contents/MacOS/Grass.sh

When you start GRASS for the first time you will only get to the start screen, but for now that is fine.

GRASS startup screen.

7.8.3 Binary installation

As of GRASS version 7.8, the binary application installation contains all required dependencies. The troubles of matching the suite of dependencies outlined above are thus removed. Details on these fully bundled versions and the installation are outlined on the GRASS GIS for Mac pages, where you can also download the binary files.

When I installed GRASS version 7.8.3 in October 2020 I just downloaded the binary file, opened the disk image (dmg file) and dragged the binary GRASS application file to my Applications directory. And magically it all worked.

STOP HERE

If your installation using the binary diskimage, and it all went through, you are fine. Skip the rest of this post. I only keep it as a backup if I ever need to revert to another kind of installation.

GRASS addons requirements

GRASS comes with an impressive amount of installed modules, but you can also install addons. To install and compile addons on a MacOS machine, you must have Xcode installed. Either the full version or the command line version. If you do not need the full version the command version works fine. If you encounter errors relating to Xcode and GRASS, please look at https://grasswiki.osgeo.org/wiki/MacOSX_GRASS_errors.

Check and manage your Xcode installation with xcode-select.

$ xcode-select –install

If that works out properly, you should be fine. But if you already had the command line tool installed, you get the response.

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

You probably do not need to floow that instruct. You only need to make sure that GRASS points towards your presently installed version of Xcode.

Check (print) the path of the active Xcode developer directory:

$ xcode-select -p

The typical response should be either

$ /Applications/Xcode.app/Contents/Developer

or

$ /Library/Developer/CommandLineTools.

To set the path to the path of the active Xcode developer directory:

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

or

sudo xcode-select -s /Library/Developer/CommandLineTools

Edit Platform.make

To compile some of the addons the GRASS compiler must point at the correct Xcode installation. GRASS 7.8.3 contains a default path that is fixed for a particular Software Development Kit (SDK) (MacOSX10.14.sdk) in the file /Applications/GRASS-7.6.app/Contents/Resources/include/Make/Platform.make. In that file, search for the following lines:

CFLAGS              = -g -O2   -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.14.sdk
CXXFLAGS            =   -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.14.sdk
INCLUDE_DIRS        =  -I/Applications/GRASS-7.8.app/Contents/Resources/include
LINK_FLAGS          =   -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.14.sdk   -L/Applications/GRASS-7.8.app/Contents/Resources/lib -Xlinker -rpath -Xlinker ${prefix}/lib -Xlinker -rpath -Xlinker ${RUN_GISBASE}/lib

...

MACOSX_SDK          = -isysroot /Developer/SDKs/MacOSX10.14.sdk

and replace them with:

CFLAGS              = -g -O2   -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS            =   -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
INCLUDE_DIRS        =  -I/Applications/GRASS-7.8.app/Contents/Resources/include
LINK_FLAGS          =   -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -L/Applications/GRASS-7.8.app/Contents/Resources/lib -Xlinker -rpath -Xlinker ${prefix}/lib -Xlinker -rpath -Xlinker ${RUN_GISBASE}/lib

...

MACOSX_SDK          = -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

This should be sufficient, but you might run into other errors relating to e.g. you c-language (clang) compiler etc.

Homebrew installation (redundant)

Trying the grasswiki instructions on Compiling on MacOSX using homebrew, the installation commands for the Long-Term Support (LTS) version (7.2) went through:

$ brew tap osgeo/osgeo4mac

$ brew install grass7-lts

But finished with an enormous list of warnings. Also related to a Postgres installation that went alongside. And I could not get the HomeBrew installed version of GRASS to run. The complete installation report from Homebrew is under the Hide/Show button below.

I thus opted for uninstalling the unsuccessful installation.

$ brew uninstall grass7-lts

But that only uninstallas grass-lts, not the dependencies:

Installing dependencies for osgeo/osgeo4mac/grass7-lts: flex, bison, lbzip2, libiconv, expat, qhull, brotli, c-ares, libidn, libmetalink, libssh2, jansson, jemalloc, libev, nghttp2, openldap, curl-openssl, freexl, python, geos, jpeg-turbo, json-c, libpq, jpeg, isl, mpfr, libmpc, gcc, openblas, numpy, eigen, hwloc, open-mpi, arpack, szip, hdf5, armadillo, boost, cgal, sfcgal, ant, swig, glib, mdbtools, libzip, cryptopp, osgeo-proj, osgeo-libgeotiff, libxml2, osgeo-libspatialite, osgeo-libkml, osgeo-netcdf, osgeo-hdf4, cfitsio, popt, epsilon, jasper, libdap, zstd, webp, unixodbc, xerces-c, tcl-tk, krb5, python2, perl, osgeo-postgresql, gdal2, fftw, python@2, wxpython and ghostscript

I will just have to see if I get into conflicts when installing further components. If there are conflicts I will have to solve that then. But will list them here as well. If this is the last text before the Resources heading there should be no conflicts.

Resources

OSGeo, the Open Source Geospatial Foundation

GDAL

QGIS

GRASS

KyngChaos packaged installers for macOS geospatial data processing engines by William Kyngesburye.

Install GRASS 7 on macOS by Martin Trauth.