我正在使用geoDjango
。我已从源Gdal
,proj1.4
,geos3.3.5
和Postgis2.0.1
安装了以下软件包。我是ubuntu用户。当我在此之后运行syncdb
时,我遇到了以下错误。我错过了什么吗?感谢
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)
答案 0 :(得分:8)
也许我有点迟了但我解决了这个问题(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);
中提取的
答案 1 :(得分: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 # Create the template spatial database. sudo -u postgres createlang -d template_postgis1 plpgsql # Adding PLPGSQL language support. 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 # Loading the PostGIS SQL routines 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;" # Enabling users to alter spatial tables. 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
答案 2 :(得分: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