Skip to content

Installing Open Source Geo Software: Mac Edition

mojodna edited this page Mar 31, 2013 · 38 revisions

(back to general Software section). Switch to the Ubuntu version »

Really this is a revised copy of the general software page stubbed out for Seth to finish! Assumes Mac OS X.

Reference more from here: http://www.axismaps.com/blog/2012/01/dont-panic-an-absolute-beginners-guide-to-building-a-map-server/ and http://mojodna.net/2009/12/05/the-os-x-spatial-stack.html

General

  • XCode: Compiling source code into binary applications. Once XCode is installed, make sure to also install the command line tools.
  • Homebrew: installing general Unix software on the Mac.
  • PIP: installing Python tools.

Specific packages

Python 2.7

Your machine might come with an older version, upgrade fist. Not everything is Python 3.x compatible yet so we're sticking with 2.7 for the time being.

After Python is updated, let's install developer tools:

sudo easy_install python-dev

GDAL/OGR/GEOS

This and it's dependencies, which are installed automatically, is the general workhorse for open source geo.

Basic GDAL/OGR install:

brew install gdal

Advanced GDAL/OGR install:

If you want full awesomeness with FileGeoDB support and new cutting edge features:

  1. Download and install the Esri FileGDB API as described by Ragi. Don't worry about the aliasing (soft links) bits.

  2. brew install gdal --enable-unsupported -complete --with-postgres --HEAD

HEAD gets you the development version which is pretty stable and has all the latest goodies. Postgres because it's for big geo data, enable unsupported for FileGDB, complete for more file formats.

QGIS

tk tk tk. Right now brew is fucked, so KyngChaos for a while yet.

Most basic operations (and a some super complex!) can be undertaken in Python using Shapely.

pip install Shapely

When OGR is better, but is ugly. A better python interface for OGR (see above).

pip install Fiona

Mapnik (version 2)

Download and run the Mac installer »

TopoJSON

Requires Node, too.

tk tk tk

TileStache

First some dependencies:

sudo pip install -U werkzeug
sudo pip install -U simplejson
sudo pip install -U modestmaps

Optional dependencies:

sudo pip install -U pil

Now the main application:

sudo easy_install tilestache

Postgres & PostGIS & PGAdmin3

tk tk tk

Make sure your to add these locations to your home directory's bash profile path

cd ~

#Add postgres binary path to your bash profile
echo "export PATH=$PATH:/usr/local/pgsql/bin" >> .bash_profile

#Add a postgres data directory variable to your environment
echo "export PGDATA=/usr/local/pgsql/data" >> .bash_profile

psycopg2

For accessing Postgres from Python:

sudo easy_install psycopg2

Misc

  • avce00
  • pgdbf

CREATE SCRIPTS TO START AND STOP POSTGRES

For some reason, it’s not clear how to stop and start postgres from OSX, and using the kyngchaos binaries doesn’t seem to properly start them (or at least it didn’t on my machine). I think this was due to the permissions not being set properly on the data directory.

Go to your home directory

cd ~

#create scripts to start/stop postgres && set permissions on them
echo "sudo launchctl load /Library/LaunchDaemons/org.postgresql.postgres.plist" >> start_pg.sh

echo "sudo launchctl unload /Library/LaunchDaemons/org.postgresql.postgres.plist" >> stop_pg.sh
chmod 755 start_pg.sh
chmod 755 stop_pg.sh

Finally, you should be able to start and stop postgres (check the activity monitor for postgres processes, making sure to view “all processes”) by running:

./start_pg.sh

#and to stop:
./stop_pg.sh</code

from your home directory. If you can't see the postgres process in your activity monitor, let me know!)

INITIALISE DATABASE

Ok, assuming we have postgres up and running and all the bindings sorted, we are ready to initialise our DB for our first project. At this point, I recommend following along from step 2 of the official geoDjango guide.

#Setting up your shell environment (bash assumed here):

This file sets up your Terminal session settings:

/Users/your_username/.bash_profile

Note: This file is invidible, so you'll need to find it or type nano ~/.bash_profile on the command line.

Let's edit it!

