5

我正在使用geoDjango. 我已经从源代码Gdalproj1.4和. 我是 ubuntu 用户。当我在那之后运行时,我收到以下错误。我错过了什么吗?谢谢geos3.3.5Postgis2.0.1syncdb

Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Failed to install index for cities.City model: operator class "gist_geometry_ops" does not exist for access method "gist"

Failed to install index for cities.District model: operator class "gist_geometry_ops" does not exist for access method "gist"

Failed to install index for cities.PostalCodeCA model: operator class "gist_geometry_ops" does not exist for access method "gist"

Installed 0 object(s) from 0 fixture(s)
4

3 回答 3

9

也许我来晚了,但我解决了这个问题(Django 1.4.x、Postgis 2.0.1 和 PostgreSQL 9.2),在 template_postgis 数据库中创建了一个操作符类,如下所示:

CREATE OPERATOR CLASS gist_geometry_ops
FOR TYPE geometry USING GIST AS
STORAGE box2df,
OPERATOR        1        <<  ,
OPERATOR        2        &<  ,
OPERATOR        3        &&  ,
OPERATOR        4        &>  ,
OPERATOR        5        >>  ,
OPERATOR        6        ~=  ,
OPERATOR        7        ~   ,
OPERATOR        8        @   ,
OPERATOR        9        &<| ,
OPERATOR        10       <<| ,
OPERATOR        11       |>> ,
OPERATOR        12       |&> ,

OPERATOR        13       <-> FOR ORDER BY pg_catalog.float_ops,
OPERATOR        14       <#> FOR ORDER BY pg_catalog.float_ops,
FUNCTION        8        geometry_gist_distance_2d (internal, geometry, int4),

FUNCTION        1        geometry_gist_consistent_2d (internal, geometry, int4),
FUNCTION        2        geometry_gist_union_2d (bytea, internal),
FUNCTION        3        geometry_gist_compress_2d (internal),
FUNCTION        4        geometry_gist_decompress_2d (internal),
FUNCTION        5        geometry_gist_penalty_2d (internal, internal, internal),
FUNCTION        6        geometry_gist_picksplit_2d (internal, internal),
FUNCTION        7        geometry_gist_same_2d (geom1 geometry, geom2 geometry, internal);

这是从这个链接中提取的http://trac.osgeo.org/postgis/ticket/1287#comment:8

于 2013-04-01T15:32:31.447 回答
2

您需要创建一个 postgis 模板并加载相关的 postgis.sql

说你的 postgis 路径是 /usr/share/postgresql/8.4/contrib 运行这个

POSTGIS_SQL_PATH=/usr/share/postgresql/8.4/contrib
sudo -u postgres createdb -E UTF8 template_postgis1 # 创建模板空间数据库。
sudo -u postgres createlang -d template_postgis1 plpgsql # 添加 PLPGSQL 语言支持。
sudo -u postgres psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis1';"
sudo -u postgres psql -d template_postgis1 -f $POSTGIS_SQL_PATH/postgis.sql # 加载 PostGIS SQL 例程
sudo -u postgres psql -d template_postgis1 -f $POSTGIS_SQL_PATH/spatial_ref_sys.sql
sudo -u postgres psql -d template_postgis1 -c "GRANT ALL ON geometry_columns TO PUBLIC;" # 使用户能够改变空间表。
sudo -u postgres psql -d template_postgis1 -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"



然后需要使用创建的模板模板创建您的数据库

sudo -u postgres createdb database_name -T template_postgis1
于 2012-10-29T10:24:25.897 回答
0

对于任何来这里的人,如果您将 Postgis 2.0 与 PostgreSQL 9.1+ 一起使用,则有一种更简单的方法:

#create your database if necessary and connect to it.
$ createdb  <db name>
$ psql <db name>

然后从您运行的 psql shell:

CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;

来自 Django 文档:https ://docs.djangoproject.com/en/dev/ref/contrib/gis/install/postgis/#post-installation

于 2013-05-07T10:48:55.383 回答