【问题标题】:Error when using GeoDjango with SpatiaLite on Ubuntu在 Ubuntu 上将 GeoDjango 与 SpatiaLite 一起使用时出错
【发布时间】:2011-08-28 16:23:30
【问题描述】:

我试图让 GeoDjango 在 Ubuntu 11.04 上的 SpatiaLite 上运行,即使设置非常简单,我也遇到了一个奇怪的错误。保存带有地理字段的模型实例有效,但再次加载失败并出现exception

Error encountered checking Geometry returned from GEOS C function "GEOSWKBReader_read_r".

settings.py的相关部分

DATABASES = {
    'default': {
    'ENGINE': 'django.contrib.gis.db.backends.spatialite',
        'NAME': '/tmp/test.db',
    }
}

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'django.contrib.gis',
    'testapp',
)

testapp.models:

from django.contrib.gis.db import models

class TestModel(models.Model):
    name = models.CharField(max_length=10)
    location = models.PointField()

testapp.admin

from django.contrib.gis import admin

from testapp.models import TestModel

admin.site.register(TestModel, admin.OSMGeoAdmin)

/edit:完全相同的代码在 PostgreSQL/postgis 上运行没有问题

【问题讨论】:

    标签: python django geodjango spatialite


    【解决方案1】:

    好的,我自己发现了问题:我忘记使用models.GeoManager 作为默认管理器。这解决了我的问题:

    class TestModel(models.Model):
        name = models.CharField(max_length=10)
        location = models.PointField()
    
        objects = models.GeoManager()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-23
      • 2010-12-20
      • 1970-01-01
      • 1970-01-01
      • 2013-12-28
      • 2020-07-10
      • 2013-03-10
      • 2013-04-12
      相关资源
      最近更新 更多