Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when using GeoDjango with SpatiaLite on Ubuntu

I'm trying to get GeoDjango running on SpatiaLite on Ubuntu 11.04, and even with a very minimal setup, I'm hitting a strange error. Saving an instance of a model with geo-fields works, but loading it again fails with an exception:

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

relevant parts of my 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: the same exact code works without problems on PostgreSQL/postgis

like image 765
Benjamin Wohlwend Avatar asked Dec 11 '25 17:12

Benjamin Wohlwend


1 Answers

OK, I found the problem myself: I forgot to use models.GeoManager as the default manager. This fixes my problem:

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

    objects = models.GeoManager()
like image 148
Benjamin Wohlwend Avatar answered Dec 14 '25 08:12

Benjamin Wohlwend