#Only this one should be postfixed with :$PATH
export PATH=/usr/local/bin:/usr/local/sbin:$PATH

Subsequent path exports should have the reverse structure, like:

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

If you installed Postgres above:

export PATH=$PATH:/usr/local/pgsql/bin
export PGDATA=/usr/local/pgsql/data

If you get lost in VIM, try Nano for your default text editor:

export EDITOR=nano
export VISUAL=nano

If you GIT on the command line, let's use pretty colors to improve legibility.

First in the bash profile:

source /usr/local/etc/bash_completion

function __git_status_flag {
  git_status="$(git status 2> /dev/null)"
  remote_pattern="^# Your branch is (.*) of"
  diverge_pattern="# Your branch and (.*) have diverged"
  if [[ ! ${git_status} =~ "nothing to commit" ]]; then
    state="⚡"
    spacer=" "
  fi
 
  if [[ ${git_status} =~ ${remote_pattern} ]]; then
    spacer=" "
    if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
      remote="↑"
    else
      remote="↓"
    fi
  fi
 
  if [[ ${git_status} =~ ${diverge_pattern} ]]; then
    remote="↕"
    spacer=" "
  fi
 
  echo "${state}${remote}${spacer}"
}
 
PS1='\[\e[32m\]\u@\[\e[1m\]\h\[\e[22m\]:\[\e[1;34m\]\w\[\e[22;35m\]$(__git_ps1 " [\[\e[33m\]$(__git_status_flag)\[\e[35m\]%s]")\[\e[33m\] \$ \[\e[0m\]'

Second, we need to install bash_completion:

brew install bash-completion

#Troubleshooting

  1. Bad / partial / aborted brew install * leaves won't let you finish install:

    rm $(brew --cache)/Formula/software_name_like_gdal.brewing

    Note: Where software_name_like_gdal is filled in by you, or use * to remove all partially brewed recipes.

(WIP) Installation Steps

These steps are known to work on 10.8 (Mountain Lion) and presumed to work on 10.7.

Prerequisites

  • Install Xcode from the Mac App Store.
  • Install the Xcode Command Line Tools by opening Xcode, Xcode → Preferences → Downloads → Components → "Install" button to the right of "Command Line Tools".
  • Install Homebrew by following the directions at that link.
  • Install pip:
sudo easy_install pip
  • (optional) Install the esri File Geodatabase API to enable GDAL support for FileGDBs (created with ArcGIS >= 10.x). h/t Ragi
cd /tmp
unzip ~/Downloads/FileGDB_API_1_2-64.zip
cp -R /tmp/FileGDB_API/include/* /usr/local/include/
cp -R /tmp/FileGDB_API/lib/* /usr/local/lib/
  • Install GDAL/OGR. --complete may be omitted if you have simple needs (it installs the kitchen sink to work with a wide variety of formats). --enable-unsupported may be omitted if you did not install the FileGDB API (and do not have other proprietary libraries for gdal to try linking to). If you'd like the current development version, add --HEAD. --with-postgres will install PostgreSQL. This will take a while, especially if --complete was included.
brew install gdal --complete --enable-unsupported --with-postgres
  • Add /usr/local/lib/python2.7/site-packages to your PYTHONPATH. This is but one way to achieve this:
echo 'export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages' >> ~/.bash_profile

Most basic operations (and a some super complex!) can be undertaken in Python using Shapely.

sudo ARCHFLAGS='-arch x86_64' pip install Shapely
``

## [Fiona](https://github.com/sgillies/Fiona)

Fiona is a better python interface for OGR (see above).

```bash
sudo ARCHFLAGS='-arch x86_64' pip install Fiona

This will install TileStache and its dependencies (not including werkzeug?)

sudo pip install tilestache

First, install XQuartz. You can log out later.

Next, install Mapnik. If you need bleeding edge features, include --HEAD.

brew install mapnik --with-cairo --with-gdal --with-geos

Miscellany

avce00 will convert E00s to binary coverages, which OGR is happier dealing with. pgdbf will load DBFs into Postgres.

brew install avce00 pgdbf

QGIS

Clone this wiki locally