Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#20252 closed Cleanup/optimization (fixed)

GeoDjango - GeoQuerySet.geojson NotImplementedError with Spatialite

Reported by: burton449geo@… 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

  1. response = callback(request, *callback_args, callback_kwargs)

File "C:\Python27\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view

  1. return view_func(request, *args, kwargs)

File "c:\mygeosite\geodjango\ezmapping\views.py" in editShapefile

  1. feature_geoJson = features.geojson()

File "C:\Python27\lib\site-packages\django\contrib\gis\db\models\query.py" in geojson

  1. 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)

20252.diff (1.1 KB ) - added by Claude Paroz 11 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 by Claude Paroz, 11 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

geojson support for Spatialite has been added in Django 1.5. I'll add the missing notice to the docs.

comment:2 by Claude Paroz <claude@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 991ce52bc872f827de8e7b5b441e2dfa2185bfd2:

[1.5.x] Fixed #20252 -- Mentionned geojson Spatialite support from 1.5

Thanks burton449geo at gmail.com for the report.
Backport of d58e985aa from master.

comment:3 by anonymous, 11 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 Claude Paroz, 11 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 burton449geo@…, 11 years ago

Version: 1.41.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
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "C:\python27\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
  25.                 return view_func(request, *args, **kwargs)
File "c:\mygeosite\geodjango\ezmapping\views.py" in editShapefile
  59.     bounds = features.geojson()
File "C:\python27\lib\site-packages\django\contrib\gis\db\models\query.py" in geojson
  149.             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.
Last edited 11 years ago by Claude Paroz (previous) (diff)

comment:6 by Claude Paroz, 11 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 burton449geo@…, 11 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 Claude Paroz, 11 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 burton449geo@…, 11 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 Claude Paroz, 11 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 Claude Paroz, 11 years ago

Attachment: 20252.diff added

comment:11 by burton449geo@…, 11 years ago

I do not have the error anymore with the patch installed. Good job and thank you!

comment:12 by Claude Paroz <claude@…>, 11 years ago

In 9176fa70c1541d29d4d1865770d48b174e5dd968:

[1.5.x] Fixed geojson detection with Spatialite

This is a partial backport of commit eb9430fc4be1. Without this,
geojson support is never detected with Spatialite.
Refs #20252 and #19028.

Note: See TracTickets for help on using tickets.
Back to Top