Skip to content

Instantly share code, notes, and snippets.

@blorenz
Last active December 21, 2015 08:08
Show Gist options
  • Save blorenz/6275803 to your computer and use it in GitHub Desktop.
Save blorenz/6275803 to your computer and use it in GitHub Desktop.
Create a PostGIS database
brew install postgis20
#now link it properly by getting the information for it
brew info postgresql92
initdb /usr/local/var/postgres -E utf8
# YOU MADE NEED TO: rm -rf /usr/local/var/postgres
export POSTGIS_SQL_PATH='/usr/local/Cellar/postgis20/2.0.4/share/postgis/'
# Creating the template spatial database.
createdb -E UTF8 template_postgis
createlang -d template_postgis plpgsql # Adding PLPGSQL language support.
# Allows non-superusers the ability to create from this template
psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';"
# Loading the PostGIS SQL routines
psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis.sql
psql -d template_postgis -f $POSTGIS_SQL_PATH/spatial_ref_sys.sql
psql -d template_postgis -f $POSTGIS_SQL_PATH/rtpostgis.sql
psql -d template_postgis -f $POSTGIS_SQL_PATH/topology.sql
# Enabling users to alter spatial tables.
psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;"
psql -d template_postgis -c "GRANT ALL ON geography_columns TO PUBLIC;"
psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"
#
createdb db_name -T template_postgis
#brandon=# CREATE DATABASE db_name OWNER brandon TEMPLATE template_postgis ENCODING 'utf8';
#db_name=# SELECT PostGIS_full_version();
# settings.py
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'db_name',
'USER': 'brandon',
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment