#20252 closed Cleanup/optimization (fixed)
GeoDjango - GeoQuerySet.geojson NotImplementedError with Spatialite
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | GIS | Version: | 1.5-rc-1 |
Severity: | Normal | Keywords: | GeoDjango, Spatialite |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
As the documentation mentions (https://docs.djangoproject.com/en/dev/ref/contrib/gis/geoquerysets/#django.contrib.gis.db.models.GeoQuerySet.geojson) GeoQuerySet.geojson should be available with Spatialite but it is not.
Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
- response = callback(request, *callback_args, callback_kwargs)
File "C:\Python27\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
- return view_func(request, *args, kwargs)
File "c:\mygeosite\geodjango\ezmapping\views.py" in editShapefile
- feature_geoJson = features.geojson()
File "C:\Python27\lib\site-packages\django\contrib\gis\db\models\query.py" in geojson
- raise NotImplementedError('Only PostGIS 1.3.4+ supports GeoJSON serialization.')
Exception Type: NotImplementedError at /ezmapping/layer/edit/1
Exception Value: Only PostGIS 1.3.4+ supports GeoJSON serialization.
Attachments (1)
Change History (13)
comment:1 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:3 by , 12 years ago
I dont understand, I have updated Django to 1.5.1 and still got an error. Is this function implement with Spatialite 4.0? Thats the version im using.
comment:4 by , 12 years ago
For the record, this was added in #19028 - [95f7ea3af185]
If you get an error with 1.5.1, we'll need the traceback, please.
comment:5 by , 12 years ago
Version: | 1.4 → 1.5-rc-1 |
---|
This error using Django 1.5.1 ans Spatialite 4.0 when calling function GeoQuerySet.geojson()
Traceback:
File "C:\python27\lib\site-packages\django\core\handlers\base.py" in get_response
- response = callback(request, *callback_args, callback_kwargs)
File "C:\python27\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
- return view_func(request, *args, kwargs)
File "c:\mygeosite\geodjango\ezmapping\views.py" in editShapefile
- bounds = features.geojson()
File "C:\python27\lib\site-packages\django\contrib\gis\db\models\query.py" in geojson
- raise NotImplementedError('Only PostGIS 1.3.4+ and SpatiaLite 3.0+ '
Exception Type: NotImplementedError at /ezmapping/layer/edit/1
Exception Value: Only PostGIS 1.3.4+ and SpatiaLite 3.0+ support GeoJSON serialization.
comment:6 by , 12 years ago
Could you try this snippet inside your project:
$ python manage.py shell >>> from django.db import connection >>> print(connection.ops.spatial_version)
It may be that your Django instance does not use the expected Spatialite installation.
comment:7 by , 12 years ago
The return is None. I have made a test and re-creating a new spatialite db from spatialite_gui v.4.0, but it still returned None. When I use a PostGIS settings it returns 2.0.3. Do you know what could be the meaning?
comment:8 by , 12 years ago
Oh, sorry, spatial_version
is a cached property in master, but it is a method in 1.5. So the last snippet line should read print(connection.ops.spatial_version())
. Here is the code:
https://github.com/django/django/blob/stable/1.5.x/django/contrib/gis/db/backends/spatialite/operations.py#L246
Basically, this executes the SQL query SELECT spatialite_version();
(you can also try it at the spatialite prompt).
It would also be interesting to get the result of connection.ops.spatialite_version_tuple()
.
comment:9 by , 12 years ago
In the django project shell: print(connection.ops.spatial_version()) returns 3.0.1 and connection.ops.spatialite_version_tuple() returns (u'3.0.1', 3,0,1)
In spatialite prompt: SELECT spatialite_version(); returns 4.0.0
There is no error on those results, it was done on the same spatilatie db defined in settings.py
comment:10 by , 12 years ago
OK, now I see the bug, which has been fixed in master by commit [eb9430fc4be1]. It was unfortunately a bit late to enter the 1.5 branch. I will try to make a more limited patch for the stable branch. Could you test the following patch to see if it resolves your issue?
by , 12 years ago
Attachment: | 20252.diff added |
---|
comment:11 by , 12 years ago
I do not have the error anymore with the patch installed. Good job and thank you!
geojson support for Spatialite has been added in Django 1.5. I'll add the missing notice to the docs.