Skip to content

Installing Open Source Geo Software: Mac Edition

Seth Fitzsimmons edited this page May 11, 2013 · 38 revisions

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

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

Making Postgres fast

The defaults live in 1990s land. Upgrade your computer's gray matter!

  • Give Postgres more system memory, lots! - More is better here, set to the total RAM on your machine.
  • PGTune: Postgres config file: set the shared ram for each worker to ~2 to 4 gigs, depending on your setup. More (4 gb) is better unless you're running multiple concurrent sessions and need to play nice (2 gb).

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:

# extracted from @mojodna's .bashrc, learned from the internet
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

(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 is a better python interface for OGR (see above).

sudo ARCHFLAGS='-arch x86_64' pip install Fiona

This will install TileStache and its core dependencies:

sudo pip install tilestache

To install additional dependencies (for compositing and testing):

sudo pip install PIL werkzeug

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

Quantum GIS

If you don't mind running QGIS from the command link (qgis), install it with Homebrew. Otherwise, install the KyngChaos build.

brew tap homebrew/science
brew install pyqt
brew install qgis --with-grass --with-postgis
brew linkapps
mkdir -p ~/.MacOSX
defaults write ~/.MacOSX/environment.plist PYTHONPATH -string "/usr/local/lib/python2.7/site-packages"

brew linkapps and setting PYTHONPATH in your global environment should allow you to run QGIS from ~/Applications, but something is currently preventing QGIS from seeing the correct PYTHONPATH, so you'll need to run it from the command line in the meantime.

TopoJSON requires Node.js, so you'll need that first. Installing from Homebrew is the easiest way to stay up-to-date (although you'll want /usr/local/share/npm/bin in your PATH):

brew install node

The official installer / binaries are another option, as is nvm, which is most appropriate if you're developing apps using Node and want/need to use multiple versions simultaneously.

Once Node is installed, TopoJSON can be installed globally using NPM (the Node Package Manager):

npm install -g topojson

PostgreSQL

PostGIS

Accessing PostgreSQL from Python

psycopg2 is one option:

sudo pip install psycopg2

Miscellany

avce00 will convert E00s to binary coverages, which OGR is happier dealing with. pgdbf will load DBFs into Postgres. shapelib includes some DBF and Shapefile utilities.

brew install avce00 pgdbf shapelib

Troubleshooting

  1. Bad / partial / aborted brew install <whatever> won't let you finish installing:
rm $(brew --cache)/Formula/<software_name_like_gdal>.brewing

Note: use * to remove all partially brewed recipes.

Additional References

Clone this wiki locally