我想实现一些位置感知/空间查找功能,以我的Django项目。我意识到我需要切换到PostGIS启用的数据库,而不仅仅是一个普通的Postgres数据库,我希望这是正确的? 我一直在阅读无数的教程,例如这一个https://www.chicagodjango.com/blog/geo-django-quickstart/ 这表明我需要创建一个地理空间模板,然后才能实际创建或启用PostGIS数据库。请参见下面的代码:首次使用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的东西听起来令人难以置信的混乱。
我会建议以下[this](https://docs.djangoproject.com/en/1.7/ref/contrib/gis/tutorial/)指南。创建扩展是你在Postgres中注册额外的包。所以,创建扩展Postgis基本上加载了一堆函数和类型,这将允许你做空间。如果你先做这一步,针对你想使用的db,然后做geodjango设置,你应该没问题。几周前我自己做了这件事,尽管我是一位非常有经验的Postgres/Postgis用户,但我从未使用过Django,并且它第一次工作。祝你好运。 – 2015-02-09 09:49:49
你的链接是1.5,目前有一个2.x版本有一些重大变化。 – 2015-02-09 11:57:39
@JakubKania,我只能找到1.8和dev。也许你可以建立一个链接,回答这个问题?关于创建扩展postgis的问题仍然存在,不是吗? – 2015-02-09 14:26:03