【问题标题】:Geometry Doesn't exist in GEODJANGOGEODJANGO 中不存在几何
【发布时间】:2014-06-22 21:21:43
【问题描述】:

我已经安装了 Geodjango 的所有依赖项!现在我正在关注它的教程https://docs.djangoproject.com/en/1.2/ref/contrib/gis/tutorial/ -- 问题:命令 python manage.py syncdb 在mpoly geometry(multipolygon 4326) not null that geometry does not exist 处生成错误

from django.contrib.gis.db import models

class WorldBorders(models.Model):
    # Regular Django fields corresponding to the attributes in the
    # world borders shapefile.
    name = models.CharField(max_length=50)
    area = models.IntegerField()
    pop2005 = models.IntegerField('Population 2005')
    fips = models.CharField('FIPS Code', max_length=2)
    iso2 = models.CharField('2 Digit ISO', max_length=2)
    iso3 = models.CharField('3 Digit ISO', max_length=3)
    un = models.IntegerField('United Nations Code')
    region = models.IntegerField('Region Code')
    subregion = models.IntegerField('Sub-Region Code')
    lon = models.FloatField()
    lat = models.FloatField()

    # GeoDjango-specific: a geometry field (MultiPolygonField), and
    # overriding the default manager with a GeoManager instance.
    mpoly = models.MultiPolygonField() //ERROR HERE

如何解决这个错误?

更新:

python manage.py sqlall world 生成以下输出:

BEGIN;
CREATE TABLE "world_worldborders" (
    "id" serial NOT NULL PRIMARY KEY,
    "name" varchar(50) NOT NULL,
    "area" integer NOT NULL,
    "pop2005" integer NOT NULL,
    "fips" varchar(2) NOT NULL,
    "iso2" varchar(2) NOT NULL,
    "iso3" varchar(3) NOT NULL,
    "un" integer NOT NULL,
    "region" integer NOT NULL,
    "subregion" integer NOT NULL,
    "lon" double precision NOT NULL,
    "lat" double precision NOT NULL,
    "mpoly" geometry(MULTIPOLYGON,4326) NOT NULL
)
;
CREATE INDEX "world_worldborders_mpoly_id" ON "world_worldborders" USING GIST ( "mpoly" );

COMMIT;

python manage.py syncdb 生成:Program Error Geometry Doesn't exist

root@cvp-linux:~/geodjango# python manage.py syncdb Syncing... Creating tables ... Creating table django_admin_log Creating table auth_permission Creating table auth_group_permissions Creating table auth_group Creating table auth_user_groups Creating table auth_user_user_permissions Creating table auth_user Creating table django_content_type Creating table django_session Creating table world_worldborders Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line utility.execute() File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute output = self.handle(*args, **options) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 415, in handle return self.handle_noargs(**options) File "/usr/local/lib/python2.7/dist-packages/south/management/commands/syncdb.py", line 92, in handle_noargs syncdb.Command().execute(**options) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute output = self.handle(*args, **options) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 415, in handle return self.handle_noargs(**options) File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 107, in handle_noargs cursor.execute(statement) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 69, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 53, in execute return self.cursor.execute(sql, params) File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 99, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 51, in execute return self.cursor.execute(sql) django.db.utils.ProgrammingError: type "geometry" does not exist LINE 14: "mpoly" geometry(MULTIPOLYGON,4326) NOT NULL

【问题讨论】:

  • 你解决了吗?你能和我们分享一下吗?谢谢

标签: python django geodjango


【解决方案1】:

尝试添加

objects = models.GeoManager()

在你的 models.py 中的 mpoly 之后

【讨论】:

  • 你应该edit你的答案添加描述如何这回答了这个问题。
【解决方案2】:

就我而言,问题在于命令:

-- Enable PostGIS (includes raster)
CREATE EXTENSION postgis;
-- Enable Topology
CREATE EXTENSION postgis_topology;
-- fuzzy matching needed for Tiger
CREATE EXTENSION fuzzystrmatch;
-- Enable US Tiger Geocoder
CREATE EXTENSION postgis_tiger_geocoder;

应该在特定数据库的上下文中运行,所以你需要先连接到your_db

\connect your_db

然后在上面跑!

【讨论】:

    【解决方案3】:

    需要检查的几件事:

    • 你已经运行CREATE EXTENSION postgis;
    • GEOS_LIBRARY_PATH 在项目的 settings.py 文件中设置

    第二点给我带来了一些麻烦,尽管它是第一点最终成功了。我在 Cygwin 64 位上运行它,所以需要做一些额外的工作才能让它工作。如果您没有在 Cygwin 环境中运行,那么您要查找的文件很可能是 libgeos_c.so;我需要将其指向 cyggeos_c-1.dll(仍在 Windows 上运行,因此我需要找到 .dll 扩展名)。

    我确信我已经运行了 CREATE EXTENSION 命令,但我可能没有在 Cygwin 环境中运行它。或者我尝试过,但没有记住我有一个配置的噩梦,以至于 postgres 服务器没有在 localhost 上运行,所以我避免使用 psql。这是我自己的厚度品牌。

    【讨论】:

      【解决方案4】:

      这是固定票,

      https://code.djangoproject.com/ticket/21547

      使用 PostGIS 2 输出更新了 GeoDjango 教程

      【讨论】:

      • 在此处发布问题之前,我阅读了此内容,但我不明白那张票。你能解释一下解决这个问题的步骤吗?
      • 试试这个python manage.py sqlall world 并在你的问题中发布输出
      • django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS version for database "geodjango". GeoDjango requires at least PostGIS version 1.3. Was the database created from a spatial database template?@dhana `
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-23
      • 2012-03-28
      • 2016-06-21
      • 2016-02-16
      • 1970-01-01
      相关资源
      最近更新 更多