我正在尝试在我的django项目中实现一些位置感知/空间查找功能。我已经意识到我需要切换到一个支持PostGIS的数据库,而不仅仅是一个普通的Postgres数据库,我希望这是正确的?我一直在阅读无数的教程,比如这个https://www.chicagodjango.com/blog/geo-django-quickstart/,它建议我在实际创建或启用PostGIS数据库之前,需要创建一个地理空间模板。请参见以下代码:
POSTGIS_SQL_PATH=`pg_config --sharedir`/contrib/postgis-1.5
# Creating the template spatial database.
sudo -u postgres createdb -E UTF8 template_postgis
sudo -u postgres createlang -d template_postgis plpgsql # Adding PLPGSQL language support.
# Allows non-superusers the ability to create from this template
sudo -u postgres psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';"
# Loading the PostGIS SQL routines
sudo -u postgres psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis.sql
sudo -u postgres psql -d template_postgis -f $POSTGIS_SQL_PATH/spatial_ref_sys.sql
# Enabling users to alter spatial tables.
sudo -u postgres psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;"
sudo -u postgres psql -d template_postgis -c "GRANT ALL ON geography_columns TO PUBLIC;"
sudo -u postgres psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"但我读过的其他教程说,我可以简单地创建一个新的Postgresql数据库,或者使用我现有的数据库并执行以下操作:
psql -d yourdatabase -c "CREATE EXTENSION postgis;"
psql -d yourdatabase -c "CREATE EXTENSION postgis_topology;"
psql -d yourdatabase -c "CREATE EXTENSION postgis_tiger_geocoder;"是哪一个?我这条路走对了吗?这个PostGIS的东西听起来令人难以置信的困惑。
发布于 2015-02-10 07:10:09
如果您使用的是PostgreSQL 9.1 (或更高版本)和PostGIS 2.x,那么一定要先尝试CREATE EXTENSION postgis;方法,因为它要简单得多。只有在需要拓扑和/或TIGER地理编码支持时才添加其他扩展(大多数人不需要)。
模板有点过时了,这些指令可以忽略。在2011年引入扩展之前,模板很有用。(你发布的博客是在支持扩展的PostgreSQL 9.1发布的那个月发布的)。您可能看到的用于启用PostGIS数据库的其他技术是运行启用程序脚本,但如果可以,请再次忽略这些脚本。
https://stackoverflow.com/questions/28402872
复制相似问题