Created
November 10, 2021 23:29
-
-
Save sfate/0c5a3903a3c225ef527afffbcf334322 to your computer and use it in GitHub Desktop.
Install postgis with postgresql@12 for macOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TMP_DIR="./tmp" | |
mkdir -p $TMP_DIR | |
function install_sfcgal() { | |
SFCGAL_FORMULAE_PATH="$TMP_DIR/sfcgal.rb" | |
DOWNLOAD_URL="https://gist.githubusercontent.com/sfate/cc92b94657ed4fcf3b35b17849e4d65a/raw/69db8b4c9401c8914babf854af5512ab4f897e19/sfcgal.rb" | |
curl -s $DOWNLOAD_URL -o "$SFCGAL_FORMULAE_PATH" | |
# installed patched formulae for apple silicon chip (M1) | |
brew install --formula $SFCGAL_FORMULAE_PATH | |
} | |
function install_postgis() { | |
POSTGIS_VERSION='postgis-3.0.3' | |
POSTGIS_ARCHIVE="$POSTGIS_VERSION.tar.gz" | |
POSTGIS_ARCHIVE_PATH="$TMP_DIR/$POSTGIS_ARCHIVE" | |
DOWNLOAD_URL="https://download.osgeo.org/postgis/source/$POSTGIS_ARCHIVE" | |
# download suitable archive (v3.0.3) for postgres@12 | |
curl -s $DOWNLOAD_URL -o $POSTGIS_ARCHIVE_PATH | |
# unpack archive | |
cd $TMP_DIR | |
tar xzf $POSTGIS_ARCHIVE | |
cd "$TMP_DIR/$POSTGIS_VERSION" | |
# install dependencies | |
install_sfcgal | |
brew install 'gdal' | |
brew install 'geos' | |
brew install 'json-c' | |
brew install 'pcre' | |
brew install 'proj@7' | |
brew install 'protobuf-c' | |
# generate Makefile | |
# --prefix parameter is currently broken, as the package will only install into the PostgreSQL installation directory. | |
# Visit http://trac.osgeo.org/postgis/ticket/635 to track this bug. | |
./configure \ | |
--disable-nls \ | |
--with-pgconfig=$(brew --prefix postgresql@12)/bin/pg_config \ | |
--with-sfcgal=$(brew --prefix sfcgal)/bin/sfcgal-config \ | |
--with-gdalconfig=$(brew --prefix gdal)/bin/gdal-config \ | |
--with-geosconfig=$(brew --prefix geos)/bin/geos-config \ | |
--with-jsondir=$(brew --prefix json-c) \ | |
--with-pcredir=$(brew --prefix pcre) \ | |
--with-projdir=$(brew --prefix proj@7) \ | |
--with-protobufdir=$(brew --prefix protobuf-c) | |
# link header files for build | |
ln -s "$(brew --prefix postgresql@12)/include/postgresql/server" "$(brew --prefix postgresql@12)/include/server" | |
# build source code from Makefile | |
make | |
# copy installation files into appropriate subdirectory | |
make install | |
} | |
brew install postgresql@12 | |
# load posgresql@12 cli functions into environment | |
echo 'PATH="$(brew --prefix postgresql@12)/bin:$PATH"' >> ~/.bashrc | |
brew services start postgresql@12 | |
install_postgis |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment